public function move($direction) { $nb_cats = SimpleBlogCategory::getNbCats($this->id_parent); if ($direction != 'l' && $direction != 'r') { return false; } if ($nb_cats <= 1) { return false; } if ($direction == 'l' && $this->position <= 1) { return false; } if ($direction == 'r' && $this->position >= $nb_cats) { return false; } $new_position = $direction == 'l' ? $this->position - 1 : $this->position + 1; Db::getInstance()->execute(' UPDATE `' . _DB_PREFIX_ . 'simpleblog_category` sbc SET position = ' . (int) $this->position . ' WHERE id_parent = ' . (int) $this->id_parent . ' AND position = ' . (int) $new_position); $this->position = $new_position; return $this->update(); }
public function postProcess() { if (Tools::isSubmit('viewsimpleblog_category') && ($id_simpleblog_category = (int) Tools::getValue('id_simpleblog_category')) && ($SimpleBlogCategory = new SimpleBlogCategory($id_simpleblog_category, $this->context->language->id)) && Validate::isLoadedObject($SimpleBlogCategory)) { $redir = $SimpleBlogCategory->getObjectLink($id_lang); Tools::redirectAdmin($redir); } if (Tools::isSubmit('deleteCover')) { $this->deleteCover((int) Tools::getValue('id_simpleblog_category')); } if (($id_simpleblog_category = (int) Tools::getValue('id_simpleblog_category')) && ($direction = Tools::getValue('move')) && Validate::isLoadedObject($SimpleBlogCategory = new SimpleBlogCategory($id_simpleblog_category))) { if ($SimpleBlogCategory->move($direction)) { Tools::redirectAdmin(self::$currentIndex . '&token=' . $this->token); } } elseif (Tools::getValue('position') && !Tools::isSubmit('submitAdd' . $this->table)) { if ($this->tabAccess['edit'] !== '1') { $this->errors[] = Tools::displayError('You do not have permission to edit this.'); } elseif (!Validate::isLoadedObject($object = new SimpleBlogCategory((int) Tools::getValue($this->identifier)))) { $this->errors[] = Tools::displayError('An error occurred while updating the status for an object.') . ' <b>' . $this->table . '</b> ' . Tools::displayError('(cannot load object)'); } if (!$object->updatePosition((int) Tools::getValue('way'), (int) Tools::getValue('position'))) { $this->errors[] = Tools::displayError('Failed to update the position.'); } else { Tools::redirectAdmin(self::$currentIndex . '&conf=5&token=' . Tools::getAdminTokenLite('AdminSimpleBlogCategories')); } } else { // Temporary add the position depend of the selection of the parent category if (!Tools::isSubmit('id_simpleblog_category')) { $_POST['position'] = SimpleBlogCategory::getNbCats(Tools::getValue('id_parent')); } } return parent::postProcess(); }