/** * Overridable delete callback * * Called by a TIP_Form instance to process the delete action. * The default handler deletes the row and calls the * _onMasterDelete() signal for every configured module that has * this module as 'master'. */ public function _onDelete(&$row, $old_row) { $engine =& $this->data->getProperty('engine'); if (!$engine->startTransaction()) { // This error must be caught here to avoid the rollback return false; } // Process the row $done = $this->data->deleteRow($row) && $this->_onDbAction('Delete', $row, $old_row); $done = $engine->endTransaction($done) && $done; return $done; }
public function _processRow($row) { // Processed row null by default $this->_row = null; // Check "on_process" callback validity if (is_null($this->on_process)) { return; } elseif (!is_callable($this->on_process)) { TIP::error("invalid on_process callback passed to TIP_Form ({$this->id})"); return; } if ($this->_transaction_protected) { if (is_null($engine =& $this->_data->getProperty('engine'))) { return; } } else { $engine = null; } if ($engine && !$engine->startTransaction()) { // This error must be caught here to avoid the rollback return; } // Apply the converters on every field of $row $done = true; foreach ($this->_converter as $field => $type) { if (!$this->{'_converter' . $type}($row, $field)) { $done = false; break; } } // Run the process callback $done = $done && call_user_func_array($this->on_process, array(&$row, $this->_defaults)); if ($done) { $this->notify_done && TIP::notifyInfo('done'); $this->_row =& $row; } else { TIP::notifyError($this->action_id); } $engine && $engine->endTransaction($done); }
private function &_nodesToRows($nodes, $parent = null) { static $autoincrement = 0; // Stop recursion $rows = null; if (empty($nodes)) { return $rows; } if (is_null($parent)) { $autoincrement = 1; } $primary_key = $this->_data->getProperty('primary_key'); $rows = array(); while (list(, $node) = each($nodes)) { unset($row); $row = $this->_nodeToRow($node); if (!is_array($row)) { // Invalid row: silently skip it continue; } if (!array_key_exists($primary_key, $row)) { // The primary key must be autogenerated $row[$primary_key] = $autoincrement; ++$autoincrement; } $id = $row[$primary_key]; $rows[$id] =& $row; if (!isset($this->parent_field)) { // No recursion needed continue; } if (!array_key_exists($this->parent_field, $row)) { // Parent field not explicitely set by the model $rows[$id][$this->parent_field] = $parent; } $subrows =& $this->_nodesToRows($node->xpath($this->row_xpath), $id); if (isset($subrows)) { $rows = array_merge($rows, $subrows); unset($subrows); } } return $rows; }