Alias of getIdFieldName. Used for JTableInterface compatibility.
public getKeyName ( ) : string | ||
return | string | The name of the primary key for the table. |
/** * Replace string with tags that reference fields * * @param string $text Text to process * * @return string Text with tags replace */ protected function parseFieldTags($text) { $ret = $text; // Replace [ITEM:ID] in the URL with the item's key value (usually: // the auto-incrementing numeric ID) $keyfield = $this->item->getKeyName(); $replace = $this->item->{$keyfield}; $ret = str_replace('[ITEM:ID]', $replace, $ret); // Replace the [ITEMID] in the URL with the current Itemid parameter $ret = str_replace('[ITEMID]', $this->form->getContainer()->input->getInt('Itemid', 0), $ret); // Replace other field variables in the URL $fields = $this->item->getTableFields(); foreach ($fields as $fielddata) { $fieldname = $fielddata->Field; if (empty($fieldname)) { $fieldname = $fielddata->column_name; } $search = '[ITEM:' . strtoupper($fieldname) . ']'; $replace = $this->item->{$fieldname}; if (!is_string($replace)) { continue; } $ret = str_replace($search, $replace, $ret); } return $ret; }
/** * Get the rendering of this field type for a repeatable (grid) display, * e.g. in a view listing many item (typically a "browse" task) * * @since 2.0 * * @return string The field HTML * * @throws DataModelRequired */ public function getRepeatable() { // Should I support checked-out elements? $checkoutSupport = false; if (isset($this->element['checkout'])) { $checkoutSupportValue = (string) $this->element['checkout']; $checkoutSupport = in_array(strtolower($checkoutSupportValue), array('yes', 'true', 'on', 1)); } if (!$this->item instanceof DataModel) { throw new DataModelRequired(__CLASS__); } // Is this record checked out? $userId = $this->form->getContainer()->platform->getUser()->get('id', 0); $checked_out = false; if ($checkoutSupport) { $checked_out = $this->item->isLocked($userId); } // Get the key id for this record $key_field = $this->item->getKeyName(); $key_id = $this->item->{$key_field}; // Get the HTML return JHtml::_('grid.id', $this->rowid, $key_id, $checked_out); }
/** * Method to get the field input markup for this field type. * * @since 2.0 * * @return string The field input markup. */ protected function getInput() { $html = array(); $attr = ''; // Initialize some field attributes. $attr .= !empty($this->class) ? ' class="' . $this->class . '"' : ''; $attr .= $this->disabled ? ' disabled' : ''; $attr .= !empty($this->size) ? ' size="' . $this->size . '"' : ''; // Initialize JavaScript field attributes. $attr .= !empty($this->onchange) ? ' onchange="' . $this->onchange . '"' : ''; $this->item = $this->form->getModel(); $keyfield = $this->item->getKeyName(); $itemId = $this->item->{$keyfield}; $query = $this->getQuery(); // Create a read-only list (no name) with a hidden input to store the value. if ($this->readonly) { $html[] = JHtml::_('list.ordering', '', $query, trim($attr), $this->value, $itemId ? 0 : 1); $html[] = '<input type="hidden" name="' . $this->name . '" value="' . $this->value . '"/>'; } else { // Create a regular list. $html[] = JHtml::_('list.ordering', $this->name, $query, trim($attr), $this->value, $itemId ? 0 : 1); } return implode($html); }
public function onBeforeDelete(DataModel &$model, $oid) { if (!$model->isAssetsTracked()) { return true; } $k = $model->getKeyName(); // If the table is not loaded, let's try to load it with the id if (!$model->{$k}) { $model->load($oid); } // If I have an invalid assetName I have to stop $name = $model->getAssetName(); // Do NOT touch JTable here -- we are loading the core asset table which is a JTable, not a FOF Table $asset = \JTable::getInstance('Asset'); if ($asset->loadByName($name)) { // Since we are using JTable, there is no way to mock it and test for failures :( // @codeCoverageIgnoreStart if (!$asset->delete()) { throw new \Exception($asset->getError()); } // @codeCoverageIgnoreEnd } return true; }
/** * Get the rendering of this field type for a repeatable (grid) display, * e.g. in a view listing many item (typically a "browse" task) * * @since 2.0 * * @return string The field HTML */ public function getRepeatable() { if (is_array($this->value)) { $this->value = print_r($this->value, true); } if (isset($this->element['legacy'])) { return $this->getInput(); } // Should I support checked-out elements? $checkoutSupport = false; if (isset($this->element['checkout'])) { $checkoutSupportValue = (string) $this->element['checkout']; $checkoutSupport = in_array(strtolower($checkoutSupportValue), array('yes', 'true', 'on', 1)); } // Initialise $class = $this->class ? $this->class : $this->id; $format_string = $this->element['format'] ? (string) $this->element['format'] : ''; $format_if_not_empty = in_array((string) $this->element['format_if_not_empty'], array('true', '1', 'on', 'yes')); $parse_value = in_array((string) $this->element['parse_value'], array('true', '1', 'on', 'yes')); $link_url = $this->element['url'] ? (string) $this->element['url'] : ''; $empty_replacement = $this->element['empty_replacement'] ? (string) $this->element['empty_replacement'] : ''; $format_source_file = empty($this->element['format_source_file']) ? '' : (string) $this->element['format_source_file']; $format_source_class = empty($this->element['format_source_class']) ? '' : (string) $this->element['format_source_class']; $format_source_method = empty($this->element['format_source_method']) ? '' : (string) $this->element['format_source_method']; if ($link_url && $this->item instanceof DataModel) { $link_url = $this->parseFieldTags($link_url); } else { $link_url = false; } // Get the (optionally formatted) value $value = $this->value; if (!empty($empty_replacement) && empty($this->value)) { $value = JText::_($empty_replacement); } if ($parse_value) { $value = $this->parseFieldTags($value); } if (!empty($format_string) && (!$format_if_not_empty || $format_if_not_empty && !empty($this->value))) { $format_string = $this->parseFieldTags($format_string); $value = sprintf($format_string, $value); } elseif ($format_source_class && $format_source_method) { // Maybe we have to load a file? if (!empty($format_source_file)) { $format_source_file = $this->form->getContainer()->template->parsePath($format_source_file, true); if ($this->form->getContainer()->filesystem->fileExists($format_source_file)) { include_once $format_source_file; } } // Make sure the class and method exist if (class_exists($format_source_class, true) && in_array($format_source_method, get_class_methods($format_source_class))) { $value = $format_source_class::$format_source_method($value); $value = $this->parseFieldTags($value); } else { $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); } } else { $value = htmlspecialchars($value, ENT_COMPAT, 'UTF-8'); } // Create the HTML $html = '<span class="' . $class . '">'; $userId = $this->form->getContainer()->platform->getUser()->id; if ($checkoutSupport && $this->item->isLocked($userId)) { $key_field = $this->item->getKeyName(); $key_id = $this->item->{$key_field}; $lockedBy = ''; $lockedOn = ''; if ($this->item->hasField('locked_by')) { $lockedUser = $this->form->getContainer()->platform->getUser($this->item->getFieldValue('locked_by')); $lockedBy = $lockedUser->name . ' (' . $lockedUser->username . ')'; } if ($this->item->hasField('locked_on')) { $lockedOn = $this->item->getFieldValue('locked_on'); } $html .= \JHtml::_('jgrid.checkedout', $key_id, $lockedBy, $lockedOn, '', true); } if ($link_url) { $html .= '<a href="' . $link_url . '">'; } $html .= $value; if ($link_url) { $html .= '</a>'; } $html .= '</span>'; return $html; }
/** * Apply the ordering field * * @param \FOF30\Model\DataModel $model * @param \SimpleXMLElement $headerSet * @param \SimpleXMLElement $fieldSet * @param array $allFields */ private function applyPrimaryKeyField(DataModel $model, \SimpleXMLElement &$headerSet, \SimpleXMLElement &$fieldSet, array &$allFields) { $keyField = $model->getKeyName(); $langDefs = $this->getFieldLabel($keyField); $this->addString($langDefs['label']['key'], $langDefs['label']['value']); $this->addString($langDefs['desc']['key'], $langDefs['desc']['value']); $header = $headerSet->addChild('header'); $header->addAttribute('name', $keyField); $header->addAttribute('type', 'RowSelect'); $header->addAttribute('label', $langDefs['label']['key']); $header->addAttribute('sortable', 'true'); $header->addAttribute('tdwith', '20'); $field = $fieldSet->addChild('field'); $field->addAttribute('name', $keyField); $field->addAttribute('type', 'SelectRow'); $field->addAttribute('label', $langDefs['label']['key']); unset($allFields[$keyField]); }
/** * Renders a Form for an Edit view and returns the corresponding HTML * * @param Form &$form The form to render * @param DataModel $model The model providing our data * * @return string The HTML rendering of the form */ public function renderFormEdit(Form &$form, DataModel $model) { // Get the key for this model's table $key = $model->getKeyName(); $keyValue = $model->getId(); $html = ''; $validate = strtolower($form->getAttribute('validate')); if (in_array($validate, array('true', 'yes', '1', 'on'))) { \JHTML::_('behavior.formvalidation'); $class = ' form-validate'; $this->loadValidationScript($form); } else { $class = ''; } // Check form enctype. Use enctype="multipart/form-data" to upload binary files in your form. $template_form_enctype = $form->getAttribute('enctype'); if (!empty($template_form_enctype)) { $enctype = ' enctype="' . $form->getAttribute('enctype') . '" '; } else { $enctype = ''; } // Check form name. Use name="yourformname" to modify the name of your form. $formname = $form->getAttribute('name'); if (empty($formname)) { $formname = 'adminForm'; } // Check form ID. Use id="yourformname" to modify the id of your form. $formid = $form->getAttribute('id'); if (empty($formid)) { $formid = $formname; } // Check if we have a custom task $customTask = $form->getAttribute('customTask'); if (empty($customTask)) { $customTask = ''; } // Get the form action URL $platform = $this->container->platform; $actionUrl = $platform->isBackend() ? 'index.php' : \JUri::root() . 'index.php'; $itemid = $this->container->input->getCmd('Itemid', 0); if ($platform->isFrontend() && $itemid != 0) { $uri = new \JUri($actionUrl); if ($itemid) { $uri->setVar('Itemid', $itemid); } $actionUrl = \JRoute::_($uri->toString()); } $html .= '<form action="' . $actionUrl . '" method="post" name="' . $formname . '" id="' . $formid . '"' . $enctype . ' class="form-horizontal' . $class . '">' . "\n"; $html .= "\t" . '<input type="hidden" name="option" value="' . $this->container->componentName . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="view" value="' . $form->getView()->getName() . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="task" value="' . $customTask . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="' . $key . '" value="' . $keyValue . '" />' . "\n"; $html .= "\t" . '<input type="hidden" name="' . \JFactory::getSession()->getFormToken() . '" value="1" />' . "\n"; $html .= $this->renderFormRaw($form, $model, 'edit'); $html .= '</form>'; return $html; }