public function after_save(Table $table, Record $new_record) { // Don't save changes to the changes tables. if (in_array($table->getName(), self::tableNames())) { return false; } $changesetsTable = $this->db->getTable('changesets', false); if (!$changesetsTable || !$changesetsTable->getRecord(self::$currentChangesetId)) { throw new \Exception("Failed to open changeset #" . self::$currentChangesetId); } // Save a change for each changed column. foreach ($table->getColumns() as $column) { $col_name = $column->isForeignKey() ? $column->getName() . Record::FKTITLE : $column->getName(); $old_val = is_callable(array($this->oldRecord, $col_name)) ? $this->oldRecord->{$col_name}() : null; $new_val = $new_record->{$col_name}(); if ($new_val == $old_val) { // Ignore unchanged columns. continue; } $sql = "INSERT INTO changes SET " . " `changeset` = :changeset, " . " `change_type` = 'field', " . " `table_name` = :table_name, " . " `column_name` = :column_name, " . " `record_ident` = :record_ident, " . " `old_value` = :old_value, " . " `new_value` = :new_value "; $data = array('changeset' => self::$currentChangesetId, 'table_name' => $table->getName(), 'column_name' => $column->getName(), 'record_ident' => $new_record->getPrimaryKey(), 'old_value' => $old_val, 'new_value' => $new_val); // Save the change record. $this->db->query($sql, $data); } // Close the changeset if required. if (!self::$keepChangesetOpen) { $this->closeChangeset(); } }
/** * @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; }
public function getUrl() { return Config::baseUrl() . '/record/' . $this->table->getName() . '/' . $this->getPrimaryKey(); }
/** * Get a list of records that reference this record in one of their columns. * * @param string|\Tabulate\DB\Table $foreignTable * @param string|\Tabulate\DB\Column $foreignColumn * @param boolean $withPagination Whether to only return the top N records. * @return \Tabulate\DB\Record[] */ public function getReferencingRecords($foreignTable, $foreignColumn, $withPagination = true) { $foreignTable->resetFilters(); $foreignTable->addFilter($foreignColumn, '=', $this->getPrimaryKey(), true); return $foreignTable->getRecords($withPagination); }
/** * Get a set of results for Foreign Key lookups. * @param \Tabulate\DB\Table $table The table to search. * @param string $operator One of the permitted filter operators. * @param string $term The search term. * @return string[] */ protected function foreign_key_values_build($table, $operator, $term) { $table->resetFilters(); $table->addFilter($table->getTitleColumn(), $operator, $term); $out = array(); foreach ($table->getRecords() as $record) { $out[$record->getPrimaryKey()] = array('value' => $record->getPrimaryKey(), 'label' => $record->getTitle()); } return $out; }
protected function send_file($ext, $mime, $content, $download_name = false) { $download_name = date('Y-m-d') . '_' . $this->table->getName(); parent::send_file($ext, $mime, $content, $download_name); }
public function __construct(\Tabulate\DB\Database $database, $name = 'users') { parent::__construct($database, $name); }
/** * Get the name of the session key under which this table's record count is stored. * @return string */ public function sessionKey() { return $this->table->getName() . '_count'; }