function addItem($loginId, $listId, $itemId) { // transpose of defaults list // 1 => favorites, 2 => wishlist etc. $transpose = array_flip($this->defaults); if (array_key_exists($listId, $transpose)) { //create new list with dl_bit set to 1 $name = $transpose[$listId]; $listId = $this->create($loginId, $name, $itemId, 1); return $listId; } // list ownership check is required // when we do not pass the loginId to backend // someone assuming a "fake" loginId is a problem // that data layer cannot solve! $this->isOwner($loginId, $listId); $postId = PseudoId::decode($itemId); $row = $this->getOnId($listId); $dbItemsJson = $row["items_json"]; $dbItems = json_decode($dbItemsJson); $dbItemIds = array(); foreach ($dbItems as $dbItem) { array_push($dbItemIds, $dbItem->id); } // update items_json summary only if // #1 - the number of items < 4 // #2 - we have not seen this item earlier if (sizeof($dbItemIds) < 4 && !in_array($itemId, $dbItemIds)) { //get item row $postDao = new \com\indigloo\sc\dao\Post(); $imgv = $postDao->tryImageOnId($postId); if (!is_null($imgv)) { $json = new \stdClass(); $json->id = $itemId; $json->thumbnail = $imgv["thumbnail"]; array_push($dbItems, $json); } } $itemsJson = json_encode($dbItems); $itemsJson = Util::formSafeJson($itemsJson); mysql\Lists::addItem($listId, $itemsJson, $postId); return $listId; }