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 9d77e60 commit 4fd55a7
Show file tree
Hide file tree
Showing 12 changed files with 571 additions and 533 deletions.
49 changes: 25 additions & 24 deletions code/cms/MemberAdmin.php
Original file line number Diff line number Diff line change
@@ -1,31 +1,32 @@
<?php

class MemberAdmin extends ModelAdmin{

private static $url_segment = "members";
private static $menu_title = "Members";
private static $menu_icon = 'members/images/members-icon.png';
class MemberAdmin extends ModelAdmin
{

private static $url_segment = "members";
private static $menu_title = "Members";
private static $menu_icon = 'members/images/members-icon.png';

private static $managed_models = array(
'Member'
);
private static $managed_models = array(
'Member'
);

private static $model_importers = array(
'Member' => 'MemberBulkLoader'
);
private static $model_importers = array(
'Member' => 'MemberBulkLoader'
);

public function getEditForm($id = null, $fields = null) {
$form = parent::getEditForm();
public function getEditForm($id = null, $fields = null)
{
$form = parent::getEditForm();

if($this->modelClass == "Member"){
if($columns = Member::config()->export_fields){
$form->Fields()->fieldByName("Member")->getConfig()
->getComponentByType("GridFieldExportButton")
->setExportColumns($columns);
}
}
if ($this->modelClass == "Member") {
if ($columns = Member::config()->export_fields) {
$form->Fields()->fieldByName("Member")->getConfig()
->getComponentByType("GridFieldExportButton")
->setExportColumns($columns);
}
}

return $form;
}

}
return $form;
}
}
70 changes: 36 additions & 34 deletions code/cms/MemberBulkLoader.php
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
<?php

/**
* Add some additional functionality to MemberCsvBulkLoader
*/
class MemberBulkLoader extends MemberCsvBulkLoader {

public $columnMap = array(
'Name' => '->importFirstAndLastName'
);

static function importFirstAndLastName(&$obj, $val, $record) {
$nameParts = explode(' ', trim($val));
$obj->FirstName = array_shift($nameParts);
$obj->Surname = join(' ', $nameParts);
}

public function processRecord($record, $columnMap, &$results, $preview = false) {
$skip = false;
$this->extend('preprocess', $record, $columnMap, $results, $preview, $skip);
if($skip){
return 0;
}
$id = parent::processRecord($record, $columnMap, $results, $preview);
if($member = Member::get()->byID($id)){
$this->extend('postprocess', $member, $record, $columnMap, $results, $preview);//callback for doing other custom stuff
$member->write();
$member->destroy();
unset($member);
}
return $id;
}

}
<?php

/**
* Add some additional functionality to MemberCsvBulkLoader
*/
class MemberBulkLoader extends MemberCsvBulkLoader
{

public $columnMap = array(
'Name' => '->importFirstAndLastName'
);

public static function importFirstAndLastName(&$obj, $val, $record)
{
$nameParts = explode(' ', trim($val));
$obj->FirstName = array_shift($nameParts);
$obj->Surname = join(' ', $nameParts);
}

public function processRecord($record, $columnMap, &$results, $preview = false)
{
$skip = false;
$this->extend('preprocess', $record, $columnMap, $results, $preview, $skip);
if ($skip) {
return 0;
}
$id = parent::processRecord($record, $columnMap, $results, $preview);
if ($member = Member::get()->byID($id)) {
$this->extend('postprocess', $member, $record, $columnMap, $results, $preview);//callback for doing other custom stuff
$member->write();
$member->destroy();
unset($member);
}
return $id;
}
}
108 changes: 57 additions & 51 deletions code/extensions/MemberProfileExtension.php
Original file line number Diff line number Diff line change
@@ -1,53 +1,59 @@
<?php

