Example #1
0
 function approve($id)
 {
     if ($_POST) {
         $rs = new Category($id);
         $rs->from_array($_POST);
         $rs->save();
     }
     // echo $_POST['status'];
 }
Example #2
0
 function approve($id)
 {
     if ($_POST) {
         $categories = new Category($id);
         $_POST['approve_id'] = $this->session->userdata('id');
         $categories->from_array($_POST);
         $categories->save();
     }
 }
Example #3
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $category = new Category($id);
         $_POST['name'] = lang_encode($_POST['name']);
         $category->from_array($_POST);
         $category->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('newsletters/admin/categories/member_index');
 }
Example #4
0
 function save($id = FALSE)
 {
     if ($_POST) {
         $category = new Category($id);
         if (!$id) {
             $_POST['user_id'] = $this->session->userdata('id');
         }
         $_POST['name'] = lang_encode($_POST['name']);
         $category->from_array($_POST);
         $category->save();
         set_notify('success', lang('save_data_complete'));
     }
     redirect('galleries/admin/categories');
 }
Example #5
0
 function edit($id = FALSE)
 {
     if ($_POST) {
         $c = new Category($id);
         $c->from_array($this->input->post(), array('name', 'color'));
         if ($c->save()) {
             $this->session->set_flashdata('msg', '<div class="alert alert-success">Category was edited succesfully</div>');
             redirect('categories/index');
         } else {
             $this->data['errors'] = $c->error->all;
         }
     }
     $this->data['c'] = new Category($id);
 }
Example #6
0
 function save_orderlist($id = FALSE)
 {
     if ($_POST) {
         foreach ($_POST['orderlist'] as $key => $item) {
             if ($item) {
                 $category = new Category(@$_POST['orderid'][$key]);
                 $category->from_array(array('orderlist' => $item));
                 $category->save();
             }
         }
         set_notify('success', lang('save_data_complete'));
     }
     redirect('categories/admin/categories/' . $_POST['module']);
 }
Example #7
0
 function save($id = FALSE)
 {
     if ($_POST) {
         if (isset($_POST['orderlist'])) {
             foreach ($_POST['orderlist'] as $key => $item) {
                 if ($item) {
                     $category = new Category(@$_POST['orderid'][$key]);
                     $category->from_array(array('orderlist' => $item));
                     $category->save();
                 }
             }
             set_notify('success', lang('save_data_complete'));
         } else {
             $category = new Category($id);
             $_POST['name'] = lang_encode($_POST['name']);
             $category->from_array($_POST);
             $category->save();
             set_notify('success', lang('save_data_complete'));
         }
     }
     redirect('webboards/admin/categories');
 }
 function index()
 {
     list($params, $id, $slug) = $this->parse_params(func_get_args());
     // Create or update
     if ($this->method != 'get') {
         $c = new Category();
         switch ($this->method) {
             case 'post':
             case 'put':
                 if ($this->method == 'put') {
                     if (is_null($id)) {
                         $this->error('403', 'Required parameter "id" not present.');
                         return;
                     }
                     // Update
                     $c->get_by_id($id);
                     if (!$c->exists()) {
                         $this->error('404', "Category with ID: {$id} not found.");
                         return;
                     }
                 }
                 // Don't allow these fields to be saved generically
                 $private = array('album_count', 'content_count', 'text_count');
                 foreach ($private as $p) {
                     unset($_POST[$p]);
                 }
                 if (!$c->from_array($_POST, array(), true)) {
                     // TODO: More info
                     $this->error('500', 'Save failed.');
                     return;
                 }
                 $this->redirect("/categories/{$c->id}");
                 break;
             case 'delete':
                 if (is_null($id)) {
                     $this->error('403', 'Required parameter "id" not present.');
                     return;
                 } else {
                     if (is_numeric($id)) {
                         $category = $c->get_by_id($id);
                         $title = $category->title;
                         if ($category->exists()) {
                             $s = new Slug();
                             $this->db->query("DELETE FROM {$s->table} WHERE id = 'category.{$category->slug}'");
                             if (!$category->delete()) {
                                 // TODO: More info
                                 $this->error('500', 'Delete failed.');
                                 return;
                             }
                             $id = null;
                         } else {
                             $this->error('404', "Category with ID: {$id} not found.");
                             return;
                         }
                     } else {
                         $id = explode(',', $id);
                         $c->where_in('id', $id);
                         $cats = $c->get_iterated();
                         foreach ($cats as $c) {
                             if ($c->exists()) {
                                 $s = new Slug();
                                 $this->db->query("DELETE FROM {$s->table} WHERE id = 'category.{$c->slug}'");
                                 $c->delete();
                             }
                         }
                     }
                 }
                 exit;
                 break;
         }
     }
     $c = new Category();
     // No id, so we want a list
     if (is_null($id) && !$slug) {
         $final = $c->listing($params);
     } else {
         if (!is_null($id)) {
             $category = $c->get_by_id($id);
         } else {
             if ($slug) {
                 $category = $c->where('slug', $slug)->get();
             }
         }
         if ($category->exists()) {
             $options = array('page' => 1, 'limit' => 50);
             $options = array_merge($options, $params);
             $category_arr = $category->to_array($options);
             $options['category'] = $category->id;
             list($final, $counts) = $this->aggregate('category', $options);
             $prev = new Category();
             $next = new Category();
             $prev->where('title <', $category->title)->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '>', 0), null)->order_by('title DESC, id DESC');
             $next->where('title >', $category->title)->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '>', 0), null)->order_by('title ASC, id ASC');
             $max = $next->get_clone()->count();
             $min = $prev->get_clone()->count();
             $context = array('total' => $max + $min + 1, 'position' => $min + 1);
             $prev->limit(1)->get();
             $next->limit(1)->get();
             unset($options['category']);
             if ($prev->exists()) {
                 $context['previous'] = array($prev->to_array($options));
             } else {
                 $context['previous'] = array();
             }
             if ($next->exists()) {
                 $context['next'] = array($next->to_array($options));
             } else {
                 $context['next'] = array();
             }
             $final = array_merge($category_arr, $final);
             $final['counts'] = $counts;
             $final['context'] = $context;
         } else {
             $this->error('404', "Category with ID: {$id} not found.");
             return;
         }
     }
     $this->set_response_data($final);
 }