Beispiel #1
0
 public function update(AreaUpdateEvent $event)
 {
     if (null !== ($area = AreaQuery::create()->findPk($event->getAreaId()))) {
         $area->setDispatcher($event->getDispatcher())->setName($event->getAreaName())->save();
         $event->setArea($area);
     }
 }
 public function verifyAreaExist($value, ExecutionContextInterface $context)
 {
     $area = AreaQuery::create()->findPk($value);
     if (null === $area) {
         $context->addViolation(Translator::getInstance()->trans("This area doesn't exists."));
     }
 }
Beispiel #3
0
 public function buildModelCriteria()
 {
     $id = $this->getId();
     $search = AreaQuery::create();
     if ($id) {
         $search->filterById($id, Criteria::IN);
     }
     $withZone = $this->getWith_zone();
     if ($withZone) {
         $search->joinAreaDeliveryModule('with_zone')->where('`with_zone`.delivery_module_id ' . Criteria::EQUAL . ' ?', $withZone, \PDO::PARAM_INT);
     }
     $withoutZone = $this->getWithout_zone();
     if ($withoutZone) {
         $search->joinAreaDeliveryModule('without_zone', Criteria::LEFT_JOIN)->addJoinCondition('without_zone', 'delivery_module_id ' . Criteria::EQUAL . ' ?', $withoutZone, null, \PDO::PARAM_INT)->where('`without_zone`.delivery_module_id ' . Criteria::ISNULL);
     }
     $notAssigned = $this->getUnassigned();
     if ($notAssigned) {
         $search->joinAreaDeliveryModule('unassigned', Criteria::LEFT_JOIN)->where('`unassigned`.delivery_module_id ' . Criteria::ISNULL);
     }
     $modules = $this->getModuleId();
     if ($modules) {
         $search->useAreaDeliveryModuleQuery()->filterByDeliveryModuleId($modules, Criteria::IN)->endUse();
     }
     return $search;
 }
Beispiel #4
0
 public function editprices()
 {
     // Get data & treat
     $post = $this->getRequest();
     $operation = $post->get('operation');
     $area = $post->get('area');
     $weight = $post->get('weight');
     $price = $post->get('price');
     if (preg_match("#^add|delete\$#", $operation) && preg_match("#^\\d+\$#", $area) && preg_match("#^\\d+\\.?\\d*\$#", $weight)) {
         // check if area exists in db
         $exists = AreaQuery::create()->findPK($area);
         if ($exists !== null) {
             if (null !== ($data = Colissimo::getConfigValue(ColissimoConfigValue::PRICES, null))) {
                 $json_data = json_decode($data, true);
             }
             if ((double) $weight > 0 && $operation == "add" && preg_match("#\\d+\\.?\\d*#", $price)) {
                 $json_data[$area]['slices'][$weight] = $price;
             } elseif ($operation == "delete") {
                 if (isset($json_data[$area]['slices'][$weight])) {
                     unset($json_data[$area]['slices'][$weight]);
                 }
             } else {
                 throw new \Exception("Weight must be superior to 0");
             }
             ksort($json_data[$area]['slices']);
             Colissimo::setConfigValue(ColissimoConfigValue::PRICES, json_encode($json_data));
         } else {
             throw new \Exception("Area not found");
         }
     } else {
         throw new \ErrorException("Arguments are missing or invalid");
     }
     return $this->redirectToConfigurationPage();
 }
 public function checkArea($value, ExecutionContextInterface $context)
 {
     $check = AreaQuery::create()->findPk($value);
     if ($check === null) {
         $context->addViolation(Translator::getInstance()->trans("The area \"%id\" doesn't exist", ["%id" => $value]));
     }
 }
