Created
March 5, 2014 22:45
-
-
Save Thijzer/9378277 to your computer and use it in GitHub Desktop.
Fork:FE-Module-Detail action + form
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* This is the FE -Module -Detail action + form Gist | |
* sublime hooks : -Module -Detail | |
* | |
* | |
* @author Thijs De Paepe <[email protected]> | |
* | |
*/ | |
class Frontend-Module-Detail extends FrontendBaseBlock | |
{ | |
/** | |
* | |
* @var array | |
*/ | |
private $record; | |
private $item; | |
private $frm; | |
/** | |
* Execute the extra | |
*/ | |
public function execute() | |
{ | |
parent::execute(); | |
$this->loadTemplate(); | |
$this->getData(); | |
// drop specific methods here | |
$this->loadForm(); | |
$this->validateForm(); | |
$this->parse(); | |
} | |
/** | |
* Load the data, don't forget to validate the incoming data | |
*/ | |
private function getData() | |
{ | |
/* | |
// validate incoming parameters | |
if($this->URL->getParameter(1) === null) $this->redirect(FrontendNavigation::getURL(404)); | |
// get by URL | |
$this->record = FrontendFaqModel::get($this->URL->getParameter(1)); | |
// anything found? | |
if(empty($this->record)) $this->redirect(FrontendNavigation::getURL(404)); | |
// overwrite URLs | |
$this->record['sub_full_url'] = FrontendNavigation::getURLForBlock( | |
'mod', 'sub') . '/' . $this->record['sub_url']; | |
$this->record['full_url'] = FrontendNavigation::getURLForBlock( | |
'mob', 'sub') . '/' . $this->record['url']; | |
// get tags | |
$this->record['tags'] = FrontendTagsModel::getForItem('mod', $this->record['id']); | |
// get settings | |
$this->settings = FrontendModel::get-ModuleSettings('mod'); | |
// reset allow comments | |
if(!$this->settings['allow_feedback']) $this->record['allow_feedback'] = false; | |
// get status | |
$this->status = $this->URL->getParameter(2); | |
if($this->status == FL::getAction('Success')) $this->status = 'success'; | |
if($this->status == FL::getAction('Spam')) $this->status = 'spam'; | |
*/ | |
} | |
/** | |
* Load the form | |
*/ | |
private function loadForm() | |
{ | |
/* | |
$this->frm = new FrontendForm('form'); | |
$this->frm->addHidden('some_hidden_id', $this->record['id']); | |
$this->frm->addTextarea('message'); | |
$this->frm->addRadiobutton('useful', array( | |
array('label' => FL::lbl('Yes'), 'value' => 'Y'), | |
array('label' => FL::lbl('No'), 'value' => 'N') | |
)); | |
$this->frm->addText(); | |
$this->frm->addEmail(); | |
*/ | |
} | |
/** | |
* Parse the data into the template | |
*/ | |
private function parse() | |
{ | |
/* | |
// add to breadcrumb | |
if($this->settings['allow_multiple_categories']) $this->breadcrumb->addElement($this->record['category_title'], $this->record['category_full_url']); | |
$this->breadcrumb->addElement($this->record['question']); | |
// set meta | |
if($this->settings['allow_multiple_categories']) $this->header->setPageTitle($this->record['category_title']); | |
$this->header->setPageTitle($this->record['question']); | |
// assign article | |
$this->tpl->assign('item', $this->record); | |
// assign settings | |
$this->tpl->assign('settings', $this->settings); | |
// parse the form | |
if(empty($this->status)) $this->frm->parse($this->tpl); | |
// parse the form status | |
if(!empty($this->status)) $this->tpl->assign($this->status, true); | |
*/ | |
} | |
/** | |
* Validate the form | |
*/ | |
private function validateForm() | |
{ | |
/* | |
if($this->frm->isSubmitted()) | |
{ | |
// cleanup the submitted fields, ignore fields that were added by hackers | |
$this->frm->cleanupFields(); | |
// check the fields | |
if($this->frm->isCorrect()) | |
{ | |
// reformat data | |
$item = array(); | |
// set from value and math name with DB | |
$item['title'] = $this->frm->getField('title')->getValue(); | |
$item['name'] = $this->frm->getField('name')->getValue(); | |
$item['email'] = $this->frm->getField('email')->getValue(); | |
// auto fields like datetime | |
$item['id'] = ''; | |
$item['created_on'] = ''; | |
$item['edited_on'] = ''; | |
$item['published_on'] = ''; | |
// update the record | |
Frontend-ModuleModel::set('mod_DB_name' $this->record['id'], $item); | |
// save status | |
$this->redirect($this->record['full_url'] . '/' . FL::getAction('Success')); | |
} | |
} | |
*/ | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment