/** * 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; }
/** * Sets attributes (i.e. fields) on the model * * This must be used when setting data to be saved. Otherwise, the properties * will be attached directly to the model itself and not included in the save. * * @param array|string $key The key to set, or array of key/value pairs * @param mixed $value The value to set if key is string * @return object $this Chainable * @since 2.1.0 */ public function set($key, $value = null) { if (is_string($key) && $key == 'guest') { return $this->guest = $value; } if (is_string($key) && $key == 'uidNumber') { $key = 'id'; } return parent::set($key, $value); }