/** * Append action buttons to the end of this form * * @param bool|null $valid Whether the form was validated */ private function _addButtons($valid) { $buttons = $valid === false ? $this->buttons : TIP_FORM_BUTTON_CLOSE; $group = array(); if ($buttons & TIP_FORM_BUTTON_SUBMIT) { $group[] =& $this->_createElement('submit'); } if ($buttons & TIP_FORM_BUTTON_RESET) { $group[] =& $this->_createElement('reset'); } if ($buttons & TIP_FORM_BUTTON_OK) { $uri = TIP::modifyActionUri(null, null, null, array('process' => 1)); $group[] =& $this->_createElement('link', 'ok', array('href' => $uri)); } if ($buttons & TIP_FORM_BUTTON_DELETE && $this->action_id == TIP_FORM_ACTION_DELETE) { $uri = TIP::modifyActionUri(null, null, null, array('process' => 1)); $group[] =& $this->_createElement('link', 'delete', array('href' => $uri)); } if ($buttons & TIP_FORM_BUTTON_CANCEL) { $group[] =& $this->_createElement('link', 'cancel', array('href' => $this->referer)); } if ($buttons & TIP_FORM_BUTTON_CLOSE) { $group[] =& $this->_createElement('link', 'close', array('href' => $this->follower)); } if ($buttons & TIP_FORM_BUTTON_DELETE && $this->action_id != TIP_FORM_ACTION_DELETE) { $data =& $this->master->getProperty('data'); $primary_key = $data->getProperty('primary_key'); $uri = TIP::buildActionUri($this->id, 'delete', $this->_form->getElementValue($primary_key)); $group[] =& $this->_createElement('link', 'delete', array('href' => $uri)); } // Append the group of buttons to the form $this->_form->addElement('group', 'buttons', null, $group, ' ', false); }
/** * Remove all comments linked to a master row * * @param array &$row The subject row * @param array|null $old_row The old row or null on no old row * @return bool true on success or false on error */ public function _onMasterDelete(&$row, $old_row) { $data =& $this->getProperty('data'); $master_data =& $this->master->getProperty('data'); $primary_key = $master_data->getProperty('primary_key'); if (!isset($row[$primary_key])) { return false; } $filter = $data->filter($this->parent_field, $row[$primary_key]); return $data->deleteRows($filter); }
private function _render() { if (!empty($this->_tree)) { return true; } $filter = $this->master->getProperty('data')->order($this->date_field); if (is_null($view =& $this->master->startDataView($filter))) { return false; } $rows =& $view->getProperty('rows'); if (empty($rows)) { $this->_tree = array(); $this->master->endView(); return true; } $tree =& $this->_tree; foreach ($rows as $id => &$row) { $action = str_replace('-id-', $id, $this->action); $row['url'] = TIP::buildActionUriFromTag($action, (string) $this->master); $row['title'] = $this->_renderField($this->title_field, $row); // Suppose the date is in SQL format $date = $row[$this->date_field]; list($y, $m, $day) = sscanf($date, "%d-%d-%d"); // Compute the year $year = sprintf('%04d', $y); if (!array_key_exists($year, $tree)) { $tree[$year] = array('title' => $year, 'url' => TIP::modifyActionUri(null, null, null, array($this->id => $year)), 'sub' => array(), 'ITEMS' => 0); isset($this->count_field) && ($tree[$year]['COUNT'] = 0); } ++$tree[$year]['ITEMS']; isset($this->count_field) && ($tree[$year]['COUNT'] += $row[$this->count_field]); // Compute the month $months =& $tree[$year]['sub']; $month = strftime('%B', mktime(0, 0, 0, $m, $day, $year)); $month_id = $year . sprintf('%02d', $m); if (!array_key_exists($month_id, $months)) { $months[$month_id] = array('title' => $month, 'url' => TIP::modifyActionUri(null, null, null, array($this->id => $month_id)), 'sub' => array(), 'ITEMS' => 0); isset($this->count_field) && ($months[$month_id]['COUNT'] = 0); } ++$months[$month_id]['ITEMS']; isset($this->count_field) && ($months[$month_id]['COUNT'] += $row[$this->count_field]); $months[$month_id]['sub'][$id] =& $row; isset($this->count_field) && ($row['COUNT'] = $row[$this->count_field]); } return true; }
/** * Update the history on a master row deletion * * Updates the linked list by skipping the deleted history row * before deleting the row itsself. */ public function _onMasterDelete(&$row, $old_row) { $master_data =& $this->master->getProperty('data'); $id = $row[$master_data->getProperty('primary_key')]; $engine =& $this->data->getProperty('engine'); $query = $this->data->rowFilter($id); // Start the transaction here to avoid race conditions if (!$engine->startTransaction()) { // This error must be caught here to avoid the rollback return false; } // Get the current version row if (!($view =& $this->startDataView($query))) { $engine->endTransaction(false); return false; } $current_row = $view->current(); $this->endView(); if (empty($current_row)) { // No history found: return operation done (just in case...) return $engine->endTransaction(true); } // Get the previous version row $query = $this->data->filter($this->next_field, $id); if (!($view =& $this->startDataView($query))) { $engine->endTransaction(false); TIP::warning("no row to delete ({$id})"); TIP::notifyError('notfound'); return false; } $previous_row = $view->current(); $this->endView(); // Perform the operations $done = $this->data->deleteRow($id); if ($done && is_array($previous_row)) { // Update the next_field of previous_row $new_previous_row = $previous_row; $new_previous_row[$this->next_field] = $current_row[$this->next_field]; $done = $this->data->updateRow($new_previous_row, $previous_row); } // Close the transaction $done = $engine->endTransaction($done) && $done; return $done; }
public function _onMasterEdit(&$row, &$old_row) { if (is_array($old_row)) { // Check for the public flag $public = $this->master->getProperty('public_field'); $old_public = !isset($public, $old_row[$public]) || $old_row[$public] == 'yes'; $new_public = isset($row, $row[$public]) ? $row[$public] == 'yes' : $old_public; // Check for the parent $parent = $this->master_field; $old_parent = @$old_row[$parent]; $new_parent = isset($row[$parent]) ? $row[$parent] : $old_parent; // If something rilevant has changed, update the counters if ($old_public != $new_public || $old_parent != $new_parent) { $old_public && $this->_updateCount($old_parent, -1); $new_public && $this->_updateCount($new_parent, +1); } } return true; }