Esempio n. 1
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;
 }
Esempio n. 2
0
 /**
  * Gets an attribute by key
  *
  * This will not retrieve properties directly attached to the model,
  * even if they are public - those should be accessed directly!
  *
  * Also, make sure to access properties in transformers using the get method.
  * Otherwise you'll just get stuck in a loop!
  *
  * @param   string  $key      The attribute key to get
  * @param   mixed   $default  The value to provide, should the key be non-existent
  * @return  mixed
  */
 public function get($key, $default = null)
 {
     if ($key == 'guest') {
         return $this->isGuest();
     }
     if ($key == 'uidNumber') {
         $key = 'id';
     }
     // Legacy code expects get('id') to always
     // return an integer, even if user is logged out
     if ($key == 'id' && is_null($default)) {
         $default = 0;
     }
     return parent::get($key, $default);
 }
Esempio n. 3
0
 /**
  * Gets an attribute by key
  *
  * This will not retrieve properties directly attached to the model,
  * even if they are public - those should be accessed directly!
  *
  * Also, make sure to access properties in transformers using the get method.
  * Otherwise you'll just get stuck in a loop!
  *
  * @param   string  $key      The attribute key to get
  * @param   mixed   $default  The value to provide, should the key be non-existent
  * @return  mixed
  */
 public function get($key, $default = null)
 {
     if ($key == 'id') {
         $key = 'gidNumber';
     }
     // Legacy code expects get('id') to always return an integer
     if ($key == 'gidNumber' && is_null($default)) {
         $default = 0;
     }
     return parent::get($key, $default);
 }