public function delete($model)
 {
     $type = get_class($model);
     $this->getMapper()->delete($model);
     \App::audit("Deleted {$type} with Id {$model->getId()}", $model);
     return true;
 }
 public function updateScreening(CommercialGroupModel $commGroup)
 {
     $commGroupId = $commGroup->getId();
     if (!isset($commGroupId) && !strlen($commGroupId)) {
         throw new AppEx\InvalidArgumentException('Supplied supplServices model must have an Id');
     }
     $this->validate($commGroup, true);
     $result = $this->getMapper()->updateScreening($commGroup);
     if ($result) {
         \App::audit('Changed Screening for commercial Group: ' . $commGroup->getId() . '. TransactionId: ' . $result, $commGroup);
     }
     return $result;
 }
 public function unpublish($preBill)
 {
     if ($preBill instanceof PreBillModel) {
         $mapper = PreBillMapper::getInstance();
         $result = $mapper->unpublish($preBill->getId());
         if ($result) {
             \App::audit('Unpublished prebill with Id ' . $preBill->getId(), $preBill);
             return $result;
         }
     } else {
         throw new AppEx\ValidateException('Invalid prebill');
     }
 }
 public function modifyStatus($data, $orgId)
 {
     if ($data) {
         $mapper = $this->getMapper();
         if ($transactionId = $mapper->modifyStatusEricsson($data, $orgId)) {
             $sim = new SimModel(array($data['subscription_id']['id_type'] => $data['subscription_id']['id']));
             \App::audit('Lifecycle status modified successfully', $sim);
             return $transactionId;
         } else {
             throw new AppEx\InvalidArgumentException('Error modifying lifecycle status');
         }
     } else {
         throw new AppEx\ValidateException('Invalid lifecycle information');
     }
 }
 /**
  * Delete one model
  *
  * @param  string|models\ModelAbstract $idOrModel
  * @return boolean
  */
 public function delete($idOrModel)
 {
     if ($idOrModel instanceof models\ModelAbstract) {
         $model = $idOrModel;
     } else {
         $model = $this->load($idOrModel);
     }
     $id = $model->getId();
     if (!$model || !isset($id)) {
         throw new InvalidArgumentException('Invalid Id');
     }
     $type = get_class($model);
     $model->delete();
     \App::audit("Deleted {$type} with Id {$model->getId()}", $model);
     return true;
 }
 public function close($id, Attendance $attendance)
 {
     /**
      * @var $mapper AlarmMapper
      */
     $mapper = AlarmMapper::getInstance();
     if (!isset($id) && !strlen($id) || !$attendance) {
         throw new InvalidArgumentException("Invalid params");
     }
     $alarm = $mapper->findOneById($id);
     if ($alarm->state == AlarmModel::STATE_CLOSED) {
         throw new ValidateException("Can't close an alarm already closed", ValidationCodes::ALARM_ALREADY_CLOSED);
     }
     $this->validate($attendance, true);
     $result = $mapper->close($id, $attendance);
     \App::audit('Close alarm for alarmId:' . $id, $attendance);
     return $result;
 }
 /**
  * Create report
  *
  * @param $type string
  * @param $params array
  * @return models\ModelAbstract
  */
 public function createReport($type, $params = array())
 {
     $params[ReportFilterFields::REPORT_TYPE] = $type;
     switch ($type) {
         // Supervision
         case ReportModel::PRESENCE_MONTHLY:
         case ReportModel::PRESENCE_DAILY:
         case ReportModel::LOCATION_DAILY:
         case ReportModel::LOCATION_MONTHLY:
         case ReportModel::OPENED_SUP_ALARMS_DAILY:
         case ReportModel::OPENED_SUP_ALARMS_MONTHLY:
         case ReportModel::CLOSED_SUP_ALARMS_DAILY:
         case ReportModel::CLOSED_SUP_ALARMS_MONTHLY:
         case ReportModel::ACCUMULATED_SUMMARY_DAILY:
             $model = $this->createSupervisionReport($params, $type);
             break;
             // Expense and consumption
         // Expense and consumption
         case ReportModel::CONSUMPTION_DAILY:
             $model = $this->createConsumptionReport($params, $type);
             break;
         case ReportModel::EXPENSE_DETAIL_MONTHLY:
         case ReportModel::EXPENSE_DETAIL_DAILY:
         case ReportModel::CONSUMPTION_DETAIL_DAILY:
             $model = $this->createChargesDetailReport($params, $type);
             break;
             // Business
         // Business
         case ReportModel::SUBSCRIPTION_BASE_MONTHLY:
             $model = $this->createSubscriptionBaseReport($params, $type);
             break;
         case ReportModel::SUBSCRIPTION_SNAPSHOT_DAILY:
             $model = $this->createSubscriptionSnapshotReport($params, $type);
             break;
         case ReportModel::KPI_MONTHLY:
             $model = $this->createKpiReport($params, $type);
             break;
         case ReportModel::SMIP_CONSUMPTION_MONTHLY:
             $model = $this->createSmipConsumptionMonthly($params);
             break;
         case ReportModel::SMIP_CONSUMPTION_DAILY:
             $model = $this->createSmipConsumptionDaily($params);
             break;
         case ReportModel::CORRELATION:
             $model = $this->createCorrelationReport();
             break;
         default:
             throw new InvalidArgumentException('Invalid report type');
     }
     \App::audit("Created async report with Id {$model->id}", $model);
     return $model;
 }
 public function delete($id, $type = null)
 {
     if ($id instanceof TariffPlanLifeCycleModel || $id instanceof TariffPlanServicesModel) {
         $id = $id->getId();
         if ($id instanceof TariffPlanLifeCycleModel) {
             $type = self::TYPE_LIFECYCLE;
         } else {
             $type = self::TYPE_SERVICES;
         }
     }
     if (!is_string($id) || !strlen($id)) {
         throw new AppEx\InvalidArgumentException('Supplied tariff model must have Id');
     }
     switch (strtolower($type)) {
         case self::TYPE_LIFECYCLE:
             $tariff = new TariffPlanLifeCycleModel(array('id' => $id));
             break;
         case self::TYPE_SERVICES:
             $tariff = self::load(self::TYPE_SERVICES, $id);
             $zonePlan = ZonePlanService::getInstance()->load($tariff->zonePlanId);
             $zonePlan->delete();
             break;
         default:
             throw new AppEx\InvalidArgumentException("Invalid Type given");
     }
     $tariff->delete();
     if ($tariff instanceof TariffPlanLifeCycleModel) {
         \App::audit('Deleted life cycle tariff with Id ' . $tariff->getId(), $tariff);
     } else {
         \App::audit('Deleted services tariff with Id ' . $tariff->getId(), $tariff);
     }
     return true;
 }
 public function update(ModelAbstract $model)
 {
     $contractService = ContractService::getInstance();
     $contracts = $contractService->getContractsByServiceType('csrm')->getItems();
     if (empty($contracts)) {
         return;
     }
     $type = get_class($model);
     $item = $this->loadByServicePack($model->getServicePackId());
     $id = $item->getId();
     $resId = $item->getResId();
     if (!isset($id) && !strlen($id)) {
         throw new InvalidArgumentException("Supplied model '{$type}' has no Id");
     }
     $model->setId($id);
     $model->setResId($resId);
     if ($this->_validator) {
         $this->validate($model, true);
     }
     $this->reorderSteeringList($model);
     // Persist the changes
     $model->save();
     \App::audit("Updated model '{$type}' with Id {$model->getId()} for service pack {$model->servicePackId}" . " with resId {$model->resId}", $model);
     return $model;
 }
