コード例 #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
ファイル: MapController.php プロジェクト: tabulate/tabulate3
 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->getRecords(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->getTitle());
         $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->getColumns() as $col) {
             if ($col->getName() == $this->point_col_name) {
                 // Don't include the geometry column.
                 continue;
             }
             $fktitle = $col->getName() . \Tabulate\DB\Record::FKTITLE;
             $value = $record->{$fktitle}();
             $categories->addChild('gpxx:Categories', $col->getTitle() . ": {$value}", 'gpxx');
             $waypoint_extension->addChild('gpxx:' . $col->getName(), $value, 'gpxx');
         }
     }
     // Send to browser.
     $this->send_file('gpx', 'application/gpx+xml', $gpx->asXML());
 }
コード例 #3
0
ファイル: Record.php プロジェクト: tabulate/tabulate3
 /**
  * Get the value of this Record's title column.
  * @return string
  */
 public function getTitle()
 {
     $title_col = $this->table->getTitleColumn();
     if ($title_col !== $this->table->getPkColumn()) {
         $title_col_name = $title_col->getName();
         return $this->data->{$title_col_name};
     } else {
         $title_parts = array();
         foreach ($this->table->getColumns() as $col) {
             $col_name = $col->getName() . self::FKTITLE;
             $title_parts[] = $this->{$col_name}();
         }
         return '[ ' . join(' | ', $title_parts) . ' ]';
     }
 }