示例#1
0
文件: Model.php 项目: irto/neomongo
 /**
  * Make new relation from $startDoc to $endDoc of type $type.
  *
  * @param Object $startDoc
  * @param Object $endDoc
  * @param String $type [null]
  *
  * @return instanced this
  */
 public static function make($startDoc, $endDoc, $type = null)
 {
     if (is_null($type)) {
         $type = get_called_class();
     }
     $instance = new static($startDoc, $endDoc);
     $instance->setType($type);
     $instance->isNew(true);
     return $instance;
 }
示例#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;
 }