Exemple #1
0
 public function save($forceOperation = false)
 {
     parent::save($forceOperation);
     if ($this->newFileUploaded) {
         $this->moveFile();
     }
 }
 public function save($forceOperation = false)
 {
     if (!$this->isExistingRecord()) {
         $this->setNextPosition();
     }
     parent::save($forceOperation);
 }
Exemple #3
0
 protected function insert()
 {
     if (is_null($this->position->get())) {
         $this->setLastPosition('type');
     }
     parent::insert();
 }
Exemple #4
0
 /**
  * Gets an existing record instance (persisted on a database).
  * @param mixed $recordID
  *
  * @param bool $loadRecordData
  * @param bool $loadReferencedRecords
  * @param array $data	Record data array (may include referenced record data)
  *
  * @return DeliveryZone
  */
 public static function getInstanceByID($recordID, $loadRecordData = false, $loadReferencedRecords = false, $data = array())
 {
     if (0 == $recordID && $loadRecordData) {
         return self::getDefaultZoneInstance();
     } else {
         return parent::getInstanceByID(__CLASS__, $recordID, $loadRecordData, $loadReferencedRecords, $data);
     }
 }
Exemple #5
0
 public static function transformArray($array, ARSchema $schema)
 {
     $array = parent::transformArray($array, $schema);
     $array['formattedPrice'] = array();
     foreach (self::getApplication()->getCurrencySet() as $id => $currency) {
         $array['formattedPrice'][$id] = $currency->getFormattedPrice(self::getPriceDiff($id, $array['priceDiff']));
     }
     return $array;
 }
Exemple #6
0
 public function delete()
 {
     if (ActiveRecordModel::getApplication()->getConfig()->get('CLONE_STORE_TYPE') == 'CLONE_STORE_MASTER') {
         return parent::delete();
     } else {
         ActiveRecordModel::executeUpdate('SET FOREIGN_KEY_CHECKS=0');
         ActiveRecordModel::executeUpdate('UPDATE ' . __CLASS__ . ' SET typeID=NULL, protectedFields="|typeID|" WHERE ID=' . $this->getID());
     }
 }
 protected function insert()
 {
     // get max position
     $f = new ARSelectFilter();
     $f->setCondition($this->getParentCondition());
     $f->setOrder(new ARFieldHandle(get_class($this), 'position'), 'DESC');
     $f->setLimit(1);
     $rec = ActiveRecord::getRecordSetArray(get_class($this), $f);
     $position = is_array($rec) && count($rec) > 0 ? $rec[0]['position'] + 1 : 1;
     $this->position->set($position);
     return parent::insert();
 }
 public function autoComplete()
 {
     $f = new ARSelectFilter();
     $f->setLimit(20);
     $resp = array();
     $field = $this->request->get('field');
     if ('specField_' == substr($field, 0, 10)) {
         list($foo, $id) = explode('_', $field);
         $handle = new ARFieldHandle('EavStringValue', 'value');
         $locale = $this->locale->getLocaleCode();
         $searchHandle = MultilingualObject::getLangSearchHandle($handle, $locale);
         $f->setCondition(new EqualsCond(new ARFieldHandle('EavStringValue', 'fieldID'), $id));
         $f->mergeCondition(new LikeCond($handle, '%:"' . $this->request->get($field) . '%'));
         $f->mergeCondition(new LikeCond($searchHandle, $this->request->get($field) . '%'));
         $f->setOrder($searchHandle, 'ASC');
         $results = ActiveRecordModel::getRecordSet('EavStringValue', $f);
         foreach ($results as $value) {
             $resp[$value->getValueByLang('value', $locale, MultilingualObject::NO_DEFAULT_VALUE)] = true;
         }
         $resp = array_keys($resp);
     }
     return new AutoCompleteResponse($resp);
 }
Exemple #9
0
 /**
  * Load service rates record set
  *
  * @param ARSelectFilter $filter
  * @param bool $loadReferencedRecords
  *
  * @return ARSet
  */
 public static function getRecordSet(ARSelectFilter $filter, $loadReferencedRecords = false)
 {
     return parent::getRecordSet(__CLASS__, $filter, $loadReferencedRecords);
 }
Exemple #10
0
 /**
  *	Returns array representations
  *
  *	@return array
  */
 public function toArray()
 {
     $array = parent::toArray();
     $imagePath = $this->getImagePath();
     if (file_exists($imagePath)) {
         $array['imagePath'] = $imagePath;
     }
     $this->setArrayData($array);
     return $array;
 }