Example #10
0
 public function changeLteSync($state, $simId)
 {
     $this->_validateLteState($state);
     $state = filter_var($state, FILTER_VALIDATE_BOOLEAN);
     $result = $this->getMapper()->changeLteSync($state, $simId);
     \App::audit('Changed LTE status on sim to ' . $state . '. Handler: ' . $result, null);
     return $result;
 }
 public function undelegateSims($listOrFilter)
 {
     $mapper = $this->getMapper();
     $result = $mapper->undelegateSims($listOrFilter);
     if ($result) {
         if (is_array($listOrFilter)) {
             foreach ($listOrFilter as $item) {
                 \App::audit('Undelegating sims ' . $item, $item);
             }
         } else {
             if ($listOrFilter instanceof \App_ListFilter) {
                 \App::audit('Undelegating all sims from handler ' . $listOrFilter->getCursor(), null);
             } else {
                 throw new AppEx\ValidateException('Invalid SIM list');
             }
         }
     }
     return $result;
 }
 /**
  * @param  Application\Model\SupplServicesModel $service
  * @return boolean
  */
 public function removeCustomer(SupplServicesModel $service, OrgCustomerModel $org)
 {
     if (!strlen((string) $service->getId())) {
         throw new AppEx\InvalidArgumentException("Supplementary Services does not have an Id");
     }
     if (!$org instanceof OrgCustomerModel) {
         throw new AppEx\InvalidArgumentException("Organization must be a customer.");
     }
     $orgId = $org->getId();
     if (!isset($orgId) && !strlen($orgId)) {
         throw new AppEx\InvalidArgumentException("Organization customer does not have an Id");
     }
     if ($service->getPublished() != \Application\Model\SupplServicesModel::STATUS_PUBLISHED) {
         throw new AppEx\InvalidArgumentException("Supplementary Services must be published to have customers");
     }
     if ($service->subscriptionCount) {
         throw new AppEx\InvalidArgumentException("Customer sims are using supplementary services");
     }
     $result = $this->getMapper()->removeCustomer($service->getId(), $org->getId());
     \App::audit('Removed customer ' . $org->getId() . ' from supplementary services with Id ' . $service->getId(), $service);
     return $result;
 }
 /**
  *
  * @param  UserModel $user
  * @param  string    $reason
  * @return boolean
  */
 public function blockUser($user, $reason)
 {
     if ($user->getStatus() !== UserModel::USER_STATUS_BLOCKED) {
         // Block user
         $user->status = UserModel::USER_STATUS_BLOCKED;
         $user->save();
         \App::audit("User " . $user->getUserName() . " has been blocked due to {$reason}", $user);
         \App::log()->debug("User " . $user->getUserName() . " status changed to BLOCKED");
         $this->_sendEvent('update', $user);
         $this->_sendEvent('block', $user);
         return true;
     }
     return false;
 }
Example #14
0
 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;
 }
 public function setVoucherOnlyDiscounts($sp)
 {
     $this->validate($sp, true, new ServicePack\VoucherOnlyDiscountsValidate());
     $this->getMapper()->setVoucherOnlyDiscounts($sp, $sp->getVoucherOnlyDiscounts());
     \App::audit('Change discounts for service pack with Id ' . $sp->getId(), $sp);
     return true;
 }