public function isValid($value, $context = null)
 {
     $this->_messages = array();
     if (!is_string($value)) {
         $message = $this->_createMessage(self::ERROR_INVALID_TYPE, $value);
         $this->_messages[self::ERROR_INVALID_TYPE] = $message;
         return false;
     }
     $service = ServicePackService::getInstance();
     try {
         $list = $service->listAll()->getItems();
     } catch (Application\Exceptions\GlobalServiceException $e) {
         $message = $this->_createMessage(self::ERROR_ON_CONNECTION, $value);
         $this->_messages[self::ERROR_ON_CONNECTION] = $message;
         return false;
     }
     foreach ($list as $sp) {
         if ($sp->getName() === $value) {
             $item = $sp;
             break;
         }
     }
     if (isset($item) && (!isset($context['id']) || $item->getId() != $context['id'])) {
         $message = $this->_createMessage(self::ERROR_SERVICE_PACK_NAME_ALREADY_USED, $value);
         $this->_messages[self::ERROR_SERVICE_PACK_NAME_ALREADY_USED] = $message;
         return false;
     }
     return true;
 }
 public function assert(Zend_Acl $acl, Zend_Acl_Role_Interface $role = null, Zend_Acl_Resource_Interface $resource = null, $privilege = null)
 {
     if (!$resource instanceof CommercialGroupModel) {
         throw new Exception('Resource must be an instance of CommercialGroupModel');
     }
     $service = ServicePackService::getInstance();
     try {
         $spack = $service->load($resource->servicePackId);
     } catch (Exception $e) {
         $spack = null;
     }
     if (!isset($spack)) {
         throw new Exception('No service pack found');
     }
     if ($spack->customers) {
         if ($resource->customerId) {
             foreach ($spack->customers as $custRest) {
                 if ($custRest->customerId == $resource->customerId) {
                     if ($custRest->restricted) {
                         return false;
                     } else {
                         break;
                     }
                 }
             }
         } else {
             throw new Exception('No customer found');
         }
     }
     return true;
 }
 public function init()
 {
     $this->_spSrv = ServicePackService::getInstance();
     $this->_lifeCycleSrv = LifeCycleService::getInstance();
     $this->_restrictionsSrv = RestrictionService::getInstance();
     $this->_tariffSrv = TariffPlanService::getInstance();
     $this->_orgSrv = \Application\Service\OrgService::getInstance();
 }
 public function init()
 {
     $this->_spSrv = ServicePackService::getInstance();
     $this->_lifeCycleSrv = LifeCycleService::getInstance();
     $this->_restrictionsSrv = RestrictionService::getInstance();
     $this->_tariffSrv = TariffPlanService::getInstance();
     $this->_steeringListSrv = SteeringListService::getInstance();
 }
 public function isValid($value, $context = array())
 {
     $this->_messages = array();
     if (!is_string($value)) {
         $this->_error(self::ERROR_INVALID_TYPE, $value);
         return false;
     }
     $service = ServicePackService::getInstance();
     try {
         $item = $service->load($value);
     } catch (\Application\Exceptions\NotFoundException $e) {
         $item = null;
     } catch (\Application\Exceptions\GlobalServiceException $e) {
         $this->_error(self::ERROR_ON_CONNECTION, $value);
         return false;
     }
     if (!isset($item)) {
         $this->_error(self::ERROR_SERVICE_PACK_NOT_FOUND, $value);
         return false;
     }
     if ($this->getCheckRestrictions() && !isset($context['id'])) {
         switch (\App::getOrgUserLogged()->getType()) {
             case OrgCustomerModel::ORG_TYPE:
                 $restriction = $item->getCustomerRestriction(\App::getOrgUserLogged()->id);
                 if ($restriction === false) {
                     break;
                 }
                 if ($restriction === true) {
                     $this->_error(self::ERROR_SERVICE_PACK_RESTRICTED, $value);
                 } else {
                     $this->_error(self::ERROR_SERVICE_PACK_NOT_FOUND, $value);
                 }
                 return false;
             case OrgServiceProviderModel::ORG_TYPE:
                 $restriction = $item->getCustomerRestriction($context['customerId']);
                 if ($restriction === false) {
                     $this->_error(self::ERROR_SERVICE_PACK_NOT_RESTRICTED, $value);
                     return false;
                 }
         }
     }
     if ($this->getCheckPublished() && $item->published !== ServicePackModel::STATUS_PUBLISHED) {
         $this->_error(self::ERROR_SERVICE_PACK_NOT_PUBLISHED, $value);
         return false;
     }
     return true;
 }
 public function isValid($value, $context = array())
 {
     $this->_messages = array();
     if (!is_string($value)) {
         $this->_error(self::ERROR_INVALID_TYPE, $value);
         return false;
     }
     $service = ServicePackService::getInstance();
     try {
         $spack = $service->load($value);
     } catch (\Exception $e) {
         $spack = null;
     }
     if (!isset($spack)) {
         $this->_error(self::NO_SPACK_FOUND);
         return false;
     }
     if (isset($context['customerId'])) {
         $custId = $context['customerId'];
         try {
             $org = OrgService::getInstance()->load($custId);
         } catch (\Exception $e) {
             $org = null;
         }
         if (!isset($org)) {
             $this->_error(self::NO_ORG_FOUND);
             return false;
         }
         if ($org->currency == $spack->currency) {
             return true;
         } else {
             $this->_error(self::NO_CURRENCY_MATCHING);
             return false;
         }
     } else {
         $this->_error(self::NO_CUSTOMER_ID);
         return false;
     }
 }
 public function init()
 {
     $this->_tariffPlanSrv = \Application\Service\TariffPlanService::getInstance();
     $this->_servicePackSrv = \Application\Service\ServicePackService::getInstance();
 }
 public function init()
 {
     $this->_spSrv = ServicePackService::getInstance();
 }
 public function init()
 {
     $this->_spSrv = \Application\Service\ServicePackService::getInstance();
     $this->_orgSrv = \Application\Service\OrgService::getInstance();
 }
 /**
  * @expectedException \Application\Exceptions\ValidateException
  * @expectedExceptionMessage The ServicePack does not pass the validation rules.
  */
 public function testSumaDiscountsValidationException()
 {
     $sp = array("id" => "123", "name" => "BS_All_Act", "description" => "Description", "published" => "PUBLISHED", "customers" => array(array("id" => "customer-4ddd31cd0e49ad4073000003", "name" => "customer")), "serviceProviderId" => "provider-movistar1376f0c049eGAFyImcQxeblg", "serviceProviderName" => "movistar", "currency" => "978", "tariffPlanServicesId" => "2", "tariffPlanServicesName" => "1395771944.3417", "tariffPlanLifeCycleId" => "2", "tariffPlanLifeCycleName" => "1395771944.2079", "lifeCycleId" => "2", "lifeCycleName" => "1395771944.6719", "modified" => false, "listsLocked" => true, "discounts" => array("discounts" => array(array("customerId" => "customer-4ddd31cd0e49ad4073000003", "customerName" => "customer", "voice" => 9000, "data" => 2000, "sms" => 3000)), "modified" => true), "voucherOnlyDiscounts" => array("discounts" => array(array("customerId" => "customer-4ddd31cd0e49ad4073000003", "customerName" => "customer", "voice" => 9000, "data" => 2000, "sms" => 3000)), "modified" => true), "maxSubscriptions" => 0);
     $srvModel = new ServicePackModel();
     $srvModel->load($sp['id']);
     $srvModel->setId($sp['id']);
     $srvModel->setDiscounts($sp['discounts']['discounts']);
     $service = \Application\Service\ServicePackService::getInstance();
     $service->validate($srvModel, true, new ServicePack\VoucherOnlyDiscountsValidate());
 }