/** * */ function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['topics']['fromTime']) ? $data['topics']['fromTime'] : 0; $topicLoadedIds = isset($data['topics']['loadedIds']) ? array_values($data['topics']['loadedIds']) : array(); $includeCards = isset($data['topics']['includeCards']) ? $data['topics']['includeCards'] : false; $ids = isset($data['topics']['restrictIds']) ? array_values($data['topics']['restrictIds']) : array(); //select topics the user can access $select = "id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName("Right")." WHERE user_id=$this->userId AND mask>=".MediabirdTopicAccessConstants::allowViewingCards." )"; if(count($ids)>0) { $select = "id IN (".join(",",$ids).") AND ".$select; } $topics = array(); $referredTagIds = array(); $checkedPdfs = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName("Topic",true),$select)) { foreach($records as $record) { $topic = (object)null; $topic->id = intval($record->id); MediabirdUtility::arrayRemove($topicLoadedIds,$topic->id); $modified = $this->db->timestamp($record->modified); if($modified > $fromTime) { $topic->modified = $modified; $topic->title = $record->title; $topic->license = intval($record->license); $topic->modifier = intval($record->modifier); } else if(!$includeCards) { //ignore rest continue; } $select = "topic_id=$record->id"; $cards = array(); $cardIds = array(); if($cardRecords = $this->db->getRecords(MediabirdConfig::tableName("Card",true),$select,'index_num ASC')) { //retrieve cards foreach($cardRecords as $cardRecord) { $card = (object)null; $card->id = intval($cardRecord->id); $cardModified = $this->db->timestamp($cardRecord->modified); if($cardModified > $fromTime) { //only collect modified cards for tag retrieval $cardIds []= $card->id; //create empty tags array, will be filled below $card->tags = array(); $card->modified = $cardModified; $card->title = $cardRecord->title; $card->index = intval($cardRecord->index_num); $card->modifier = intval($cardRecord->modifier); $card->type = intval($cardRecord->content_type); if($card->type==MediabirdConstants::cardTypePdf) { $card->uploadId = intval($cardRecord->content_id); $card->page = intval($cardRecord->content_index); //only check file auth if it has not been checked for that file if(!isset($checkedPdfs[$card->uploadId])) { $checkedPdfs[$card->uploadId] = $this->controller->Files->checkFileAuth($card->uploadId); } if(!$checkedPdfs[$card->uploadId]) { $card->needsPassword = true; } } $cards []= $card; } else { //return index if topic changed if(property_exists($topic,"modified")) { $card->index = intval($cardRecord->index_num); } $cards []= $card; } } //retrieve related CardTags, but only if topic was changed if(count($cardIds)>0 && $modified > $fromTime) { $select = "card_id IN (".join(",",$cardIds).")"; if($cardTagRecords = $this->db->getRecords(MediabirdConfig::tableName("CardTag",true),$select)) { foreach($cardTagRecords as $cardTagRecord) { $tagId = intval($cardTagRecord->tag_id); //save tag id for later retrieval if(!in_array($tagId,$referredTagIds)) { $referredTagIds []= $tagId; } $cardId = intval($cardTagRecord->card_id); //attach tags to card objects foreach($cards as $card) { if($card->id == $cardId) { $card->tags []= $tagId; } } } } } } //save cards in $topic $topic->cards = $cards; //only consider rights if topic has changed if($modified > $fromTime) { //retrieve rights! $rights = array(); if($rightRecords = $this->db->getRecords(MediabirdConfig::tableName('Right',true),"topic_id=$record->id")) { foreach($rightRecords as $rightRecord) { $right = (object)null; $right->id = intval($rightRecord->id); $right->modified = $this->db->timestamp($rightRecord->modified); //this has been commented out since a user that did not know about this topic //won't get the complete right set if they have been added later on //if($right->modified > $fromTime) { $right->mask = intval($rightRecord->mask); $right->userId = intval($rightRecord->user_id); $rights []= $right; //} //else { // //save traffic // unset($right->modified); // $rights []= $right; //} } } //save rights in $topic $topic->rights = $rights; } //add topic if it is to be considered $topics []= $topic; } } if(count($referredTagIds)>0) { $tags = array(); $select = "id IN (".join(",",$referredTagIds).")"; if($tagRecords = $this->db->getRecords(MediabirdConfig::tableName("Tag",true),$select)) { foreach($tagRecords as $tagRecord) { $tag = (object)array( 'id'=>intval($tagRecord->id), 'color'=>$tagRecord->color, 'title'=>$tagRecord->title ); $tags []= $tag; } } if(count($tags)>0) { $results['tags'] = $tags; } } if(count($topics)>0) { $results['topics'] = $topics; } if(count($topicLoadedIds)>0) { $results['removedTopicIds'] = $topicLoadedIds; } return true; }
/** * Loads list of buddies */ function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['users']['fromTime']) ? $data['users']['fromTime'] : 0; $fromTopic = isset($data['users']['fromTopic']) ? $data['users']['fromTopic'] : 0; $loadStatesOnly = isset($data['users']['states']) ? $data['users']['states'] : false; $loadedIds = isset($data['users']['loadedIds']) ? array_values($data['users']['loadedIds']) : array(); $avoidIds = isset($data['users']['avoidIds']) ? array_values($data['users']['avoidIds']) : array(); $ids = isset($data['users']['restrictIds']) ? array_values($data['users']['restrictIds']) : array(); $users = array(); //if we're loading states, we'll refer to session table which //refers to users using user_id rather than id itself $className = $loadStatesOnly ? "Session" : "User"; $userIdColumn = $loadStatesOnly ? "user_id" : "id"; //select users the current user knows $select = "$userIdColumn IN (SELECT user_id FROM ".MediabirdConfig::tableName('Right')." WHERE mask>0 AND"; //restrict to a given topic if desired if($fromTopic>0) { $select .= " topic_id=$fromTopic AND"; } //select users from topics the current user has access to if($topics = $this->db->getRecords(MediabirdConfig::tableName('Right',true),"user_id=$this->userId AND mask>0",'','topic_id')) { $topicIds = array(); foreach($topics as $topic) { if(!in_array($topic->topic_id,$topicIds)) { $topicIds []= $topic->topic_id; } } $select .= " topic_id IN (".join(",",$topicIds)."))"; } else { //no known users return true; } //only load certain users if desired if(count($ids)>0) { $select = "$userIdColumn IN (".join(",",$ids).") AND ".$select; } if(count($avoidIds)>0) { $select = "$userIdColumn NOT IN (".join(",",$avoidIds).") AND ".$select; } $objects = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName($className,true),$select)) { $time = time(); foreach($records as $record) { $obj = (object)null; $obj->id = intval($record->id); MediabirdUtility::arrayRemove($loadedIds,$obj->id); if($loadStatesOnly) { //will be saved as int $obj->modified = intval($record->modified); } else { //will be saved as datetime or int $obj->modified = $this->db->timestamp($record->modified); } if($obj->modified > $fromTime){ if($loadStatesOnly) { $obj->userId = intval($record->user_id); $obj->online = $obj->modified > ($time - $this->sessionTimeout); $obj->editing = intval($record->editing); $obj->cardId = $obj->online ? intval($record->card_id) : 0; } else { $obj->active = intval($record->active); $obj->name = $record->name; $obj->email = $record->email; $obj->lastLogin = $this->db->timestamp($record->last_login); $obj->picUrl = $record->pic_url; } $objects []= $obj; } } } if(count($objects)>0) { $results[strtolower($className).'s'] = $objects; } if(count($loadedIds)>0) { $results['removed'.$className.'Ids'] = $loadedIds; } return true; }
/** * Determine changes from a given time for the given user * @param $types string[] * @param $since * @param $userId * @return MediabirdChangeInfo[] */ function getChanges($types,$since=null,$userId=null) { $changes = array(); foreach($types as $type) { if( $type==self::changeTypeCheckConfirmed || $type==self::changeTypeCheckPending) { $itemTypes = array(); //create select clause $select = " modified>'".$this->db->datetime($since)."' AND ( user_id=$userId OR id IN ( SELECT relation_id FROM ".MediabirdConfig::tableName("Relation")." WHERE relation_type='check' AND marker_id IN ( SELECT id FROM ".MediabirdConfig::tableName("Marker")." WHERE (user_id=$userId OR shared=1) AND topic_id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName("Right")." WHERE user_id=$userId AND mask>=".MediabirdTopicAccessConstants::allowViewingCards." ) ) ) ) "; $sort = 'modified DESC'; //retrieve matching records from db $checkRecords = $this->db->getRecords( MediabirdConfig::tableName('Check',true), $select, $sort ); if($checkRecords) { $checkIds = array(); foreach($checkRecords as $checkRecord) { $checkIds []= intval($checkRecord->id); } if($type==self::changeTypeCheckPending) { //count check states that are pending and related to a check from above $select = "status=0 AND check_id IN (".join(",",$checkIds).")"; $count = $this->db->countRecords(MediabirdConfig::tableName("CheckStatus"),$select); } else if($type==self::changeTypeCheckConfirmed) { //count checks that have been confirmed $select = "status=0 AND check_id IN (".join(",",$checkIds).")"; $checkStatusRecords = $this->db->getRecords(MediabirdConfig::tableName("CheckStatus"),$select); if($checkStatusRecords) { foreach($checkStatusRecords as $checkStatusRecord) { MediabirdUtility::arrayRemove($checkIds,$checkStatusRecord->check_id); } } $count = count($checkIds); } else { continue; } $changeInfo = new MediabirdChangeInfo($this->name,$since,$userId); $changeInfo->changeType = $type; $changeInfo->itemCount = $count; $changes[$type] []= $changeInfo; } } } return $changes; }
function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['questions']['fromTime']) ? $data['questions']['fromTime'] : 0; $fromTopic = isset($data['questions']['fromTopic']) ? $data['questions']['fromTopic'] : 0; $questionLoadedIds = isset($data['questions']['loadedIds']) ? array_values($data['questions']['loadedIds']) : array(); $answerLoadedIds = isset($data['answers']['loadedIds']) ? array_values($data['answers']['loadedIds']) : array(); $voteLoadedIds = isset($data['votes']['loadedIds']) ? array_values($data['votes']['loadedIds']) : array(); $starLoadedIds = isset($data['stars']['loadedIds']) ? array_values($data['stars']['loadedIds']) : array(); $ids = isset($data['questions']['restrictIds']) ? array_values($data['questions']['restrictIds']) : array(); if($fromTopic == 0) { $select = "(user_id=$this->userId OR id IN ( SELECT relation_id FROM ".MediabirdConfig::tableName("Relation")." WHERE relation_type='question' AND marker_id IN ( SELECT id FROM ".MediabirdConfig::tableName("Marker")." WHERE (user_id=$this->userId OR shared=1) AND topic_id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName("Right")." WHERE user_id=$this->userId AND mask>=".MediabirdTopicAccessConstants::allowViewingCards." ) ) ))"; if(count($ids)>0) { $select = "id IN (".join(",",$ids).") AND ".$select; } } else { $select = "id IN ( SELECT relation_id FROM ".MediabirdConfig::tableName("Relation")." WHERE relation_type='question' AND marker_id IN ( SELECT id FROM ".MediabirdConfig::tableName("Marker")." WHERE (user_id=$this->userId OR shared=1) AND topic_id=$fromTopic ) )"; } $questions = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName("Question",true),$select)) { foreach($records as $record) { $hasChanges = false; //defines if this question should be returned or not $question = (object)null; $question->id = intval($record->id); MediabirdUtility::arrayRemove($questionLoadedIds,$question->id); $question->modified = $this->db->timestamp($record->modified); //this more complicated approach is required, //because question records won't be updated even //if answers, votes or stars change! //as a result, we have to go through all related records //even if the question is up to date! if($question->modified > $fromTime) { //send question and modification date back if newer than fromTime $question->question = $record->question; $question->mode = intval($record->question_mode); $question->userId = intval($record->user_id); $question->modifier = intval($record->modifier); //in case database was upgraded, it won't feature a valid modifier entry if($question->modifier==0) { $question->modifier = $question->userId; } $hasChanges = true; } //load answers $select = "question_id=$question->id"; if($answerRecords = $this->db->getRecords(MediabirdConfig::tableName("Answer",true),$select)) { $question->answers = array(); $question->votes = array(); foreach($answerRecords as $answerRecord) { $answer = (object) array( 'id'=>intval($answerRecord->id), 'answer'=>$answerRecord->answer, 'userId'=>intval($answerRecord->user_id), 'modified'=>$this->db->timestamp($answerRecord->modified) ); MediabirdUtility::arrayRemove($answerLoadedIds,$answer->id); if($answer->modified > $fromTime) { $question->answers []= $answer; $hasChanges = true; } //load votes $select = "answer_id=$answerRecord->id"; if($voteRecords = $this->db->getRecords(MediabirdConfig::tableName("Vote",true),$select)) { foreach($voteRecords as $voteRecord) { $vote = (object)array( 'id'=>intval($voteRecord->id), 'modified'=>$this->db->timestamp($voteRecord->modified), 'userId'=>intval($voteRecord->user_id), 'answerId'=>intval($voteRecord->answer_id) ); MediabirdUtility::arrayRemove($voteLoadedIds,$vote->id); if($vote->modified > $fromTime) { $question->votes []= $vote; $hasChanges = true; } } } } } //load star for current user $select = "question_id=$question->id AND user_id=$this->userId"; if($starRecord = $this->db->getRecord(MediabirdConfig::tableName("Star",true),$select)) { $star = (object) array( 'id'=>intval($starRecord->id), 'userId'=>intval($starRecord->user_id), 'answerId'=>intval($starRecord->answer_id), 'modified'=>$this->db->timestamp($starRecord->modified) ); MediabirdUtility::arrayRemove($starLoadedIds,$star->id); if($star->modified > $fromTime) { $question->stars = array($star); $hasChanges = true; } } if($hasChanges) { $questions []= $question; } } } if(count($questions)>0) { $results['questions'] = $questions; } if(count($questionLoadedIds)>0) { $results['removedQuestionIds'] = $questionLoadedIds; } if(count($voteLoadedIds)>0) { $results['removedVoteIds'] = $voteLoadedIds; } if(count($starLoadedIds)>0) { $results['removedStarIds'] = $starLoadedIds; } if(count($answerLoadedIds)>0) { $results['removedAnswerIds'] = $answerLoadedIds; } return true; }
function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['links']['fromTime']) ? $data['links']['fromTime'] : 0; $loadedIds = isset($data['links']['loadedIds']) ? array_values($data['links']['loadedIds']) : array(); $ids = isset($data['links']['restrictIds']) ? array_values($data['links']['restrictIds']) : array(); $links = array(); $select = "(user_id=$this->userId OR id IN ( SELECT relation_id FROM ".MediabirdConfig::tableName("Relation")." WHERE relation_type='link' AND marker_id IN ( SELECT id FROM ".MediabirdConfig::tableName("Marker")." WHERE (user_id=$this->userId OR shared=1) AND topic_id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName("Right")." WHERE user_id=$this->userId AND mask>=".MediabirdTopicAccessConstants::allowViewingCards." ) ) ))"; if(count($ids)>0) { $select = "id IN (".join(",",$ids).") AND ".$select; } $links = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName("Link",true),$select)) { foreach($records as $record) { $link = (object)null; $link->id = intval($record->id); MediabirdUtility::arrayRemove($loadedIds,$link->id); $link->modified = $this->db->timestamp($record->modified); if($link->modified > $fromTime){ $link->title = $record->title; $link->url = $record->url; $link->type = intval($record->type_num); $link->userId = intval($record->user_id); $link->modifier = intval($record->modifier); //in case database was upgraded, it won't feature a valid modifier entry if($link->modifier==0) { $link->modifier = $link->userId; } $links []= $link; } } } $results['links'] = $links; if(count($loadedIds)>0) { $results['removedLinkIds'] = $loadedIds; } return true; }
/** * Loads list of files */ function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['files']['fromTime']) ? $data['files']['fromTime'] : 0; $loadedIds = isset($data['files']['loadedIds']) ? array_values($data['files']['loadedIds']) : array(); $ids = isset($data['files']['restrictIds']) ? array_values($data['files']['restrictIds']) : array(); $links = array(); //select files owned by current user $select = "user_id=$this->userId"; //select files current user was granted access to (protected files) $select .= " OR id IN ( SELECT upload_id FROM ".MediabirdConfig::tableName("UploadAccess")." WHERE user_id=$this->userId AND mask>0 )"; //select files of users the current user knows $select .= " OR id IN ( SELECT content_id FROM ".MediabirdConfig::tableName("Card")." WHERE content_type=".MediabirdConstants::cardTypePdf." AND topic_id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName('Right')." WHERE user_id=$this->userId AND mask>0 ) )"; if(count($ids)>0) { $select = "id IN (".join(",",$ids).") AND (".$select.")"; } $files = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName("Upload",true),$select)) { foreach($records as $record) { $file = (object)null; $file->id = intval($record->id); MediabirdUtility::arrayRemove($loadedIds,$file->id); $file->created = $this->db->timestamp($record->created); if($file->created > $fromTime){ $file->type = intval($record->type); $file->userId = intval($record->user_id); $file->filename = basename($record->filename); if($file->type==MediabirdConstants::fileTypePdf) { $this->extendPdfInfo($file,$record); } if(!property_exists($file,'title') || $file->title == $file->filename) { $file->title = $record->title; } $files []= $file; } } } $results['files'] = $files; if(count($loadedIds)>0) { $results['removedFileIds'] = $loadedIds; } return true; }
function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['flashcards']['fromTime']) ? $data['flashcards']['fromTime'] : 0; $loadedIds = isset($data['flashcards']['loadedIds']) ? array_values($data['flashcards']['loadedIds']) : array(); $ids = isset($data['flashcards']['restrictIds']) ? array_values($data['flashcards']['restrictIds']) : array(); $flashcards = array(); $select = "user_id=$this->userId"; if(count($ids)>0) { $select = "id IN (".join(",",$ids).") AND ".$select; } $flashcards = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName("Flashcard",true),$select)) { foreach($records as $record) { $flashcard = (object)null; $flashcard->id = intval($record->id); MediabirdUtility::arrayRemove($loadedIds,$flashcard->id); $modified = $this->db->timestamp($record->modified); if($modified>$fromTime){ $flashcard->level = intval($record->level_num); $flashcard->answerTime = intval($record->answer_time); $flashcard->results = $this->resultsFromTraining($record->results); $flashcards []= $flashcard; } } } if(count($flashcards)>0) { $results['flashcards'] = $flashcards; } if(count($loadedIds)>0) { $results['removedFlashcardIds'] = $loadedIds; } return true; }
function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['markers']['fromTime']) ? $data['markers']['fromTime'] : 0; $fromTopic = isset($data['markers']['fromTopic']) ? $data['markers']['fromTopic'] : 0; $markerLoadedIds = isset($data['markers']['loadedIds']) ? array_values($data['markers']['loadedIds']) : array(); $relationLoadedIds = isset($data['relations']['loadedIds']) ? array_values($data['relations']['loadedIds']) : array(); $ids = isset($data['markers']['restrictIds']) ? array_values($data['markers']['restrictIds']) : array(); $parentIds = isset($data['markers']['parentIds']) ? array_values($data['markers']['parentIds']) : array(); $returnAllMarkerIds = isset($data['markers']['returnAllIds']) ? $data['markers']['returnAllIds'] : false; $select = "user_id=$this->userId OR (shared=1 AND topic_id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName("Right")." WHERE user_id=$this->userId AND mask>=".MediabirdTopicAccessConstants::allowViewingCards." ))"; if(count($ids)>0) { $select = "id IN (".join(",",$ids).") AND (".$select.")"; } else if(count($parentIds)>0) { $select = "card_id IN (".join(",",$parentIds).") AND (".$select.")"; } else if($fromTopic > 0) { $select = "topic_id=$fromTopic AND (".$select.")"; } //if no loaded ids are given, save time by including modified condition into sql query if($fromTime > 0 && count($markerLoadedIds)==0 && count($relationLoadedIds)==0 && !$returnAllMarkerIds) { $select = "modified>'".$this->db->datetime($fromTime)."' AND $select"; } $markers = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName("Marker",true),$select)) { foreach($records as $record) { $marker = (object)null; $marker->id = intval($record->id); //remove marker from the check list MediabirdUtility::arrayRemove($markerLoadedIds,$marker->id); $marker->modified = $this->db->timestamp($record->modified); //only load further details if marker was updated within the desired time frame if($marker->modified > $fromTime) { $marker->tool = $record->tool; $marker->range = $record->range_store; $marker->shared = intval($record->shared); $marker->cardId = intval($record->card_id); $marker->userId = intval($record->user_id); //load relations $select = "marker_id=$marker->id AND user_id IN (0,$this->userId)"; if($relationRecords = $this->db->getRecords(MediabirdConfig::tableName("Relation",true),$select)) { $marker->relations = array(); foreach($relationRecords as $relationRecord) { $relation = (object)null; $relation->id = intval($relationRecord->id); //remove relation from the check list MediabirdUtility::arrayRemove($relationLoadedIds,$relationRecord->id); $relation->modified = $this->db->timestamp($relationRecord->modified); //do not let returning relations depend on their modified value //this will render the post-loading broken //id from one of the data tables $relation->relatedId = intval($relationRecord->relation_id); //name of the data table $relation->type = $relationRecord->relation_type; $marker->relations []= $relation; } //now check if any of the relations misses any dependency //example: questions need one flashcard per user, this will be created here (the object itself won't be returned) if($fromTime==0) { $time = time(); $dbRelations = array_values($marker->relations); foreach($dbRelations as $relation) { $type = $relation->type; $className = ucfirst($type); if(method_exists($this->controller->$className,"checkDependencies")) { $requiredRelations = $this->controller->$className->checkDependencies($relation,$marker->relations); if($requiredRelations && count($requiredRelations)) { foreach($requiredRelations as $relationDummy) { $relationRecord = (object)null; $relationRecord->relation_id = $relationDummy->relatedId; $relationRecord->relation_type = $relationDummy->type; $relationRecord->marker_id = $marker->id; $relationRecord->user_id = $relationDummy->shared ? 0 : $this->userId; //redundant value $relationRecord->topic_id = $record->topic_id; $relationRecord->created = $relationRecord->modified = $this->db->datetime($time); //insert new record if($relationRecord->id = $this->db->insertRecord(MediabirdConfig::tableName("Relation",true),$relationRecord)) { $newRelation = (object)null; $newRelation->id = intval($relationRecord->id); $newRelation->modified = $time; $newRelation->relatedId = $relationDummy->relatedId; $newRelation->type = $relationDummy->type; $marker->relations []= $newRelation; } } } } } } } $markers []= $marker; } else if($returnAllMarkerIds){ //save traffic unset($marker->modified); $markers []= $marker; } } } if(count($markers)>0 || $returnAllMarkerIds) { $results['markers'] = $markers; } if(count($markerLoadedIds)>0) { $results['removedMarkerIds'] = $markerLoadedIds; } if(count($relationLoadedIds)>0) { $results['removedRelationIds'] = $relationLoadedIds; } return true; }
function load($data,&$results) { if(!isset($data)) { $data = array(); } $fromTime = isset($data['contents']['fromTime']) ? $data['contents']['fromTime'] : 0; $loadedIds = isset($data['contents']['loadedIds']) ? array_values($data['contents']['loadedIds']) : array(); $ids = isset($data['contents']['restrictIds']) ? array_values($data['contents']['restrictIds']) : array(); $avoidIds = isset($data['contents']['avoidIds']) ? array_values($data['contents']['avoidIds']) : array(); $parentIds = isset($data['contents']['parentIds']) ? array_values($data['contents']['parentIds']) : array(); $select = "topic_id IN ( SELECT topic_id FROM ".MediabirdConfig::tableName('Right')." WHERE mask>=".MediabirdTopicAccessConstants::allowViewingCards." AND user_id=$this->userId )"; if(count($ids)>0) { $select = "card_id IN (".join(",",$ids).") AND (".$select.")"; } else if(count($parentIds)>0) { $select = "topic_id IN (".join(",",$parentIds).") AND (".$select.")"; } if(count($avoidIds)>0) { $select = "card_id NOT IN (".join(",",$avoidIds).") AND ".$select; } //if no loaded ids are given, save time by including modified condition into sql query if($fromTime > 0 && count($loadedIds)==0) { $select = "modified>'".$this->db->datetime($fromTime)."' AND $select"; } $contents = array(); $cards = array(); $cardIds = array(); if($records = $this->db->getRecords(MediabirdConfig::tableName('CardContent',true),$select)) { foreach($records as $record) { //determine card id $content = (object)null; $content->id = intval($record->card_id); //override global from time with individual settings if given if(isset($data['contents'][$content->id])) { $fromTime = $data['contents'][$content->id]; } MediabirdUtility::arrayRemove($loadedIds,$content->id); $content->modified = $this->db->timestamp($record->modified); if($content->modified>$fromTime) { $content->content = $record->content; $contents []= $content; } } } if(count($contents)>0) { $results['contents'] = $contents; } if(count($loadedIds)>0) { $results['removedContentIds'] = $loadedIds; } return true; }