function find_by_criteria($module, $id_in_module = null, $type = null, $identifier = null, $poster_id = null, $fixer_id = null) { global $Sql; $criterias = array(); if (empty($module) || !is_string($module)) { return array(); } $criterias[] = "module = '" . strprotect($module) . "'"; if ($id_in_module != null) { $criterias[] = "id_in_module = '" . intval($id_in_module) . "'"; } if ($type != null) { $criterias[] = "type = '" . strprotect($type) . "'"; } if ($identifier != null) { $criterias[] = "identifier = '" . strprotect($identifier) . "'"; } if ($poster_id != null) { $criterias[] = "poster_id = '" . intval($poster_id) . "'"; } if ($fixer_id != null) { $criterias[] = "fixer_id = '" . intval($fixer_id) . "'"; } $array_result = array(); $where_clause = "contribution_type = '" . CONTRIBUTION_TYPE . "' AND " . implode($criterias, " AND "); $result = $Sql->query_while("SELECT id, entitled, fixing_url, auth, current_status, module, creation_date, fixing_date, poster_id, fixer_id, poster_member.login poster_login, fixer_member.login fixer_login, identifier, id_in_module, type, description\n\t\tFROM " . DB_TABLE_EVENTS . " c\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " poster_member ON poster_member.user_id = c.poster_id\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " fixer_member ON fixer_member.user_id = c.fixer_id\n\t\tWHERE " . $where_clause, __LINE__, __FILE__); while ($row = $Sql->fetch_assoc($result)) { $contri = new Contribution(); $contri->build($row['id'], $row['entitled'], $row['description'], $row['fixing_url'], $row['module'], $row['current_status'], new Date(DATE_TIMESTAMP, TIMEZONE_SYSTEM, $row['creation_date']), new Date(DATE_TIMESTAMP, TIMEZONE_SYSTEM, $row['fixing_date']), unserialize($row['auth']), $row['poster_id'], $row['fixer_id'], $row['id_in_module'], $row['identifier'], $row['type'], $row['poster_login'], $row['fixer_login']); $array_result[] = $contri; } return $array_result; }
/** * @desc Builds a list of the contributions matching the required criteria(s). All the parameters represent the criterias you can use. * If you don't want to use a criteria, let the null value. The returned contribution match all the criterias (it's a AND condition). * @param string $module The module identifier. * @param int $id_in_module The id in module field. * @param string $type The contribution type. * @param string $identifier The contribution identifier. * @param int $poster_id The poster. * @param int $fixer_id The fixer. * @return Contribution[] The list of the contributions matching all the criterias. */ public static function find_by_criteria($module, $id_in_module = null, $type = null, $identifier = null, $poster_id = null, $fixer_id = null) { $criterias = array(); //The module parameter must be specified and of string type, otherwise we can't continue if (empty($module) || !is_string($module)) { return array(); } $criterias[] = "module = '" . TextHelper::strprotect($module) . "'"; if ($id_in_module != null) { $criterias[] = "id_in_module = '" . intval($id_in_module) . "'"; } if ($type != null) { $criterias[] = "type = '" . TextHelper::strprotect($type) . "'"; } if ($identifier != null) { $criterias[] = "identifier = '" . TextHelper::strprotect($identifier) . "'"; } if ($poster_id != null) { $criterias[] = "poster_id = '" . intval($poster_id) . "'"; } if ($fixer_id != null) { $criterias[] = "fixer_id = '" . intval($fixer_id) . "'"; } $array_result = array(); $result = self::$db_querier->select("SELECT id, entitled, fixing_url, auth, current_status, module, creation_date, fixing_date, poster_id, fixer_id, poster_member.display_name poster_login, fixer_member.display_name fixer_login, identifier, id_in_module, type, description\n\t\tFROM " . DB_TABLE_EVENTS . " c\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " poster_member ON poster_member.user_id = c.poster_id\n\t\tLEFT JOIN " . DB_TABLE_MEMBER . " fixer_member ON fixer_member.user_id = c.fixer_id\n\t\tWHERE contribution_type = '" . self::CONTRIBUTION_TYPE . "' AND " . implode(" AND ", $criterias)); while ($row = $result->fetch()) { $contri = new Contribution(); $contri->build($row['id'], $row['entitled'], $row['description'], $row['fixing_url'], $row['module'], $row['current_status'], new Date($row['creation_date'], Timezone::SERVER_TIMEZONE), new Date($row['fixing_date']), unserialize($row['auth']), $row['poster_id'], $row['fixer_id'], $row['id_in_module'], $row['identifier'], $row['type'], $row['poster_login'], $row['fixer_login']); $array_result[] = $contri; } $result->dispose(); return $array_result; }