Changed PagerAction, search and order methods of Model, #16
git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@148 4cb57b5f-5bbd-dd11-951b-001d605cbbc5
This commit is contained in:
@ -139,6 +139,45 @@ abstract class Model implements iCacheable
|
||||
}
|
||||
return $autoindent ? $this->identify($this->table) : $this->table;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates order sql string
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $sortable
|
||||
* @return string
|
||||
*/
|
||||
protected function order($params, $sortable = array('id'))
|
||||
{
|
||||
$sql = '';
|
||||
if (isset($params['sort'])) {
|
||||
$order = (isset($params['order']) && $params['order'] == 'desc') ? 'DESC' : 'ASC';
|
||||
if (in_array($params['sort'], $sortable)) {
|
||||
$sql = ' ORDER BY ' . $this->identify($params['sort']) . ' ' . $order;
|
||||
}
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* Searches using like
|
||||
*
|
||||
* @param array $params
|
||||
* @param array $searchable
|
||||
* @param string $table_prefix
|
||||
* @return string
|
||||
*/
|
||||
protected function search($params, $searchable = array('id'), $table_prefix = '')
|
||||
{
|
||||
$sql = '';
|
||||
if (isset($params['q']) && isset($params['qt']) && in_array($params['qt'], $searchable)) {
|
||||
if ($table_prefix) {
|
||||
$sql = $table_prefix . '.';
|
||||
}
|
||||
$sql .= $this->identify($params['qt']) . ' LIKE ' . $this->quote('%' . $params['q'] . '%');
|
||||
}
|
||||
return $sql;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return Cache
|
||||
@ -238,4 +277,4 @@ abstract class Model implements iCacheable
|
||||
}
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user