コード例 #1
0
ファイル: ChangeTracker.php プロジェクト: tabulate/tabulate3
 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();
     }
 }
コード例 #2
0
 /**
  * @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;
 }
コード例 #3
0
ファイル: Record.php プロジェクト: tabulate/tabulate3
 public function getUrl()
 {
     return Config::baseUrl() . '/record/' . $this->table->getName() . '/' . $this->getPrimaryKey();
 }
コード例 #4
0
ファイル: Record.php プロジェクト: tabulate/tabulate3
 /**
  * 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);
 }
コード例 #5
0
ファイル: ApiController.php プロジェクト: tabulate/tabulate3
 /**
  * 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;
 }
コード例 #6
0
ファイル: MapController.php プロジェクト: tabulate/tabulate3
 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);
 }
コード例 #7
0
ファイル: Users.php プロジェクト: tabulate/tabulate3
 public function __construct(\Tabulate\DB\Database $database, $name = 'users')
 {
     parent::__construct($database, $name);
 }
コード例 #8
0
ファイル: RecordCounter.php プロジェクト: tabulate/tabulate3
 /**
  * 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';
 }