/** * Create template field array for the given edit field. * * @param array $fields all fields * @param int $index field index * @param string $mode mode (add/edit) * @param string $tab active tab * * @return array template field */ public function createTplField(&$fields, $index, $mode, $tab) { $field =& $fields[$index]; // visible sections, both the active sections and the tab names (attribute that are // part of the anonymous section of the tab) $visibleSections = array_merge($this->m_node->getActiveSections($tab, $mode), $this->m_node->getTabs($mode)); $tplfield = []; $classes = []; if (isset($field['class'])) { $classes = is_array($field['class']) ? $field['class'] : explode(' ', $field['class']); } if ($field['sections'] == '*') { $classes[] = 'alltabs'; } else { if (isset($field['html']) && $field['html'] == 'section') { // section should only have the tab section classes foreach ($field['tabs'] as $section) { $classes[] = 'section_' . str_replace('.', '_', $section); } if ($this->isSectionInitialHidden($field['name'], $fields)) { $classes[] = 'atkAttrRowHidden'; } } else { if (is_array($field['sections'])) { foreach ($field['sections'] as $section) { $classes[] = 'section_' . str_replace('.', '_', $section); } } } } if (isset($field['initial_hidden']) && $field['initial_hidden']) { $classes[] = 'atkAttrRowHidden'; } $tplfield['class'] = implode(' ', $classes); $tplfield['tab'] = $tplfield['class']; // for backwards compatibility // Todo fixme: initial_on_tab kan er uit, als er gewoon bij het opstarten al 1 keer showTab aangeroepen wordt (is netter dan aparte initial_on_tab check) // maar, let op, die showTab kan pas worden aangeroepen aan het begin. $tplfield['initial_on_tab'] = ($field['tabs'] == '*' || in_array($tab, $field['tabs'])) && (!is_array($field['sections']) || count(array_intersect($field['sections'], $visibleSections)) > 0); // ar_ stands for 'attribrow'. $tplfield['rowid'] = 'ar_' . (!empty($field['id']) ? $field['id'] : Tools::getUniqueId('anonymousattribrows')); // The id of the containing row // check for separator if (isset($field['html']) && $field['html'] == '-' && $index > 0 && $fields[$index - 1]['html'] != '-') { $tplfield['type'] = 'line'; $tplfield['line'] = '<hr>'; } elseif (isset($field['html']) && $field['html'] == '-') { } elseif (isset($field['html']) && $field['html'] == 'section') { $tplfield['type'] = 'section'; list($tab, $section) = explode('.', $field['name']); $tplfield['section_name'] = "section_{$tab}_{$section}"; $tplfield['line'] = $this->getSectionControl($field, $mode); } elseif (isset($field['line'])) { $tplfield['type'] = 'custom'; $tplfield['line'] = $field['line']; } else { $tplfield['type'] = 'attribute'; if ($field['attribute']->m_ownerInstance->getNumbering()) { $this->_addNumbering($field, $tplfield, $index); } /* does the field have a label? */ if (isset($field['label']) && $field['label'] !== 'AF_NO_LABEL' || !isset($field['label'])) { if (!isset($field['label']) || empty($field['label'])) { $tplfield['label'] = ''; } else { $tplfield['label'] = $field['label']; if ($field['error']) { // TODO KEES $tplfield['error'] = $field['error']; } } } else { $tplfield['label'] = 'AF_NO_LABEL'; } /* obligatory indicator */ if ($field['obligatory']) { $tplfield['obligatory'] = true; } // Make the attribute and node names available in the template. $tplfield['attribute'] = $field['attribute']->fieldName(); $tplfield['node'] = $field['attribute']->m_ownerInstance->atkNodeUri(); /* html source */ $tplfield['widget'] = $field['html']; $editsrc = $field['html']; $tplfield['id'] = str_replace('.', '_', $this->m_node->atkNodeUri() . '_' . $field['id']); $tplfield['htmlid'] = $field['id']; $tplfield['full'] = $editsrc; $column = $field['attribute']->getColumn(); $tplfield['column'] = $column; $tplfield['readonly'] = $field['attribute']->isReadonlyEdit($mode); } // allow passing of extra arbitrary data, for example if a user overloads the editArray method // to pass custom extra data per attribute to the template if (isset($field['extra'])) { $tplfield['extra'] = $field['extra']; } return $tplfield; }
/** * Display a tabbed pane with attributes. * * @param array $record Array with fields * @param string $mode The mode * * @return string html code */ public function display($record, $mode) { // get active tab $active_tab = $this->getDefaultTab(); $fields = []; $tab = ''; $node = $this->m_ownerInstance; $ui = $node->getUi(); // For all attributes we use the display() function to display the // attributes current value. This may be overridden by supplying // an <attributename>_display function in the derived classes. foreach ($this->m_attribsList as $name => $tab) { $p_attrib = $node->getAttribute($name); if (is_object($p_attrib)) { $tplfield = []; if (!$p_attrib->hasFlag(self::AF_HIDE_VIEW)) { $fieldtab = $this->m_attribsList[$name]; $tplfield['class'] = "tabbedPaneAttr tabbedPaneTab{$fieldtab}"; $tplfield['rowid'] = 'tabbedPaneAttr_' . Tools::getUniqueId('anonymousattribrows'); // The id of the containing row $tplfield['tab'] = $tplfield['class']; // for backwards compatibility $tplfield['initial_on_tab'] = $fieldtab == $active_tab; // An <attributename>_display function may be provided in a derived // class to display an attribute. If it exists we will use that method // else we will just use the attribute's display method. $funcname = $p_attrib->m_name . '_display'; if (method_exists($node, $funcname)) { $editsrc = $node->{$funcname}($record, 'view'); } else { $editsrc = $p_attrib->display($record, 'view'); } $tplfield['full'] = $editsrc; $tplfield['widget'] = $editsrc; // in view mode, widget and full are equal // The Label of the attribute (can be suppressed with self::AF_NOLABEL or self::AF_BLANKLABEL) // For each attribute, a txt_<attributename> must be provided in the language files. if (!$p_attrib->hasFlag(self::AF_NOLABEL) && !$this->isAttributeSingleOnTab($name)) { if ($p_attrib->hasFlag(self::AF_BLANKLABEL)) { $tplfield['label'] = ''; } else { $tplfield['label'] = $p_attrib->label(); } } else { // Make the rest fill up the entire line $tplfield['label'] = ''; $tplfield['line'] = $tplfield['full']; } $fields[] = $tplfield; } } else { Tools::atkerror("Attribute {$name} not found!"); } } $innerform = $ui->render($node->getTemplate('view', $record, $tab), array('fields' => $fields)); return $this->tabulate('view', $innerform); }
/** * Get the view page. * * @param array $record The record * @param string $mode The mode we're in (defaults to "view") * @param string $template The template to use for the view form * * @return string HTML code of the page */ public function viewForm($record, $mode = 'view', $template = '') { $node = $this->m_node; // get data, transform into form, return $data = $node->viewArray($mode, $record); // get active tab $tab = $node->getActiveTab(); // get all tabs of current mode $tabs = $node->getTabs($mode); $fields = []; $attributes = []; // For all attributes we use the display() function to display the // attributes current value. This may be overridden by supplying // an <attributename>_display function in the derived classes. for ($i = 0, $_i = count($data['fields']); $i < $_i; ++$i) { $field =& $data['fields'][$i]; $tplfield = []; $classes = []; if ($field['sections'] == '*') { $classes[] = 'alltabs'; } else { if ($field['html'] == 'section') { // section should only have the tab section classes foreach ($field['tabs'] as $section) { $classes[] = 'section_' . str_replace('.', '_', $section); } } else { if (is_array($field['sections'])) { foreach ($field['sections'] as $section) { $classes[] = 'section_' . str_replace('.', '_', $section); } } } } $tplfield['class'] = implode(' ', $classes); $tplfield['tab'] = $tplfield['class']; // for backwards compatibility // visible sections, both the active sections and the tab names (attribute that are // part of the anonymous section of the tab) $visibleSections = array_merge($this->m_node->getActiveSections($tab, $mode), $tabs); // Todo fixme: initial_on_tab kan er uit, als er gewoon bij het opstarten al 1 keer showTab aangeroepen wordt (is netter dan aparte initial_on_tab check) // maar, let op, die showTab kan pas worden aangeroepen aan het begin. $tplfield['initial_on_tab'] = ($field['tabs'] == '*' || in_array($tab, $field['tabs'])) && (!is_array($field['sections']) || count(array_intersect($field['sections'], $visibleSections)) > 0); // Give the row an id if it doesn't have one yet if (!isset($field['id']) || empty($field['id'])) { $field['id'] = Tools::getUniqueId('anonymousattribrows'); } // ar_ stands voor 'attribrow'. $tplfield['rowid'] = 'ar_' . $field['id']; // The id of the containing row /* check for separator */ if ($field['html'] == '-' && $i > 0 && $data['fields'][$i - 1]['html'] != '-') { $tplfield['line'] = '<hr>'; } elseif ($field['html'] == '-') { } elseif ($field['html'] == 'section') { $tplfield['line'] = $this->getSectionControl($field, $mode); } elseif (isset($field['line'])) { $tplfield['line'] = $field['line']; } else { if ($field['attribute']->m_ownerInstance->getNumbering()) { $this->_addNumbering($field, $tplfield, $i); } /* does the field have a label? */ if (isset($field['label']) && $field['label'] !== 'AF_NO_LABEL' || !isset($field['label'])) { if ($field['label'] == '') { $tplfield['label'] = ''; } else { $tplfield['label'] = $field['label']; } } else { $tplfield['label'] = 'AF_NO_LABEL'; } // Make the attribute and node names available in the template. $tplfield['attribute'] = $field['attribute']->fieldName(); $tplfield['node'] = $field['attribute']->m_ownerInstance->atkNodeUri(); /* html source */ $tplfield['widget'] = $field['html']; $editsrc = $field['html']; $tplfield['id'] = str_replace('.', '_', $node->atkNodeUri() . '_' . $field['id']); $tplfield['full'] = $editsrc; $column = $field['attribute']->getColumn(); $tplfield['column'] = $column; } $fields[] = $tplfield; // make field available in numeric array $params[$field['name']] = $tplfield; // make field available in associative array $attributes[$field['name']] = $tplfield; // make field available in associative array } $ui = $this->getUi(); $tabTpl = $this->_getTabTpl($node, $tabs, $mode, $record); if ($template) { $innerform = $ui->render($template, array('fields' => $fields, 'attributes' => $attributes)); } else { if (count(array_unique($tabTpl)) > 1) { $tabForm = $this->_renderTabs($fields, $tabTpl); $innerform = implode(null, $tabForm); } else { $innerform = $ui->render($node->getTemplate('view', $record, $tab), array('fields' => $fields, 'attributes' => $attributes)); } } return $innerform; }
/** * Gets the cache of the recordlist and registers the appropriate javascript. * * @return string The cached recordlist */ public function getCache() { $output = false; $this->_setCacheId(); if (file_exists($this->m_cacheid) && filesize($this->m_cacheid) && !$this->noCaching()) { $page = Page::getInstance(); $page->register_script(Config::getGlobal('assets_url') . 'javascript/formselect.js'); $page->register_script(Config::getGlobal('assets_url') . 'javascript/recordlist.js'); /* * RecordlistCache must call Tools::getUniqueId() too, or the counter will be off. */ Tools::getUniqueId('normalRecordList'); $sm = SessionManager::getInstance(); $stackID = $sm->atkStackID(); $page->register_loadscript(str_replace('*|REPLACESTACKID|*', $stackID, file_get_contents($this->m_cacheid . '_actionloader'))); $output = str_replace('*|REPLACESTACKID|*', $stackID, file_get_contents($this->m_cacheid)); } return $output; }