public function assignAggregatorAction()
 {
     if (!$this->getRequest()->isPost()) {
         throw new AppEx\UnexpectedException("Resquest must be POST");
     }
     $data = $this->_helper->requestData();
     $cgId = $data['cgId'];
     if (!isset($cgId) && !strlen($cgId)) {
         throw new AppEx\InvalidArgumentException('You must indicate a commercial group id');
     }
     $commercialGroup = $this->_cgSrv->load($cgId);
     // Check permissions
     $this->_helper->allowed('assign_aggregator', $commercialGroup);
     //GLOBALPORTAL-34278
     //TODO: very hacky approach don't like it
     $commercialGroupData = $commercialGroup->exportData();
     $commercialGroupData = $this->_cgSrv->cleanDataForUpdate($commercialGroupData);
     $commercialGroupData = $this->_cgSrv->clearDataForUpdate($commercialGroupData);
     $commercialGroup->importData($commercialGroupData);
     if (empty($commercialGroup)) {
         throw new NotFoundException("Commercial Group {$cgId} not found", 404);
     }
     $aggregatorId = $data['aggregatorId'];
     if (!isset($aggregatorId) && !strlen($aggregatorId)) {
         throw new AppEx\InvalidArgumentException('You must indicate a aggregator id');
     }
     $aggregator = Application\Service\OrgService::getInstance()->load($aggregatorId);
     if (empty($aggregator)) {
         throw new Exceptions\NotFoundException("Aggregator given not found");
     }
     $result = $this->_cgSrv->assignAggregator($commercialGroup, $aggregatorId);
     // Response with the organization id
     $this->view->data = $result;
 }
 public function isValid($value)
 {
     if (!$this->getType()) {
         throw new Application\Exceptions\InvalidArgumentException('Not organization type defined.');
     }
     if (is_string($value)) {
         try {
             $newValue = Application\Service\OrgService::getInstance()->getTypeById($value);
         } catch (Exception $e) {
             \App::log()->warn($e);
             $this->_error(self::INVALID_DATA, $value);
             return false;
         }
     } else {
         if ($value instanceof Application\Model\OrgModelAbstract) {
             $newValue = $value::ORG_TYPE;
         }
     }
     if (!is_string($value) || !$newValue) {
         $this->_error(self::INVALID_DATA, $newValue);
         return false;
     }
     if ($newValue != $this->getType()) {
         $this->_error(self::NOT_VALID_ORG_TYPE, $newValue);
         return false;
     }
     return true;
 }
 public function testUpdateTrialDuration()
 {
     $this->loginByUserId(\App_Test_PHPUnit_Framework_TestCase::PROVIDER_COMMERCIAL_API_ID, $this->_authType);
     $data = array('customerData' => array('trialDuration' => 12));
     $this->put($this->_controllerUrl . '/' . $this->_customerId, $this->_queryParams, $data);
     $org = Application\Service\OrgService::getInstance()->load($this->_customerId);
     $this->assertEquals(12, $org->trialDuration);
 }
 protected function _getResource($value)
 {
     if (is_string($value)) {
         $value = Application\Service\OrgService::getInstance()->load($value);
     }
     if (!$value instanceof Application\Model\OrgModelAbstract) {
         $this->_error(self::INVALID_DATA);
         return false;
     }
     return $value;
 }
