-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
helpfulrobot
committed
Dec 31, 2015
1 parent
78d3765
commit f18c3d4
Showing
5 changed files
with
246 additions
and
232 deletions.
There are no files selected for viewing
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
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,69 @@ | ||
<?php | ||
class CustomerQuestion extends DataObject { | ||
class CustomerQuestion extends DataObject | ||
{ | ||
|
||
static $singular_name = "Customer Question"; | ||
static $plural_name = "Customer Questions"; | ||
public static $singular_name = "Customer Question"; | ||
public static $plural_name = "Customer Questions"; | ||
|
||
static $db = array( | ||
"Name" => "Varchar(255)", | ||
"Cellphone" => "Varchar", | ||
"Email" => "Varchar(255)", | ||
"Question" => "Text", | ||
"Answer" => "Text", | ||
"Answered" => "Boolean", | ||
); | ||
public static $db = array( | ||
"Name" => "Varchar(255)", | ||
"Cellphone" => "Varchar", | ||
"Email" => "Varchar(255)", | ||
"Question" => "Text", | ||
"Answer" => "Text", | ||
"Answered" => "Boolean", | ||
); | ||
|
||
//Fields to show in the DOM | ||
static $summary_fields = array( | ||
"Name" => "Name", | ||
"Email" => "Email" | ||
); | ||
|
||
public function getCMSFields() { | ||
$fields = parent::getCMSFields(); | ||
$fields->removeFieldFromTab("Root.Main","Answered"); | ||
$fields->addFieldToTab("Root.Main", TextField::create('Name',_t('CustomerQuestion.NAME',"Name"))->setAttribute('readonly', true)); | ||
$fields->addFieldToTab("Root.Main", TextField::create('Cellphone',_t('CustomerQuestion.CELLPHONE',"Cell Phone"))->setAttribute('readonly', true)); | ||
$fields->addFieldToTab("Root.Main", TextField::create('Email',_t('CustomerQuestion.EMAIL',"Email"))->setAttribute('readonly', true)); | ||
$fields->addFieldToTab("Root.Main", TextareaField::create('Question',_t('CustomerQuestion.QUESTION',"Question"))->setAttribute('readonly', true)); | ||
//Fields to show in the DOM | ||
public static $summary_fields = array( | ||
"Name" => "Name", | ||
"Email" => "Email" | ||
); | ||
|
||
public function getCMSFields() | ||
{ | ||
$fields = parent::getCMSFields(); | ||
$fields->removeFieldFromTab("Root.Main", "Answered"); | ||
$fields->addFieldToTab("Root.Main", TextField::create('Name', _t('CustomerQuestion.NAME', "Name"))->setAttribute('readonly', true)); | ||
$fields->addFieldToTab("Root.Main", TextField::create('Cellphone', _t('CustomerQuestion.CELLPHONE', "Cell Phone"))->setAttribute('readonly', true)); | ||
$fields->addFieldToTab("Root.Main", TextField::create('Email', _t('CustomerQuestion.EMAIL', "Email"))->setAttribute('readonly', true)); | ||
$fields->addFieldToTab("Root.Main", TextareaField::create('Question', _t('CustomerQuestion.QUESTION', "Question"))->setAttribute('readonly', true)); | ||
|
||
$answer = TextareaField::create('Answer',_t('CustomerQuestion.ANSWER',"Your Answer")); | ||
$answer = TextareaField::create('Answer', _t('CustomerQuestion.ANSWER', "Your Answer")); | ||
|
||
|
||
if ($this->Answered) { | ||
$fields->addFieldToTab("Root.Main", $answer->setAttribute('readonly', true)); | ||
} | ||
else{ | ||
$fields->addFieldToTab("Root.Main", $answer); | ||
} | ||
|
||
$this->extend('updateCMSFields', $fields); | ||
return $fields; | ||
} | ||
|
||
public function onBeforeWrite(){ | ||
|
||
parent::onBeforeWrite(); | ||
// if this 2 conditions are met i know the user is inside the CMS and can answer the question | ||
if (!$this->Answered && !empty($this->Answer)) { | ||
//Set data | ||
$From = $this->Email; | ||
$cp = DataObject::get_one("ContactPage"); | ||
$To = $cp->Mailto; | ||
|
||
$Subject = _t('CustomerQuestion.ANSWER',"Here is your Answer!"); | ||
$Body = $this->Answer; | ||
$email = new Email($From, $To, $Subject, $Body); | ||
//set template | ||
$email->setTemplate('ContactAnswer'); | ||
//send mail | ||
if ($email->send()) { | ||
$this->Answered = 1; | ||
return Injector::inst()->get("Dashboard")->Link(); | ||
}else{ | ||
Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/error"); | ||
} | ||
} | ||
} | ||
} | ||
if ($this->Answered) { | ||
$fields->addFieldToTab("Root.Main", $answer->setAttribute('readonly', true)); | ||
} else { | ||
$fields->addFieldToTab("Root.Main", $answer); | ||
} | ||
|
||
$this->extend('updateCMSFields', $fields); | ||
return $fields; | ||
} | ||
|
||
public function onBeforeWrite() | ||
{ | ||
parent::onBeforeWrite(); | ||
// if this 2 conditions are met i know the user is inside the CMS and can answer the question | ||
if (!$this->Answered && !empty($this->Answer)) { | ||
//Set data | ||
$From = $this->Email; | ||
$cp = DataObject::get_one("ContactPage"); | ||
$To = $cp->Mailto; | ||
|
||
$Subject = _t('CustomerQuestion.ANSWER', "Here is your Answer!"); | ||
$Body = $this->Answer; | ||
$email = new Email($From, $To, $Subject, $Body); | ||
//set template | ||
$email->setTemplate('ContactAnswer'); | ||
//send mail | ||
if ($email->send()) { | ||
$this->Answered = 1; | ||
return Injector::inst()->get("Dashboard")->Link(); | ||
} else { | ||
Controller::curr()->redirect(Director::baseURL(). $this->URLSegment . "/error"); | ||
} | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,14 @@ | ||
<?php | ||
|
||
class CustomerQuestionsAdmin extends ModelAdmin { | ||
public static $managed_models = array('CustomerQuestion'); // Can manage multiple models | ||
static $url_segment = 'customer-questions'; | ||
static $menu_title = 'Customer Questions'; | ||
public $showImportForm = false; | ||
|
||
function BackLink() { | ||
return Injector::inst()->get("Dashboard")->Link(); | ||
} | ||
} | ||
class CustomerQuestionsAdmin extends ModelAdmin | ||
{ | ||
public static $managed_models = array('CustomerQuestion'); // Can manage multiple models | ||
public static $url_segment = 'customer-questions'; | ||
public static $menu_title = 'Customer Questions'; | ||
public $showImportForm = false; | ||
|
||
public function BackLink() | ||
{ | ||
return Injector::inst()->get("Dashboard")->Link(); | ||
} | ||
} |
Oops, something went wrong.