Renamed a few methods for clarification.
This commit is contained in:
parent
f94186a20f
commit
6723ece603
@ -106,13 +106,13 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
|||||||
$data['action_uc'] = ucwords($action);
|
$data['action_uc'] = ucwords($action);
|
||||||
|
|
||||||
$fd = new FieldDefinition($action);
|
$fd = new FieldDefinition($action);
|
||||||
$fd->addFieldValues($_SESSION[$skey]);
|
$fd->setFieldValues($_SESSION[$skey]);
|
||||||
$fieldData = $fd->getFieldData();
|
$fieldData = $fd->getFieldData();
|
||||||
$fields = $fieldData['fields'];
|
$fields = $fieldData['fields'];
|
||||||
|
|
||||||
$data['email_date'] = date('r');
|
$data['email_date'] = date('r');
|
||||||
$data = array_merge($data, $fields);
|
$data = array_merge($data, $fields);
|
||||||
$mo->addTemplateVars($data);
|
$mo->setTemplateVars($data);
|
||||||
$mo->setSubject('[FRS] ' . $data['action_uc'] . ' Reservation');
|
$mo->setSubject('[FRS] ' . $data['action_uc'] . ' Reservation');
|
||||||
$mo->addRecipient($data['user']['email'], $data['user']['name_first'] . ' ' . $data['user']['name_last']);
|
$mo->addRecipient($data['user']['email'], $data['user']['name_first'] . ' ' . $data['user']['name_last']);
|
||||||
$mail_sent = $mo->send();
|
$mail_sent = $mo->send();
|
||||||
@ -144,7 +144,7 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
|||||||
$action = 'rentalcar';
|
$action = 'rentalcar';
|
||||||
require 'prep_form.php';
|
require 'prep_form.php';
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
if (!$tpl_done) {
|
if (!$tpl_done) {
|
||||||
$ho->setTemplate('loggedin_html');
|
$ho->setTemplate('loggedin_html');
|
||||||
$tpl_done = true;
|
$tpl_done = true;
|
||||||
@ -160,5 +160,5 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
|||||||
|
|
||||||
$data['action'] = $_GET['action'];
|
$data['action'] = $_GET['action'];
|
||||||
|
|
||||||
$ho->addTemplateVars($data);
|
$ho->setTemplateVars($data);
|
||||||
$ho->sendOutputToStdout();
|
$ho->sendOutputToStdout();
|
||||||
|
@ -124,17 +124,22 @@ class FieldDefinition
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds a placeholder token and the desired replacement value.
|
* Sets a placeholder token and the desired replacement value.
|
||||||
*
|
*
|
||||||
* @param string $placeholder Placeholder, e.g. USER_NAME
|
* @param string $placeholder Placeholder, e.g. USER_NAME
|
||||||
* @param string $replacement Replacement value, e.g. John Doe
|
* @param string $replacement Replacement value, e.g. John Doe
|
||||||
*/
|
*/
|
||||||
public function addPlaceholder($placeholder, $replacement)
|
public function setPlaceholder($placeholder, $replacement)
|
||||||
{
|
{
|
||||||
$this->placeholders[$placeholder] = $replacement;
|
$this->placeholders[$placeholder] = $replacement;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addPlaceholders($placeholders)
|
/**
|
||||||
|
* Sets multiple placeholders and their values.
|
||||||
|
*
|
||||||
|
* @param array $placeholders Associative array of placeholders and values
|
||||||
|
*/
|
||||||
|
public function setPlaceholders($placeholders)
|
||||||
{
|
{
|
||||||
$this->placeholders = array_merge($this->placeholders, $placeholders);
|
$this->placeholders = array_merge($this->placeholders, $placeholders);
|
||||||
}
|
}
|
||||||
@ -150,12 +155,11 @@ class FieldDefinition
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds the given $values or default values and replaces $placeholders. Also
|
* Sets the given $values for the given fields.
|
||||||
* adds some helping attributes to fields.
|
|
||||||
*
|
*
|
||||||
* @param mixed[] Key-value-array of values (value) to assign to fields (key)
|
* @param mixed[] Key-value-array of values (value) to assign to fields (key)
|
||||||
*/
|
*/
|
||||||
public function addFieldValues($values = array())
|
public function setFieldValues($values = array())
|
||||||
{
|
{
|
||||||
foreach ($this->fieldData['fields'] as $key=>$meta) {
|
foreach ($this->fieldData['fields'] as $key=>$meta) {
|
||||||
// Assign session value if set, or use default if set
|
// Assign session value if set, or use default if set
|
||||||
|
@ -33,12 +33,12 @@ class GenericOutput
|
|||||||
$this->template = $this->templateEngine->loadTemplate($templateName);
|
$this->template = $this->templateEngine->loadTemplate($templateName);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addTemplateVar($key, $value)
|
public function setTemplateVar($key, $value)
|
||||||
{
|
{
|
||||||
$this->templateVars[$key] = $value;
|
$this->templateVars[$key] = $value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function addTemplateVars($tplVars)
|
public function setTemplateVars($tplVars)
|
||||||
{
|
{
|
||||||
// maybe use array_merge_recursive one day... but currently I think this is better
|
// maybe use array_merge_recursive one day... but currently I think this is better
|
||||||
$this->templateVars = array_merge($this->templateVars, $tplVars);
|
$this->templateVars = array_merge($this->templateVars, $tplVars);
|
||||||
|
@ -15,8 +15,8 @@ $placeholders = array(
|
|||||||
'USER_NAME' => $data['user']['name_first'] . ' ' . $data['user']['name_last'],
|
'USER_NAME' => $data['user']['name_first'] . ' ' . $data['user']['name_last'],
|
||||||
'USER_EMAIL' => $data['user']['email'],
|
'USER_EMAIL' => $data['user']['email'],
|
||||||
);
|
);
|
||||||
$fd->addPlaceholders($placeholders);
|
$fd->setPlaceholders($placeholders);
|
||||||
$fd->addFieldValues($_SESSION[$skey]);
|
$fd->setFieldValues($_SESSION[$skey]);
|
||||||
|
|
||||||
$by_group = $fd->getGroups();
|
$by_group = $fd->getGroups();
|
||||||
|
|
||||||
|
@ -34,8 +34,8 @@ class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testAddFieldValues()
|
public function testAddFieldValues()
|
||||||
{
|
{
|
||||||
$fdo = new FieldDefinition('hotel');
|
$fdo = new FieldDefinition('hotel');
|
||||||
$fdo->addPlaceholder('USER_NAME', 'John Doe');
|
$fdo->setPlaceholder('USER_NAME', 'John Doe');
|
||||||
$fdo->addFieldValues(array('url'=>'http://example.org/'));
|
$fdo->setFieldValues(array('url'=>'http://example.org/'));
|
||||||
$fd = $fdo->getFieldData();
|
$fd = $fdo->getFieldData();
|
||||||
$this->assertArrayHasKey('fields', $fd);
|
$this->assertArrayHasKey('fields', $fd);
|
||||||
$this->assertArrayHasKey('url', $fd['fields']);
|
$this->assertArrayHasKey('url', $fd['fields']);
|
||||||
@ -47,7 +47,7 @@ class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
public function testSupportValues()
|
public function testSupportValues()
|
||||||
{
|
{
|
||||||
$fdo = new FieldDefinition('hotel');
|
$fdo = new FieldDefinition('hotel');
|
||||||
$fdo->addFieldValues(array('modifiedTime'=>'2016-01-01 01:01:01'));
|
$fdo->setFieldValues(array('modifiedTime'=>'2016-01-01 01:01:01'));
|
||||||
$fd = $fdo->getFieldData();
|
$fd = $fdo->getFieldData();
|
||||||
$this->assertArrayHasKey('today', $fd['fields']['modifiedTime']);
|
$this->assertArrayHasKey('today', $fd['fields']['modifiedTime']);
|
||||||
$this->assertEquals(date('Y-m-d'), $fd['fields']['modifiedTime']['today']);
|
$this->assertEquals(date('Y-m-d'), $fd['fields']['modifiedTime']['today']);
|
||||||
@ -57,7 +57,7 @@ class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
|||||||
{
|
{
|
||||||
ini_set('date.timezone', 'Europe/Berlin');
|
ini_set('date.timezone', 'Europe/Berlin');
|
||||||
$fdo = new FieldDefinition('hotel');
|
$fdo = new FieldDefinition('hotel');
|
||||||
$fdo->addFieldValues(array('modifiedTime'=>'2016-01-01 01:01:01'));
|
$fdo->setFieldValues(array('modifiedTime'=>'2016-01-01 01:01:01'));
|
||||||
$fd = $fdo->getFieldData();
|
$fd = $fdo->getFieldData();
|
||||||
$this->assertArrayHasKey('value_unixtime', $fd['fields']['modifiedTime']);
|
$this->assertArrayHasKey('value_unixtime', $fd['fields']['modifiedTime']);
|
||||||
$this->assertEquals(1451606461, $fd['fields']['modifiedTime']['value_unixtime']);
|
$this->assertEquals(1451606461, $fd['fields']['modifiedTime']['value_unixtime']);
|
||||||
|
Reference in New Issue
Block a user