/**
  * this method returns a Propel ModelCriteria
  *
  * @return \Propel\Runtime\ActiveQuery\ModelCriteria
  */
 public function buildModelCriteria()
 {
     $search = CustomerCustomerFamilyQuery::create();
     if (null !== ($customerId = $this->getCustomerId())) {
         $search->filterByCustomerId($customerId, Criteria::IN);
     }
     if (null !== ($customerFamilyId = $this->getCustomerFamilyId())) {
         $search->filterByCustomerFamilyId($customerFamilyId, Criteria::IN);
     }
     return $search;
 }
 /**
  * Removes this object from datastore and sets delete attribute.
  *
  * @param      ConnectionInterface $con
  * @return void
  * @throws PropelException
  * @see CustomerCustomerFamily::setDeleted()
  * @see CustomerCustomerFamily::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(CustomerCustomerFamilyTableMap::DATABASE_NAME);
     }
     $con->beginTransaction();
     try {
         $deleteQuery = ChildCustomerCustomerFamilyQuery::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;
     }
 }
Example #3
0
 /**
  * If this collection has already been initialized with
  * an identical criteria, it returns the collection.
  * Otherwise if this CustomerFamily is new, it will return
  * an empty collection; or if this CustomerFamily has previously
  * been saved, it will retrieve related CustomerCustomerFamilies from storage.
  *
  * This method is protected by default in order to keep the public
  * api reasonable.  You can provide public methods for those you
  * actually need in CustomerFamily.
  *
  * @param      Criteria $criteria optional Criteria object to narrow the query
  * @param      ConnectionInterface $con optional connection object
  * @param      string $joinBehavior optional join type to use (defaults to Criteria::LEFT_JOIN)
  * @return Collection|ChildCustomerCustomerFamily[] List of ChildCustomerCustomerFamily objects
  */
 public function getCustomerCustomerFamiliesJoinCustomer($criteria = null, $con = null, $joinBehavior = Criteria::LEFT_JOIN)
 {
     $query = ChildCustomerCustomerFamilyQuery::create(null, $criteria);
     $query->joinWith('Customer', $joinBehavior);
     return $this->getCustomerCustomerFamilies($query, $con);
 }
 /**
  * Callback used to add some fields to the Thelia's CustomerCreateForm.
  * It add two fields : one for the SIRET number and one for VAT.
  * @param TheliaFormEvent $event
  */
 public function addCustomerFamilyFieldsForUpdate(TheliaFormEvent $event)
 {
     // Adding new fields
     $customer = $this->request->getSession()->getCustomerUser();
     if (is_null($customer)) {
         // No customer => no account update => stop here
         return;
     }
     $customerCustomerFamily = CustomerCustomerFamilyQuery::create()->findOneByCustomerId($customer->getId());
     $cfData = array(self::CUSTOMER_FAMILY_CODE_FIELD_NAME => (is_null($customerCustomerFamily) or is_null($customerCustomerFamily->getCustomerFamily())) ? '' : $customerCustomerFamily->getCustomerFamily()->getCode(), self::CUSTOMER_FAMILY_SIRET_FIELD_NAME => is_null($customerCustomerFamily) ? false : $customerCustomerFamily->getSiret(), self::CUSTOMER_FAMILY_VAT_FIELD_NAME => is_null($customerCustomerFamily) ? false : $customerCustomerFamily->getVat());
     // Retrieving CustomerFamily choices
     $customerFamilyChoices = array();
     /** @var \CustomerFamily\Model\CustomerFamily $customerFamilyChoice */
     foreach (CustomerFamilyQuery::create()->find() as $customerFamilyChoice) {
         $customerFamilyChoices[$customerFamilyChoice->getCode()] = self::trans($customerFamilyChoice->getTitle());
     }
     // Building additional fields
     $event->getForm()->getFormBuilder()->add(self::CUSTOMER_FAMILY_CODE_FIELD_NAME, 'choice', array('constraints' => array(new Constraints\Callback(array('methods' => array(array($this, 'checkCustomerFamily')))), new Constraints\NotBlank()), 'choices' => $customerFamilyChoices, 'empty_data' => false, 'required' => false, 'label' => self::trans('Customer family'), 'label_attr' => array('for' => 'customer_family_id'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_CODE_FIELD_NAME]))->add(self::CUSTOMER_FAMILY_SIRET_FIELD_NAME, 'text', array('required' => true, 'empty_data' => false, 'label' => self::trans('Siret number'), 'label_attr' => array('for' => 'siret'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_SIRET_FIELD_NAME]))->add(self::CUSTOMER_FAMILY_VAT_FIELD_NAME, 'text', array('required' => true, 'empty_data' => false, 'label' => self::trans('Vat'), 'label_attr' => array('for' => 'vat'), 'mapped' => false, 'data' => $cfData[self::CUSTOMER_FAMILY_VAT_FIELD_NAME]));
 }
 /**
  * @param CustomerCustomerFamilyEvent $event
  */
 public function customerCustomerFamilyUpdate(CustomerCustomerFamilyEvent $event)
 {
     $customerCustomerFamily = CustomerCustomerFamilyQuery::create()->findOneByCustomerId($event->getCustomerId());
     if ($customerCustomerFamily === null) {
         $customerCustomerFamily = new CustomerCustomerFamily();
         $customerCustomerFamily->setCustomerId($event->getCustomerId());
     }
     $customerCustomerFamily->setCustomerFamilyId($event->getCustomerFamilyId())->setSiret($event->getSiret())->setVat($event->getVat())->save();
 }
 /**
  * Performs an INSERT on the database, given a CustomerCustomerFamily or Criteria object.
  *
  * @param mixed               $criteria Criteria or CustomerCustomerFamily 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(CustomerCustomerFamilyTableMap::DATABASE_NAME);
     }
     if ($criteria instanceof Criteria) {
         $criteria = clone $criteria;
         // rename for clarity
     } else {
         $criteria = $criteria->buildCriteria();
         // build Criteria from CustomerCustomerFamily object
     }
     // Set the correct dbName
     $query = CustomerCustomerFamilyQuery::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;
 }