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 record_format(Table $table, $attrs, $query = null)
 {
     if (!isset($query[$table->get_name()]) || !is_scalar($query[$table->get_name()])) {
         return '';
     }
     $record = $table->get_record($query[$table->get_name()]);
     if ($record === false) {
         return $this->error("No record found.");
     }
     $template = new Template('record/view.html');
     $template->table = $table;
     $template->record = $record;
     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';
 }
 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);
 }