public function setUp()
 {
     $this->_db = App::getMongoDB();
     $this->_templateService = \Application\Service\TemplateService::getInstance();
     $this->_oldTariffTemplate = json_decode('{"_id":"4f0ef97096d52f505d000000","currency":"978","data":[],"defaultData":{"pool":false,"t6Q":"500","t6N":"1"},"defaultOrigVoice":{"pool":false,"t2N":"60","t2S":"100","t2Q":"100"},"defaultSms":{"pool":false,"t2N":"1","t2Q":"100"},"defaultTermVoice":{"pool":false,"t2N":"180","t2S":"300","t2Q":"300"},"description":"","modified":false,"name":"Zdef2D","organizationId":"provider-4ddd31cd0e49ad4073000002","origVoice":[{"pool":false,"t2N":"120","t2S":"200","t2Q":"200","zoneId":"-1","destinationId":"2"},{"pool":false,"t2N":"240","t2S":"400","t2Q":"400","zoneId":"2","destinationId":"-1"}],"sms":[{"pool":false,"t2N":"1","t2Q":"300","zoneId":"-1","destinationId":"3"},{"pool":false,"t2N":"1","t2Q":"400","zoneId":"2","destinationId":"-1"}],"termVoice":[{"pool":false,"t2N":"180","t2S":"300","t2Q":"300","zoneId":"2"}],"type":"tariffPlanService"}', true);
     $this->_db->templates->insert($this->_oldTariffTemplate);
 }
 public function init()
 {
     $this->_templateSrv = TemplateService::getInstance();
 }
 /**
  * Validate element value
  *
  * If a translation adapter is registered, any error messages will be
  * translated according to the current locale, using the given error code;
  * if no matching translation is found, the original message will be
  * utilized.
  *
  * Note: The *filtered* value is validated.
  *
  * @param  array   $data
  * @param  mixed   $context
  * @return boolean
  */
 public function isValid($data, $context = null, $removeNotPresentFields = false)
 {
     if (!$data instanceof TemplateModel) {
         $this->_messages = array();
         $this->_messages[self::NOT_TEMPLATE] = $this->_messageTemplatesUser[self::NOT_TEMPLATE];
         return false;
     }
     if (!parent::isValid($data, $context, $removeNotPresentFields)) {
         return false;
     }
     if ($data instanceof TemplateModel) {
         $data = $data->exportData();
     }
     $type = $data['type'];
     $options = array('isTemplateValidation' => true);
     switch ($type) {
         case 'tariffPlanLifeCycle':
             $data = new Model\TariffPlanLifeCycleModel($data);
             $validator = new TariffPlanLifeCycleValidate($options);
             break;
         case 'tariffPlanService':
             $data = new Model\TariffPlanServicesModel($data);
             $validator = new TariffPlanServicesValidate($options);
             break;
         case 'lifeCycle':
             $data = new Model\LifeCycleModel($data);
             $validator = new LifeCycleValidate($options);
             break;
         case 'restrictions':
             $data = new Model\RestrictionModel($data);
             $validator = new RestrictionsValidate($options);
             break;
         case 'supplementaryServices':
             $data = new Model\SupplServicesModel($data);
             $validator = new SupplServicesValidate($options);
             break;
         case 'zonePlan':
             $data = new Model\ZonePlanModel($data);
             $validator = new ZonePlanValidate($options);
             break;
     }
     if (!$validator->isValid($data)) {
         $this->_messages = $validator->getMessages();
         return false;
     }
     //check if name exist
     $templateService = \Application\Service\TemplateService::getInstance();
     $filterList = array('name' => $data->getName(), 'type' => $type);
     $filterList = $templateService->buildFilterList($filterList, \App::getOrgUserLogged());
     $items = $templateService->listAll(array('filterList' => $filterList))->getItems();
     if (!empty($items)) {
         foreach ($items as $item) {
             if ($item->getId() === $data->getId()) {
                 return true;
             }
         }
         $this->_messages[] = 'Template name already exist';
         return false;
     }
     return true;
 }
 public function setUp()
 {
     $this->_service = TemplateService::getInstance();
     $this->_org = OrgService::getInstance()->load(self::PROVIDER_COMMERCIAL_ORG_ID);
     \App::getOrgUserLogged($this->_org);
 }
 public function delete($orgOrId)
 {
     if (!isset($orgOrId) && !strlen($orgOrId)) {
         throw new InvalidArgumentException('function param cannot be null');
     }
     if (!$orgOrId instanceof \Application\Model\OrgModelAbstract) {
         $org = $this->load($orgOrId);
     } else {
         $org = $orgOrId;
     }
     $validator = new \Application\Model\Validate\Organization\CustomerIsErasable();
     if (!$validator->isValid($org)) {
         throw new ValidateException("customer {$orgOrId} is not erasable", array('validationErrors' => $validator->getMessages()));
     }
     $type = $this->getChildrenTypeByOrg($org);
     $filterListOrgService = $this->buildFilterList(array('type' => $type, \Application\Model\Filter\OrgFilterFields::PARENT_ID => $org->getId()));
     if ($org->getType() != OrgAggregatorModel::ORG_TYPE) {
         $list = $this->listAll($type, array('filterList' => $filterListOrgService));
         $items = $list->getItems();
         if (count($items) > 0) {
             throw new InvalidArgumentException('The organization has ChildOrgs and can not be deleted');
         }
     }
     $templateService = TemplateService::getInstance();
     $userService = UserService::getInstance();
     $APPIdService = APIIdService::getInstance();
     $this->deleteOrgElements($org, $templateService);
     $this->deleteOrgElements($org, $userService);
     $this->deleteOrgElements($org, $APPIdService);
     $mapper = $this->getMapperByType($this->getTypeById($org->getId()));
     $result = $mapper->delete($org->getId());
     WatcherService::getInstance()->removeByScope('organization', $org->id);
     \App::audit('The organization with Id ' . $org->getId() . "has been deleted", $org);
     $this->_sendEvent('delete', $org);
     return $result;
 }