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(); } }
public function gpx($args) { $this->set_up($args); // Create GPX. $gpx = new \SimpleXMLElement('<gpx xmlns:gpxx="http://www.garmin.com/xmlschemas/GpxExtensions/v3" />'); $gpx->addAttribute('version', '1.1'); $gpx->addAttribute('xmlns', 'http://www.topografix.com/GPX/1/1'); $gpx->addAttribute('creator', $this->byline()); foreach ($this->table->get_records(false) as $record) { $geom = \geoPHP::load($record->{$this->point_col_name}()); $wpt = $gpx->addChild('wpt'); $wpt->addAttribute('lat', $geom->getY()); $wpt->addAttribute('lon', $geom->getX()); $wpt->addChild('name', $record->get_title()); $wpt->addChild('description', htmlentities('<a href="' . $record->get_url() . '">View record.</a>')); $extensions = $wpt->addChild('extensions'); $waypoint_extension = $extensions->addChild('gpxx:WaypointExtension', '', 'gpxx'); $categories = $waypoint_extension->addChild('gpxx:Categories', '', 'gpxx'); foreach ($this->table->get_columns() as $col) { if ($col->get_name() == $this->point_col_name) { // Don't include the geometry column. continue; } $fktitle = $col->get_name() . \WordPress\Tabulate\DB\Record::FKTITLE; $value = $record->{$fktitle}(); $categories->addChild('gpxx:Categories', $col->get_title() . ": {$value}", 'gpxx'); $waypoint_extension->addChild('gpxx:' . $col->get_name(), $value, 'gpxx'); } } // Send to browser. $this->send_file('gpx', 'application/gpx+xml', $gpx->asXML()); }