Beispiel #5
0
 /**
  * Validate element value
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($data, $context = null, $removeNotPresentFields = false)
 {
     if ($context && isset($context['organizationId']) && $context['organizationId']) {
         $orgId = $context['organizationId'];
         try {
             $orgType = Application\Service\OrgService::getInstance()->getTypeById($orgId);
             $this->setOrgType($orgType);
         } catch (Exception $e) {
             \App::log()->warn($e);
         }
     }
     return parent::isValid($data, $context, $removeNotPresentFields);
 }
 public function testFindAllByParentId()
 {
     //TODO: @alfred dice que lo arregla, lo curioso es que si ejecutas el
     //test solo funciona, si ejecutas todos da un error de permisos
     $this->markTestIncomplete();
     $masterData = array('name' => 'ORG_TEST_PARENT1' . microtime(true), 'description' => "Description", 'status' => OrgMasterModel::ORG_STATUS_ACTIVATED, 'defaultLanguage' => "es", 'type' => OrgMasterModel::ORG_TYPE, 'primaryContact' => array('firstName' => 'pcfn', 'lastName' => 'pcln', 'phone' => '933453212', 'email' => '*****@*****.**', 'mobile' => '665348765', 'fax' => '933453232'), 'companyAddress' => array('line1' => 'line1', 'line2' => 'line2', 'city' => 'Barcelona', 'state' => 'Catalunya', 'region' => 'Barcelona', 'country' => 'ES', 'postalCode' => '08005'));
     $masters = array(new OrgMasterModel($masterData), new OrgMasterModel(array('name' => 'ORG_TEST_PARENT2' . microtime(true)) + $masterData));
     foreach ($masters as $parent) {
         $parent->save();
     }
     $childData = $this->_model->exportData();
     if (isset($childData['id'])) {
         unset($childData['id']);
     }
     $parentId = $masters[0]->getId();
     //         $this->_addUser(OrganizationMapper::cleanOrgId($parentId), OrgMasterModel::ORG_TYPE);
     $childData['parentId'] = $parentId;
     for ($i = 0; $i < 3; $i++) {
         $childData['name'] = 'child' . $i . 'ofParent1' . microtime(true);
         $childData['commercialName'] = 'child' . $i . 'ofParent1-' . microtime(true);
         $child = new OrgServiceProviderModel($childData);
         $child->save();
     }
     $filterList = \Application\Service\OrgService::getInstance()->buildFilterList(array('parentId' => $parentId, 'type' => OrgServiceProviderModel::ORG_TYPE));
     $childsParent1 = $this->_mapper->findAll(array('filterList' => $filterList))->getItems();
     $this->assertTrue(is_array($childsParent1));
     $this->assertEquals(3, count($childsParent1));
     $parentId = $masters[1]->getId();
     $this->_addUser(OrganizationMapper::cleanOrgId($parentId), OrgMasterModel::ORG_TYPE);
     $childData['parentId'] = $parentId;
     for ($i = 0; $i < 5; $i++) {
         $childData['name'] = 'child' . $i . 'ofParent2' . microtime(true);
         $childData['commercialName'] = 'child' . $i . 'ofParent2-' . microtime(true);
         $child = new OrgServiceProviderModel($childData);
         $child->save();
     }
     $filterList = Application\Service\OrgService::getInstance()->buildFilterList(array('parentId' => $parentId, 'type' => OrgServiceProviderModel::ORG_TYPE));
     $childsParent2 = $this->_mapper->findAll(array('filterList' => $filterList))->getItems();
     $this->assertTrue(is_array($childsParent2));
     $this->assertEquals(5, count($childsParent2));
     $this->_addUser(OrganizationMapper::cleanOrgId($masters[0]), OrgMasterModel::ORG_TYPE);
     foreach ($childsParent1 as $child) {
         $child->delete();
     }
     $this->_addUser(OrganizationMapper::cleanOrgId($masters[1]), OrgMasterModel::ORG_TYPE);
     foreach ($childsParent2 as $child) {
         $child->delete();
     }
     foreach ($masters as $parent) {
         $parent->delete();
     }
 }
Beispiel #7
0
 /**
  *
  * Enter description here ...
  * @param  \Application\Model\OrgModelAbstract $setOrg
  * @return \Application\Model\OrgModelAbstract
  * @throws UnexpectedValueException
  */
 public static function getOrgUserLogged($setOrg = NULL)
 {
     static $org;
     if (NULL !== $setOrg) {
         $org = $setOrg;
     }
     if (empty($org)) {
         $user = Zend_Auth::getInstance()->getIdentity();
         $org = Application\Service\OrgService::getInstance()->load($user['orgId']);
         if ($org === null) {
             throw new UnexpectedValueException("App::getOrgUserLogged User Organization is null");
         }
     }
     return $org;
 }