Example #1
0
 public function after_save(Table $table, Record $new_record)
 {
     // Don't save changes to the changes tables.
     if (in_array($table->get_name(), self::table_names())) {
         return false;
     }
     // Save a change for each changed column.
     foreach ($table->get_columns() as $column) {
         $col_name = $column->is_foreign_key() ? $column->get_name() . Record::FKTITLE : $column->get_name();
         $old_val = is_callable(array($this->old_record, $col_name)) ? $this->old_record->{$col_name}() : null;
         $new_val = $new_record->{$col_name}();
         if ($new_val == $old_val) {
             // Ignore unchanged columns.
             continue;
         }
         $data = array('changeset_id' => self::$current_changeset_id, 'change_type' => 'field', 'table_name' => $table->get_name(), 'column_name' => $column->get_name(), 'record_ident' => $new_record->get_primary_key());
         // Daft workaround for https://core.trac.wordpress.org/ticket/15158
         if (!is_null($old_val)) {
             $data['old_value'] = $old_val;
         }
         if (!is_null($new_val)) {
             $data['new_value'] = $new_val;
         }
         // Save the change record.
         $this->wpdb->insert($this->changes_name(), $data);
     }
     // Close the changeset if required.
     if (!self::$keep_changeset_open) {
         $this->close_changeset();
     }
 }
 protected function table_format(Table $table, $attrs)
 {
     $template = new Template('data_table.html');
     $template->table = $table;
     $template->links = false;
     $template->record = $table->get_default_record();
     $template->records = $table->get_records(false);
     return $template->render();
 }
 /**
  * Get the name of the transient under which this table's record count is
  * stored. All Tabulate transients start with TABULATE_SLUG.
  * @return string
  */
 public function transient_name()
 {
     return TABULATE_SLUG . '_' . $this->table->get_name() . '_count';
 }
 /**
  * Get a set of results for Foreign Key lookups.
  * @param \WordPress\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->reset_filters();
     $table->add_filter($table->get_title_column(), $operator, $term);
     $out = array();
     foreach ($table->get_records() as $record) {
         $out[$record->get_primary_key()] = array('value' => $record->get_primary_key(), 'label' => $record->get_title());
     }
     return $out;
 }
Example #5
0
 /**
  * Get a list of records that reference this record in one of their columns.
  *
  * @param string|\WordPress\Tabulate\DB\Table $foreign_table
  * @param string|\WordPress\Tabulate\DB\Column $foreign_column
  * @param boolean $with_pagination Whether to only return the top N records.
  * @return \WordPress\Tabulate\DB\Record[]
  */
 public function get_referencing_records($foreign_table, $foreign_column, $with_pagination = true)
 {
     $foreign_table->reset_filters();
     $foreign_table->add_filter($foreign_column, '=', $this->get_primary_key(), true);
     return $foreign_table->get_records($with_pagination);
 }
 protected function send_file($ext, $mime, $content, $download_name = false)
 {
     $download_name = date('Y-m-d') . '_' . $this->table->get_name();
     parent::send_file($ext, $mime, $content, $download_name);
 }