getFieldAlias() 공개 메소드

Get the real name of a field name based on its alias. If the field is not aliased $alias is returned
public getFieldAlias ( string $alias ) : string
$alias string The field to get an alias for
리턴 string The real name of the field
예제 #1
0
파일: Actions.php 프로젝트: akeeba/fof
 /**
  * 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()
 {
     if (!$this->item instanceof DataModel) {
         throw new DataModelRequired(__CLASS__);
     }
     $config = $this->getConfig();
     $html = '<div class="btn-group">';
     // Render a published field
     if ($this->item->hasField('enabled')) {
         $publishedFieldName = $this->item->getFieldAlias('enabled');
         if ($config['published'] || $config['unpublished']) {
             // Generate a FieldInterfacePublished field
             $publishedField = $this->getPublishedField($publishedFieldName);
             // Render the publish button
             $html .= $publishedField->getRepeatable();
         }
         if ($config['archived']) {
             $archived = $this->item->getFieldValue($publishedFieldName) == 2 ? true : false;
             // Create dropdown items
             $action = $archived ? 'unarchive' : 'archive';
             JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid);
         }
         if ($config['trash']) {
             $trashed = $this->item->getFieldValue($publishedFieldName) == -2 ? true : false;
             $action = $trashed ? 'untrash' : 'trash';
             JHtml::_('actionsdropdown.' . $action, 'cb' . $this->rowid);
         }
         // Render dropdown list
         if ($config['archived'] || $config['trash']) {
             $html .= JHtml::_('actionsdropdown.render', $this->item->title);
         }
     }
     $html .= '</div>';
     return $html;
 }
예제 #2
0
파일: Assets.php 프로젝트: Joal01/fof
 public function onAfterSave(DataModel &$model)
 {
     if (!$model->hasField('asset_id') || !$model->isAssetsTracked()) {
         return true;
     }
     $assetFieldAlias = $model->getFieldAlias('asset_id');
     $currentAssetId = $model->getFieldValue('asset_id');
     unset($model->{$assetFieldAlias});
     // Create the object used for inserting/udpating data to the database
     $fields = $model->getTableFields();
     // Let's remove the asset_id field, since we unset the property above and we would get a PHP notice
     if (isset($fields[$assetFieldAlias])) {
         unset($fields[$assetFieldAlias]);
     }
     // Asset Tracking
     $parentId = $model->getAssetParentId();
     $name = $model->getAssetName();
     $title = $model->getAssetTitle();
     $asset = \JTable::getInstance('Asset');
     $asset->loadByName($name);
     // Re-inject the asset id.
     $this->{$assetFieldAlias} = $asset->id;
     // Check for an error.
     $error = $asset->getError();
     // Since we are using JTable, there is no way to mock it and test for failures :(
     // @codeCoverageIgnoreStart
     if ($error) {
         throw new \Exception($error);
     }
     // @codeCoverageIgnoreEnd
     // Specify how a new or moved node asset is inserted into the tree.
     // Since we're unsetting the table field before, this statement is always true...
     if (empty($model->{$assetFieldAlias}) || $asset->parent_id != $parentId) {
         $asset->setLocation($parentId, 'last-child');
     }
     // Prepare the asset to be stored.
     $asset->parent_id = $parentId;
     $asset->name = $name;
     $asset->title = $title;
     if ($model->getRules() instanceof \JAccessRules) {
         $asset->rules = (string) $model->getRules();
     }
     // Since we are using JTable, there is no way to mock it and test for failures :(
     // @codeCoverageIgnoreStart
     if (!$asset->check() || !$asset->store()) {
         throw new \Exception($asset->getError());
     }
     // @codeCoverageIgnoreEnd
     // Create an asset_id or heal one that is corrupted.
     if (empty($model->{$assetFieldAlias}) || $currentAssetId != $model->{$assetFieldAlias} && !empty($model->{$assetFieldAlias})) {
         // Update the asset_id field in this table.
         $model->{$assetFieldAlias} = (int) $asset->id;
         $k = $model->getKeyName();
         $db = $model->getDbo();
         $query = $db->getQuery(true)->update($db->qn($model->getTableName()))->set($db->qn($assetFieldAlias) . ' = ' . (int) $model->{$assetFieldAlias})->where($db->qn($k) . ' = ' . (int) $model->{$k});
         $db->setQuery($query)->execute();
     }
     return true;
 }
예제 #3
0
 /**
  * Builds the query for the ordering list.
  *
  * @since 2.3.2
  *
  * @return \JDatabaseQuery  The query for the ordering form field
  */
 protected function getQuery()
 {
     $ordering = $this->name;
     $title = $this->element['ordertitle'] ? (string) $this->element['ordertitle'] : $this->item->getFieldAlias('title');
     $db = $this->form->getContainer()->platform->getDbo();
     $query = $db->getQuery(true);
     $query->select(array($db->quoteName($ordering, 'value'), $db->quoteName($title, 'text')))->from($db->quoteName($this->item->getTableName()))->order($ordering);
     return $query;
 }
예제 #4
0
파일: Modified.php 프로젝트: akeeba/fof
 /**
  * @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');
     }
 }
예제 #5
0
파일: Created.php 프로젝트: Joal01/fof
 /**
  * @param   DataModel  $model
  * @param   \stdClass  $dataObject
  */
 public function onBeforeCreate(&$model, &$dataObject)
 {
     // Handle the created_on field
     if ($model->hasField('created_on')) {
         $nullDate = $model->getDbo()->getNullDate();
         $created_on = $model->getFieldValue('created_on');
         if (empty($created_on) || $created_on == $nullDate) {
             $model->setFieldValue('created_on', $model->getContainer()->platform->getDate()->toSql(false, $model->getDbo()));
             $createdOnField = $model->getFieldAlias('created_on');
             $dataObject->{$createdOnField} = $model->getFieldValue('created_on');
         }
     }
     // Handle the created_by field
     if ($model->hasField('created_by')) {
         $created_by = $model->getFieldValue('created_by');
         if (empty($created_by)) {
             $model->setFieldValue('created_by', $model->getContainer()->platform->getUser()->id);
             $createdByField = $model->getFieldAlias('created_by');
             $dataObject->{$createdByField} = $model->getFieldValue('created_by');
         }
     }
 }
예제 #6
0
 /**
  * Apply the ordering field
  *
  * @param \FOF30\Model\DataModel $model
  * @param \SimpleXMLElement      $headerSet
  * @param \SimpleXMLElement      $fieldSet
  * @param array                  $allFields
  */
 private function applyOrderingField(DataModel $model, \SimpleXMLElement &$headerSet, \SimpleXMLElement &$fieldSet, array &$allFields)
 {
     $langDefs = $this->getFieldLabel('ordering');
     $this->addString($langDefs['label']['key'], $langDefs['label']['value']);
     $this->addString($langDefs['desc']['key'], $langDefs['desc']['value']);
     $fieldName = $model->getFieldAlias('ordering');
     $header = $headerSet->addChild('header');
     $header->addAttribute('name', $fieldName);
     $header->addAttribute('type', 'Ordering');
     $header->addAttribute('label', $langDefs['label']['key']);
     $header->addAttribute('sortable', 'true');
     $header->addAttribute('tdwith', '1%');
     $field = $fieldSet->addChild('field');
     $field->addAttribute('name', $fieldName);
     $field->addAttribute('type', 'Ordering');
     $field->addAttribute('label', $langDefs['label']['key']);
     $field->addAttribute('class', 'input-mini input-sm');
     unset($allFields[$fieldName]);
 }