Source of file AddToshortlistAction.php
Size: 1,457 Bytes - Last Modified: 2021-12-23T10:19:40+00:00
/var/www/docs.ssmods.com/process/src/code/factories/AddToshortlistAction.php
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758 | <?php /** * @file AddToshortlistAction.php * * * */ class AddToshortlistAction extends AbstractShortlistAction { /** * Add item to shortlist * * @param shortlist shortlist to perform action on. * @param ID id of the object to add. * @param type classname of the item to remove. * @param session session id. * * */ public function performAction( ShortList $shortlist = null, $ID = false, $type = null, $session = false) { if (!$ID || is_null($type) || !$session) { return false; } if (!$shortlist || !$shortlist->exists()) { $shortlist = new ShortList(); $shortlist->SessionID = $session; $shortlist->write(); } // check whether the itme is already in the list // before attempting to add it. $existing = $shortlist->ShortListItems()->filter( array('ItemID' => $ID, 'ItemType' => $type) ); // Item already exists, we're not going to add it again. if ($existing->count() == 1) { return $shortlist; } $shortlistItem = new ShortListItem(); $shortlistItem->ShortListID = $shortlist->ID; $shortlistItem->ItemID = $ID; $shortlistItem->ItemType = $type; $shortlist->ShortListItems()->add($shortlistItem); $shortlist->write(); return $shortlist; } } |