_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); $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(); $diff = new Diff($previousData, $currentData); $updatedData = $diff->getDiff(); if ($updatedData) { $subject = SettingsObj::get('changeProfileEmailSubject'); $from = SettingsObj::getEmailFrom('changeProfileEmailFrom'); $to = SettingsObj::getAdminEmails(); $body = SettingsObj::get('changeProfileEmailBody'); $data = $this->_getDataObj()->getData(); $data['link'] = BASE_URL_LANGUAGE; if (false !== ($link = Qs_SiteMap::findFirst(null, ['type' => 'User\\Admin\\'], null, 'url'))) { $query = ['action' => 'edit', 'id' => $this->_getDataObj()->getPrimaryKey()]; $data['link'] = $link . '?' . http_build_query($query); } $data['changedFields'] = $this->_renderChangedFields($updatedData); $escapedFields = ['changedFields']; foreach ($data as $field => $value) { if (is_array($value)) { continue; } if (!in_array($field, $escapedFields)) { $value = htmlspecialchars($value); } $body = str_replace('{' . $field . '}', $value, $body); } $this->_sendMail(compact('subject', 'from', 'to', 'body')); } return $this; } protected function _renderChangedFields(array $data) { $smarty = $this->_doc->getSmarty(); $smarty->assign('DOC', $this->_doc); $item['templatePath'] = (array) $this->_getTemplatePath(); $item['fields'] = $data; $itemObj = new Qs_Doc_Item($item); $smarty->assign('item', $itemObj); return $smarty->fetch($itemObj->getTemplate('changed-fields-render.tpl')); } protected function _getRedirectUrl() { $redirectUrl = Qs_SiteMap::findFirst(null, ['type' => 'User\\'], ['defaultAction' => 'view'], 'url'); if (!$redirectUrl) { /** * якщо немає сторінки з блоком інформації про юзера, то робимо перехід на першу сторінку в юзерського меню */ $redirectUrl = Qs_SiteMap::findFirst(['isAccountNavigation' => 'y'], null, null, 'url'); } if (!$redirectUrl) { $redirectUrl = BASE_URL_LANGUAGE . '/' . PARENT_PAGE; } return $redirectUrl; } protected function _doView() { if ($this->_doc->isPagePreviewMode()) { /** * Якщо ми на прев’юві сторінки, то дані про юзера треба браит з конфігі, а не з БД. */ $item = $this->getConfig('previewData')->dbData->toArray(); } else { $item = $this->_getDataObj()->getDataForView(); } if (empty($item) || Entity::STATUS_ACTIVE != $item['status']) { $this->_doc->display404(); } $item['personBlockClass'] = 'person-info'; $item['companyBlockClass'] = 'company-info'; $options['selector'] = '.' . $item['personBlockClass'] . ', ' . '.' . $item['companyBlockClass']; $this->_doc->addInitFunction('qs.html.justifyHeight', [$options]); $item['config'] = $this->getConfig()->toArray(); $item['showPhoto'] = Module::MODE_ASSOCIATION === $this->getConfig('mode'); $item['tpl'] = $this->getTemplate('view.tpl'); $this->_addItem($item); $this->_postView(); return $this; } protected function _doEdit() { if ($this->_doc->isPagePreviewMode()) { /** * Якщо ми на прев’юві сторінки, то дані про юзера треба брати з конфігу, а не з БД. */ $data = $this->getConfig('previewData')->dbData->toArray(); } else { $data = $this->_getDataObj()->getData(); } if (null === $data) { $this->_setBackError(static::MSG_DATA_UNAVAILABLE); $this->_doBack(); } if (!$this->_lock()) { $this->_setBackAttention($this->_createMessage(static::MSG_LOCKED, $this->_getLocker())); $this->_doBack(); } $form = $this->_getEditForm(['defaults' => $data]); $form->setDefaults(); $this->_addFormItem($form); $this->_postEdit(); return $this; } }