Ejemplo n.º 1
0
 /**
  * this method returns a Propel ModelCriteria
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildModelCriteria()
 {
     $search = CustomerFamilyQuery::create();
     /* manage translations */
     $this->configureI18nProcessing($search, array('TITLE'));
     if (null !== ($id = $this->getId())) {
         $search->filterById($id, Criteria::IN);
     }
     if (null !== ($code = $this->getCode())) {
         $search->filterByCode($code, Criteria::IN);
     }
     if (null !== ($excludeId = $this->getExcludeId())) {
         $search->filterById($excludeId, Criteria::NOT_IN);
     }
     return $search;
 }
Ejemplo n.º 2
0
 /**
  * @param $code
  * @param null $title
  * @param string $locale
  *
  * @return Model\CustomerFamily
  */
 public static function getCustomerFamilyByCode($code, $title = null, $locale = "fr_FR")
 {
     if ($title == null) {
         $title = $code;
     }
     /** @var CustomerFamilyModel $customerFamily */
     if (null == ($customerFamily = CustomerFamilyQuery::create()->useCustomerFamilyI18nQuery()->filterByLocale($locale)->endUse()->filterByCode($code)->findOne())) {
         //Be sure that you don't create it twice
         /** @var CustomerFamilyModel $customerF */
         if (null != ($customerF = CustomerFamilyQuery::create()->findOneByCode($code))) {
             $customerF->setLocale($locale)->setTitle($title)->save();
         } else {
             $customerFamily = new CustomerFamilyModel();
             $customerFamily->setCode($code)->setLocale($locale)->setTitle($title)->save();
         }
     }
     return $customerFamily;
 }
 /**
  * Performs an INSERT on the database, given a CustomerFamily or Criteria object.
  *
  * @param mixed               $criteria Criteria or CustomerFamily 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(CustomerFamilyTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from CustomerFamily object
     }
     if ($criteria->containsKey(CustomerFamilyTableMap::ID) && $criteria->keyContainsValue(CustomerFamilyTableMap::ID)) {
         throw new PropelException('Cannot insert a value for auto-increment primary key (' . CustomerFamilyTableMap::ID . ')');
     }
     // Set the correct dbName
     $query = CustomerFamilyQuery::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;
 }
 /**
  * Get the associated ChildCustomerFamily object
  *
  * @param      ConnectionInterface $con Optional Connection object.
  * @return                 ChildCustomerFamily The associated ChildCustomerFamily object.
  * @throws PropelException
  */
 public function getCustomerFamily(ConnectionInterface $con = null)
 {
     if ($this->aCustomerFamily === null && $this->customer_family_id !== null) {
         $this->aCustomerFamily = ChildCustomerFamilyQuery::create()->findPk($this->customer_family_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->aCustomerFamily->addCustomerCustomerFamilies($this);
            */
     }
     return $this->aCustomerFamily;
 }
Ejemplo n.º 5
0
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see CustomerFamily::setDeleted()
  * @see CustomerFamily::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(CustomerFamilyTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCustomerFamilyQuery::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;
     }
 }
 /**
  * Validate a field only if the customer family is valid
  *
  * @param string                    $value
  * @param ExecutionContextInterface $context
  */
 public function checkCustomerFamily($value, ExecutionContextInterface $context)
 {
     if (CustomerFamilyQuery::create()->filterByCode($value)->count() == 0) {
         $context->addViolation(self::trans('The customer family is not valid'));
     }
 }
 /**
  * @param CustomerCreateOrUpdateEvent $event
  */
 public function customerUpdateProfile(CustomerCreateOrUpdateEvent $event)
 {
     $form = $this->request->request->get(self::THELIA_CUSTOMER_UPDATE_FORM_NAME);
     if (is_null($form) or !array_key_exists(CustomerFamilyFormListener::CUSTOMER_FAMILY_CODE_FIELD_NAME, $form)) {
         // Nothing to update => stop here !
         return;
     }
     // Erase SIRET and VAT if the customer is now in the 'particular' customer family.
     if ($form[CustomerFamilyFormListener::CUSTOMER_FAMILY_CODE_FIELD_NAME] == CustomerFamily::CUSTOMER_FAMILY_PARTICULAR) {
         $siret = '';
         $vat = '';
     } else {
         $siret = $form[CustomerFamilyFormListener::CUSTOMER_FAMILY_SIRET_FIELD_NAME];
         $vat = $form[CustomerFamilyFormListener::CUSTOMER_FAMILY_VAT_FIELD_NAME];
     }
     $newCustomerFamily = CustomerFamilyQuery::create()->findOneByCode($form[CustomerFamilyFormListener::CUSTOMER_FAMILY_CODE_FIELD_NAME]);
     $updateEvent = new CustomerCustomerFamilyEvent($event->getCustomer()->getId());
     $updateEvent->setCustomerFamilyId($newCustomerFamily->getId())->setSiret($siret)->setVat($vat);
     $event->getDispatcher()->dispatch(CustomerFamilyEvents::CUSTOMER_CUSTOMER_FAMILY_UPDATE, $updateEvent);
 }
 public function deleteAction($id)
 {
     if (null !== ($response = $this->checkAuth(array(AdminResources::MODULE), array('CustomerFamily'), AccessManager::DELETE))) {
         return $response;
     }
     $error = "";
     $form = new CustomerFamilyDeleteForm($this->getRequest());
     try {
         $formValidate = $this->validateForm($form);
         $customerFamily = CustomerFamilyQuery::create()->findPk($id);
         if ($customerFamily === null) {
             throw new \Exception("Customer Family not found by Id");
         }
         $event = new CustomerFamilyEvent($customerFamily);
         $this->dispatch(CustomerFamilyEvents::CUSTOMER_FAMILY_DELETE, $event);
     } catch (\Exception $e) {
         $error = $e->getMessage();
     }
     $message = Translator::getInstance()->trans("Customer family was deleted successfully", array(), CustomerFamily::MODULE_DOMAIN);
     return self::renderAdminConfig($form, $message, $error);
 }