Esempio n. 1
0
 /**
  *  Note that the form may not always contain all the fields of the model, so we must always
  *  make sure that the data for the particular field has actually been submitted to avoid
  *  setting empty values for fields that weren't included in the form
  */
 public function loadRequestData(Request $request, $prefix = '')
 {
     $enabledFields = is_array($prefix) ? array_flip($prefix) : null;
     $schema = ActiveRecordModel::getSchemaInstance(get_class($this));
     foreach ($schema->getFieldList() as $field) {
         if (!($field instanceof ARForeignKey || $field instanceof ARPrimaryKey)) {
             $name = $field->getName();
             $reqName = $prefix . $name;
             if (is_array($enabledFields) && !isset($enabledFields[$name])) {
                 continue;
             }
             if ($request->isValueSet($reqName) || $request->isValueSet('checkbox_' . $reqName) && 'ARBool' == get_class($field->getDataType())) {
                 switch (get_class($field->getDataType())) {
                     case 'ARArray':
                         $this->setValueArrayByLang(array($name), self::getApplication()->getDefaultLanguageCode(), self::getApplication()->getLanguageArray(LiveCart::INCLUDE_DEFAULT), $request);
                         break;
                     case 'ARBool':
                         $this->setFieldValue($name, in_array(strtolower($request->get($reqName)), array('on', 1, 'yes', 'true')));
                         break;
                     case 'ARInteger':
                     case 'ARFloat':
                         if (is_numeric($request->get($reqName))) {
                             $this->setFieldValue($name, $request->get($reqName));
                         }
                         break;
                     default:
                         $this->setFieldValue($name, $request->get($reqName));
                         break;
                 }
             }
         }
     }
     if ($this instanceof EavAble) {
         $hasSpecification = $this->isSpecificationLoaded();
         $this->getSpecification()->loadRequestData($request, $prefix);
         if (!$hasSpecification && !$this->getSpecification()->hasValues()) {
             $this->removeSpecification();
         }
     }
 }
 public function isValid($value)
 {
     if ($this->specField->isMultiValue->get()) {
         $other = $this->request->get('other');
         if (isset($other[$this->specField->getID()][0]) && "" != $other[$this->specField->getID()][0]) {
             return true;
         }
         foreach ($this->specField->getValuesSet() as $value) {
             if ($this->request->isValueSet("specItem_" . $value->getID())) {
                 return true;
             }
         }
     } else {
         if ($this->request->isValueSet($this->specField->getFormFieldName())) {
             return true;
         } else {
             if ('other' == $value) {
                 $other = $this->request->get('other');
                 return !empty($other[$this->specField->getID()]);
             }
         }
     }
     return false;
 }
Esempio n. 3
0
 public function setValueArrayByLang($fieldNameArray, $defaultLangCode, $langCodeArray, Request $request)
 {
     foreach ($fieldNameArray as $fieldName) {
         foreach ($langCodeArray as $langCode) {
             if ($langCode == $defaultLangCode) {
                 $requestVarName = $fieldName;
             } else {
                 $requestVarName = $fieldName . "_" . $langCode;
             }
             if ($request->isValueSet($requestVarName)) {
                 $this->setValueByLang($fieldName, $langCode, $request->get($requestVarName));
             }
         }
     }
 }
