/** * @param UserModel $user * @return UserModel */ public function create(models\ModelAbstract $user) { if (!$user instanceof UserModel) { throw new InvalidArgumentException('Supplied data must be a user model'); } // Generate a random password $password = $this->generatePassword(); // Fetch password hashing resource $bootstrap = \Zend_Controller_Front::getInstance()->getParam('bootstrap'); $phpass = $bootstrap->getResource('PHPass'); // Store a hashed version of the password in the user profile $user->setPassword($phpass->hashPassword($password)); // Set initial Last password change $user->setLastPasswordChange(time()); // Set initial status $user->setStatus(UserModel::USER_STATUS_PENDING); parent::create($user); //Save password in lastUsedPasswords list UserMapper::getInstance()->insertLastUsedPasswords($user->id, array(sha1($password))); $token = $this->generateAndSaveActivationLink($user); try { $this->sendEmailWelcome($user, $password, $token); } catch (\Exception $e) { \App::log()->ERR('[mailto:' . $user->getEmail() . '] ' . $e->getMessage()); } return $user; }
/** * @throws ForbiddenException * @throws Zend_Controller_Exception * @param string $privilege * @param \Application\Model\ModelAbstract $resource */ public function direct($privilege, $resource) { if ($resource instanceof App_ListFilter && $resource->getSortingField()) { $priv = $privilege . '_' . $resource->getSortingField(); if (!$this->_privilegeExists($priv, $resource)) { $priv = $privilege . '_default'; } $this->_allowed($priv, $resource); } }
protected function _checkProtectedFields(ModelAbstract $originalModel, ModelAbstract $newModel, array $protectedFields) { $orginalData = $originalModel->exportData(); $newData = $newModel->exportData(); foreach ($protectedFields as $field) { if ($orginalData[$field] !== $newData[$field]) { return false; } } return true; }
/** * @param TemplateModel $template * @return TemplateModel */ public function create(ModelAbstract $template, $org = null) { if ($template->getId()) { throw new InvalidArgumentException('Supplied template model already has an Id'); } if (!$template->getType()) { throw new InvalidArgumentException('Supplied template model needs a type'); } if (!$org) { $org = \App::getOrgUserLogged(); } $template->setOrganizationId($org->getId()); return parent::create($template); }
public function update(models\ModelAbstract $model) { if (!strlen((string) $model->getId())) { throw new AppEx\InvalidArgumentException('Supplied supplServices model must have an Id', \Application\Error\ValidationCodes::MODEL_SUPPL_SERVICE_PACK); } if ($model->getPublished() == \Application\Model\SupplServicesModel::STATUS_PUBLISHED) { // If the supplementary service pack is published, applicationOriginatedSmsMsisdn, // currency can't be updated if ($model->getCurrency()) { unset($model->currency); } } return parent::update($model); }
/** * * @param Application\Model\OrgModelAbstract $org * @return Application\Model\OrgModelAbstract */ public function update(ModelAbstract $org) { if ($org instanceof OrgCustomerModel) { // Check if exists before update $checkOrg = $this->load($org->getId()); if (NULL === $checkOrg) { throw new \Application\Exceptions\NotFoundException("Organization not exists"); } // Default + Other billing accounts $billings = $org->getAllBillingAccounts(); // Capture billing cycle info foreach ($billings as $billing) { if ($billing->billingAccountId !== null) { // Needs modification? $oldBilling = $checkOrg->getBillingAccount($billing->billingAccountId); if (!$oldBilling) { throw new \Application\Exceptions\NotFoundException("Billing account {$billing->billingAccountId} not exists"); } $oldBillingDay = $oldBilling->billingCycleStartDay === null || $oldBilling->billingCycleStartDay === $org->billingCycleStart->dayOfMonth ? 0 : $oldBilling->billingCycleStartDay; if (isset($billing->billingCycleStartDay) && $billing->billingCycleStartDay !== $oldBillingDay) { // Send async request $transacionId = $this->changeBillingCycleStartDay($org->getId(), $billing->billingAccountId, $billing->billingCycleStartDay ?: null); // Log action (ignoring async response) \App::audit("Updating customer {$org->getId()} billing account {$billing->billingAccountId} " . "cycle start day from {$billing->billingCycleNextStartDay} to " . "{$billing->billingCycleStartDay}: async transaction {$transacionId}", $org); } else { \App::log()->info("Customer {$org->getId()} billing account {$billing->billingAccountId} " . "cycle start day not modified"); } // Unset update info unset($billing->billingCycleStartDay); } else { if (!$billing->billingCycleStartDay) { unset($billing->billingCycleStartDay); } } // Unset read info unset($billing->billingCycleNextStartDay); unset($billing->billingCycleModifiable); } if ($org->billingCycleStart->dayOfMonth !== $checkOrg->billingCycleStart->dayOfMonth) { $transacionId = $this->changeBillingCycleStartDay($org->getId(), null, $org->billingCycleStart->dayOfMonth); \App::log()->info("Updating customer {$org->getId()} default cycle start day from " . "{$checkOrg->billingCycleStart->dayOfMonth} to {$org->billingCycleStart->dayOfMonth}: " . "async transaction {$transacionId}"); } } return parent::update($org); }
public function setNumber($fieldName, $fieldValue) { parent::setNumber($fieldName, $fieldValue); // Latitude and longitude to int (see LocationValidate.php) if (is_float($this->{$fieldName})) { $this->set($fieldName, (int) ($this->{$fieldName} * 1000000.0)); } return $this; }
/** * * @param array $data */ public function __construct(array $data = null) { parent::__construct($data); $this->_init(); }
public function update(models\ModelAbstract $tariff) { if (!$tariff instanceof TariffPlanLifeCycleModel && !$tariff instanceof TariffPlanServicesModel) { throw new AppEx\InvalidArgumentException('Supplied data must be a tariff model'); } if (!strlen((string) $tariff->getId())) { throw new AppEx\InvalidArgumentException('Supplied tariff model must have Id'); } // Make sure that defaultTermVoice/T2SModified has a value if ($tariff instanceof TariffPlanServicesModel) { if ($tariff->getDefaultTermVoice()->getT2SModified() == null) { if ($tariff->getDefaultTermVoice()->getT2S() == null) { $tariff->getDefaultTermVoice()->setT2S(0); } $tariff->getDefaultTermVoice()->setT2SModified($tariff->getDefaultTermVoice()->getT2S()); } //Zone Plan, $this->_createZonePlan($tariff); } $valid = $this->validate($tariff, true); $tariff->save(); if ($tariff instanceof TariffPlanLifeCycleModel) { \App::audit('Updated life cycle tariff with Id ' . $tariff->getId(), $tariff); } else { \App::audit('Updated services tariff with Id ' . $tariff->getId(), $tariff); } return $tariff->getId(); }
/** * * @param array $data */ public function __construct(array $data = null) { $data['exceptionCategory'] = self::CATEGORY; // Default parent::__construct($data); }
/** * @param Application\Model\ServicePackModel $service * @return Application\Model\ServicePackModel */ public function update(Model\ModelAbstract $service) { if (!strlen((string) $service->getId())) { throw new AppEx\InvalidArgumentException("The Service Pack must have an id"); } $tariffService = TariffPlanService::getInstance(); if ($tariff = $service->getTariffPlanLifeCycle()) { $tariff->setName((string) microtime(true)); $tariff->setId(null); $tariffService->create($tariff); $service->setTariffPlanLifeCycleId($tariff->getId()); } if ($tariff = $service->getTariffPlanServices()) { $tariff->setName((string) microtime(true)); $tariff->setId(null); $tariffService->create($tariff); $service->setTariffPlanServicesId($tariff->getId()); } $lcService = LifeCycleService::getInstance(); if ($lc = $service->getLifeCycle()) { $lc->setName((string) microtime(true)); $lc->setId(null); $lcService->create($lc); $service->setLifeCycleId($lc->getId()); } $restricService = RestrictionService::getInstance(); if ($re = $service->getRestrictions()) { $re->setName((string) microtime(true)); $re->setId(null); $restricService->create($re); $service->setRestrictionsId($re->getId()); } $result = parent::update($service); $steeringListService = SteeringListService::getInstance(); $steeringListService->applySteering($service->getRestrictions(), $service->id); return $result; }