Exemplo n.º 1
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id !== null && BackendBlocksModel::exists($this->id)) {
         parent::execute();
         $this->record = (array) BackendBlocksModel::get($this->id);
         BackendBlocksModel::delete($this->id);
         Model::triggerEvent($this->getModule(), 'after_delete', array('id' => $this->id));
         $this->redirect(Model::createURLForAction('Index') . '&report=deleted&var=' . urlencode($this->record['title']));
     } else {
         $this->redirect(Model::createURLForAction('Index') . '&error=non-existing');
     }
 }
Exemplo n.º 2
0
 /**
  * Execute the action
  */
 public function execute()
 {
     $this->id = $this->getParameter('id', 'int');
     // does the item exist
     if ($this->id == null || !BackendBlocksModel::existsCategory($this->id)) {
         $this->redirect(Model::createURLForAction('categories') . '&error=non-existing');
     }
     // fetch the category
     $this->record = (array) BackendBlocksModel::getCategory($this->id);
     // delete item
     BackendBlocksModel::deleteCategory($this->id);
     Model::triggerEvent($this->getModule(), 'after_delete_category', array('item' => $this->record));
     // category was deleted, so redirect
     $this->redirect(Model::createURLForAction('categories') . '&report=deleted-category&var=' . urlencode($this->record['title']));
 }
Exemplo n.º 3
0
 public function execute()
 {
     parent::execute();
     // get parameters
     $newIdSequence = trim(\SpoonFilter::getPostValue('new_id_sequence', null, '', 'string'));
     // list id
     $ids = (array) explode(',', rtrim($newIdSequence, ','));
     // loop id's and set new sequence
     foreach ($ids as $i => $id) {
         $item['id'] = $id;
         $item['sequence'] = $i + 1;
         // update sequence
         if (BackendBlocksModel::existsCategory($id)) {
             BackendBlocksModel::updateCategory($item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Exemplo n.º 4
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(Language::err('TitleIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['language'] = Language::getWorkingLanguage();
             $item['meta_id'] = $this->meta->save();
             $item['sequence'] = BackendBlocksModel::getMaximumCategorySequence() + 1;
             // save the data
             $item['id'] = BackendBlocksModel::insertCategory($item);
             Model::triggerEvent($this->getModule(), 'after_add_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(Model::createURLForAction('categories') . '&report=added-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Exemplo n.º 5
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(Language::err('TitleIsRequired'));
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = $this->record['language'];
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['meta_id'] = $this->meta->save(true);
             $item['extra_id'] = $this->record['extra_id'];
             // update the item
             BackendBlocksModel::updateCategory($item);
             Model::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(Model::createURLForAction('categories') . '&report=edited-category&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }
Exemplo n.º 6
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         $fields['title']->isFilled(Language::err('FieldIsRequired'));
         // validate meta
         $this->meta->validate();
         // validate redirect
         $redirectValue = $this->frm->getField('redirect')->getValue();
         if ($redirectValue == 'internal') {
             $this->frm->getField('internal_redirect')->isFilled(Language::err('FieldIsRequired'));
         }
         if ($redirectValue == 'external') {
             $this->frm->getField('external_redirect')->isURL(Language::err('InvalidURL'));
         }
         if ($this->frm->isCorrect()) {
             $item['id'] = $this->id;
             $item['language'] = Language::getWorkingLanguage();
             $item['title'] = $fields['title']->getValue();
             $item['text'] = $fields['text']->getValue();
             //$item['link'] = $fields['link']->getValue();
             $item['linktext'] = $fields['linktext']->getValue();
             if ($redirectValue == 'internal') {
                 $item['link'] = null;
                 $item['page_id'] = $this->frm->getField('internal_redirect')->getValue();
             }
             if ($redirectValue == 'external') {
                 $item['link'] = $this->frm->getField('external_redirect')->getValue();
                 $item['page_id'] = null;
             }
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/image';
             // create folders if needed
             if (!\SpoonDirectory::exists($imagePath . '/800x')) {
                 \SpoonDirectory::create($imagePath . '/800x');
             }
             if (!\SpoonDirectory::exists($imagePath . '/x800')) {
                 \SpoonDirectory::create($imagePath . '/x800');
             }
             if (!\SpoonDirectory::exists($imagePath . '/450x250')) {
                 \SpoonDirectory::create($imagePath . '/450x250');
             }
             if (!\SpoonDirectory::exists($imagePath . '/600x300')) {
                 \SpoonDirectory::create($imagePath . '/600x300');
             }
             if (!\SpoonDirectory::exists($imagePath . '/128x128')) {
                 \SpoonDirectory::create($imagePath . '/128x128');
             }
             if (!\SpoonDirectory::exists($imagePath . '/source')) {
                 \SpoonDirectory::create($imagePath . '/source');
             }
             // image provided?
             if ($fields['image']->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getUrl() . '.' . $fields['image']->getExtension();
                 // upload the image & generate thumbnails
                 $fields['image']->generateThumbnails($imagePath, $item['image']);
             }
             $item['hidden'] = $fields['hidden']->getValue();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['extra_id'] = $this->record['extra_id'];
             $item['meta_id'] = $this->meta->save();
             BackendBlocksModel::update($item);
             $item['id'] = $this->id;
             Model::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(Model::createURLForAction('Index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }