Source of file MemberEditProfileForm.php
Size: 3,469 Bytes - Last Modified: 2022-02-21T10:00:12+00:00
/var/www/docs.ssmods.com/process/src/code/forms/MemberEditProfileForm.php
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 | <?php /* * Member Profile Editor Form * @author Anton Fedianin aka Tony Air <tony@twma.pro> * https://tony.twma.pro/ * */ class MemberEditProfileForm extends Form { protected $member; public function __construct($controller, $name, Member $member) { $this->member = $member; $fields = $this->member->getMemberFormFields(); $fields->push(HiddenField::create('ID', 'ID', $this->member->ID)); $fields->removeByName('Password'); $actions = FieldList::create( FormAction::create( 'updatedetails', _t('MemberEditProfileForm.UPDATE', 'Update') ) ); $validator = Member_Validator::create( 'FirstName', 'Surname', 'Email' ); parent::__construct($controller, $name, $fields, $actions, $validator); $passwordfield = $this->getChangePasswordField(); if ($passwordfield) { $fields->push($passwordfield); } $this->member->extend('updateMemberEditProfileForm', $this); $this->loadDataFrom($this->member); } public function updatedetails($data, $form) { $form->saveInto($this->member); if (Member::config()->send_frontend_update_notifications) { $this->sendUpdateNotification($data); } $this->member->extend('updateMemberEditProfileFormSubmit', $data, $form); $this->member->write(); $form->sessionMessage(_t('MemberEditProfileForm.UPDATED', 'Your member details have been updated.'), 'good'); return $this->controller->redirectBack(); } public function sendUpdateNotification($data) { $body = _t( 'MemberEditProfileForm.UPDATEDMSGCONTENT', '{name} has updated their details via the website. Here is the new information:<br/>', ['name' => $this->member->getName()] ); $notifyOnFields = Member::config() ->frontend_update_notification_fields ?: DataObject::database_fields('Member'); $changedFields = $this->member->getChangedFields(true, 2); $send = false; foreach ($changedFields as $key => $field) { if (in_array($key, $notifyOnFields)) { $body .= "<br/><strong>$key:</strong><br/>". "<b style='color:red;'>".$field['before'].'</b><br/>'. "<span style='color:green;'>".$field['after'].'</span><br/>'; $send = true; } } if ($send) { $email = StyledHtmlEmail::create( Email::config()->admin_email, Email::config()->admin_email, _t( 'MemberEditProfileForm.UPDATEDMSGTITLE', 'Member details update: {name}', ['name' => $this->member->getName()] ), $body ); $email->send(); } } protected function getChangePasswordField() { if ($this->member->ID != Member::currentUserID()) { return false; } return LiteralField::create( 'ChangePasswordLink', '<div class="field"><p>' .'<a href="Security/changepassword?BackURL='.$this->controller->Link().'">' ._t('MemberEditProfileForm.CHANGEPASSWORD', 'Сhange password') .'</a></p></div>' ); } } |