public function get_entry_revisions()
 {
     $CI =& get_instance();
     $CI->load->model('revisions_model');
     $Revisions = new Revisions_model();
     $Revisions->where_related('revision_resource_types', 'key_name', 'ENTRY')->where('resource_id', $this->id)->order_by('id', 'desc')->get();
     return $Revisions;
 }
Exemple #2
0
 function save_inline_content()
 {
     if (!is_ajax()) {
         return show_404();
     }
     $this->load->model('entries_model');
     $this->load->model('revisions_model');
     $this->load->add_package_path(APPPATH . 'modules/content/content_fields');
     $response['status'] = 'success';
     $data = array();
     foreach ($_POST as $key => $content) {
         // Preg match the entry id and the field id from the html element's id attribute
         if (preg_match("/cc_field_(\\d+)_(\\d+|title)/", $key, $matches)) {
             $entry_id = $matches[1];
             $field_id = $matches[2];
             // Build a new data array sorted by entry
             $data[$entry_id]['field_id_' . $field_id] = $content;
         }
     }
     foreach ($data as $entry_id => $fields) {
         $Entry = new Entries_model();
         // If user not a super admin check if user's group is allowed access
         if ($this->Group_session->type != SUPER_ADMIN) {
             $Entry->group_start()->where('restrict_admin_access', 0)->or_where_related('content_types/admin_groups', 'group_id', $this->Group_session->id)->group_end();
         }
         $Entry->get_by_id($entry_id);
         // Either entry doesn't exist or user doesn't have permission to it so skip it
         if (!$Entry->exists()) {
             continue;
         }
         $Content_type = $Entry->content_types->get();
         // Load content fields library
         $config['Entry'] = $Entry;
         $config['content_type_id'] = $Entry->content_type_id;
         $Content_fields = $this->load->library('content_fields');
         $Content_fields->initialize($config);
         // Get content fields html
         $field_validation = $Content_fields->inline_validate();
         // Validation and process form
         if ($this->form_validation->run() == TRUE && $field_validation) {
             if (isset($fields['field_id_title'])) {
                 $Entry->title = $fields['field_id_title'];
             }
             $Entry->modified_date = date('Y-m-d H:i:s');
             $Entry->save();
             $Content_fields->from_array($fields);
             $Content_fields->save();
             // Add Revision if versioing enabled
             if ($Content_type->enable_versioning) {
                 // Delete old revsions so that not to exceed max revisions setting
                 $Revision = new Revisions_model();
                 $Revision->where_related('revision_resource_types', 'key_name', 'ENTRY')->where('resource_id', $entry_id)->order_by('id', 'desc')->limit(25, $Content_type->max_revisions - 1)->get()->delete_all();
                 // Serialize and save post data to entry revisions table
                 $User = $this->secure->get_user_session();
                 $Revision = new Revisions_model();
                 $Revision->resource_id = $Entry->id;
                 $Revision->revision_resource_type_id = Revision_resource_types_model::ENTRY;
                 $Revision->content_type_id = $Entry->content_type_id;
                 $Revision->author_id = $User->id;
                 $Revision->author_name = $User->first_name . ' ' . $User->last_name;
                 $Revision->revision_date = date('Y-m-d H:i:s');
                 $Revision->revision_data = serialize($this->input->post());
                 $Revision->save();
             }
         }
     }
     // Check if there were any validation errors
     if (validation_errors()) {
         $validation_errors = validation_errors("-", " ");
         $response['status'] = 'error';
         $response['message'] = $validation_errors;
     }
     // Clear cache so updates will show on next page load
     $this->load->library('cache');
     $this->cache->delete_all('entries');
     // Clear navigation cache so updates will show on next page load
     $this->load->library('navigations/navigations_library');
     $this->navigations_library->clear_cache();
     echo json_encode($response);
 }
 public function delete_revisions()
 {
     $CI =& get_instance();
     $CI->load->model('revisions_model');
     $Revisions = new Revisions_model();
     $Revisions->where_related('revision_resource_types', 'key_name', 'CONTENT_TYPE')->where('resource_id', $this->id)->get();
     $Revisions->delete_all();
 }