コード例 #1
0
 public function getMessageCollections($userId, $appId, $fields, $options)
 {
     // TODO: Supports filtered fields, options. Supports unread and total.
     $this->checkDb();
     $appId = intval($appId);
     $userId = intval($userId);
     $countQuery = "select count(*) from message_collections where person_id = {$userId} and app_id = {$appId}";
     $res = mysqli_query($this->db, $countQuery);
     if ($res !== false) {
         list($totalResults) = mysqli_fetch_row($res);
     } else {
         $totalResults = '0';
     }
     $startIndex = $options->getStartIndex();
     $count = $options->getCount();
     $collections = array();
     $collections['totalResults'] = $totalResults;
     $collections['startIndex'] = $startIndex;
     $collections['count'] = $count;
     $query = "select id, title, updated, urls from message_collections where person_id = {$userId} and app_id = {$appId} limit {$startIndex}, {$count}";
     $res = mysqli_query($this->db, $query);
     if ($res) {
         if (@mysqli_num_rows($res)) {
             while ($row = @mysqli_fetch_array($res, MYSQLI_ASSOC)) {
                 $collection = new MessageCollection($row['id'], $row['title']);
                 $collection->setUpdated($row['updated']);
                 $collection->setTitle($row['title']);
                 if (isset($row['urls'])) {
                     $collection->setUrls(json_decode($row['urls']));
                 }
                 $collections[] = $collection;
             }
         }
         return $collections;
     } else {
         throw new SocialSpiException("Can't retrieve message collections.", ResponseError::$INTERNAL_ERROR);
     }
 }