/** * Returns an array of getter options for retrieving attachments in the thread * * @param array $options Additional options * @return array */ public function getAttachmentsFilterOptions(array $options = array()) { $hash = $this->message->getHash(); $map = elgg_get_metastring_map(['msgHash', $hash]); $options['joins']['md_msgHash'] = "\n\t\t\tJOIN {$this->dbprefix}metadata md_msgHash\n\t\t\t\tON e.guid = md_msgHash.entity_guid\n\t\t\t"; $options['wheres'][] = "\n\t\t\tmd_msgHash.name_id = {$map['msgHash']}\n\t\t\t\tAND md_msgHash.value_id = {$map[$hash]}\n\t\t\t\t"; $options['joins']['er_attached'] = "\n\t\t\tJOIN {$this->dbprefix}entity_relationships er_attached\n\t\t\tON er_attached.guid_two = e.guid\n\t\t\t"; $options['joins'][] = "er_attached.relationship = 'attached'"; return $options; }
/** * Returns the unread messages in a user's inbox * * @param int $user_guid GUID of user whose inbox we're counting (0 for logged in user) * @param int $limit Number of unread messages to return (default from settings) * @param int $offset Start at a defined offset (for listings) * @param bool $count Switch between entities array or count mode * * @return array, int (if $count = true) * @since 1.9 */ function messages_get_unread($user_guid = 0, $limit = null, $offset = 0, $count = false) { if (!$user_guid) { $user_guid = elgg_get_logged_in_user_guid(); } $db_prefix = elgg_get_config('dbprefix'); // denormalize the md to speed things up. // seriously, 10 joins if you don't. $map = elgg_get_metastring_map(['toId', $user_guid, 'readYet', 0]); if ($limit === null) { $limit = elgg_get_config('default_limit'); } $options = array('joins' => array("JOIN {$db_prefix}metadata msg_toId on e.guid = msg_toId.entity_guid", "JOIN {$db_prefix}metadata msg_readYet on e.guid = msg_readYet.entity_guid"), 'wheres' => array("msg_toId.name_id='{$map['toId']}' AND msg_toId.value_id='{$map[$user_guid]}'", "msg_readYet.name_id='{$map['readYet']}' AND msg_readYet.value_id='{$map[0]}'"), 'owner_guid' => $user_guid, 'limit' => $limit, 'offset' => $offset, 'count' => $count, 'distinct' => false); return elgg_get_entities($options); }
/** * Metastring ID mapping * * @param array $metastrings An array of metastrings * @return array */ private static function getMetaMap($metastrings = []) { return elgg_get_metastring_map($metastrings); }