Пример #1
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 (BackendCatalogModel::existsBrand($id)) {
             BackendCatalogModel::updateBrand($item);
         }
     }
     // success output
     $this->output(self::OK, null, 'sequence updated');
 }
Пример #2
0
 /**
  * Validate the form
  */
 private function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validate fields
         $this->frm->getField('title')->isFilled(BL::err('TitleIsRequired'));
         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();
         if ($this->frm->isCorrect()) {
             // build item
             $item['id'] = $this->id;
             $item['title'] = $this->frm->getField('title')->getValue();
             $item['meta_id'] = $this->meta->save(true);
             // the image path
             $imagePath = FRONTEND_FILES_PATH . '/catalog/brands';
             // create folders if needed
             $fs = new Filesystem();
             if (!$fs->exists($imagePath . '/source/')) {
                 $fs->mkdir($imagePath . '/source/');
                 $fs->mkdir($imagePath . '/150x150/');
             }
             if ($this->frm->getField('delete_image')->isChecked()) {
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
                 $item['image'] = null;
             }
             // image provided?
             if ($this->frm->getField('image')->isFilled()) {
                 BackendModel::deleteThumbnails($imagePath, $this->record['image']);
                 // 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::updateBrand($item);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit_brand', array('item' => $item));
             // everything is saved, so redirect to the overview
             $this->redirect(BackendModel::createURLForAction('brands') . '&report=edited-brand&var=' . urlencode($item['title']) . '&highlight=row-' . $item['id']);
         }
     }
 }