Query helper
Rather than using MVC "Models", we use Query and Record helpers.
The query objects are nothing more than classes created in:
/app/library/query/
And are loaded with the function call:
$item_query = query_get('item');
$item_query = query_get('item', $config);
The object then exposes methods that relate to that thing, typically returning an array.
For example:
/app/library/query/user.php
<?php
class user_query extends query {
protected function setup($config) {
$this->config = $config;
}
public function trainers_get() { // Might be based on license records.
$db = db_get();
$trainers = [];
$sql = 'SELECT
u.id,
CONCAT(u.name_last, ", ", u.name_first) AS name
FROM
' . DB_PREFIX . 'user AS u
WHERE
u.type = "trainer" AND
u.deleted = "0000-00-00 00:00:00"
ORDER BY
name';
foreach ($db->fetch_all($sql) as $row) {
$trainers[$row['id']] = $row['name'];
}
return $trainers;
}
public function search($config) {
$config = array_merge(array(
'rules' => [], // licenses, courses, organisations, etc.
'rule_match' => 'all', // or 'any'
'fields' => array('id', 'name_first', 'name_last'),
'paginate' => false,
'order_sql' => NULL,
'limit_offset' => 0,
'limit_count' => NULL,
), $config);
$db = db_get();
// Processing
return array(
'results' => $db->fetch_all($sql),
'paginator' => $paginator,
);
}
}
?>