/** * Get most recent changes. * @return \PDOStatement */ public function getChanges($lim = 10) { $limit = (int) $lim; $sql = "SELECT cs.id AS changeset_id, c.id AS change_id, date_and_time, " . "u.name, table_name, record_ident, column_name, old_value, " . "new_value, comment " . "FROM `changes` c " . " JOIN `changesets` cs ON (c.changeset = cs.id) " . " JOIN `users` u ON (u.id = cs.user) " . "WHERE table_name = :table AND record_ident = :ident " . "ORDER BY date_and_time DESC, cs.id DESC " . "LIMIT {$limit}"; $params = array('table' => $this->table->getName(), 'ident' => $this->getPrimaryKey()); return $this->table->getDatabase()->query($sql, $params)->fetchAll(); }
/** * @return \Tabulate\Template */ private function getTemplate(\Tabulate\DB\Table $table) { $template = new Template('record/edit.twig'); $customTemplate = 'record/' . $table->getName() . '/edit.twig'; if ($template->getLoader()->exists($customTemplate)) { $template->setTemplateName($customTemplate); } $template->table = $table; $template->controller = 'record'; $template->title = $table->getTitle(); $template->tables = $table->getDatabase()->getTables(); return $template; }
/** * Get the record count of this table. Will use a cached value only for base * tables and where there are no filters. * @return integer The record count. */ public function getCount() { // Only cache if this is a base table and there are no filters. $canCache = $this->table->isTable() && count($this->table->get_filters()) === 0; if ($canCache) { if (isset($_SESSION[$this->sessionKey()])) { return $_SESSION[$this->sessionKey()]; } } // Otherwise, run the COUNT() query. $pkCol = $this->table->getPkColumn(); if ($pkCol instanceof Column) { $count_col = '`' . $this->table->getName() . '`.`' . $pkCol->getName() . '`'; } else { $count_col = '*'; } $sql = 'SELECT COUNT(' . $count_col . ') as `count` FROM `' . $this->table->getName() . '`'; $params = $this->table->applyFilters($sql); $count = $this->table->getDatabase()->query($sql, $params)->fetchColumn(); if ($canCache) { $_SESSION[$this->sessionKey()] = $count; } return (int) $count; }