/** * Update statistic on the master module * * Updates the counter of the linked row in the master module according * to the specified $offset. * * This is an high level method that raises errors and notify them to the * user on any errors. * * @param array &$comment_row The comment row * @param int $offset The offset of the counter (+1 add, -1 delete) * @return bool true on success or false on errors */ private function _updateMaster(&$comment_row, $offset) { if (!isset($this->master_count)) { // No count field to update return true; } $id = @$comment_row[$this->parent_field]; if (empty($id)) { // No master row specified: don't update anything return true; } if (is_null($row =& $this->master->fromRow($id, false))) { // Error: master row specified but not found return false; } if (!array_key_exists($this->master_count, $row)) { // No count field found in master: don't update anything return true; } $old_row = $row; $row[$this->master_count] += $offset; if (!$this->master->getProperty('data')->updateRow($row, $old_row)) { return false; } return true; }
/** * Get a specific row * * Overrides the default method to merge also the child row fields * to the returned array. * * @param mixed $id The row id * @param bool $end_view Whether to end the view or not * @return array|null The row or null on errors */ public function &fromRow($id = null, $end_view = true) { // Get the current "master" row if (is_null($row = parent::fromRow($id, $end_view))) { return $row; } // Try to get the child row, if possible: the class name is // retrieved from the post (if found) or from the current $row if (is_null($class = TIP::getPost($this->class_field, 'string'))) { $class = $row[$this->class_field]; } $child =& $this->_getChildModule($class); if ($child === false) { $row = null; } elseif ($child && !is_null($child_row = $child->fromRow($id, $end_view))) { $row = array_merge($child_row, $row); } return $row; }