Browse Source

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
master
pzinovkin 15 years ago
parent
commit
70ccc8bc26
  1. 18
      app/PagerAction.php
  2. 41
      model/Model.php
  3. 2
      model/MySQLiDriver.php
  4. 5
      model/MySQLiStatement.php

18
app/PagerAction.php

@ -11,22 +11,22 @@
class PagerAction extends Action
{
public $page;
public $last_page;
public $page = 1;
public $last_page = 1;
protected $offset = 0;
protected $count = 0;
protected $limit;
public function __construct($count, $limit = 20)
public function __construct($limit = 20)
{
$this->count = $count;
$this->limit = $limit;
parent::__construct();
}
protected function execute()
protected function execute() {}
public function setCount($count)
{
$this->last_page = ceil($this->count / $this->limit);
$this->last_page = ceil($count / $this->limit);
if (Env::Get('p') == 'last') {
$page = $this->last_page;
} else {
@ -38,12 +38,12 @@ class PagerAction extends Action
public function getOffset()
{
return $this->offset;
return (int) $this->offset;
}
public function getLimit()
{
return $this->limit;
return (int) $this->limit;
}
protected function getTemplate()

41
model/Model.php

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

2
model/MySQLiDriver.php

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

5
model/MySQLiStatement.php

@ -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;
}
}
}
Loading…
Cancel
Save