_setMessage('Your profile has been updated', static::MSG_UPDATED); $lockMessage = 'Your profile is currently being edited by "%firstName% %lastName%" %userRoleTitle%. ' . 'Please try again later.'; $this->_setMessage($lockMessage, static::MSG_LOCKED); if (!Qs_Request::getGetValue('sessionName')) { $this->_setBackUrl($this->_getRedirectUrl()); } return $this; } protected function _initAction() { $defaultAction = $this->getConfig('defaultAction'); if (!in_array($defaultAction, $this->_actions)) { throw new Qs_Exception('Default action is not set properly'); } $this->_defaultAction = $defaultAction; return parent::_initAction(); } protected function _getLog() { if (null === $this->_log) { parent::_getLog(); $this->_log->setAction('edit', 'Headed to Edit Profile'); $this->_log->setAction('update', 'Profile has been updated'); } return $this->_log; } protected function _callAction() { $this->_getDataObj()->setPrimarykey($this->_doc->getAuthData('id')); parent::_callAction(); } protected function _initFromForm(\Qs_Form $form) { $this->_newPassword = $form->getElement('password')->getValue(); return parent::_initFromForm($form); } protected function _postUpdate() { $this->_updateCredential(); if (Module::MODE_ASSOCIATION == $this->getConfig('mode')) { $this->_sendProfileUpdateNotification(); } return parent::_postUpdate(); } protected function _updateCredential() { if (!empty($this->_newPassword)) { $data = $this->_doc->getAuth()->getStorage()->read(); $data['credential'] = $this->_newPassword; $this->_doc->getAuth()->getStorage()->write($data); } return $this; } protected function _sendProfileUpdateNotification() { $previousData = $this->_getDataObj()->getPreviousData(); $currentData = $this->_getDataObj()->clearData()->getData(); $diffMail = new DiffMail($previousData, $currentData); $diffMail->send(); return $this; } protected function _getRedirectUrl() { $redirectUrl = Qs_SiteMap::findFirst(null, ['type' => 'User\\'], ['defaultAction' => 'view'], 'url'); if (!$redirectUrl) { /** * якщо немає сторінки з блоком інформації про юзера, то робимо перехід на першу сторінку в юзерського меню */ $page = Qs_SiteMap::findFirst(['isAccountNavigation' => 'y']); $redirectUrl = ('y' == $page['redirect']) ? $page['redirectAlias'] : $page['url']; } if (!$redirectUrl) { $redirectUrl = BASE_URL_LANGUAGE . '/' . PARENT_PAGE; } return $redirectUrl; } protected function _doView() { $item = $this->_getDataObj()->getDataForView(); if (empty($item) || Entity::STATUS_ACTIVE != $item['status']) { $this->_doc->display404(); } $item['config'] = $this->getConfig()->toArray(); $item['tpl'] = $this->getTemplate('view.tpl'); $this->_addItem($item); $this->_postView(); return $this; } protected function _getFormInstance($type, array $options = array()) { if ('edit' == $type) { $hasPermission = (bool) $this->_doc->getAuthData('hasPermission'); $options['jobTitleElementMode'] = $hasPermission ? SelectOther::MODE_SELECT_OTHER : SelectOther::MODE_SELECT; $options['companyId'] = $this->_doc->getAuthData('companyId'); $options['hasCompanyInformation'] = $hasPermission; $options['hasLeadership'] = (bool) $this->_doc->getAuthData('leadershipGroupId'); } return parent::_getFormInstance($type, $options); } }