public function afterRegistry() { $this->user = $this->loader->getUserLoader()->getUserByStaffId($this->staffId); parent::afterRegistry(); $this->user = $this->loader->getUserLoader()->getUserByStaffId($this->staffId); $mailFields = $this->user->getMailFields(); $this->addMailFields($mailFields); $this->addTo($this->user->getEmailAddress(), $this->user->getFullName()); $this->setLanguage($this->user->getLocale()); }
/** * Returns the organization id that should currently be used for this form. * * @return int Returns the current organization id, if any */ public function getCurrentOrganizationId() { $userLoader = $this->loader->getUserLoader(); // Url determines organization first. if ($orgId = $userLoader->getOrganizationIdByUrl()) { $this->_organizationFromUrl = true; $userLoader->getCurrentUser()->setCurrentOrganization($orgId); return $orgId; } $request = $this->getRequest(); if ($request->isPost() && ($orgId = $request->getParam($this->organizationFieldName))) { return $orgId; } return $userLoader->getCurrentUser()->getCurrentOrganizationId(); }
/** * Add organization id and gul_user_class when needed * * @param mixed $row array or \Traversable row * @param scalar $key * @return mixed Row array or false when errors occurred */ public function translateRowValues($row, $key) { $row = parent::translateRowValues($row, $key); if (!$row) { return false; } if (!isset($row['gsf_id_organization'])) { $row['gsf_id_organization'] = $this->_organization->getId(); if (!isset($row['gul_user_class'])) { $row['gul_user_class'] = $this->_organization->get('gor_user_class'); } } elseif (!isset($row['gul_user_class'])) { $row['gul_user_class'] = $this->loader->getUserLoader()->getOrganization($row['gsf_id_organization'])->get('gor_user_class'); } return $row; }
/** * Hook that allows actions when data was saved * * When not rerouted, the form will be populated afterwards * * @param int $changed The number of changed rows (0 or 1 usually, but can be more) */ protected function afterSave($changed) { if ($changed) { $this->accesslog->logChange($this->request, null, $this->formData); // Reload the current user data $user = $this->currentUser; $currentOrg = $user->getCurrentOrganizationId(); $this->loader->getUserLoader()->unsetCurrentUser(); $user = $this->loader->getUser($user->getLoginName(), $user->getBaseOrganizationId())->setAsCurrentUser(); $user->setCurrentOrganization($currentOrg); // In case locale has changed, set it in a cookie \Gems_Cookies::setLocale($this->formData['gsf_iso_lang'], $this->basepath); $this->addMessage($this->_('Saved your setup data', $this->formData['gsf_iso_lang'])); } else { $this->addMessage($this->_('No changes to save!')); } if ($this->cacheTags && $this->cache instanceof \Zend_Cache_Core) { $this->cache->clean(\Zend_Cache::CLEANING_MODE_MATCHING_ANY_TAG, (array) $this->cacheTags); } }
/** * Save a single model item. * * Makes sure the password is saved too using the userclass * * @param array $newValues The values to store for a single model item. * @param array $filter If the filter contains old key values these are used * to decide on update versus insert. * @param array $saveTables Optional array containing the table names to save, * otherwise the tables set to save at model level will be saved. * @return array The values as they are after saving (they may change). */ public function save(array $newValues, array $filter = null, array $saveTables = null) { //First perform a save $savedValues = parent::save($newValues, $filter, $saveTables); //Now check if we need to save config values if (isset($newValues['gor_user_class']) && !empty($newValues['gor_user_class'])) { $definition = $this->loader->getUserLoader()->getUserDefinition($newValues['gor_user_class']); if ($definition instanceof \Gems_User_UserDefinitionConfigurableInterface && $definition->hasConfig()) { $savedValues = $definition->saveConfig($savedValues, $newValues); if ($definition->getConfigChanged() > 0 && $this->getChanged() < 1) { $this->setChanged(1); } } } return $savedValues; }
/** * Save a single model item. * * Makes sure the password is saved too using the userclass * * @param array $newValues The values to store for a single model item. * @param array $filter If the filter contains old key values these are used * to decide on update versus insert. * @param array $saveTables Optional array containing the table names to save, * otherwise the tables set to save at model level will be saved. * @return array The values as they are after saving (they may change). */ public function save(array $newValues, array $filter = null, array $saveTables = null) { //First perform a save $savedValues = parent::save($newValues, $filter, $saveTables); //Now check if we need to set the password if (isset($newValues['fld_password']) && !empty($newValues['fld_password'])) { if ($this->getChanged() < 1) { $this->setChanged(1); } //Now load the userclass and save the password use the $savedValues as for a new //user we might not have the id in the $newValues $user = $this->loader->getUserLoader()->getUserByStaffId($savedValues['gsf_id_user']); if ($user->canSetPassword()) { $user->setPassword($newValues['fld_password']); } } return $savedValues; }