Esempio n. 1
0
 private function _addWidget($id)
 {
     // Avoid duplicates
     if ($this->_form->elementExists($id)) {
         return;
     }
     $field =& $this->fields[$id];
     $default = TIP::pickElement($id, $this->_defaults);
     // By default, fields starting with '_' and automatic fields
     // cannot be edited, so are included as hidden (if defined)
     if (substr($id, 0, 1) == '_' || $field['automatic']) {
         is_null($default) || $this->_form->addElement('hidden', $id, $default);
         return;
     }
     $flags = isset($field['flags']) ? explode(',', strtolower($field['flags'])) : array();
     $explicit_default = TIP::pickElement($id, $this->defaults);
     // Check for "placeholder" flag
     if (is_null($explicit_default) && in_array('placeholder', $flags)) {
         // Special case: placeholder flag and no default value provided
         // The widget must not be built. The value will be automagically
         // handled by _converterPlaceholder()
         $this->_transaction_protected = true;
         $this->_addConverter($id, 'Placeholder');
         return;
     }
     // Create the widget
     $old_tabindex = $this->_tabindex;
     $method = '_widget' . @$field['widget'];
     method_exists($this, $method) || ($method = '_widgetText');
     $element =& $this->{$method}($field, @$field['widget_args']);
     // Check for "immutable" flag and explicit default value provided
     if (!is_null($explicit_default) && in_array('immutable', $flags)) {
         $element->freeze();
     }
     // Check if the field is in the "readonly" list
     if (in_array($id, $this->readonly)) {
         $element->freeze();
     }
     // Remove the element on "trailing" flag set:
     // the element will be appended in the render() method
     if (in_array('trailing', $flags)) {
         $this->_trailing_elements[$id] =& $element;
         $this->_form->removeElement($id, false);
         $this->_tabindex = $old_tabindex;
     }
 }
Esempio n. 2
0
 /**
  * Render a row to an array
  *
  * Renders $row as required by toArray(), that is append to the row
  * data some missing info (the {{id}}, {{title}} and {{tooltip}} fields).
  *
  * @param  array   &$row  The subject row
  * @param  mixed    $id   The id of the row
  * @internal
  */
 private function _rowToArray(&$row, $id)
 {
     isset($row['id']) || ($row['id'] = $id);
     // Use the custom "title_field" or
     // leave the default $row['title'] untouched
     if (isset($this->title_field) && $this->title_field != 'title') {
         $row['title'] = TIP::pickElement($this->title_field, $row);
     }
     // Try to set the custom tooltip field
     if (isset($this->tooltip_field) && $this->tooltip_field != 'tooltip') {
         $row['tooltip'] = TIP::pickElement($this->tooltip_field, $row);
     }
 }
Esempio n. 3
0
 public function _createModel(&$view)
 {
     if (!is_null($this->_model)) {
         return true;
     }
     $this->_model = array();
     $rows = $view->getProperty('rows');
     if (empty($rows)) {
         return true;
     }
     // By default, counting is enable if the "count_field" property is set
     isset($this->count_field) && ($total_count = 0);
     $primary_key = $this->data->getProperty('primary_key');
     foreach (array_keys($rows) as $id) {
         $row =& $rows[$id];
         isset($row['id']) || ($row['id'] = $id);
         isset($row['CLASS']) || ($row['CLASS'] = 'item');
         // Use the custom "title_field" or
         // leave the default $row['title'] untouched
         if (isset($this->title_field) && @$this->title_field != 'title') {
             $row['title'] = TIP::pickElement($this->title_field, $row);
         }
         // Try to set the custom tooltip field
         if (isset($this->tooltip_field) && @$this->tooltip_field != 'tooltip') {
             $row['tooltip'] = TIP::pickElement($this->tooltip_field, $row);
         }
         if (isset($this->count_field)) {
             $count = @$row[$this->count_field];
             isset($row['COUNT']) || ($row['COUNT'] = 0);
             $row['COUNT'] += $count;
             $total_count += $count;
         }
         if (isset($this->parent_field, $row[$this->parent_field]) && !empty($row[$this->parent_field])) {
             do {
                 $parent =& $rows[$row[$this->parent_field]];
                 if (@$parent['CLASS'] != 'folder') {
                     if ($this->self_reference) {
                         // Autogenerate a new instance of parent
                         // and put it as its child (so parent has
                         // always itsself as child)
                         $tmp = $parent;
                         $parent['sub'][$row[$this->parent_field]] = $tmp;
                     }
                     $parent['CLASS'] = 'folder';
                 }
                 $parent['sub'][$row[$primary_key]] =& $row;
                 if (isset($count)) {
                     isset($parent['COUNT']) || ($parent['COUNT'] = 0);
                     $parent['COUNT'] += $count;
                 }
                 $row =& $parent;
             } while (!empty($row[$this->parent_field]));
         } else {
             $this->_model[$id] =& $row;
         }
     }
     if (isset($total_count)) {
         $view->setSummary('TOTAL_COUNT', $total_count);
     }
     return true;
 }