Exemple #11
0
 protected function insert()
 {
     // get current max position
     if (!$this->position->get()) {
         $filter = new ARSelectFilter();
         $cond = new EqualsCond(new ARFieldHandle(get_class($this), $this->getFieldIDColumnName()), $this->getField()->get()->getID());
         $filter->setCondition($cond);
         $filter->setOrder(new ARFieldHandle(get_class($this), 'position'), 'DESC');
         $filter->setLimit(1);
         $res = ActiveRecordModel::getRecordSet(get_class($this), $filter);
         if ($res->size() > 0) {
             $item = $res->get(0);
             $pos = $item->position->get() + 1;
         } else {
             $pos = 0;
         }
         $this->position->set($pos);
     }
     return parent::insert();
 }
Exemple #12
0
 public function __destruct()
 {
     unset($this->specificationInstance);
     unset($this->pricingHandlerInstance);
     parent::destruct(array('defaultImageID', 'parentID'));
 }
Exemple #13
0
 public static function transformArray($array, ARSchema $schema, $ownerClass, $ownerField)
 {
     $array = parent::transformArray($array, $schema);
     if (!$array['ID']) {
         return $array;
     }
     $array['paths'] = $array['urls'] = array();
     $app = self::getApplication();
     $router = $app->getRouter();
     foreach (call_user_func(array($schema->getName(), 'getImageSizes')) as $key => $value) {
         $productID = isset($array[$ownerClass]['ID']) ? $array[$ownerClass]['ID'] : (isset($array[$ownerField]) ? $array[$ownerField] : false);
         if (!$productID) {
             break;
         }
         $urlPrefix = null;
         $array['paths'][$key] = self::getRelativePath(call_user_func_array(array($schema->getName(), 'getImagePath'), array($array['ID'], $productID, $key)), $urlPrefix);
         $url = $app->getFullUploadUrl($urlPrefix . $array['paths'][$key]);
         $url = str_replace('/public//public/', '/public/', $url);
         $array['urls'][$key] = $url;
     }
     $array['paths']['original'] = self::getRelativePath(call_user_func_array(array($schema->getName(), 'getImagePath'), array($array['ID'], $productID, 'original')), $urlPrefix);
     return $array;
 }
Exemple #14
0
 protected function importAttributes(ActiveRecordModel $instance, $record, $fields, $attrIdentifier = 'eavField')
 {
     if (isset($fields[$attrIdentifier])) {
         $impReq = new Request();
         $fieldClass = ucfirst($attrIdentifier);
         $valueClass = 'eavField' == $attrIdentifier ? 'EavValue' : $fieldClass . 'Value';
         foreach ($fields[$attrIdentifier] as $specFieldID => $csvIndex) {
             if (empty($record[$csvIndex])) {
                 continue;
             }
             $attr = ActiveRecordModel::getInstanceByID($fieldClass, $specFieldID, ActiveRecord::LOAD_DATA);
             if ($attr->isSimpleNumbers()) {
                 $impReq->set($attr->getFormFieldName(), (double) $record[$csvIndex]);
             } else {
                 if ($attr->isSelector()) {
                     if ($attr->isMultiValue->get()) {
                         $values = explode(',', $record[$csvIndex]);
                     } else {
                         $values = array($record[$csvIndex]);
                     }
                     foreach ($values as $fieldValue) {
                         $fieldValue = trim($fieldValue);
                         $f = new ARSelectFilter(new LikeCond(MultilingualObject::getLangSearchHandle(new ARFieldHandle($valueClass, 'value'), $this->application->getDefaultLanguageCode()), $fieldValue . '%'));
                         $f->setLimit(1);
                         if (!($value = $attr->getRelatedRecordSet($valueClass, $f)->shift())) {
                             $value = call_user_func_array(array($valueClass, 'getNewInstance'), array($attr));
                             if ($attr->type->get() == EavFieldCommon::TYPE_NUMBERS_SELECTOR) {
                                 $value->value->set($fieldValue);
                             } else {
                                 $value->setValueByLang('value', $this->application->getDefaultLanguageCode(), $fieldValue);
                             }
                             $value->save();
                         }
                         if (!$attr->isMultiValue->get()) {
                             $impReq->set($attr->getFormFieldName(), $value->getID());
                         } else {
                             $impReq->set($value->getFormFieldName(), true);
                         }
                     }
                 } else {
                     $impReq->set($attr->getFormFieldName(), $record[$csvIndex]);
                 }
             }
         }
         $instance->loadRequestData($impReq);
         $instance->save();
     }
 }
