/**
  *
  * @return type
  */
 public function getParent()
 {
     if (NULL === $this->_parent) {
         $this->_parent = OrgService::load($this->getParentId());
     }
     return $this->_parent;
 }
 public function testOrgConfigMaster()
 {
     $org = $this->_service->load(self::MASTER_ORG_ID);
     $config = $this->_service->getOrgConfig($org);
     $this->assertInstanceOf('Application\\Model\\Organization\\Types\\OrgConfigModel', $config);
     $this->assertEmpty($config->exportData());
 }
 public function impersonateAction()
 {
     // Session user
     $user = $this->_getUser();
     if ($this->getRequest()->isPost()) {
         if (!$this->_hasParam('orgId')) {
             throw new InvalidArgumentException("Organization Id is required");
         }
         $orgId = $this->_getParam('orgId');
         $org = $this->_orgSrv->load($orgId);
         if (!isset($org)) {
             throw new InvalidArgumentException("Invalid organization: " . $orgId);
         }
         $this->_helper->allowed('impersonate', $org);
         $this->_userSrv->impersonate($org);
         $this->view->data = $orgId;
     } else {
         if ($this->getRequest()->isDelete()) {
             if (!$user->isImpersonating()) {
                 throw new InvalidArgumentException("User is not impersonating.");
             }
             $this->_userSrv->impersonate();
             $this->view->data = true;
         } else {
             throw new ForbiddenException("Impersonate must be a post or delete request");
         }
     }
 }
 public function testActivate()
 {
     // Persist the org model
     $this->_org->save();
     $this->_service->deactivate($this->_org->getId());
     $org = $this->_service->load($this->_org->getId());
     $this->assertEquals($org->status, OrgAggregatorModel::ORG_STATUS_DEACTIVATED);
     $this->_service->activate($this->_org->getId());
     $org = $this->_service->load($this->_org->getId());
     $this->assertEquals($org->status, OrgAggregatorModel::ORG_STATUS_ACTIVATED);
 }
 /**
  * AUX METHODS
  */
 protected function _getOrganization()
 {
     $orgId = $this->_getParam('orgId', null);
     if (empty($orgId)) {
         throw new \Application\Exceptions\ValidateException('Invalid parameter value: orgId.');
     }
     $org = $this->_orgSrv->load($orgId);
     if (empty($org)) {
         throw new \Application\Exceptions\NotFoundException("Resource {$orgId} does not exists");
     }
     return $org;
 }
 /**
  * Deletes the given organization
  */
 public function deleteAction()
 {
     // Try to load the chosen organization
     $id = $this->getRequest()->getParam('id');
     $org = $this->_orgSrv->load($id);
     if (empty($org)) {
         throw new NotFoundException('Organization ' . $id . ' not found', 404);
     }
     // Check permissions
     $this->_helper->allowed('delete', $org);
     $this->_orgSrv->delete($org);
     $this->view->data = true;
 }
 public function changeBillingCycleStartDayAction()
 {
     if ($this->getRequest()->isPost()) {
         // Get params
         $id = $this->getRequest()->getParam('id');
         $org = $this->_orgSrv->load($id);
         // Check permissions
         $this->_helper->allowed('update_field_billingAccounts:*:billingCycleStartDay', $org);
         // Change billing day
         $data = $this->_helper->requestData();
         $this->_orgSrv->changeBillingCycleStartDay($id, @$data['billingAccountId'], @$data['billingCycleStartDay']);
     }
 }
 /**
  * AUX METHODS
  */
 protected function _getOrganization()
 {
     $orgId = $this->_getParam('orgId', null);
     if (empty($orgId)) {
         $e = new \Application\Exceptions\MissingParameterException('Customer id not defined');
         $e->setParamName('customerId');
         throw $e;
     }
     try {
         $type = OrgService::getInstance()->getTypeById($orgId);
     } catch (Exception $e) {
         throw new AppEx\InvalidArgumentException('Invalid parameter value: customerId. Supported values are customer-xxxxxxxx');
     }
     if ($type != OrgCustomerModel::ORG_TYPE) {
         throw new AppEx\InvalidArgumentException('Invalid parameter value: customerId. Supported values are customer-xxxxxxxx');
     }
     $org = $this->_orgSrv->load($orgId);
     if (empty($org)) {
         throw new \Application\Exceptions\NotFoundException("Resource {$orgId} does not exists");
     }
     return $org;
 }
 /**
  * @expectedException Application\Exceptions\InvalidArgumentException
  */
 public function testLoadOrgWithoutId()
 {
     $org = $this->_service->load(null);
 }