Skip to content

Commit

Permalink
Converted to PSR-2
Browse files Browse the repository at this point in the history
  • Loading branch information
helpfulrobot committed Dec 31, 2015
1 parent fd272b8 commit 3c8ffbf
Show file tree
Hide file tree
Showing 4 changed files with 226 additions and 249 deletions.
191 changes: 93 additions & 98 deletions code/EditProfilePage.php
@@ -1,98 +1,93 @@
<?php

class EditProfilePage extends Page
{
}

class EditProfilePage_Controller extends Page_Controller
{
static $allowed_actions = array(
'EditProfileForm'
);

function EditProfileForm()
{
//Create our fields
$fields = new FieldList(
new TextField('FirstName', '<span>*</span> Firstname'),
new TextField('Surname', '<span>*</span> Surname'),
new EmailField('Email', '<span>*</span> Email'),
new TextField('JobTitle', 'Job Title'),
new TextField('Website', 'Website (Without http://)'),
new TextareaField('Blurb'),
new ConfirmedPasswordField('Password', 'New Password')
);

// Create action
$actions = new FieldList(
new FormAction('SaveProfile', 'Save')
);

// Create action
$validator = new RequiredFields('FirstName', 'Email');

//Create form
$Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);

//Populate the form with the current members data
$Member = Member::CurrentUser();
$Form->loadDataFrom($Member->data());

//Return the form
return $Form;
}

//Save profile
function SaveProfile($data, $form)
{
//Check for a logged in member
if($CurrentMember = Member::currentUser())
{
//Check for another member with the same email address
if($member = DataObject::get_one("Member", "Email = '". Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID))
{
//Set error message
$form->sessionMessage($data['Email'].". Sorry, that email address already exists. Please choose another.", 'bad');

//Return back to form
return $this->redirectBack();
//return Director::redirectBack();
}
//Otherwise check that user IDs match and save
else
{
$form->saveInto($CurrentMember);

$CurrentMember->write();

return $this->redirect($this->Link('?saved=1'));
}
}
//If not logged in then return a permission error
else
{
return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:');
}
}

//Check for just saved
function Saved()
{
return $this->request->getVar('saved');
}

/*
//Check for success status
function Success()
{
return $this->request->getVar('success');
}
*/

//Check for edit status
function Edit(){
return $this->request->getVar('edit');
}


}
<?php

class EditProfilePage extends Page
{
}

class EditProfilePage_Controller extends Page_Controller
{
public static $allowed_actions = array(
'EditProfileForm'
);

public function EditProfileForm()
{
//Create our fields
$fields = new FieldList(
new TextField('FirstName', '<span>*</span> Firstname'),
new TextField('Surname', '<span>*</span> Surname'),
new EmailField('Email', '<span>*</span> Email'),
new TextField('JobTitle', 'Job Title'),
new TextField('Website', 'Website (Without http://)'),
new TextareaField('Blurb'),
new ConfirmedPasswordField('Password', 'New Password')
);

// Create action
$actions = new FieldList(
new FormAction('SaveProfile', 'Save')
);

// Create action
$validator = new RequiredFields('FirstName', 'Email');

//Create form
$Form = new Form($this, 'EditProfileForm', $fields, $actions, $validator);

//Populate the form with the current members data
$Member = Member::CurrentUser();
$Form->loadDataFrom($Member->data());

//Return the form
return $Form;
}

//Save profile
public function SaveProfile($data, $form)
{
//Check for a logged in member
if ($CurrentMember = Member::currentUser()) {
//Check for another member with the same email address
if ($member = DataObject::get_one("Member", "Email = '". Convert::raw2sql($data['Email']) . "' AND ID != " . $CurrentMember->ID)) {
//Set error message
$form->sessionMessage($data['Email'].". Sorry, that email address already exists. Please choose another.", 'bad');

//Return back to form
return $this->redirectBack();
//return Director::redirectBack();
}
//Otherwise check that user IDs match and save
else {
$form->saveInto($CurrentMember);

$CurrentMember->write();

return $this->redirect($this->Link('?saved=1'));
}
}
//If not logged in then return a permission error
else {
return Security::PermissionFailure($this->controller, 'You must <a href="register">registered</a> and logged in to edit your profile:');
}
}

//Check for just saved
public function Saved()
{
return $this->request->getVar('saved');
}

/*
//Check for success status
function Success()
{
return $this->request->getVar('success');
}
*/

//Check for edit status
public function Edit()
{
return $this->request->getVar('edit');
}
}
53 changes: 26 additions & 27 deletions code/MemberDecorator.php
@@ -1,27 +1,26 @@
<?php
class MemberDecorator extends DataExtension{

private static $db=array(
"JobTitle" => 'Varchar',
"Blurb" => "Text",
"Website" => "Varchar(100)"
);

//Add form fields to CMS
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab("Root.Profile", new TextField('JobTitle', 'Job Title'));
$fields->addFieldToTab("Root.Profile", new TextField('Website', 'Website', 'http://'));
$fields->addFieldToTab("Root.Profile", new TextareaField('Blurb', 'Blurb'));
}

//Link to the edit profile page
function Link()
{
if($ProfilePage = DataObject::get_one('EditProfilePage'))
{
return $ProfilePage->Link();
}
}

}
<?php
class MemberDecorator extends DataExtension
{

private static $db=array(
"JobTitle" => 'Varchar',
"Blurb" => "Text",
"Website" => "Varchar(100)"
);

//Add form fields to CMS
public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab("Root.Profile", new TextField('JobTitle', 'Job Title'));
$fields->addFieldToTab("Root.Profile", new TextField('Website', 'Website', 'http://'));
$fields->addFieldToTab("Root.Profile", new TextareaField('Blurb', 'Blurb'));
}

//Link to the edit profile page
public function Link()
{
if ($ProfilePage = DataObject::get_one('EditProfilePage')) {
return $ProfilePage->Link();
}
}
}
45 changes: 22 additions & 23 deletions code/MemberPage.php
@@ -1,27 +1,26 @@
<?php
class MemberPage extends Page{

class MemberPage extends Page
{
}

class MemberPage_Controller extends Page_Controller{

static $allowed_actions = array('index');

function index(){
$Member = Member::CurrentUser();
if ($Member==null) {
//echo "do resgistration";
if ($RegistrationPage = DataObject::get_one('RegistrationPage')){
return $this->redirect($RegistrationPage->Link());
}
}
else{
//echo "do edit registration";
if ($EditProfilePage = DataObject::get_one('EditProfilePage')){
return $this->redirect($EditProfilePage->Link());
class MemberPage_Controller extends Page_Controller
{

}
}
}

}
public static $allowed_actions = array('index');

public function index()
{
$Member = Member::CurrentUser();
if ($Member==null) {
//echo "do resgistration";
if ($RegistrationPage = DataObject::get_one('RegistrationPage')) {
return $this->redirect($RegistrationPage->Link());
}
} else {
//echo "do edit registration";
if ($EditProfilePage = DataObject::get_one('EditProfilePage')) {
return $this->redirect($EditProfilePage->Link());
}
}
}
}

0 comments on commit 3c8ffbf

Please sign in to comment.