class MemberProfileExtension extends DataExtension{

private static $has_one = array(
'Image' => 'Image'
);

public function updateCMSFields(FieldList $fields) {
$fields->addFieldToTab("Root.Image",
UploadField::create("Image","Profile Image")
);
}

public function getProfileLink($action = null) {
if($directorypage = MembersDirectoryPage::get()->first()){
return Controller::join_links(
$directorypage->Link(),
"view",
$this->owner->ID,
$action
);
}
return Director::baseURL().MemberProfilePage_Controller::config()->url_segment;
}

//allow content editors to CVED (CRUD)

public function canCreate($member = null) {
if(Permission::check("CMS_ACCESS_CMSMain")){
return true;
}
}

public function canView($member = null) {
if(Permission::check("CMS_ACCESS_CMSMain")){
return true;
}
}

public function canEdit($member = null) {
if(Permission::check("CMS_ACCESS_CMSMain")){
return true;
}
}

public function canDelete($member = null) {
if(Permission::check("CMS_ACCESS_CMSMain")){
return true;
}
}

}
class MemberProfileExtension extends DataExtension
{

private static $has_one = array(
'Image' => 'Image'
);

public function updateCMSFields(FieldList $fields)
{
$fields->addFieldToTab("Root.Image",
UploadField::create("Image", "Profile Image")
);
}

public function getProfileLink($action = null)
{
if ($directorypage = MembersDirectoryPage::get()->first()) {
return Controller::join_links(
$directorypage->Link(),
"view",
$this->owner->ID,
$action
);
}
return Director::baseURL().MemberProfilePage_Controller::config()->url_segment;
}

//allow content editors to CVED (CRUD)

public function canCreate($member = null)
{
if (Permission::check("CMS_ACCESS_CMSMain")) {
return true;
}
}

public function canView($member = null)
{
if (Permission::check("CMS_ACCESS_CMSMain")) {
return true;
}
}

public function canEdit($member = null)
{
if (Permission::check("CMS_ACCESS_CMSMain")) {
return true;
}
}

public function canDelete($member = null)
{
if (Permission::check("CMS_ACCESS_CMSMain")) {
return true;
}
}
}
122 changes: 63 additions & 59 deletions code/extensions/SendTempPasswordExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,69 @@
/**
* Provides a to generate and send a password to a user.
*/
class TemporaryPasswordExtension extends DataExtension{

private $called = false;
class TemporaryPasswordExtension extends DataExtension
{

private $called = false;

/**
* Add 'Send temp password' action to cms
*/
public function updateCMSFields(FieldList $fields) {
//requirements: ajax link
if(!$this->called && $this->owner->hasMethod("Link")) //hack because member getCMSFields calls parent, which also has the extend->('updateCMSFields')
$fields->addFieldToTab('Root.Actions',
new LiteralField('TempPasswordLink',
'<a href="'.$this->owner->Link('sendnewpassword').'" target="new">send temp password</a>'
)
);
$this->called = true;
}
/**
* Add 'Send temp password' action to cms
*/
public function updateCMSFields(FieldList $fields)
{
//requirements: ajax link
if (!$this->called && $this->owner->hasMethod("Link")) { //hack because member getCMSFields calls parent, which also has the extend->('updateCMSFields')
$fields->addFieldToTab('Root.Actions',
new LiteralField('TempPasswordLink',
'<a href="'.$this->owner->Link('sendnewpassword').'" target="new">send temp password</a>'
)
);
}
$this->called = true;
}

/**
* Create the temporary password, and set it.
*/
public function setupTempPassword($expires = false){
if($expires){
$this->owner->PassworExpiry = date($expires); //TODO: not working yet
}
$password = substr(md5(microtime()),0,6);
$this->owner->changePassword($password);
return $password;
}

/**
* Send temporary password to user via email.
*/
public function sendTempPasswordEmail($template = null, $subject = null, $extradata = null){
//set expiry
$template = ($template) ? $template : 'TempPasswordEmail';
$subject = ($subject) ? $subject : "Temporary Password";

$data = array(
'CleartextTempPassword' => $this->owner->setupTempPassword()
);
if($extradata){
$data = array_merge($data, $extradata);
}
$body = $this->owner->customise($data)->renderWith($template);

if(Email::validEmailAddress($this->owner->Email)){
$email = new Email(
Email::getAdminEmail(),
$this->owner->Email,
$subject,
$body
);
if($email->send()){
return true;
}
return false;
}
return false;
}

/**
* Create the temporary password, and set it.
*/
public function setupTempPassword($expires = false)
{
if ($expires) {
$this->owner->PassworExpiry = date($expires); //TODO: not working yet
}
$password = substr(md5(microtime()), 0, 6);
$this->owner->changePassword($password);
return $password;
}

/**
* Send temporary password to user via email.
*/
public function sendTempPasswordEmail($template = null, $subject = null, $extradata = null)
{
//set expiry
$template = ($template) ? $template : 'TempPasswordEmail';
$subject = ($subject) ? $subject : "Temporary Password";

$data = array(
'CleartextTempPassword' => $this->owner->setupTempPassword()
);
if ($extradata) {
$data = array_merge($data, $extradata);
}
$body = $this->owner->customise($data)->renderWith($template);

if (Email::validEmailAddress($this->owner->Email)) {
$email = new Email(
Email::getAdminEmail(),
$this->owner->Email,
$subject,
$body
);
if ($email->send()) {
return true;
}
return false;
}
return false;
}
}
Loading

0 comments on commit 4fd55a7

Please sign in to comment.