public function testLoad()
 {
     /** @var Application\Model\TariffPlanServicesModel **/
     $tp = $this->_service->load(TariffPlanService::TYPE_SERVICES, "9887635");
     $this->assertNotNull($tp);
     $this->assertInstanceOf('\\Application\\Model\\TariffPlanServicesModel', $tp);
     // Check dynamic
     $this->assertNotNull($tp->getDefaultSms(), "defaultSms is NULL");
     $this->assertNotNull($tp->getDefaultSms()->getDynamic(), "defaultSms.dynamic is NULL");
     $this->assertTrue(is_bool($tp->getDefaultSms()->getDynamic()), "defaultSms.dynamic is not boolean");
     // Check pool
     $this->assertNotNull($tp->getDefaultSms(), "defaultSms is NULL");
     $this->assertNotNull($tp->getDefaultSms()->getPool(), "defaultSms.pool is NULL");
     $this->assertTrue(is_bool($tp->getDefaultSms()->getPool()), "defaultSms.pool is not boolean");
 }
 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;
     }
     if (!isset($context['lifeCycleId']) || !$context['lifeCycleId']) {
         $message = $this->_createMessage(self::ERROR_LIFECYCLE_NOT_DEFINED, $value);
         $this->_messages[self::ERROR_LIFECYCLE_NOT_DEFINED] = $message;
         return false;
     }
     $lifeCycleId = $context['lifeCycleId'];
     $service = TariffPlanService::getInstance();
     try {
         $item = $service->load(TariffPlanService::TYPE_LIFECYCLE, $value, $lifeCycleId);
     } catch (Application\Exceptions\GlobalServiceException $e) {
         $message = $this->_createMessage(self::ERROR_ON_CONNECTION, $value);
         $this->_messages[self::ERROR_ON_CONNECTION] = $message;
         return false;
     }
     if (!isset($item)) {
         $message = $this->_createMessage(self::ERROR_TARIFFPLAN_LIFECYCLE_NOT_FOUND, $value);
         $this->_messages[self::ERROR_TARIFFPLAN_LIFECYCLE_NOT_FOUND] = $message;
         return false;
     }
     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)
 {
     $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 = TariffPlanService::getInstance();
     try {
         $item = $service->load(TariffPlanService::TYPE_SERVICES, $value);
     } catch (Application\Exceptions\GlobalServiceException $e) {
         $message = $this->_createMessage(self::ERROR_ON_CONNECTION, $value);
         $this->_messages[self::ERROR_ON_CONNECTION] = $message;
         return false;
     }
     if (!isset($item)) {
         $message = $this->_createMessage(self::ERROR_TARIFFPLAN_SERVICES_NOT_FOUND, $value);
         $this->_messages[self::ERROR_TARIFFPLAN_SERVICES_NOT_FOUND] = $message;
         return false;
     }
     return true;
 }
 public function init()
 {
     $this->_tariffPlanSrv = \Application\Service\TariffPlanService::getInstance();
     $this->_servicePackSrv = \Application\Service\ServicePackService::getInstance();
 }
 /**
  * Update a servicePack identified by its Id
  */
 public function putAction()
 {
     $data = $this->_helper->requestData(true);
     $data = $this->_helper->filter($data)->blacklist(array('lifeCycleId', 'restrictionsId', 'tariffPlanServicesId', 'tariffPlanServices.zonePlanId', 'published'));
     $spId = $this->_getParam('id');
     $servicePack = $this->_spSrv->load($spId);
     if (empty($servicePack)) {
         throw new NotFoundException("ServicePack {$spId} not found", 404);
     }
     // If servicepack is published, only allow modify tariffs, discounts, name or maxSubscription
     if ($servicePack->isPublished()) {
         if (isset($data['tariffPlanLifeCycle']) && isset($data['tariffPlanLifeCycle']['modified']) && isset($data['tariffPlanLifeCycle']['id']) && $data['tariffPlanLifeCycle']['modified'] === true) {
             $id = $data['tariffPlanLifeCycle']['id'];
             $tariffPlan = $this->_tariffSrv->load(TariffPlanService::TYPE_LIFECYCLE, $id);
             if (empty($tariffPlan)) {
                 throw new NotFoundException("Tariff plan {$id} not found", 404);
             }
             $this->_helper->allowed('update', $tariffPlan);
             $tariffPlan->importData($data['tariffPlanLifeCycle']);
             $result['tariffPlanLifeCycle'] = $this->_tariffSrv->update($tariffPlan);
         }
         if (isset($data['lifeCycle']) && isset($data['lifeCycle']['modified']) && isset($data['lifeCycle']['id']) && $data['lifeCycle']['modified'] === true) {
             $id = $data['lifeCycle']['id'];
             $lifeCycle = $this->_lifeCycleSrv->load($id);
             if (empty($lifeCycle)) {
                 throw new NotFoundException("Life Cycle {$id} not found", 404);
             }
             $lifeCycle->importData($data['lifeCycle']);
             $lifeCycle->published = $servicePack->published;
             $result['lifeCycle'] = $this->_lifeCycleSrv->update($lifeCycle);
         }
         if (isset($data['tariffPlanServices']) && isset($data['tariffPlanServices']['modified']) && isset($data['tariffPlanServices']['id']) && $data['tariffPlanServices']['modified'] === true) {
             $id = $data['tariffPlanServices']['id'];
             $tariffPlan = $this->_tariffSrv->load(TariffPlanService::TYPE_SERVICES, $id);
             if (empty($tariffPlan)) {
                 throw new NotFoundException("Tariff plan {$id} not found", 404);
             }
             $this->_helper->allowed('update', $tariffPlan);
             $tariffPlan->importData($data['tariffPlanServices']);
             $tariffPlan->published = $servicePack->published;
             $result['tariffPlanServices'] = $this->_tariffSrv->update($tariffPlan);
         }
         if (isset($data['restrictions']) && isset($data['restrictions']['modified']) && isset($data['restrictions']['id']) && $data['restrictions']['modified'] === true) {
             $id = $data['restrictions']['id'];
             $restrictions = $this->_restrictionsSrv->load($id);
             if (empty($restrictions)) {
                 throw new NotFoundException("Restrictions {$id} not found", 404);
             }
             $restrictions->importData($data['restrictions']);
             if ($restrictions->restrictionsModified) {
                 unset($restrictions->restrictionsModified);
             }
             $restrictions->published = $servicePack->published;
             $steeringListService = SteeringListService::getInstance();
             try {
                 $result['restrictions'] = $this->_restrictionsSrv->update($restrictions);
             } catch (\Application\Model\Mapper\Exception\EricssonException $e) {
                 $stOrig = $steeringListService->loadByServicePack($servicePack->id);
                 if ($e->getHttpCode() != 304 || $stOrig->steeringType == $restrictions->steering->steeringType && $stOrig->useCustomOrder == $restrictions->steering->useCustomOrder && $stOrig->steeringList == $restrictions->operator) {
                     throw $e;
                 }
                 $warn_mess = WarningsMessenger::getInstance();
                 $warn_mess->avoidModule();
             }
             $steeringListService->applySteering($restrictions, $servicePack->id);
         }
         if (isset($data['discounts'])) {
             if (isset($data['discounts']['discounts']) && $data['discounts']['modified'] === true) {
                 $this->_helper->allowed('update_discounts', $servicePack);
                 $servicePack->setDiscounts($data['discounts']['discounts']);
             } else {
                 $servicePack->setDiscounts($data['discounts']);
             }
             $result['discounts'] = $this->_spSrv->setDiscounts($servicePack);
         }
         if (isset($data['voucherOnlyDiscounts'])) {
             if (isset($data['voucherOnlyDiscounts']['discounts']) && $data['voucherOnlyDiscounts']['modified'] === true) {
                 $this->_helper->allowed('update_voucher_only_discounts', $servicePack);
                 $servicePack->setVoucherOnlyDiscounts($data['voucherOnlyDiscounts']['discounts']);
             } else {
                 $servicePack->setVoucherOnlyDiscounts($data['voucherOnlyDiscounts']);
             }
             $result['voucherOnlyDiscounts'] = $this->_spSrv->setVoucherOnlyDiscounts($servicePack);
         }
         $update = array();
         if (isset($data['name']) && $data['name'] != $servicePack->getName()) {
             $update['name'] = $data['name'];
         }
         if (isset($data['maxSubscriptions'])) {
             $update['maxSubscriptions'] = $data['maxSubscriptions'];
         }
         if (!empty($update)) {
             $servicePack->importData($update);
             $result['servicePack'] = $this->_spSrv->update($servicePack);
         }
         $this->view->data = isset($result) ? $result : array();
     } else {
         if (isset($data['tariffPlanServices']['currency'])) {
             $data['currency'] = $data['tariffPlanServices']['currency'];
         } else {
             if (isset($data['tariffPlanLifeCycle']['currency'])) {
                 $data['currency'] = $data['tariffPlanLifeCycle']['currency'];
             }
         }
         // Make sure that operator is not an empty array
         if (isset($data['restrictions']['operator']) && empty($data['restrictions']['operator'])) {
             unset($data['restrictions']['operator']);
         }
         if (isset($data['restrictions']) && isset($data['restrictions']['modified']) && isset($data['restrictions']['id']) && $data['restrictions']['modified'] === true) {
             $id = $data['restrictions']['id'];
             $restrictions = $this->_restrictionsSrv->load($id);
             if (empty($restrictions)) {
                 throw new NotFoundException("Restrictions {$id} not found", 404);
             }
             $restrictions->importData($data['restrictions']);
             $steeringListService = SteeringListService::getInstance();
             $steeringListService->applySteering($restrictions, $servicePack->id);
         }
         $servicePack->importData($data);
         // Check if it's allowed
         $this->_helper->allowed('update', $servicePack);
         // Update the service pack via its service
         $result = $this->_spSrv->update($servicePack);
         $this->view->data = $result;
     }
 }
 public function delete($model)
 {
     if (is_string($model)) {
         $model = $this->load($model);
     }
     if (!$model instanceof ServicePackModel) {
         throw new AppEx\InvalidArgumentException('Supplied service pack model must have Id');
     }
     if ($model->getCustomerCount() !== 0) {
         throw new AppEx\ForbiddenException('Delete service pack assigned to a customer is not allowed.');
     }
     $result = parent::delete($model);
     if ($model->getLifeCycleId()) {
         try {
             LifeCycleService::getInstance()->delete($model->getLifeCycleId());
         } catch (\Exception $e) {
             \App::log()->warn($e);
         }
     }
     if ($model->getRestrictionsId()) {
         try {
             RestrictionService::getInstance()->delete($model->getRestrictionsId());
         } catch (\Exception $e) {
             \App::log()->warn($e);
         }
     }
     if ($model->getTariffPlanLifeCycleId()) {
         try {
             TariffPlanService::getInstance()->delete($model->getTariffPlanLifeCycleId(), TariffPlanService::TYPE_LIFECYCLE);
         } catch (\Exception $e) {
             \App::log()->warn($e);
         }
     }
     if ($model->getTariffPlanServicesId()) {
         try {
             TariffPlanService::getInstance()->delete($model->getTariffPlanServicesId(), TariffPlanService::TYPE_SERVICES);
         } catch (\Exception $e) {
             \App::log()->warn($e);
         }
     }
     $steeringListService = SteeringListService::getInstance();
     if ($steeringList = $steeringListService->loadByServicePack($model->id)) {
         $steeringListService->delete($steeringList);
     }
     return true;
 }