Esempio n. 1
0
 /**
  * Joins the related table together for the pending query
  *
  * @return  $this
  * @since   2.0.0
  **/
 public function join()
 {
     // We do a left outer join here because we're not trying to limit the primary table's results
     // This function is primarily used when needing to sort by a field in the joined table
     $this->model->select($this->model->getQualifiedFieldName('*'))->join($this->related->getTableName(), $this->model->getQualifiedFieldName($this->localKey), $this->related->getQualifiedFieldName($this->relatedKey), 'LEFT OUTER');
     return $this;
 }
Esempio n. 2
0
 /**
  * Gets the asset id for the object instance
  *
  * @return  int
  * @since   2.0.0
  **/
 public function getId()
 {
     // Check for current asset id and compute other vars
     $current = $this->model->get('asset_id', null);
     $parentId = $this->getAssetParentId();
     $name = $this->getAssetName();
     $title = $this->getAssetTitle();
     // Get joomla jtable model for assets
     $asset = \JTable::getInstance('Asset', 'JTable', array('dbo' => \App::get('db')));
     $asset->loadByName($name);
     // Re-inject the asset id into the model
     $this->model->set('asset_id', $asset->id);
     if ($asset->getError()) {
         return false;
     }
     // Specify how a new or moved node asset is inserted into the tree
     if (!$this->model->get('asset_id', null) || $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 ($this->model->assetRules instanceof \JAccessRules) {
         $asset->rules = (string) $this->model->assetRules;
     }
     if (!$asset->check() || !$asset->store()) {
         return false;
     }
     // Register an event to update the asset name once we know the model id
     if ($this->model->isNew()) {
         $me = $this;
         Event::listen(function ($event) use($asset, $me) {
             $asset->name = $me->getAssetName();
             $asset->store();
         }, $this->model->getTableName() . '_new');
     }
     // Return the id
     return (int) $asset->id;
 }