/** * @param DataModel $model * @param \stdClass $dataObject */ public function onBeforeUpdate(&$model, &$dataObject) { // Make sure we're not modifying a locked record $userId = $model->getContainer()->platform->getUser()->id; $isLocked = $model->isLocked($userId); if ($isLocked) { return; } // Handle the modified_on field if ($model->hasField('modified_on')) { $model->setFieldValue('modified_on', $model->getContainer()->platform->getDate()->toSql(false, $model->getDbo())); $modifiedOnField = $model->getFieldAlias('modified_on'); $dataObject->{$modifiedOnField} = $model->getFieldValue('modified_on'); } // Handle the modified_by field if ($model->hasField('modified_by')) { $model->setFieldValue('modified_by', $userId); $modifiedByField = $model->getFieldAlias('modified_by'); $dataObject->{$modifiedByField} = $model->getFieldValue('modified_by'); } }
/** * 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); }
/** * 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; }