コード例 #1
0
ファイル: types.php プロジェクト: mamtasingh87/bytecode
 function add()
 {
     // Init
     $data = array();
     $data['breadcrumb'] = set_crumbs(array('content/types' => 'Content Types', current_url() => 'Add Content Type'));
     $this->load->model('content_types_model');
     $this->load->model('content_types_admin_groups_model');
     $this->load->model('content_fields_model');
     $this->load->model('users/groups_model');
     $this->load->model('category_groups_model');
     // Get theme layouts for theme layout dropdown
     $data['theme_layouts'] = $this->template->get_theme_layouts($this->settings->theme, TRUE);
     // Get all admin groups for admin group access
     $data['Admin_groups'] = $this->groups_model->where('type', ADMINISTRATOR)->order_by('name')->get();
     // Get all user groups except super admin for group access
     $Groups = new Groups_model();
     $data['Groups'] = $Groups->where('type !=', SUPER_ADMIN)->order_by('name')->get();
     // Get all category groups for dropdown
     $data['category_groups'] = option_array_value($this->category_groups_model->order_by('title')->get(), 'id', 'title', array('' => ''));
     // Form Validation
     $this->form_validation->set_rules('title', 'Title', 'trim|required');
     $this->form_validation->set_rules('short_name', 'Short Name', 'trim|required|alpha_dash|max_length[50]|is_unique[content_types.short_name]');
     $this->form_validation->set_rules('enable_dynamic_routing', 'Enable Dynamic Routing', 'trim');
     $this->form_validation->set_rules('enable_versioning', 'Enable Versioning', 'trim|required');
     $this->form_validation->set_rules('max_revisions', 'Max Revisions', 'trim|required|integer|less_than[26]');
     $this->form_validation->set_rules('category_group_id', 'Category Group', 'trim');
     $this->form_validation->set_rules('restrict_admin_access', 'Restrict Admin Access', 'trim|required');
     $this->form_validation->set_rules('selected_admin_groups[]', 'Administrative Access', 'trim');
     $this->form_validation->set_rules('access', 'Access', 'trim|required');
     $this->form_validation->set_rules('restrict_to[]', 'Group Access', 'trim');
     $this->form_validation->set_rules('entries_allowed', 'Number of Entries Allowed', 'trim|integer');
     // Add dynamic route validation if enable dynamic routing checkbox selected
     if ($this->input->post('enable_dynamic_routing') == 1) {
         $this->form_validation->set_rules('dynamic_route', 'Dynamic Route', 'trim|required|max_length[255]|callback_unique_dynamic_route');
     }
     if ($this->form_validation->run() == TRUE) {
         // Save new content type
         $Content_type = new Content_types_model();
         $Content_type->from_array($this->input->post());
         $Content_type->dynamic_route = $this->input->post('dynamic_route') != '' && $this->input->post('enable_dynamic_routing') ? $this->input->post('dynamic_route') : NULL;
         $Content_type->restrict_to = $this->input->post('access') == 2 ? serialize($this->input->post('restrict_to')) : NULL;
         $Content_type->category_group_id = $this->input->post('category_group_id') != '' ? $this->input->post('category_group_id') : NULL;
         $Content_type->theme_layout = $this->input->post('theme_layout') != '' ? $this->input->post('theme_layout') : NULL;
         $Content_type->entries_allowed = $this->input->post('entries_allowed') != '' ? $this->input->post('entries_allowed') : NULL;
         $Content_type->save();
         $Content_type->add_revision();
         // Assign admin groups to this content type
         // if restrict admin access is enabled
         if ($Content_type->restrict_admin_access && is_array($this->input->post('selected_admin_groups'))) {
             $selected_admin_groups = $this->input->post('selected_admin_groups');
             foreach ($selected_admin_groups as $admin_group) {
                 $Content_types_admin_groups = new Content_types_admin_groups_model();
                 $Content_types_admin_groups->content_type_id = $Content_type->id;
                 $Content_types_admin_groups->group_id = $admin_group;
                 $Content_types_admin_groups->save();
             }
         }
         // Clear cache
         $this->load->library('cache');
         $this->cache->delete_all('entries');
         $this->cache->delete_all('content_types');
         redirect(ADMIN_PATH . "/content/types/edit/{$Content_type->id}");
     }
     $this->template->view('admin/types/add', $data);
 }