Esempio n. 1
0
 /**
  * Overridable 'view' callback
  *
  * Called by actionView() before performing the 'view' action.
  * The default handler updates 'hits_field' and 'last_hit_field', if they
  * are present.
  *
  * @param  array &$row The data row to view
  * @return bool        true on success, false on errors
  */
 public function _onView(&$row)
 {
     $old_row = $row;
     isset($this->last_hit_field) && array_key_exists($this->last_hit_field, $row) && ($row[$this->last_hit_field] = TIP::formatDate('datetime_sql'));
     isset($this->hits_field) && array_key_exists($this->hits_field, $row) && ++$row[$this->hits_field];
     // Update user statistics, if the user module exists
     if (!is_null($user =& TIP_Application::getSharedModule('user'))) {
         $user->increment($this->user_statistic['_onView']);
     }
     return $this->data->updateRow($row, $old_row);
 }
Esempio n. 2
0
 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);
 }
Esempio n. 3
0
 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;
 }