Skip to content

Commit

Permalink
Merge branch 'datefix'
Browse files Browse the repository at this point in the history
  • Loading branch information
inghamn committed Sep 15, 2016
2 parents 2cb5a31 + 5b6908f commit 79dca9d
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 29 deletions.
29 changes: 28 additions & 1 deletion crm/Controllers/TicketsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,28 @@ public function index()
}

$search = new Search();
$solrObject = $search->query($_GET, $format=='raw' ? true : false);
$query = $_GET;

if (isset ($query['enteredDate']['start'])) {
if (!empty($query['enteredDate']['start'])) {
try { $query['enteredDate']['start'] = new \DateTime($query['enteredDate']['start'].' 00:00:00'); }
catch (\Exception $e) {
unset($query['enteredDate']['start']);
}
}
else { unset($query['enteredDate']['start']); }
}
if (isset ($query['enteredDate']['end'])) {
if (!empty($query['enteredDate']['end'])) {
try { $query['enteredDate']['end'] = new \DateTime($query['enteredDate']['end'].' 11:59:59'); }
catch (\Exception $e) {
unset($query['enteredDate']['end']);
}
}
else { unset($query['enteredDate']['end']); }
}

$solrObject = $search->query($query, $format=='raw' ? true : false);

$resultBlock = ($format == 'map') ? 'searchResultsMap.inc' : 'searchResults.inc';
$this->template->blocks['panel-one'][] = new Block('tickets/searchForm.inc', ['solrObject'=>$solrObject]);
Expand Down Expand Up @@ -315,6 +336,12 @@ public function recordAction()

