Ejemplo n.º 1
0
 /**
  * Adds a subscription
  *
  * @param KCommandContext $context
  *
  * @return void
  */
 protected function _actionAdd(KCommandContext $context)
 {
     $payload = $this->_order->getPayload();
     if (!$this->_gateway->process($payload)) {
         throw new ComSubscriptionsDomainPaymentException('Payment error. Check the log');
     }
     $person = $this->_order->getSubscriber();
     $package = $this->_order->getPackage();
     $set = new AnObjectSet();
     $set->insert($this->_order);
     if (!$person->persisted()) {
         $person->reset();
         $user = $person->getJUserObject();
         //encrypt the password
         $user->set('password', $person->getPassword(true));
         $user->set('block', '0');
         $user->save();
         $person = $this->getService('repos://site/people.person')->find(array('userId' => $user->id));
         if ($person) {
             $set->insert($person);
             $this->_order->setSubscriber($person);
         }
     }
     if (!$package->recurring && $person->hasSubscription()) {
         $subscription = $person->changeSubscriptionTo($package);
     } else {
         $subscription = $person->subscribeTo($package);
     }
     $set->insert($subscription);
     if ($payload->getRecurring()) {
         $subscription->setValue('profileId', $payload->getRecurring()->profile_id);
         $subscription->setValue('profileStatus', $payload->getRecurring()->profile_status);
     }
     if (!$this->commit()) {
         $set->delete();
         $this->commit();
         throw new RuntimeException("Subscription can not be added");
     }
     $this->getResponse()->status = KHttpResponse::CREATED;
     dispatch_plugin('subscriptions.onAfterSubscribe', array('subscription' => $subscription));
     $this->setItem($subscription);
     return $subscription;
 }
Ejemplo n.º 2
0
 /**
  * Validates all the entities in the space. Return true if all the entities
  * pass the validation or a set of entities that failed the validation.If a $failed variable
  * is passed by reference, then a set of failed entities will be returend
  * 
  * @param mixed &$failed Return the failed set
  * 
  * @return boolean Return if all the entities passed the validations
  */
 public function validateEntities(&$failed = null)
 {
     $restult = true;
     $failed = new AnObjectSet();
     foreach ($this->getCommitables() as $entity) {
         $restult = $entity->getRepository()->validate($entity);
         if ($restult === false) {
             $failed->insert($entity);
         }
     }
     return $failed->count() === 0;
 }
Ejemplo n.º 3
0
 /**
  * (non-PHPdoc).
  *
  * @see KObjectSet::insert()
  */
 public function insert(KObjectHandlable $object)
 {
     $this->_loadData();
     parent::insert($object);
 }
Ejemplo n.º 4
0
 /**
  * Insert an entity to the aggregation. If multiple target is passed then
  * add the all of them to the collection. It prevents adding the same
  * entity into the its existing collection.
  * 
  * @param AnDomainEntityAbstract|array $target
  * @param array                        $config
  *
  * @return AnDomainEntityAbstract
  */
 public function insert($target, $config = array())
 {
     if (AnHelperArray::isIterable($target)) {
         $targets = AnHelperArray::unique($target);
         $relations = new AnObjectSet();
         foreach ($target as $target) {
             $relations->insert($this->insert($target, $config));
         }
         return $relations;
     }
     $data = array($this->_property => $this->_root, $this->_target_property => $target);
     //shouldn't be able to add the same entity into  the same collection
     $relation = $this->_child->findOrAddNew($data, $config);
     return $relation;
 }