Exemplo n.º 1
0
 protected function categories(\Base $f3, $params)
 {
     if (isset($params[2])) {
         $params = $this->parametric($params[2]);
     }
     $this->response->addTitle($f3->get('LN__AdminMenu_Categories'));
     $f3->set('title_h3', $f3->get('LN__AdminMenu_Categories'));
     if (isset($params['move'])) {
         $parent = $this->model->moveCategory($params['move'][1], $params['move'][0]);
         \Model\Routines::instance()->cacheCategories($parent);
     } elseif (isset($params['add'])) {
         $parent_cid = (isset($params['add']) and $params['add'] !== TRUE) ? (int) $params['add'] : 0;
         if (isset($_POST['form_data'])) {
             $newID = $this->model->addCategory($parent_cid, $f3->get('POST.form_data'));
         }
         if (empty($newID)) {
             // Attempted to add category, but failed
             if (@$newID === FALSE) {
                 $errors = '__failAddCategory';
             }
             $parent_info = $this->model->loadCategory($parent_cid);
             // Non-existent category, go back to overview
             if ($parent_info === FALSE) {
                 $f3->reroute('/adminCP/archive/categories', false);
             }
             // Form
             $data = ['errors' => @$errors, 'changes' => @$changes, 'id' => $parent_cid, 'info' => @$parent_info];
             $this->buffer(\View\AdminCP::addCategory($f3, $data));
             // Leave function without creating further forms or mishap
             return TRUE;
         } else {
             $f3->set('changes', 1);
         }
     } elseif (isset($params['delete'])) {
         $data = $this->model->loadCategory((int) $params['delete']);
         if (isset($data['category'])) {
             $data['stats'] = json_decode($data['stats'], TRUE);
             if ($data['stats']['sub'] === NULL and $data['stats']['count'] == 0) {
                 if (FALSE === $this->model->deleteCategory((int) $params['delete'])) {
                     $errors = $f3->get('ACP_Categories_Error_DBError', $data['category']);
                 } else {
                     $changes = $f3->get('ACP_Categories_Success_Deleted', $data['category']);
                 }
             } else {
                 $errors = $f3->get('ACP_Categories_Error_notEmpty', $data['category']);
             }
         } else {
             $errors = $f3->get('ACP_Categories_Error_badID');
         }
     } elseif (isset($_POST) and sizeof($_POST) > 0) {
         if (isset($_POST['form_data'])) {
             $changes = $this->model->saveCategory($params['id'], $f3->get('POST.form_data'));
         }
     }
     if (isset($params['id'])) {
         $data = $this->model->loadCategory($params['id']);
         $data['move'] = $this->model->loadCategoryPossibleParents($params['id']);
         if ($data['leveldown'] > 1) {
             $parent = $this->model->loadCategory($data['move'][0]['parent_cid']);
             $data['move'] = array_merge([["cid" => $parent['id'], "parent_cid" => $parent['parent_cid'], "leveldown" => $parent['leveldown'] - 1, "category" => $parent['category'] . " (one level up)"]], $data['move']);
         }
         $data['move'] = array_merge([["cid" => 0, "parent_cid" => 0, "leveldown" => -1, "category" => "__Category_MainCategory"]], $data['move']);
         $data['stats'] = json_decode($data['stats'], TRUE);
         $data['errors'] = @$errors;
         $data['changes'] = @$changes;
         $this->buffer(\View\AdminCP::editCategory($data));
         return TRUE;
     }
     $data = $this->model->categoriesListFlat();
     $feedback['errors'] = @$errors;
     $feedback['changes'] = @$changes;
     $this->buffer(\View\AdminCP::listCategories($data, $feedback));
 }
Exemplo n.º 2
0
 public function deleteCategory($cid)
 {
     $delete = new \DB\SQL\Mapper($this->db, $this->prefix . 'categories');
     $delete->load(["cid = ?", $cid]);
     if (1 != $delete->count(["cid = ?", $cid])) {
         return FALSE;
     }
     $stats = json_decode($delete->stats, TRUE);
     if ($stats['sub'] === NULL and $stats['count'] == 0) {
         $parent = $delete->parent_cid;
         $delete->erase(["cid = ?", $cid]);
         \Model\Routines::instance()->cacheCategories($parent);
         return TRUE;
     } else {
         return FALSE;
     }
 }