/** * 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 $data \Application\Model\CommercialGroupModel * @param $context \Application\Model\CommercialGroupModel The original commercialGroup * @return boolean */ public function isValid($data, $context = null, $removeNotPresentFields = false) { if (!$data instanceof CommercialGroupModel) { $this->_messages = array(); $this->_messages[self::NOT_COMMERCIAL_GROUP] = $this->_messageTemplatesCommercialGroup[self::NOT_COMMERCIAL_GROUP]; return false; } //check if is an update if ($data->getId()) { //check if the user have modified the service pack $cgMapper = CommercialGroupMapper::getInstance(); $original = $cgMapper->findOneById($data->getId()); if (!$original instanceof CommercialGroupModel) { throw new \Application\Exceptions\UnexpectedException("Commercial group Id doesn't exist for update operation"); } if (!is_null($data->getServicePackId()) && $data->getServicePackId() !== $original->getServicePackId()) { if ($original->getSubscriberCount() !== 0) { $this->_messages = array(); $this->_messages[self::COMMERCIAL_GROUP_HAVE_SUBSCRIPTIONS] = $this->_messageTemplatesCommercialGroup[self::COMMERCIAL_GROUP_HAVE_SUBSCRIPTIONS]; return false; } } } return parent::isValid($data, $context, $removeNotPresentFields); }
public function setUp() { $this->commercialGroupMapper = CommercialGroupMapper::getInstance(); $this->_user = $this->_createAuthUser(array('userName' => 'CommercialGroupUserTest', 'organizationId' => Organization\OrgCustomerModel::ORG_TYPE . self::CUSTOMER_ID)); $data = array("name" => "CG" . microtime(), "description" => "Description of commercial group", "limitVoice" => array("enabled" => true, "value" => 23), "limitSms" => array("enabled" => true, "value" => 8), "limitData" => array("enabled" => true, "value" => 30), "limitTotal" => array("enabled" => true, "value" => 103), "whiteList" => array("34666*", "34677*", "34655777888"), "blackList" => array("34866*", "34877*", "34855777888"), "roamingList" => array("34966*", "34977*", "34955777888"), "customerId" => Organization\OrgCustomerModel::ORG_TYPE . self::CUSTOMER_ID, "servicePackId" => self::SERVICE_PACK_ID, "billingAccountId" => self::BILLING_ACCOUNT_ID); $this->commercialGroup = new CommercialGroupModel($data); }
/** * @param string $userId * @return UserModel */ public static function find($userId) { return CommercialGroupMapper::getInstance()->findOneById($userId); }