/** * Пошук запису за будь-яким полем з обмеженнями на сторінку та сортуванням по даті. * @param array $fields асоціативний масив. Ключі - це назви полів у БД, * значення - шукані значення. * @return mixed масив знайдених записів. */ public static function find($fields = []) { global $link; global $shift, $count; $class = get_called_class(); $table = $class::table_name(); $user_table = User::table_name(); $where = ""; foreach ($fields as $key => $value) { if (property_exists($class, $key)) { $where = $where . "AND " . "{$key}" . " Like('%{$value}%') "; } } $where = trim($where, "AND"); $where = trim($where); $query = "SELECT {$table}.*," . $user_table . ".name" . " FROM " . "`{$table}` INNER JOIN `{$user_table}` ON \n\t\t`{$table}`.`author_id` = `{$user_table}`.`id`" . " WHERE {$where}" . " ORDER BY `{$table}`.`date` DESC" . " LIMIT {$shift}, {$count}"; if ($where == "") { $query = trim($query); $query = trim($query, "WHERE"); } $res = $link->query($query); $result = []; while ($row = mysqli_fetch_array($res)) { $result[] = $row; } return $result; }
public function testGetsCorrectTableNameWithPrefix() { $newConfig = $this->dbConfig; $newConfig['sqlite']['prefix'] = 'salsa_'; $connection = m::mock('juicyORM\\Database\\DbConnection'); $db = juicyORM\Database\DB::Instance($newConfig, $connection, true); $user = new User($db); $this->assertEquals($user->table_name(), "salsa_user"); }