public function createMessageCollection($userId, $appId, $messageCollection) { $this->checkDb(); $userId = intval($userId); $appId = intval($appId); $title = mysqli_real_escape_string($this->db, trim($messageCollection['title'])); if (strlen($title) == 0) { throw new SocialSpiException("Can't create a message collection with an empty title"); } // Stores urls as a json string. $urls = ''; if (isset($messageCollection['urls'])) { $urls = mysqli_real_escape_string($this->db, json_encode($messageCollection['urls'])); } $created = time(); mysqli_query($this->db, "insert into message_collections (person_id, app_id, title, updated, urls, created) values ({$userId}, {$appId}, '{$title}', {$created}, '{$urls}', {$created})"); if (!($messageCollectionId = mysqli_insert_id($this->db))) { throw new SocialSpiException("Insertion failed.", ResponseError::$INTERNAL_ERROR); } else { // The message collection created is returned so the client code can get the id of the created message collection. // Otherwise it's difficult for the client code to reference the created message collection. $collection = new MessageCollection($messageCollectionId, $messageCollection['title']); $collection->setUpdated($created); $collection->setTotal(0); $collection->setUnread(0); $collection->setUrls($messageCollection['urls']); return $collection; } }