Exemple #15
0
 public function __clone()
 {
     parent::__clone();
     $this->choices = null;
     $this->save();
     $defaultChoice = $this->originalRecord->defaultChoice->get();
     foreach ($this->originalRecord->getChoiceSet() as $choice) {
         $newChoice = clone $choice;
         $newChoice->option->set($this);
         $newChoice->save();
         if ($defaultChoice && $choice->getID() == $defaultChoice->getID()) {
             $this->defaultChoice->set($newChoice);
         }
     }
     $this->save();
 }
Exemple #16
0
 public function __destruct()
 {
     unset($this->specificationInstance);
     unset($this->pricingHandlerInstance);
     if ($this->removedRelationships) {
         $this->removedRelationships->__destruct();
         unset($this->removedRelationships);
     }
     if ($this->relationships) {
         foreach ($this->relationships as $set) {
             $set->__destruct();
         }
         unset($this->relationships);
     }
     parent::destruct(array('defaultImageID', 'parentID'));
 }
Exemple #17
0
 private function getNewsPostEntry($row, $params)
 {
     $row['title'] = unserialize($row['title']);
     $row = MultilingualObject::transformArray($row, ActiveRecord::getSchemaInstance('NewsPost'));
     return array('loc' => $this->router->createFullUrl(createNewsPostUrl(array('news' => $row), $this->application)));
 }
Exemple #18
0
 public function toArray()
 {
     $this->getSpecification();
     return parent::toArray();
 }
Exemple #19
0
 public static function getNewInstance()
 {
     return parent::getNewInstance(__CLASS__);
 }
Exemple #20
0
 public static function transformArray($array, ARSchema $schema)
 {
     $array = parent::transformArray($array, $schema);
     if (!empty($array['name_lang'])) {
         $array['handle'] = createHandleString($array['name_lang']);
     }
     return $array;
 }
Exemple #21
0
 private static function loadLanguageCodes()
 {
     $app = self::getApplication();
     self::$currentLanguageCode = $app->getLocaleCode();
     self::$defaultLanguageCode = $app->getDefaultLanguageCode();
 }
 public function toArray($currencyID = null)
 {
     $array = parent::toArray();
     $rs = ProductPrice::getRecurringProductPeriodPrices($this, $currencyID);
     $currencies = array();
     if ($rs && $rs->size()) {
         $mapping = array(ProductPrice::TYPE_PERIOD_PRICE => 'ProductPrice_period', ProductPrice::TYPE_SETUP_PRICE => 'ProductPrice_setup');
         while (false != ($item = $rs->shift())) {
             $itemArray = $item->toArray();
             if ($itemArray['type'] == ProductPrice::TYPE_SETUP_PRICE || $itemArray['type'] == ProductPrice::TYPE_PERIOD_PRICE) {
                 $array[$mapping[$itemArray['type']]][$itemArray['currencyID']] = $itemArray;
                 if (array_key_exists($itemArray['currencyID'], $currencies) == false) {
                     $currencies[$itemArray['currencyID']] = Currency::getInstanceByID($itemArray['currencyID']);
                 }
                 $array[$mapping[$itemArray['type']]]['formated_price'][$itemArray['currencyID']] = $currencies[$itemArray['currencyID']]->getFormattedPrice($itemArray['price']);
             }
         }
     }
     return $array;
 }
Exemple #23
0
 public function __clone()
 {
     parent::__clone();
     foreach ($this->optionChoices as $key => $option) {
         $newOpt = clone $option;
         $newOpt->orderedItem->set($this);
         $newOpt->choice->setAsModified();
         $this->optionChoices[$key] = $newOpt;
     }
 }
Exemple #24
0
 protected function insert()
 {
     $this->setLastPosition();
     parent::insert();
 }
Exemple #25
0
 protected function insert()
 {
     $this->setLastPosition('category');
     return parent::insert();
 }
Exemple #26
0
 protected function insert()
 {
     if (!$this->deliveryZone->get() || $this->deliveryZone->get()->isDefault()) {
         $this->deliveryZone->setNull();
     }
     return parent::insert();
 }
Exemple #27
0
 /**
  *	Returns SpecField array representations
  *
  *	@return array
  */
 public function toArray()
 {
     $array = parent::toArray();
     $array['fieldName'] = $this->getFormFieldName();
     $this->setArrayData($array);
     return $array;
 }