示例#1
0
 /**
  * Listen to the Page saved event.
  *
  * @param \Soda\Cms\Models\Page $page
  */
 public function created(Page $page)
 {
     if ($page->page_type_id !== null) {
         //if(!$page->type) $page->load('type');
         ModelBuilder::fromTable('soda_' . $page->type->identifier)->forceFill(['page_id' => $page->id])->save();
     }
 }
示例#2
0
 /**
  * Listen to the Block saved event.
  *
  * @param \Soda\Cms\Models\Block $block
  */
 public function saved(Block $block)
 {
     if ($block->isDirty('is_shared')) {
         if (!$block->type) {
             $block->load('type');
         }
         ModelBuilder::fromTable('soda_' . $block->type->identifier)->where($block->getRelatedField(), $block->id)->update(['is_shared' => $block->is_shared]);
     }
 }
示例#3
0
文件: Block.php 项目: sodacms/sodacms
 public function modelQuery($page_id = null)
 {
     if (!$this->type) {
         $this->load('type');
     }
     return ModelBuilder::fromTable('soda_' . $this->type->identifier)->where($this->getRelatedField(), $this->id)->where(function ($q) use($page_id) {
         $q->where('is_shared', 1);
         if ($page_id) {
             $q->orWhere('page_id', $page_id);
         }
     });
 }
示例#4
0
文件: Soda.php 项目: sodacms/sodacms
 /**
  * Load a dynamic model
  *
  * @param      $table
  * @param bool $autoprefix
  *
  * @return mixed
  */
 public function model($table, $autoprefix = true)
 {
     if ($autoprefix) {
         $table = 'soda_' . $table;
     }
     return ModelBuilder::fromTable($table, []);
 }
示例#5
0
文件: Page.php 项目: sodacms/sodacms
 protected function loadPageAttributes()
 {
     if (!$this->type) {
         $this->load('type');
     }
     if (!$this->type) {
         $model = new ModelBuilder();
     } else {
         $model = ModelBuilder::fromTable('soda_' . $this->type->identifier)->where($this->getRelatedField(), $this->id)->first();
         if (!$model) {
             $model = ModelBuilder::fromTable('soda_' . $this->type->identifier)->newInstance();
         }
     }
     return $this->setPageAttributes($model);
 }