Beispiel #6
0
 public function delete(AreaDeleteEvent $event)
 {
     if (null !== ($area = AreaQuery::create()->findPk($event->getAreaId()))) {
         $area->setDispatcher($event->getDispatcher());
         $area->delete();
         $event->setArea($area);
     }
 }
 public function editprices()
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('SoColissimo'), AccessManager::UPDATE))) {
         return $response;
     }
     // Get data & treat
     $post = $this->getRequest()->request;
     $operation = $post->get('operation');
     $area = $post->get('area');
     $weight = $post->get('weight');
     $price = $post->get('price');
     if (preg_match("#^add|delete\$#", $operation) && preg_match("#^\\d+\$#", $area) && preg_match("#^\\d+\\.?\\d*\$#", $weight)) {
         // check if area exists in db
         $exists = AreaQuery::create()->findPK($area);
         if ($exists !== null) {
             $json_path = __DIR__ . "/../" . SoColissimo::JSON_PRICE_RESOURCE;
             if (is_readable($json_path)) {
                 $json_data = json_decode(file_get_contents($json_path), true);
             } elseif (!file_exists($json_path)) {
                 $json_data = array();
             } else {
                 throw new \Exception("Can't read So Colissimo" . SoColissimo::JSON_PRICE_RESOURCE . ". Please change the rights on the file.");
             }
             if ((double) $weight > 0 && $operation == "add" && preg_match("#\\d+\\.?\\d*#", $price)) {
                 $json_data[$area]['slices'][$weight] = $price;
             } elseif ($operation == "delete") {
                 if (isset($json_data[$area]['slices'][$weight])) {
                     unset($json_data[$area]['slices'][$weight]);
                 }
             } else {
                 throw new \Exception("Weight must be superior to 0");
             }
             ksort($json_data[$area]['slices']);
             if (file_exists($json_path) ? is_writable($json_path) : is_writable(__DIR__ . "/../")) {
                 $file = fopen($json_path, 'w');
                 fwrite($file, json_encode($json_data));
                 fclose($file);
             } else {
                 throw new \Exception("Can't write So Colissimo" . SoColissimo::JSON_PRICE_RESOURCE . ". Please change the rights on the file.");
             }
         } else {
             throw new \Exception("Area not found");
         }
     } else {
         throw new \ErrorException("Arguments are missing or invalid");
     }
     return $this->generateRedirectFromRoute("admin.module.configure", array(), array('current_tab' => 'price_slices_tab', 'module_code' => "SoColissimo", '_controller' => 'Thelia\\Controller\\Admin\\ModuleController::configureAction'));
 }
Beispiel #8
0
 public function buildModelCriteria()
 {
     $id = $this->getId();
     $search = AreaQuery::create();
     if (count($id)) {
         $search->filterById($id, Criteria::IN);
     }
     $withZone = $this->getWithZone();
     if ($withZone) {
         $search->joinAreaDeliveryModule('with_zone')->where('`with_zone`.delivery_module_id ' . Criteria::EQUAL . ' ?', $withZone, \PDO::PARAM_INT);
     }
     $withoutZone = $this->getWithoutZone();
     if ($withoutZone) {
         $search->joinAreaDeliveryModule('without_zone', Criteria::LEFT_JOIN)->addJoinCondition('without_zone', 'delivery_module_id ' . Criteria::EQUAL . ' ?', $withoutZone, null, \PDO::PARAM_INT)->where('`without_zone`.delivery_module_id ' . Criteria::ISNULL);
     }
     $notAssigned = $this->getUnassigned();
     if ($notAssigned) {
         $search->joinAreaDeliveryModule('unassigned', Criteria::LEFT_JOIN)->where('`unassigned`.delivery_module_id ' . Criteria::ISNULL);
     }
     $modules = $this->getModuleId();
     if (count($modules)) {
         $search->useAreaDeliveryModuleQuery()->filterByDeliveryModuleId($modules, Criteria::IN)->endUse();
     }
     $countries = $this->getCountry();
     if (count($countries)) {
         $search->useCountryAreaQuery()->filterByCountryId($countries, Criteria::IN)->endUse();
     }
     $orders = $this->getOrder();
     foreach ($orders as $order) {
         switch ($order) {
             case 'id':
                 $search->orderById(Criteria::ASC);
                 break;
             case 'id-reverse':
                 $search->orderById(Criteria::DESC);
                 break;
             case "alpha":
                 $search->orderByName(Criteria::ASC);
                 break;
             case "alpha-reverse":
                 $search->orderByName(Criteria::DESC);
                 break;
         }
     }
     return $search;
 }
Beispiel #9
0
 /**
  * Load an existing object from the database
  */
 protected function getExistingObject()
 {
     return AreaQuery::create()->findPk($this->getAreaId());
 }
