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::exists($id)) { BackendBlocksModel::update($item); } } // success output $this->output(self::OK, null, 'sequence updated'); }
/** * 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']); } } }