if (isset($_POST['ticket_id'])) {
try {
$_POST['actionDate'] = \DateTime::createFromFormat(
DATE_FORMAT.' '.TIME_FORMAT,
$_POST['actionDate']['date'].' '.$_POST['actionDate']['time']
);
if (!$_POST['actionDate']) { throw new \Exception('invalidDate'); }

$history->handleUpdate($_POST);
$history->save();
$this->redirectToTicketView($ticket);
Expand Down
23 changes: 16 additions & 7 deletions crm/Models/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -198,14 +198,23 @@ public function query($get, $raw=false)
}
if (!empty($get[$field])) {
if (false !== strpos($field, 'Date')) {
$utc = new \DateTimeZone('UTC');

if (!empty($get[$field]['start']) || !empty($get[$field]['end'])) {
$startDate = !empty($get[$field]['start'])
? date(self::DATE_FORMAT, strtotime($get[$field]['start']))
: '*';
$endDate = !empty($get[$field]['end'])
? date(self::DATE_FORMAT, strtotime($get[$field]['end']))
: '*';
$fq[] = "$field:[$startDate TO $endDate]";
if (!empty( $get[$field]['start'])) {
$get[$field]['start']->setTimezone($utc);
$start = $get[$field]['start']->format(self::DATE_FORMAT);
}
else { $startDate = '*'; }


if (!empty($get[$field]['end'])) {
$get[$field]['end']->setTimezone($utc);
$end = $get[$field]['end']->format(self::DATE_FORMAT);
}
else { $endDate = '*'; }

$fq[] = "$field:[$start TO $end]";
}
}
// coordinates is a not a numeric value but does not need to be quoted.
Expand Down
2 changes: 1 addition & 1 deletion crm/Models/TicketHistory.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ public function setTicket(Ticket $o) { parent::setForeignKeyObject(__namespace_
public function handleUpdate($post)
{
$this->setAction_id ($post['action_id'] );
$this->setActionDate($post['actionDate']);
$this->setActionDate($post['actionDate']->format(ActiveRecord::MYSQL_DATETIME_FORMAT));
$this->setNotes ($post['notes'] );
$this->setEnteredByPerson($_SESSION['USER']);
$this->setActionPerson ($_SESSION['USER']);
Expand Down
10 changes: 3 additions & 7 deletions crm/blocks/html/reports/searchForm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -62,20 +62,16 @@ $helper = $this->template->getHelper('field');
<h1><?= $this->_('enteredDate'); ?></h1>
<?php
foreach (['start', 'end'] as $d) {
$$d = '';
$value = '';
if (!empty($_GET['enteredDate'][$d])) {
try {
$date = ActiveRecord::parseDate($_GET['enteredDate'][$d], DATE_FORMAT);
$$d = $date->format('U');
}
catch (\Exception $e) { }
$value = self::escape($_GET['enteredDate'][$d]);
}
echo $helper->field([
'name' => "enteredDate[$d]",
'id' => "enteredDate-$d",
'label' => $this->_($d),
'type' => 'date',
'value' => $$d
'value' => $value
]);
}
?>
Expand Down
14 changes: 11 additions & 3 deletions crm/blocks/html/tickets/actionForm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,20 @@
<?php
$helper = $this->template->getHelper('field');
echo $helper->field([
'name' => 'actionDate',
'id' => 'actionDate',
'name' => 'actionDate[date]',
'id' => 'actionDate_date',
'label' => $this->_('date'),
'type' => 'date',
'value' => $this->ticketHistory->getActionDate('U')
'value' => $this->ticketHistory->getActionDate(DATE_FORMAT)
]);
echo $helper->field([
'name' => 'actionDate[time]',
'id' => 'actionDate_time',
'label' =>$this->_('time'),
'type' =>'time',
'value' =>$this->ticketHistory->getActionDate(TIME_FORMAT)
]);

echo $helper->field([
'name' => 'notes',
'id' => 'notes',
Expand Down
12 changes: 3 additions & 9 deletions crm/blocks/html/tickets/searchForm.inc
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,16 @@ $this->template->addToAsset('scripts', BASE_URI.'/js/collapsible.js');
";
$fieldHelper = $this->template->getHelper('field');
foreach (['start', 'end'] as $d) {
$$d = '';
$value = '';
if (!empty($_GET['enteredDate'][$d])) {
try {
$date = ActiveRecord::parseDate($_GET['enteredDate'][$d], DATE_FORMAT);
$$d = $date->format('U');
}
catch (\Exception $e) {
// Ignore incorrectly formatted dates
}
$value = self::escape($_GET['enteredDate'][$d]);
}
$html.= $fieldHelper->field([
'name' => "enteredDate[$d]",
'id' => "enteredDate-$d",
'label' => $this->_($d),
'type' => 'date',
'value' => $$d
'value' => $value
]);
}
$html.= "
Expand Down
3 changes: 3 additions & 0 deletions crm/language/en_CA/LC_MESSAGES/labels.po
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ msgstr "Fields to display"
msgid "date"
msgstr "Date"

msgid "time"
msgstr "Time"

msgid "day"
msgid_plural "days"
msgstr[0] "Day"
Expand Down
3 changes: 3 additions & 0 deletions crm/language/en_US/LC_MESSAGES/labels.po
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ msgstr "Fields to display"
msgid "date"
msgstr "Date"

msgid "time"
msgstr "Time"

msgid "day"
msgid_plural "days"
msgstr[0] "Day"
Expand Down
3 changes: 3 additions & 0 deletions crm/language/fr_CA/LC_MESSAGES/labels.po
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,9 @@ msgstr "Champs à afficher"
msgid "date"
msgstr "Date"

msgid "time"
msgstr "Temps"

msgid "day"
msgid_plural "days"
msgstr[0] "Jour"
Expand Down
3 changes: 3 additions & 0 deletions crm/language/nl_NL/LC_MESSAGES/labels.po
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,9 @@ msgstr "Zichtbare velden"
msgid "date"
msgstr "Datum"

msgid "time"
msgstr "Tijd"

msgid "day"
msgid_plural "days"
msgstr[0] "Dag"
Expand Down
5 changes: 4 additions & 1 deletion crm/templates/html/helpers/Field.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,13 @@ public function field(array $params)
if (isset( $params['type'])) {
switch ($params['type']) {
case 'date':
$params['value'] = !empty($params['value']) ? date(DATE_FORMAT, $params['value']) : '';
$params['attr']['placeholder'] = View::translateDateString(DATE_FORMAT);
$renderInput = 'input';
break;
case 'time':
$params['attr']['placeholder'] = View::translateDateString(TIME_FORMAT);
$renderInput = 'input';
break;

case 'select':
case 'textarea':
Expand Down

0 comments on commit 79dca9d

Please sign in to comment.