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:
pzinovkin
2010-05-24 13:54:50 +00:00
parent 117943f524
commit 70ccc8bc26
4 changed files with 53 additions and 13 deletions

View File

@ -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;
}
}
}

View File

@ -122,4 +122,4 @@ class MySQLiDriver extends DbDriver
$this->connection->rollback();
$this->connection->autocommit(true);
}
}
}

View File

@ -91,11 +91,12 @@ class MySQLiStatement extends DbStatement
$result = $mysqli->query($sql);
}
if ($result === false) {
throw new Exception($mysqli->error, $mysqli->errno);
$message = $mysqli->error . "\nQuery: \"" . $sql . '"';
throw new Exception($message, $mysqli->errno);
}
if ($result instanceof MySQLi_Result) {
$this->result = $result;
}
return true;
}
}
}