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);
|
||||
|
||||
$fd = new FieldDefinition($action);
|
||||
$fd->addFieldValues($_SESSION[$skey]);
|
||||
$fd->setFieldValues($_SESSION[$skey]);
|
||||
$fieldData = $fd->getFieldData();
|
||||
$fields = $fieldData['fields'];
|
||||
|
||||
$data['email_date'] = date('r');
|
||||
$data = array_merge($data, $fields);
|
||||
$mo->addTemplateVars($data);
|
||||
$mo->setTemplateVars($data);
|
||||
$mo->setSubject('[FRS] ' . $data['action_uc'] . ' Reservation');
|
||||
$mo->addRecipient($data['user']['email'], $data['user']['name_first'] . ' ' . $data['user']['name_last']);
|
||||
$mail_sent = $mo->send();
|
||||
@ -144,7 +144,7 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
||||
$action = 'rentalcar';
|
||||
require 'prep_form.php';
|
||||
break;
|
||||
default:
|
||||
default:
|
||||
if (!$tpl_done) {
|
||||
$ho->setTemplate('loggedin_html');
|
||||
$tpl_done = true;
|
||||
@ -160,5 +160,5 @@ if (!$tpl_done && isset($_SESSION['access_token']) && $_SESSION['access_token'])
|
||||
|
||||
$data['action'] = $_GET['action'];
|
||||
|
||||
$ho->addTemplateVars($data);
|
||||
$ho->setTemplateVars($data);
|
||||
$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 $replacement Replacement value, e.g. John Doe
|
||||
*/
|
||||
public function addPlaceholder($placeholder, $replacement)
|
||||
public function setPlaceholder($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);
|
||||
}
|
||||
@ -150,12 +155,11 @@ class FieldDefinition
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the given $values or default values and replaces $placeholders. Also
|
||||
* adds some helping attributes to fields.
|
||||
* Sets the given $values for the given fields.
|
||||
*
|
||||
* @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) {
|
||||
// Assign session value if set, or use default if set
|
||||
|
@ -33,12 +33,12 @@ class GenericOutput
|
||||
$this->template = $this->templateEngine->loadTemplate($templateName);
|
||||
}
|
||||
|
||||
public function addTemplateVar($key, $value)
|
||||
public function setTemplateVar($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
|
||||
$this->templateVars = array_merge($this->templateVars, $tplVars);
|
||||
|
@ -15,8 +15,8 @@ $placeholders = array(
|
||||
'USER_NAME' => $data['user']['name_first'] . ' ' . $data['user']['name_last'],
|
||||
'USER_EMAIL' => $data['user']['email'],
|
||||
);
|
||||
$fd->addPlaceholders($placeholders);
|
||||
$fd->addFieldValues($_SESSION[$skey]);
|
||||
$fd->setPlaceholders($placeholders);
|
||||
$fd->setFieldValues($_SESSION[$skey]);
|
||||
|
||||
$by_group = $fd->getGroups();
|
||||
|
||||
|
@ -34,8 +34,8 @@ class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testAddFieldValues()
|
||||
{
|
||||
$fdo = new FieldDefinition('hotel');
|
||||
$fdo->addPlaceholder('USER_NAME', 'John Doe');
|
||||
$fdo->addFieldValues(array('url'=>'http://example.org/'));
|
||||
$fdo->setPlaceholder('USER_NAME', 'John Doe');
|
||||
$fdo->setFieldValues(array('url'=>'http://example.org/'));
|
||||
$fd = $fdo->getFieldData();
|
||||
$this->assertArrayHasKey('fields', $fd);
|
||||
$this->assertArrayHasKey('url', $fd['fields']);
|
||||
@ -47,7 +47,7 @@ class FieldDefinitionTest extends \PHPUnit_Framework_TestCase
|
||||
public function testSupportValues()
|
||||
{
|
||||
$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();
|
||||
$this->assertArrayHasKey('today', $fd['fields']['modifiedTime']);
|
||||
$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');
|
||||
$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();
|
||||
$this->assertArrayHasKey('value_unixtime', $fd['fields']['modifiedTime']);
|
||||
$this->assertEquals(1451606461, $fd['fields']['modifiedTime']['value_unixtime']);
|
||||
|
Reference in New Issue
Block a user