示例#1
0
 public static function blocks_of_type($type)
 {
     $numb_type = array();
     $block_ids = Block::getBlockIdsOfType($type);
     if (!empty($block_ids)) {
         $sw = ThemeBlock::whereIn('block_id', $block_ids)->where('show_in_pages', '=', 1)->count();
         $templates = TemplateBlock::whereIn('block_id', $block_ids)->groupBy('template_id')->get(array('template_id', DB::raw('count(*) as type')));
         foreach ($templates as $template) {
             $numb_type[$template->template_id] = $sw + $template->type;
         }
     }
     return $numb_type;
 }
示例#2
0
 public function delete()
 {
     $page_name = PageLang::getName($this->id);
     $log_id = AdminLog::new_log('Page \'' . $page_name . '\' deleted (Page ID ' . $this->id . ')');
     // make backups
     $page_versions = PageVersion::where('page_id', '=', $this->id);
     $page_langs = PageLang::where('page_id', '=', $this->id);
     $page_blocks = PageBlock::where('page_id', '=', $this->id);
     $menu_items = MenuItem::where('page_id', '=', $this->id)->orWhere('page_id', 'LIKE', $this->id . ',%');
     $user_role_page_actions = UserRolePageAction::where('page_id', '=', $this->id);
     $page_groups = PageGroupPage::where('page_id', '=', $this->id);
     $publish_request_ids = [];
     foreach ($page_versions as $page_version) {
         $publish_request_ids[] = $page_version->id;
     }
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\Page', $this);
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageVersion', $page_versions->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageLang', $page_langs->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageBlock', $page_blocks->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\MenuItem', $menu_items->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\UserRolePageAction', $user_role_page_actions->get());
     Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageGroupPage', $page_groups->get());
     // publish requests
     if (!empty($publish_request_ids)) {
         $page_publish_requests = PagePublishRequests::where('page_version_id', '=', $publish_request_ids);
         Backup::new_backup($log_id, '\\CoasterCms\\Models\\PagePublishRequests', $page_publish_requests->get());
         $page_publish_requests->delete();
     }
     // repeater data
     $repeater_block_ids = Block::getBlockIdsOfType('repeater');
     if (!empty($repeater_block_ids)) {
         $repeater_blocks = PageBlock::whereIn('block_id', $repeater_block_ids)->where('page_id', $this->id)->get();
         if (!$repeater_blocks->isEmpty()) {
             $repeater_ids = [];
             foreach ($repeater_blocks as $repeater_block) {
                 $repeater_ids[] = $repeater_block->content;
             }
             $repeater_row_keys = PageBlockRepeaterRows::whereIn('repeater_id', $repeater_ids);
             $repeater_row_keys_get = $repeater_row_keys->get();
             if (!$repeater_row_keys_get->isEmpty()) {
                 $row_keys = [];
                 foreach ($repeater_row_keys_get as $repeater_row_key) {
                     $row_keys[] = $repeater_row_key->id;
                 }
                 $repeater_data = PageBlockRepeaterData::whereIn('row_key', $row_keys);
                 Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageBlockRepeaterRows', $repeater_row_keys->get());
                 Backup::new_backup($log_id, '\\CoasterCms\\Models\\PageBlockRepeaterData', $repeater_data->get());
                 $repeater_data->delete();
                 $repeater_row_keys->delete();
             }
         }
     }
     // delete data
     $this->groups()->detach();
     $page_versions->delete();
     $page_langs->delete();
     $page_blocks->delete();
     $menu_items->delete();
     $user_role_page_actions->delete();
     PageSearchData::where('page_id', '=', $this->id)->delete();
     parent::delete();
     $return_log_ids = array($log_id);
     $child_pages = self::where('parent', '=', $this->id)->get();
     if (!empty($child_pages)) {
         foreach ($child_pages as $child_page) {
             $log_ids = $child_page->delete();
             $return_log_ids = array_merge($log_ids, $return_log_ids);
         }
     }
     sort($return_log_ids);
     return $return_log_ids;
 }