/** * 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); }
/** * Perform the browse query throught a pager * * $params is a string in the form "quanto,query_adds". * * The quanto is the number of rows per page: leave it undefined to disable * the pager. In query_adds you can specify additional SQL commands to * append to the query, such as ORDER clauses. * * This function checks if there is a row more than what specified in the * quanto: this provides a simple way to know whether the 'NEXT' button * must be rendered or not. */ protected function tagPager($params) { if (is_null($this->_pager_conditions)) { TIP::error('no active browse action'); return null; } @(list($quanto, $query_template) = explode(',', $params, 2)); $quanto = (int) $quanto; $pager = $quanto > 0; if (empty($this->_pager_conditions)) { } elseif (is_array($this->_pager_conditions)) { $conditions = array(); foreach ($this->_pager_conditions as $id => $value) { $conditions[] = $this->getData()->addFilter('', $id, $value); } $filter = 'WHERE (' . implode(' AND ', $conditions) . ')'; } elseif (empty($this->search_field)) { $filter = $this->_pager_conditions; } else { is_string($this->search_field) && ($this->search_field = explode(',', $this->search_field)); $this->_search_tokens = explode(' ', $this->_pager_conditions); $pattern = '%' . implode('%', $this->_search_tokens) . '%'; $conditions = array(); foreach ($this->search_field as $id) { $conditions[] = $this->getData()->addFilter('', $id, $pattern, 'LIKE'); } $filter = 'WHERE (' . implode(' OR ', $conditions) . ')'; } if (isset($filter)) { $filter .= ' ' . $query_template; } else { $filter = $query_template; } $filter .= $this->getData()->order($this->default_order); if ($pager) { $offset = TIP::getGet('pg_offset', 'int'); $offset > 0 || ($offset = 0); $filter .= $this->getData()->limit($quanto + 1, $offset); } else { $offset = 0; } if (is_null($view = $this->startDataView($filter))) { TIP::notifyError('select'); $this->_search_tokens = null; return null; } ob_start(); if (!$view->isValid()) { $this->tryRun(array($main_id, $this->pager_empty_template)); } else { $main_id = TIP_Application::getGlobal('id'); $partial = $pager && $view->nRows() == $quanto + 1; if ($partial) { // Remove the trailing row from the view $rows =& $view->getProperty('rows'); array_splice($rows, $quanto); } if ($pager) { if ($offset > 0) { $this->keys['PREV'] = TIP::modifyActionUri(null, null, null, array('pg_offset' => $offset - $quanto > 0 ? $offset - $quanto : 0)); } if ($partial) { $this->keys['NEXT'] = TIP::modifyActionUri(null, null, null, array('pg_offset' => $offset + $quanto)); } $pager = $partial || $offset > 0; } // Pager rendering BEFORE the rows $pager && $this->tryRun(array($main_id, $this->pager_pre_template)); // Rows rendering $empty = true; $path = array($this->id, $this->pager_template); foreach ($view as $row) { $this->run($path); $empty = false; } // Empty result set $empty && $this->tryRun(array($main_id, $this->pager_empty_template)); // Pager rendering AFTER the rows $pager && $this->tryRun(array($main_id, $this->pager_post_template)); } $this->endView(); $this->_search_tokens = null; return ob_get_clean(); }
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; }