public function isValid($value, $context = null) { $this->_messages = array(); if (!is_string($value)) { return $this->_invalidMessage(self::ERROR_INVALID_TYPE, $value); } $id = isset($context['id']) ? $context['id'] : null; if ($id && $value === $id) { // Name is the supervision group ID // If we are not modifying it, avoid validation at update return true; } try { $item = SupervisionGroupService::getInstance()->load($value); // Recheck to avoid false-positives using mocks!!! if ($item->getName() !== $value) { return true; } } catch (Application\Exceptions\NotFoundException $e) { return true; } catch (Application\Exceptions\GlobalServiceException $e) { return $this->_invalidMessage(self::ERROR_ON_CONNECTION, $value); } return $this->_invalidMessage(self::ERROR_SUPERVISION_GROUP_EXISTS, $value); }
public function isValid($value, $context = null) { $this->_messages = array(); if (!is_string($value)) { return $this->_invalidMessage(self::ERROR_INVALID_TYPE, $value); } try { $item = SupervisionGroupService::getInstance()->load($value); // Recheck to avoid false-positives using mocks!!! if ($item->getName() == $value) { return true; } } catch (Application\Exceptions\NotFoundException $e) { return $this->_invalidMessage(self::ERROR_SUPERVISION_GROUP_NOT_EXISTS, $value); } catch (Application\Exceptions\GlobalServiceException $e) { return $this->_invalidMessage(self::ERROR_ON_CONNECTION, $value); } return $this->_invalidMessage(self::ERROR_SUPERVISION_GROUP_NOT_EXISTS, $value); }
public function validateParamsSupervisionReport(&$params, $type) { $this->_validateCustomerOrg($params); $this->_validateMandatoryParams($params, array('date', ReportFilterFields::SUPERVISION_GROUP)); $found = false; $supervGroups = SupervisionGroupService::getInstance()->listAll(array('parentId' => $params[ReportFilterFields::ORGANIZATION]), array('count' => self::SUPERVISION_GROUP_MAX_ITEMS)); if (!empty($supervGroups)) { foreach ($supervGroups->getItems() as $item) { if ($item->id == $params[ReportFilterFields::SUPERVISION_GROUP]) { $found = true; break; } } } if (!$found) { throw new \Application\Exceptions\NotFoundException("Resource " . ReportFilterFields::SUPERVISION_GROUP . " does not exists"); } // Validate date $this->_validateReportDates($params, $type); }
/** * Load service group by id and user organization id * * @return SupervisionGroupModel */ protected function _load() { $id = $this->_getParam('id'); $sg = SupervisionGroupService::getInstance()->load($id); if (empty($sg)) { throw new NotFoundException("Service group {$id} not found"); } return $sg; }
public function changeSupervGroupAction() { // Check permissions according to the data type $data = $this->_checkAndGetListData('async_sim_change_superv_group', true); if (empty($data['id'])) { throw new InvalidArgumentException('Bad Request. Malformed Json. parameter {id} is required'); } // Check commercial group permissions $id = $data['id']; $suprvGroup = Service\SupervisionGroupService::getInstance()->load($id); if (empty($suprvGroup)) { throw new AppEx\NotFoundException("Supervision group {$id} not found"); } $this->_helper->allowed('read', $suprvGroup); // Respond with the transaction ID $watcher = Service\SimService::getInstance()->changeSupervisionGroup($data['list'], $id); $this->_helper->filterNotAllowedFields('read_field', $watcher); $this->view->assign('watcher', $watcher); }