Skip to content

Commit

Permalink
UPDATE: Show Agents as URL
Browse files Browse the repository at this point in the history
Show Agents as Subpage od the Team Page using page-url/show/agent-name
  • Loading branch information
Richard Rudy committed Nov 4, 2014
1 parent 1674a4e commit 67ad9b6
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 2 deletions.
9 changes: 7 additions & 2 deletions code/DataExtension/Agent.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ class Agent extends DataExtension {
"Cell" => "Varchar",
"SortOrder" => "Int",
"Bio" => "HTMLText",
"URLSegment" => "Varchar"
);

static $has_many = array(
Expand Down Expand Up @@ -69,6 +70,8 @@ public function updateCMSFields(FieldList $fields) {

function onBeforeWrite() {

$filter = URLSegmentFilter::create();
$folderName = $filter->filter($this->owner->Title);

if ($this->owner->FolderID == 0) {

Expand All @@ -77,12 +80,14 @@ function onBeforeWrite() {
* Find or Create Folder under assets/Homes named $address-$city
* Finds and attached the FolderID after its created
*/
$filter = URLSegmentFilter::create();
$folderName = $filter->filter($this->owner->Title);
$folderExists = Folder::find_or_make('Uploads/Agents/'.$folderName.'/');
$this->owner->FolderID = $folderExists->ID;
}

if(!$this->owner->URLSegment) {
$this->owner->URLSegment = $folderName;
}

parent::onBeforeWrite();
}

Expand Down
41 changes: 41 additions & 0 deletions code/Pages/TeamPage.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,11 +82,52 @@ function($item){
class TeamPage_Controller extends Page_Controller {

private static $allowed_actions = array (
"show"
);

public function init() {
parent::init();

}

public function getCurrentItem($itemID = null) {
$params = $this->request->allParams();
$class = "Member";

if($itemID)
{
return $class::get()->byID($itemID);
}
elseif(isset($params['ID']))
{
//Sanitize
$URL = Convert::raw2sql($params['ID']);

return $class::get()->filter("URLSegment", $URL)->first();
}
}

function show() {
if(($item = $this->getCurrentItem()))
{
if ($this->getCurrentItem()->canView())
{
$data = array(
'Item' => $item,
'BackLink' => base64_decode($this->request->getVar('backlink'))
);

return $this->customise(new ArrayData($data));
}
else
{
return Security::permissionFailure($this);
}
}
else
{
return $this->httpError(404);
}
}

}

0 comments on commit 67ad9b6

Please sign in to comment.