Esempio n. 4
0
 public function modifyItemOption(OrderedItem $item, ProductOption $option, Request $request, $varName)
 {
     if ($option->isBool() && $request->isValueSet('checkbox_' . $varName)) {
         if ($request->get($varName)) {
             $item->addOptionChoice($option->defaultChoice->get());
         } else {
             $item->removeOption($option);
         }
     } else {
         if ($option->isFile()) {
             if (isset($_FILES['upload_' . $varName])) {
                 $file = $_FILES['upload_' . $varName];
                 if (!empty($file['name'])) {
                     $item->removeOption($option);
                     $choice = $item->addOptionChoice($option->defaultChoice->get());
                     $choice->setFile($_FILES['upload_' . $varName]);
                 }
             }
         } else {
             if ($request->get($varName)) {
                 if ($option->isSelect()) {
                     $item->addOptionChoice($option->getChoiceByID($request->get($varName)));
                 } else {
                     if ($option->isText()) {
                         $text = $request->get($varName);
                         if ($text) {
                             $choice = $item->addOptionChoice($option->defaultChoice->get());
                             $choice->optionText->set($text);
                         } else {
                             $item->removeOption($option);
                         }
                     }
                 }
             }
         }
     }
 }
 public function loadRequestData(Request $request, $prefix = '')
 {
     $fields = $this->getSpecificationFieldSet();
     $application = ActiveRecordModel::getApplication();
     // create new select values
     if ($request->isValueSet($prefix . 'other')) {
         foreach ($request->get($prefix . 'other') as $fieldID => $values) {
             $field = call_user_func_array(array($this->getFieldClass(), 'getInstanceByID'), array($fieldID, ActiveRecordModel::LOAD_DATA));
             if (is_array($values)) {
                 // multiple select
                 foreach ($values as $value) {
                     if ($value) {
                         $fieldValue = $field->getNewValueInstance();
                         $fieldValue->setValueByLang('value', $application->getDefaultLanguageCode(), $value);
                         $fieldValue->save();
                         $request->set($prefix . 'specItem_' . $fieldValue->getID(), 'on');
                     }
                 }
             } else {
                 // single select
                 if ('other' == $request->get($prefix . 'specField_' . $fieldID)) {
                     $fieldValue = $field->getNewValueInstance();
                     $fieldValue->setValueByLang('value', $application->getDefaultLanguageCode(), $values);
                     $fieldValue->save();
                     $request->set($prefix . 'specField_' . $fieldID, $fieldValue->getID());
                 }
             }
         }
     }
     $languages = ActiveRecordModel::getApplication()->getLanguageArray(LiveCart::INCLUDE_DEFAULT);
     foreach ($fields as $field) {
         $fieldName = $prefix . $field->getFormFieldName();
         if ($field->isSelector()) {
             if (!$field->isMultiValue->get()) {
                 if ($request->isValueSet($fieldName) && !in_array($request->get($fieldName), array('other'))) {
                     if ($request->get($fieldName)) {
                         $this->setAttributeValue($field, $field->getValueInstanceByID($request->get($fieldName), ActiveRecordModel::LOAD_DATA));
                     } else {
                         $this->removeAttribute($field);
                     }
                 }
             } else {
                 $values = $field->getValuesSet();
                 foreach ($values as $value) {
                     if ($request->isValueSet($prefix . $value->getFormFieldName()) || $request->isValueSet($prefix . 'checkbox_' . $value->getFormFieldName())) {
                         if ($request->get($prefix . $value->getFormFieldName())) {
                             $this->setAttributeValue($field, $value);
                         } else {
                             $this->removeAttributeValue($field, $value);
                         }
                     }
                 }
             }
         } else {
             if ($request->isValueSet($fieldName)) {
                 if ($field->isTextField()) {
                     foreach ($languages as $language) {
                         if ($request->isValueSet($prefix . $field->getFormFieldName($language))) {
                             $this->setAttributeValueByLang($field, $language, $request->get($prefix . $field->getFormFieldName($language)));
                         }
                     }
                 } else {
                     if (strlen($request->get($fieldName))) {
                         $this->setAttributeValue($field, $request->get($fieldName));
                     } else {
                         $this->removeAttribute($field);
                     }
                 }
             }
         }
     }
 }
Esempio n. 6
0
 private function loadPricingFromRequest(Request $request, $listPrice = false)
 {
     $field = $listPrice ? 'listPrice' : 'price';
     $currencies = self::getApplication()->getCurrencyArray();
     foreach ($currencies as $currency) {
         $price = $request->get($field . '_' . $currency);
         if (strlen($price)) {
             $this->setPrice($currency, $price, $listPrice);
         } else {
             if ($request->isValueSet($field . '_' . $currency)) {
                 $this->getPricingHandler()->removePriceByCurrencyCode($currency, $listPrice);
             }
         }
     }
 }
Esempio n. 7
0
 /**
  * Connects a new route to some URL pattern.
  * URLPattern might have "variables", which has a ":" at the beggining. e.x. ":action"
  *
  * E.x.:
  * <code>
  * $router->connect(":controller/:action/:id", array(), array("id" => "[0-9]+"));
  * </code>
  *
  * The route above will map to following URL's:
  * item/add/34
  * post/view/9233
  *
  * But not to these:
  * item/add/AC331
  * post/view
  *
  * URLPattern variables :controller :action :id by default might have value from
  * a range [_.a-zA-Z0-9]. When you pass array("id" => "[0-9]") as varRequirements
  * id is required to be only numeric.
  *
  *
  * @link http://www.symfony-project.com/book/trunk/routing
  *
  * @param string $URLPattern
  * @param array $defaultValueList
  * @param array $varRequirements
  *
  */
 public function mapToRoute($URLStr, Request $request)
 {
     if ('/' == substr($URLStr, -1)) {
         $URLStr = substr($URLStr, 0, -1);
     }
     if (empty($URLStr) || !$this->isURLRewriteEnabled) {
         if (!$request->isValueSet("action")) {
             $request->set("action", $this->defaultAction);
         }
         if (!$request->isValueSet("controller")) {
             $request->set("controller", $this->defaultController);
         }
         return false;
     }
     foreach ($this->routeList as $route) {
         $routePattern = str_replace('\\047', '\\/', $route->getRecognitionPattern());
         $routePattern = str_replace('.', '\\.', $routePattern);
         if (preg_match("/^" . $routePattern . "\$/U", $URLStr, $result)) {
             unset($result[0]);
             $varList = $route->getVariableList();
             foreach ($varList as $key => $value) {
                 $request->set($value, $result[$key + 1]);
             }
             $requestValueAssigments = $route->getRequestValueAssigments();
             $request->sanitizeArray($requestValueAssigments);
             $request->setValueArray($requestValueAssigments);
             return $route;
         }
     }
     throw new RouterException("Unable to map to any route");
 }