public function testUpgradeTariffTemplate()
 {
     $oldTariffTemplate = $this->_templateService->load($this->_oldTariffTemplate['_id']);
     //Initialize db for use in included script
     $db = $this->_db;
     include App::getApplicationPath() . '/../scripts/updates/02.00rev20130312.php';
     /**
      * @var \Application\Model\TemplateModel $upgradedTariffTemplate
      */
     $upgradedTariffTemplate = $this->_templateService->load($this->_oldTariffTemplate['_id']);
     $this->assertNotNull($upgradedTariffTemplate->name);
     $this->assertNotNull($upgradedTariffTemplate->organizationId);
     $this->assertNotNull($upgradedTariffTemplate->type);
     $this->assertNotNull($upgradedTariffTemplate->id);
     $this->assertNotNull($upgradedTariffTemplate->modified);
     $this->assertNotNull($upgradedTariffTemplate->zonePlanId);
     $this->assertNotNull($upgradedTariffTemplate->zonePlan);
     $zonePlan = $upgradedTariffTemplate->zonePlan;
     $zoneGroup = $zonePlan['zoneGroups'][0];
     $this->assertNotNull($zoneGroup['id']);
     $this->assertNotNull($zoneGroup['name']);
     $this->assertNotNull($zoneGroup['zones']);
     $this->assertEquals(1, count($zoneGroup['zones']));
     $this->assertEquals($zoneGroup['zones'][0], 2);
     $termVoice = current($upgradedTariffTemplate->termVoice);
     $this->assertNull($termVoice['zoneId']);
     $this->assertNotNull($termVoice['zoneGroupId']);
     $this->assertNotNull($termVoice['zoneGroupName']);
 }
 public function existnameAction()
 {
     $name = $this->getRequest()->getParam('name');
     if (empty($name)) {
         throw new InvalidArgumentException('No name given');
     }
     $type = $this->getRequest()->getParam('type');
     if (empty($type)) {
         throw new InvalidArgumentException('No type given');
     }
     // Fetch user matching the username
     $exist = $this->_templateSrv->existName($name, $type);
     $this->view->data = $exist;
 }
 public function jsonGetMailContentAction()
 {
     if ($this->request->isPost() && $this->request->isXmlHttpRequest()) {
         $template = $this->templateService->getTemplateById($this->request->getPost()->id);
         $code = $this->request->getPost()->code;
         if ($template) {
             /* @var $template \Application\Entity\Template */
             $result = array('title' => $code == Language::CODE_ENG ? $template->getTitleEn() : $template->getTitleEt(), 'content' => $code == Language::CODE_ENG ? $template->getContentEn() : $template->getContentEt());
             return new JsonModel($result);
         }
     }
     return $this->response;
 }
 /**
  */
 public function deleteAction()
 {
     // Try to load the chosen user
     $templateId = $this->getRequest()->getParam('id');
     $template = $this->_templateSrv->load($templateId);
     if (empty($template)) {
         throw new AppEx\NotFoundException('Template ' . $templateId . ' not found', 404);
     }
     // Check permissions
     $this->_helper->allowed('delete', $template);
     // Remove the user
     $this->_templateSrv->delete($templateId);
     $this->view->data = true;
 }
 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;
 }
}, 'Application\\Service\\Mail' => function (ServiceManager $sm) {
    $service = new MailService();
    return $service;
}, 'Application\\Service\\Settings' => function (ServiceManager $sm) {
    $service = new SettingsService();
    return $service;
}, 'Application\\Service\\Statistics' => function (ServiceManager $sm) {
    $service = new StatisticsService();
    $service->setInvoiceService($sm->get('Application\\Service\\Invoice'));
    $service->setBankService($sm->get('Application\\Service\\Bank'));
    return $service;
}, 'Application\\Service\\Supplier' => function (ServiceManager $sm) {
    $service = new SupplierService();
    return $service;
}, 'Application\\Service\\Template' => function (ServiceManager $sm) {
    $service = new TemplateService();
    $service->setUserService($sm->get('User\\Service\\User'));
    return $service;
}), 'initializers' => array(function ($service, $sm) {
    if ($service instanceof TranslatorAwareInterface) {
        $service->setTranslator($sm->get('MvcTranslator'));
    }
    if ($service instanceof ObjectManagerAwareInterface) {
        $service->setObjectManager($sm->get('doctrine.entitymanager.orm_default'));
    }
})), 'view_helpers' => array('invokables' => array('service' => 'Application\\View\\Helper\\Service'), 'factories' => array('messages' => function () {
    $helper = new Messages();
    $helper->setTemplatesFolder('messages');
    return $helper;
})), 'doctrine' => array('driver' => array('Application_driver' => array('class' => 'Doctrine\\ORM\\Mapping\\Driver\\AnnotationDriver', 'cache' => 'array', 'paths' => array(__DIR__ . '/../src/Application/Entity')), 'orm_default' => array('drivers' => array('Application\\Entity' => 'Application_driver')))), 'navigation' => array('default' => require_once 'defaultNav.conf.php', 'user' => require_once 'userNav.conf.php'), 'translator' => array('locale' => 'en_US', 'translation_file_patterns' => array(array('type' => 'gettext', 'base_dir' => __DIR__ . '/../language', 'pattern' => '%s.mo'))), 'controllers' => array('invokables' => array('Application\\Controller\\Test' => 'Application\\Controller\\TestController'), 'factories' => ['Application\\Controller\\Article' => function (ControllerManager $cm) {
    $controller = new ArticleController();
 public function testCreateZonePlanTemplate()
 {
     $data = array('name' => "ZonePlanTest2", 'type' => "zonePlan", 'zoneGroups' => array(array('name' => "zoneGroup1", 'id' => 1, 'zones' => array("0"))));
     $this->_template = new TemplateModel($data);
     $this->_service->create($this->_template, \App::getOrgUserLogged());
 }
 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;
 }