Example #1
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         // required fields
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['category_id']->getValue() == 'no_category') {
             $fields['category_id']->addError(BL::err('FieldIsRequired'));
         }
         // validate meta
         $this->meta->validate();
         if ($this->frm->isCorrect()) {
             // build the item
             $item['language'] = BL::getWorkingLanguage();
             $item['price'] = $fields['price']->getValue();
             $item['summary'] = $fields['summary_nl']->getValue();
             $item['text'] = $fields['text_nl']->getValue();
             $item['allow_comments'] = $fields['allow_comments']->getChecked() ? 'Y' : 'N';
             $item['num_comments'] = 0;
             $item['sequence'] = BackendCatalogModel::getMaximumSequence() + 1;
             $item['category_id'] = $fields['category_id']->getValue();
             $item['brand_id'] = $fields['brand_id']->getValue();
             $item['meta_id'] = $this->meta->save();
             $item['ballcolor'] = $fields['ballcolor']->getValue();
             $item['frontpage'] = $fields['frontpage']->getChecked();
             $item['contact'] = $fields['contact']->getChecked();
             // insert it
             $item['id'] = BackendCatalogModel::insert($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['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), null, $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::insertLanguage($itemLanguage);
             }
             $specificationArray = array();
             // loop trough specifications and insert values
             foreach ($this->specifications as $specification) {
                 // build the specification
                 $specificationArray['product_id'] = $item['id'];
                 $specificationArray['specification_id'] = $specification['id'];
                 foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                     $field = 'specification' . $specification['id'] . '_' . $language;
                     // check if there is an value
                     if ($fields[$field]->getValue() != null) {
                         $specificationArray['value'] = $fields[$field]->getValue();
                         $specificationArray['language'] = $language;
                         // insert specification with product id and value
                         BackendCatalogModel::insertSpecificationValue($specificationArray);
                     }
                 }
             }
             // save the tags
             BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());
             // save the related products
             BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue());
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue()));
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_add', $item);
             // redirect page
             $this->redirect(BackendModel::createURLForAction('index') . '&report=added&highlight=row-' . $item['id']);
         }
     }
 }
Example #2
0
 /**
  * Validate the form
  */
 protected function validateForm()
 {
     if ($this->frm->isSubmitted()) {
         $this->frm->cleanupFields();
         // validation
         $fields = $this->frm->getFields();
         //            $fields['title']->isFilled(BL::err('FieldIsRequired'));
         //            $fields['summary']->isFilled(BL::err('FieldIsRequired'));
         $fields['category_id']->isFilled(BL::err('FieldIsRequired'));
         if ($fields['category_id']->getValue() == 'no_category') {
             $fields['category_id']->addError(BL::err('FieldIsRequired'));
         }
         // validate meta
         $this->meta->validate();
         //--Validate Media
         $this->media->validate();
         if ($this->frm->isCorrect()) {
             $item['id'] = $this->id;
             $item['language'] = BL::getWorkingLanguage();
             $item['price'] = $fields['price']->getValue();
             $item['category_id'] = $this->frm->getField('category_id')->getValue();
             $item['brand_id'] = $fields['brand_id']->getValue();
             $item['allow_comments'] = $this->frm->getField('allow_comments')->getChecked() ? 'Y' : 'N';
             $item['frontpage'] = $this->frm->getField('frontpage')->getChecked();
             $item['contact'] = $this->frm->getField('contact')->getChecked();
             $item['meta_id'] = $this->meta->save();
             $item['ballcolor'] = $fields['ballcolor']->getValue();
             BackendCatalogModel::update($item);
             $item['id'] = $this->id;
             //--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['summary'] = $this->frm->getField('summary_' . $language)->getValue();
                 $itemLanguage['text'] = $this->frm->getField('text_' . $language)->getValue();
                 $itemLanguage['url'] = BackendCatalogModel::getURLLanguage($this->frm->getField('title_' . $language)->getValue(), $item['id'], $language);
                 $itemLanguage['balltext'] = $this->frm->getField('balltext_' . $language)->getValue();
                 BackendCatalogModel::updateLanguage($itemLanguage, $language);
             }
             $specificationArray = array();
             // loop trough specifications and insert values
             foreach ($this->specifications as $specification) {
                 foreach ((array) BackendModel::get('fork.settings')->get('Core', 'languages') as $key => $language) {
                     $field = 'specification' . $specification['id'] . '_' . $language;
                     $specificationArray['value'] = $fields[$field]->getValue();
                     $specificationArray['language'] = $language;
                     $specificationArray['product_id'] = $item['id'];
                     $specificationArray['specification_id'] = $specification['id'];
                     // when specification value already exists. update value
                     if (BackendCatalogModel::existsSpecificationValue($item['id'], $specification['id'], $language) != false) {
                         // update specification with product id and value
                         BackendCatalogModel::updateSpecificationValue($specification['id'], $item['id'], $language, $specificationArray);
                     } else {
                         // when specification value doesnt exists, insert new value
                         BackendCatalogModel::insertSpecificationValue($specificationArray);
                     }
                 }
             }
             // save the tags
             BackendTagsModel::saveTags($item['id'], $fields['tags']->getValue(), $this->URL->getModule());
             // add search index
             BackendSearchModel::saveIndex($this->getModule(), $item['id'], array('title' => $this->frm->getField('title_nl')->getValue(), 'summary' => $this->frm->getField('summary_nl')->getValue(), 'text' => $this->frm->getField('text_nl')->getValue()));
             // save related projects
             BackendCatalogModel::saveRelatedProducts($item['id'], $this->frm->getField('related_products')->getValue(), $this->relatedProducts);
             // trigger event
             BackendModel::triggerEvent($this->getModule(), 'after_edit', $item);
             $this->redirect(BackendModel::createURLForAction('index') . '&report=edited&highlight=row-' . $item['id']);
         }
     }
 }