Beispiel #1
0
 function add()
 {
     if (is_ajax() && $this->input->post('files') && $this->input->post('gallery_id')) {
         $this->load->model('gallery_images_model');
         // Get the max sort number for gallery
         $Gallery_image_sort = new Gallery_images_model();
         $sort = $Gallery_image_sort->select_func('MAX', '@sort', 'max_sort')->where('gallery_id', $this->input->post('gallery_id'))->get()->max_sort;
         // Insert selected images
         foreach ($this->input->post('files') as $filename) {
             $Gallery_image = new Gallery_images_model();
             $Gallery_image->filename = urldecode($filename);
             $Gallery_image->gallery_id = $this->input->post('gallery_id');
             $info = pathinfo(urldecode($filename));
             $Gallery_image->title = ucwords(str_replace(array('_', '-'), ' ', $info['filename']));
             $sort++;
             $Gallery_image->sort = $sort;
             $Gallery_image->save();
             unset($Gallery_image);
         }
     } else {
         return show_404();
     }
 }
 function sync_db()
 {
     $CI =& get_instance();
     $CI->load->model('gallery_images_model');
     $CI->load->helper('file');
     $dir_images = $CI->gallery_images_model->directory_images($this->directory);
     $db_images = $CI->gallery_images_model->database_images($this->id);
     $delete_records = array_diff($db_images, $dir_images);
     $insert_records = array_diff($dir_images, $db_images);
     foreach ($delete_records as $id => $filename) {
         // Delete image thumbs
         $info = pathinfo($filename);
         delete_files(CMS_ROOT . ltrim($this->directory, '/') . '/thumbs/' . $info['filename'] . '_' . $info['extension'], TRUE);
         @rmdir(CMS_ROOT . ltrim($this->directory, '/') . '/thumbs/' . $info['filename'] . '_' . $info['extension']);
         // Delete image from database
         $Gallery_image = new Gallery_images_model();
         $Gallery_image->get_by_id($id);
         $Gallery_image->delete_all();
         unset($Gallery_image);
     }
     if (!empty($insert_records)) {
         $Gallery_image_sort = new Gallery_images_model();
         $sort = $Gallery_image_sort->select_func('MAX', '@sort', 'max_sort')->where('gallery_id', $this->id)->get()->max_sort;
         foreach ($insert_records as $filename) {
             $Gallery_image = new Gallery_images_model();
             $Gallery_image->filename = $filename;
             $Gallery_image->gallery_id = $this->id;
             $info = pathinfo($filename);
             $Gallery_image->title = ucwords(str_replace(array('_', '-'), ' ', $info['filename']));
             $sort++;
             $Gallery_image->sort = $sort;
             $Gallery_image->save();
             unset($Gallery_image);
         }
     }
 }