Beispiel #10
0
 /**
  * Performs an INSERT on the database, given a Area or Criteria object.
  *
  * @param mixed               $criteria Criteria or Area object containing data that is used to create the INSERT statement.
  * @param ConnectionInterface $con the ConnectionInterface connection to use
  * @return mixed           The new primary key.
  * @throws PropelException Any exceptions caught during processing will be
  *         rethrown wrapped into a PropelException.
  */
 public static function doInsert($criteria, ConnectionInterface $con = null)
 {
     if (null === $con) {
         $con = Propel::getServiceContainer()->getWriteConnection(AreaTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from Area object
     }
     if ($criteria->containsKey(AreaTableMap::ID) && $criteria->keyContainsValue(AreaTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . AreaTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = AreaQuery::create()->mergeWith($criteria);
     try {
         // use transaction because $criteria could contain info
         // for more than one table (I guess, conceivably)
         $con->beginTransaction();
         $pk = $query->doInsert($con);
         $con->commit();
     } catch (PropelException $e) {
         $con->rollBack();
         throw $e;
     }
     return $pk;
 }
Beispiel #11
0
 /**
  * Get the associated ChildArea object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildArea The associated ChildArea object.
  * @throws PropelException
  */
 public function getArea(ConnectionInterface $con = null)
 {
     if ($this->aArea === null && $this->area_id !== null) {
         $this->aArea = ChildAreaQuery::create()->findPk($this->area_id, $con);
         /* The following can be used additionally to
               guarantee the related object contains a reference
               to this object.  This level of coupling may, however, be
               undesirable since it could result in an only partially populated collection
               in the referenced object.
               $this->aArea->addCountryAreas($this);
            */
     }
     return $this->aArea;
 }
Beispiel #12
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see Area::setDeleted()
  * @see Area::isDeleted()
  */
 public function delete(ConnectionInterface $con = null)
 {
     if ($this->isDeleted()) {
         throw new PropelException("This object has already been deleted.");
     }
     if ($con === null) {
         $con = Propel::getServiceContainer()->getWriteConnection(AreaTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildAreaQuery::create()->filterByPrimaryKey($this->getPrimaryKey());
         $ret = $this->preDelete($con);
         if ($ret) {
             $deleteQuery->delete($con);
             $this->postDelete($con);
             $con->commit();
             $this->setDeleted(true);
         } else {
             $con->commit();
         }
     } catch (Exception $e) {
         $con->rollBack();
         throw $e;
     }
 }
Beispiel #13
0
 /**
  * Gets the number of ChildArea objects related by a many-to-many relationship
  * to the current object by way of the country_area cross-reference table.
  *
  * @param      Criteria $criteria Optional query object to filter the query
  * @param      boolean $distinct Set to true to force count distinct
  * @param      ConnectionInterface $con Optional connection object
  *
  * @return int the number of related ChildArea objects
  */
 public function countAreas($criteria = null, $distinct = false, ConnectionInterface $con = null)
 {
     if (null === $this->collAreas || null !== $criteria) {
         if ($this->isNew() && null === $this->collAreas) {
             return 0;
         } else {
             $query = ChildAreaQuery::create(null, $criteria);
             if ($distinct) {
                 $query->distinct();
             }
             return $query->filterByCountry($this)->count($con);
         }
     } else {
         return count($this->collAreas);
     }
 }
 public static function importJsonPrice(SocolissimoDeliveryMode $deliveryMode, ConnectionInterface $con)
 {
     $areaPrices = self::getPrices($deliveryMode);
     $priceExist = SocolissimoPriceQuery::create()->filterByDeliveryModeId($deliveryMode->getId())->findOne();
     //If at least one price exist doesn't import the xml (or it will erase the user price)
     if (null !== $priceExist) {
         return;
     }
     $con->beginTransaction();
     try {
         foreach ($areaPrices as $areaId => $area) {
             // Check if the area exists
             if (null !== AreaQuery::create()->findPk($areaId)) {
                 foreach ($area['slices'] as $weight => $price) {
                     $slice = (new SocolissimoPrice())->setAreaId($areaId)->setWeightMax($weight)->setPrice($price)->setDeliveryModeId($deliveryMode->getId());
                     $slice->save();
                 }
                 $con->commit();
             }
         }
     } catch (PropelException $e) {
         $con->rollback();
         throw $e;
     }
 }