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 (BackendCatalogModel::existsCategory($id)) {
             BackendCatalogModel::updateCategory($item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Beispiel #2
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         $recordId = $this->record['id'];
         $newParent = $this->frm->getField('parent_id')->getValue();
         if ($recordId == $newParent) {
             $this->frm->getField('parent_id')->setError(BL::err('SameCategory'));
         }
         // validate fields
         if ($this->frm->getField('image')->isFilled()) {
             $this->frm->getField('image')->isAllowedExtension(array('jpg', 'png', 'gif', 'jpeg'), BL::err('JPGGIFAndPNGOnly'));
             $this->frm->getField('image')->isAllowedMimeType(array('image/jpg', 'image/png', 'image/gif', 'image/jpeg'), BL::err('JPGGIFAndPNGOnly'));
         }
         $this->meta->validate();
         //--Validate Media
         $this->media->validate();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['language'] = $this->record['language'];
             $item['extra_id'] = $this->record['extra_id'];
             $item['title'] = $this->frm->getField('title_nl')->getValue();
             $item['parent_id'] = $this->frm->getField('parent_id')->getValue();
             $item['meta_id'] = $this->meta->save(true);
             $item['ballcolor'] = $this->frm->getField('ballcolor')->getValue();
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/' . $this->getModule() . '/categories';
             // create folders if needed
             $fs = new Filesystem();
             if (!$fs->exists($imagePath . '/150x150/')) {
                 $fs->mkdir($imagePath . '/150x150/');
             }
             if (!$fs->exists($imagePath . '/source/')) {
                 $fs->mkdir($imagePath . '/source/');
             }
             if (!$fs->exists($imagePath . '/800x')) {
                 $fs->mkdir($imagePath . '/800x');
             }
             if (!$fs->exists($imagePath . '/400x480')) {
                 $fs->mkdir($imagePath . '/400x480');
             }
             if ($this->frm->getField('delete_image')->isChecked()) {
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
                 $item['image'] = null;
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 // build the image name
                 $item['image'] = $this->meta->getUrl() . '.' . $this->frm->getField('image')->getExtension();
                 // upload the image & generate thumbnails
                 $this->frm->getField('image')->generateThumbnails($imagePath, $item['image']);
             }
             // update the item
             BackendCatalogModel::updateCategory($item);
             //--Add the languages
             foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                 $itemLanguage = array();
                 $itemLanguage['id'] = $item['id'];
                 $itemLanguage['language'] = $language;
                 $itemLanguage['title'] = $this->frm->getField('title_' . $language)->getValue();
                 $itemLanguage['description'] = $this->frm->getField('description_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLForCategoryLanguage($this->frm->getField('title_' . $language)->getValue(), $item['id'], $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::updateCategoryLanguage($itemLanguage);
             }
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_category', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('categories') . '&report=edited-category&var=' . urlencode($this->frm->getField('title_nl')->getValue()) . '&highlight=row-' . $item['id']);
         }
     }
 }