Esempio n. 1
0
 /**
  * Build a relative action URI
  *
  * $params is a string in the form "action[,id[,param1=value1,param2=value2,...]]"
  * The module name can be overriden specifying it as module=...
  */
 protected function tagActionUri($params)
 {
     return TIP::toHtml(TIP::buildActionUriFromTag($params, $this->id));
 }
Esempio n. 2
0
 /**
  * Update the URLs on a model
  *
  * Adds the 'url' field on every row of $model using $action as
  * template string. Also, recurses in the 'sub' field if it exists
  * and it is an array, as required for non-linear models
  * (TIP_Hierarchy being an example).
  *
  * @param mixed  &$model   The model to update
  * @param string  $action  The action template string
  * @internal
  */
 protected function _updateModelUrl(&$model, $action)
 {
     foreach ($model as $id => &$row) {
         if (isset($row['url'])) {
             // Explicit URL set
             continue;
         }
         // Try to use the action field (an URL that should be expanded
         // substituting the -id- pattern)
         $url = isset($row['action']) ? $row['action'] : $action;
         $url = str_replace('-id-', $id, $url);
         $row['url'] = TIP::buildActionUriFromTag($url, $this->id);
         if (@is_array($row['sub'])) {
             // Recurse in the 'sub' array, if it exists: this allows
             // to work with non-linear models, like hierarchies
             $this->_updateModelUrl($row['sub'], $action);
         }
     }
 }
Esempio n. 3
0
 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;
 }