コード例 #1
0
ファイル: TreeModel.php プロジェクト: tamboer/LaravelOctober
 public function __construct($model)
 {
     parent::__construct($model);
     $this->modelClass = get_class($model);
     if (isset($this->model->treeModelParentColumn)) {
         $this->parentColumn = $this->model->treeModelParentColumn;
     }
 }
コード例 #2
0
 public function __construct($model)
 {
     parent::__construct($model);
     if (isset($this->model->sortableModelColumn)) {
         $this->columnName = $this->model->sortableModelColumn;
     }
     $model->bindEvent('model.afterCreate', function () use($model) {
         $this->setSortableOrder($model->id);
     });
 }
コード例 #3
0
ファイル: ModelBehavior.php プロジェクト: nnmer/october
 /**
  * Constructor
  * @param October\Rain\Database\Model $model The extended model.
  */
 public function __construct($model)
 {
     parent::__construct($model);
     /*
      * Validate model properties
      */
     foreach ($this->requiredProperties as $property) {
         if (!isset($model->{$property})) {
             throw new ApplicationException(Lang::get('system::lang.behavior.missing_property', ['class' => get_class($model), 'property' => $property, 'behavior' => get_called_class()]));
         }
     }
 }
コード例 #4
0
 public function __construct($model)
 {
     parent::__construct($model);
     /*
      * Define relationships
      */
     $model->hasMany['children'] = [get_class($model), 'primaryKey' => $this->getParentColumnName(), 'order' => $this->getLeftColumnName()];
     $model->belongsTo['parent'] = [get_class($model), 'foreignKey' => $this->getParentColumnName()];
     /*
      * Model property overrides
      */
     if (isset($this->model->nestedSetModelParentColumn)) {
         $this->parentColumn = $this->model->nestedSetModelParentColumn;
     }
     if (isset($this->model->nestedSetModelLeftColumn)) {
         $this->leftColumn = $this->model->nestedSetModelLeftColumn;
     }
     if (isset($this->model->nestedSetModelRightColumn)) {
         $this->rightColumn = $this->model->nestedSetModelRightColumn;
     }
     if (isset($this->model->nestedSetModelDepthColumn)) {
         $this->depthColumn = $this->model->nestedSetModelDepthColumn;
     }
     /*
      * Bind events
      */
     $model->bindEvent('model.beforeCreate', function () {
         $this->setDefaultLeftAndRight();
     });
     $model->bindEvent('model.beforeSave', function () {
         $this->storeNewParent();
     });
     $model->bindEvent('model.afterSave', function () {
         $this->moveToNewParent();
         $this->setDepth();
     });
     $model->bindEvent('model.beforeDelete', function () {
         $this->deleteDescendants();
     });
 }