[ticket/248] Allow different types of timestrings for calendar events
B3P-248
This commit is contained in:
@@ -28,17 +28,10 @@
|
|||||||
</dl>
|
</dl>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<label for="event_start_day">{L_ACP_PORTAL_EVENT_START_DAY}:</label><br />
|
<label for="event_start_date">{L_ACP_PORTAL_EVENT_START_DATE}:</label><br />
|
||||||
<span>{L_ACP_PORTAL_EVENT_START_DAY_EXP}</span>
|
<span>{L_ACP_PORTAL_EVENT_START_DATE_EXP}</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd><input name="event_start_day" type="text" id="event_start_day" value="{EVENT_START_DAY}" maxlength="255" /></dd>
|
<dd><input name="event_start_date" type="text" id="event_start_date" value="{EVENT_START_DATE}" maxlength="255" /></dd>
|
||||||
</dl>
|
|
||||||
<dl>
|
|
||||||
<dt>
|
|
||||||
<label for="event_start_time">{L_ACP_PORTAL_EVENT_START_TIME}:</label><br />
|
|
||||||
<span>{L_ACP_PORTAL_EVENT_START_TIME_EXP}</span>
|
|
||||||
</dt>
|
|
||||||
<dd><input name="event_start_time" type="text" id="event_start_time" value="{EVENT_START_TIME}" maxlength="255" /></dd>
|
|
||||||
</dl>
|
</dl>
|
||||||
<dl>
|
<dl>
|
||||||
<dt><label for="event_all_day">{L_EVENT_ALL_DAY}:</label></dt>
|
<dt><label for="event_all_day">{L_EVENT_ALL_DAY}:</label></dt>
|
||||||
@@ -50,17 +43,10 @@
|
|||||||
<div id="end"<!-- IF EVENT_ALL_DAY -->style="display: none;"<!-- ENDIF -->>
|
<div id="end"<!-- IF EVENT_ALL_DAY -->style="display: none;"<!-- ENDIF -->>
|
||||||
<dl>
|
<dl>
|
||||||
<dt>
|
<dt>
|
||||||
<label for="event_end_day">{L_ACP_PORTAL_EVENT_END_DAY}:</label><br />
|
<label for="event_end_date">{L_ACP_PORTAL_EVENT_END_DATE}:</label><br />
|
||||||
<span>{L_ACP_PORTAL_EVENT_END_DAY_EXP}</span>
|
<span>{L_ACP_PORTAL_EVENT_END_DATE_EXP}</span>
|
||||||
</dt>
|
</dt>
|
||||||
<dd><input name="event_end_day" type="text" id="event_end_day" value="{EVENT_END_DAY}" maxlength="255" /></dd>
|
<dd><input name="event_end_date" type="text" id="event_end_date" value="{EVENT_END_DATE}" maxlength="255" /></dd>
|
||||||
</dl>
|
|
||||||
<dl>
|
|
||||||
<dt>
|
|
||||||
<label for="event_end_time">{L_ACP_PORTAL_EVENT_END_TIME}:</label><br />
|
|
||||||
<span>{L_ACP_PORTAL_EVENT_END_TIME_EXP}</span>
|
|
||||||
</dt>
|
|
||||||
<dd><input name="event_end_time" type="text" id="event_end_time" value="{EVENT_END_TIME}" maxlength="255" /></dd>
|
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div>
|
||||||
<dl>
|
<dl>
|
||||||
|
|||||||
@@ -115,14 +115,10 @@ $lang = array_merge($lang, array(
|
|||||||
'ACP_PORTAL_CALENDAR_START_INCORRECT' => 'Die eingegebene Start-Zeit ist nicht korrekt. Bitte folge genau den Anweisungen.',
|
'ACP_PORTAL_CALENDAR_START_INCORRECT' => 'Die eingegebene Start-Zeit ist nicht korrekt. Bitte folge genau den Anweisungen.',
|
||||||
'ACP_PORTAL_CALENDAR_END_INCORRECT' => 'Die eingegebene End-Zeit ist nicht korrekt. Bitte folge genau den Anweisungen.',
|
'ACP_PORTAL_CALENDAR_END_INCORRECT' => 'Die eingegebene End-Zeit ist nicht korrekt. Bitte folge genau den Anweisungen.',
|
||||||
'ACP_PORTAL_CALENDAR_EVENT_PAST' => 'Die Start-zeit der Veranstaltung muss in der Zukunft liegen.',
|
'ACP_PORTAL_CALENDAR_EVENT_PAST' => 'Die Start-zeit der Veranstaltung muss in der Zukunft liegen.',
|
||||||
'ACP_PORTAL_EVENT_START_DAY' => 'Start-Datum der Veranstaltung',
|
'ACP_PORTAL_EVENT_START_DATE' => 'Start-Datum der Veranstaltung',
|
||||||
'ACP_PORTAL_EVENT_START_DAY_EXP' => 'Gebe das Datum ein, an dem die Veranstaltung beginnt. Das Datum muss in folgendem Format sein: TT-MM-JJJJ',
|
'ACP_PORTAL_EVENT_START_DATE_EXP' => 'Gebe das Datum und Uhrzeit ein, zu der die Veranstaltung beginnt. Datum und Uhrzeit sollten in einem ähnlichen Format sein: TT.MM.JJJJ SS:MM',
|
||||||
'ACP_PORTAL_EVENT_START_TIME' => 'Start-Zeit der Veranstaltung',
|
'ACP_PORTAL_EVENT_END_DATE' => 'End-Datum der Veranstaltung',
|
||||||
'ACP_PORTAL_EVENT_START_TIME_EXP' => 'Gebe die Zeit ein, zu der die Veranstaltung beginnt. Die Zeit muss im 24 Stunden Format sein, z.B. 23:12',
|
'ACP_PORTAL_EVENT_END_DATE_EXP' => 'Gebe das Datum und Uhrzeit ein, zu der die Veranstaltung endet. Datum und Uhrzeit sollten in einem ähnlichen Format sein: TT.MM.JJJJ',
|
||||||
'ACP_PORTAL_EVENT_END_DAY' => 'End-Datum der Veranstaltung',
|
|
||||||
'ACP_PORTAL_EVENT_END_DAY_EXP' => 'Gebe das Datum ein, an dem die Veranstaltung endet. Das Datum muss in folgendem Format sein: TT-MM-JJJJ',
|
|
||||||
'ACP_PORTAL_EVENT_END_TIME' => 'End-Zeit der Veranstaltung',
|
|
||||||
'ACP_PORTAL_EVENT_END_TIME_EXP' => 'Gebe die Zeit ein, zu der die Veranstaltung endet. Die Zeit muss im 24 Stunden Forrmat sein, z.B. 23:12',
|
|
||||||
'ACP_PORTAL_CALENDAR_EVENT_START_FIRST' => 'Das Ende der Veranstaltung muss nach dem Beginn der Veranstaltung liegen.',
|
'ACP_PORTAL_CALENDAR_EVENT_START_FIRST' => 'Das Ende der Veranstaltung muss nach dem Beginn der Veranstaltung liegen.',
|
||||||
'ACP_PORTAL_CALENDAR_PERMISSION' => 'Berechtigungen für die Veranstaltung',
|
'ACP_PORTAL_CALENDAR_PERMISSION' => 'Berechtigungen für die Veranstaltung',
|
||||||
'ACP_PORTAL_CALENDAR_PERMISSION_EXP' => 'Wähle die Gruppen aus, denen es erlaubt sein soll die Veranstaltung zu sehen. Falls alle Benutzer die Veranstaltung sehen sollen, dann wähle nichts aus.<br />Wähle mehrere Gruppen aus/ab, indem du beim Klicken die <samp>Strg</samp>-Taste drückst.',
|
'ACP_PORTAL_CALENDAR_PERMISSION_EXP' => 'Wähle die Gruppen aus, denen es erlaubt sein soll die Veranstaltung zu sehen. Falls alle Benutzer die Veranstaltung sehen sollen, dann wähle nichts aus.<br />Wähle mehrere Gruppen aus/ab, indem du beim Klicken die <samp>Strg</samp>-Taste drückst.',
|
||||||
|
|||||||
@@ -115,14 +115,10 @@ $lang = array_merge($lang, array(
|
|||||||
'ACP_PORTAL_CALENDAR_START_INCORRECT' => 'The start time you entered was incorrect. Please follow the instructions carefully.',
|
'ACP_PORTAL_CALENDAR_START_INCORRECT' => 'The start time you entered was incorrect. Please follow the instructions carefully.',
|
||||||
'ACP_PORTAL_CALENDAR_END_INCORRECT' => 'The end time you entered was incorrect. Please follow the instructions carefully.',
|
'ACP_PORTAL_CALENDAR_END_INCORRECT' => 'The end time you entered was incorrect. Please follow the instructions carefully.',
|
||||||
'ACP_PORTAL_CALENDAR_EVENT_PAST' => 'The event start time needs to be in the future.',
|
'ACP_PORTAL_CALENDAR_EVENT_PAST' => 'The event start time needs to be in the future.',
|
||||||
'ACP_PORTAL_EVENT_START_DAY' => 'Event start date',
|
'ACP_PORTAL_EVENT_START_DATE' => 'Event start date',
|
||||||
'ACP_PORTAL_EVENT_START_DAY_EXP' => 'Enter the date when the event starts. The date has to be in this format: DD-MM-YYYY',
|
'ACP_PORTAL_EVENT_START_DATE_EXP' => 'Enter the date and time the event starts. The date has to be in a similar format: MM/DD/YYYY 3:00 PM',
|
||||||
'ACP_PORTAL_EVENT_START_TIME' => 'Event start time',
|
'ACP_PORTAL_EVENT_END_DATE' => 'Event end date',
|
||||||
'ACP_PORTAL_EVENT_START_TIME_EXP' => 'Enter the time when the event starts. The time has to be in a 24 hour format, i.e. 23:12',
|
'ACP_PORTAL_EVENT_END_DATE_EXP' => 'Enter the date and time the event ends. The date has to be in a similar format: MM/DD/YYYY 3:00 PM',
|
||||||
'ACP_PORTAL_EVENT_END_DAY' => 'Event end date',
|
|
||||||
'ACP_PORTAL_EVENT_END_DAY_EXP' => 'Enter the date when the event ends. The date has to be in this format: DD-MM-YYYY',
|
|
||||||
'ACP_PORTAL_EVENT_END_TIME' => 'Event end time',
|
|
||||||
'ACP_PORTAL_EVENT_END_TIME_EXP' => 'Enter the time when the event ends. The time has to be in a 24 hour format, i.e. 23:12',
|
|
||||||
'ACP_PORTAL_CALENDAR_EVENT_START_FIRST' => 'The end of the event has to be after the start of the event.',
|
'ACP_PORTAL_CALENDAR_EVENT_START_FIRST' => 'The end of the event has to be after the start of the event.',
|
||||||
'ACP_PORTAL_CALENDAR_PERMISSION' => 'Event permissions',
|
'ACP_PORTAL_CALENDAR_PERMISSION' => 'Event permissions',
|
||||||
'ACP_PORTAL_CALENDAR_PERMISSION_EXP' => 'Select the groups that should be authorized to view the event. If you want all users to be able to view the event, don’t select anything.<br />Select/Deselect multiple groups by holding <samp>CTRL</samp> and clicking.',
|
'ACP_PORTAL_CALENDAR_PERMISSION_EXP' => 'Select the groups that should be authorized to view the event. If you want all users to be able to view the event, don’t select anything.<br />Select/Deselect multiple groups by holding <samp>CTRL</samp> and clicking.',
|
||||||
|
|||||||
@@ -428,56 +428,25 @@ class calendar extends module_base
|
|||||||
|
|
||||||
$event_title = $this->request->variable('event_title', ' ', true);
|
$event_title = $this->request->variable('event_title', ' ', true);
|
||||||
$event_desc = $this->request->variable('event_desc', ' ', true);
|
$event_desc = $this->request->variable('event_desc', ' ', true);
|
||||||
$event_start_day = trim($this->request->variable('event_start_day', ''));
|
$event_start_date = trim($this->request->variable('event_start_date', ''));
|
||||||
$event_start_time = trim($this->request->variable('event_start_time', ''));
|
$event_end_date = trim($this->request->variable('event_end_date', ''));
|
||||||
$event_end_day = trim($this->request->variable('event_end_day', ''));
|
|
||||||
$event_end_time = trim($this->request->variable('event_end_time', ''));
|
|
||||||
$event_all_day = $this->request->variable('event_all_day', false); // default to false
|
$event_all_day = $this->request->variable('event_all_day', false); // default to false
|
||||||
$event_url = $this->request->variable('event_url', ' ');
|
$event_url = $this->request->variable('event_url', ' ');
|
||||||
$event_permission = $this->request->variable('permission-setting-calendar', array(0 => ''));
|
$event_permission = $this->request->variable('permission-setting-calendar', array(0 => ''));
|
||||||
$groups_ary = array();
|
$groups_ary = array();
|
||||||
|
|
||||||
/*
|
// Now get the unix timestamps out of the entered information
|
||||||
* parse the event time
|
$start_time = $this->date_to_time($event_start_date);
|
||||||
* first check for obvious errors, we don't want to waste server resources
|
$end_time = (!$event_all_day) ? $this->date_to_time($event_end_date) : '';
|
||||||
*/
|
|
||||||
if(strlen($event_start_day) < 9 || strlen($event_start_day) > 10 || (strlen($event_start_time) < 4 && !$event_all_day) || strlen($event_start_time) > 5)
|
if (!$start_time)
|
||||||
{
|
{
|
||||||
trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_START_INCORRECT']. adm_back_link($u_action), E_USER_WARNING);
|
trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_START_INCORRECT']. adm_back_link($u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
elseif((strlen($event_end_day) < 9 || strlen($event_end_day) > 10 || strlen($event_end_time) < 4 || strlen($event_end_time) > 5) && !$event_all_day)
|
else if (!$event_all_day && !$end_time)
|
||||||
{
|
{
|
||||||
trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_END_INCORRECT']. adm_back_link($u_action), E_USER_WARNING);
|
trigger_error($this->user->lang['ACP_PORTAL_CALENDAR_END_INCORRECT']. adm_back_link($u_action), E_USER_WARNING);
|
||||||
}
|
}
|
||||||
// Now get the needed numbers out of the entered information
|
|
||||||
$first_start_hyphen = strpos($event_start_day, '-', 0);
|
|
||||||
$second_start_hyphen = strpos($event_start_day, '-', $first_start_hyphen + 1);
|
|
||||||
$start_colon_pos = strpos($event_start_time, ':', 0);
|
|
||||||
$start_day_length = strlen($event_start_day);
|
|
||||||
$start_time_length = strlen($event_start_time);
|
|
||||||
$start_day = (int) substr($event_start_day, 0, $first_start_hyphen);
|
|
||||||
$start_month = (int) substr($event_start_day, $first_start_hyphen + 1, ($second_start_hyphen - $first_start_hyphen - 1));
|
|
||||||
$start_year = (int) substr($event_start_day, $second_start_hyphen + 1, $start_day_length - $second_start_hyphen);
|
|
||||||
$start_hour = (int) substr($event_start_time, 0, $start_colon_pos);
|
|
||||||
$start_minute = (int) substr($event_start_time, $start_colon_pos + 1, ($start_time_length - $start_colon_pos) - 1);
|
|
||||||
|
|
||||||
if(!$event_all_day)
|
|
||||||
{
|
|
||||||
$first_end_hyphen = strpos($event_end_day, '-', 0);
|
|
||||||
$second_end_hyphen = strpos($event_end_day, '-', $first_end_hyphen + 1);
|
|
||||||
$end_colon_pos = strpos($event_end_time, ':', 0);
|
|
||||||
$end_day_length = strlen($event_end_day);
|
|
||||||
$end_time_length = strlen($event_end_time);
|
|
||||||
$end_day = (int) substr($event_end_day, 0, $first_end_hyphen);
|
|
||||||
$end_month = (int) substr($event_end_day, $first_end_hyphen + 1, ($second_end_hyphen - $first_end_hyphen - 1));
|
|
||||||
$end_year = (int) substr($event_end_day, $second_end_hyphen + 1, $end_day_length - $second_end_hyphen);
|
|
||||||
$end_hour = (int) substr($event_end_time, 0, $end_colon_pos);
|
|
||||||
$end_minute = (int) substr($event_end_time, $end_colon_pos + 1, ($end_time_length - $end_colon_pos) - 1);
|
|
||||||
}
|
|
||||||
|
|
||||||
// UNIX timestamps
|
|
||||||
$start_time = gmmktime($start_hour, $start_minute, 0, $start_month, $start_day, $start_year);
|
|
||||||
$end_time = (!$event_all_day) ? gmmktime($end_hour, $end_minute, 0, $end_month, $end_day, $end_year) : '';
|
|
||||||
|
|
||||||
if (($end_time) <= time() && !(($start_time + self::TIME_DAY) >= time() && $event_all_day))
|
if (($end_time) <= time() && !(($start_time + self::TIME_DAY) >= time() && $event_all_day))
|
||||||
{
|
{
|
||||||
@@ -593,14 +562,13 @@ class calendar extends module_base
|
|||||||
case 'edit':
|
case 'edit':
|
||||||
case 'add':
|
case 'add':
|
||||||
$event_all_day = (isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true) ? true : false;
|
$event_all_day = (isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true) ? true : false;
|
||||||
|
$date_format = str_replace(array('D '), '', $this->user->data['user_dateformat']);
|
||||||
|
|
||||||
$this->template->assign_vars(array(
|
$this->template->assign_vars(array(
|
||||||
'EVENT_TITLE' => (isset($events[$link_id]['title']) && $action != 'add') ? $events[$link_id]['title'] : '',
|
'EVENT_TITLE' => (isset($events[$link_id]['title']) && $action != 'add') ? $events[$link_id]['title'] : '',
|
||||||
'EVENT_DESC' => (isset($events[$link_id]['desc']) && $action != 'add') ? $events[$link_id]['desc'] : '',
|
'EVENT_DESC' => (isset($events[$link_id]['desc']) && $action != 'add') ? $events[$link_id]['desc'] : '',
|
||||||
'EVENT_START_DAY' => ($action != 'add') ? $this->user->format_date($events[$link_id]['start_time'], 'd-m-Y') : '',
|
'EVENT_START_DATE' => ($action != 'add') ? $this->user->format_date($events[$link_id]['start_time'], $date_format) : '',
|
||||||
'EVENT_START_TIME' => ($action != 'add') ? $this->user->format_date($events[$link_id]['start_time'], 'G:i') : '',
|
'EVENT_END_DATE' => ($action != 'add' && !$event_all_day) ? $this->user->format_date($events[$link_id]['end_time'], $date_format) : '',
|
||||||
'EVENT_END_DAY' => ($action != 'add' && !$event_all_day) ? $this->user->format_date($events[$link_id]['end_time'], 'd-m-Y') : '',
|
|
||||||
'EVENT_END_TIME' => ($action != 'add' && !$event_all_day) ? $this->user->format_date($events[$link_id]['end_time'], 'G:i') : '',
|
|
||||||
'EVENT_ALL_DAY' => (isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true) ? true : false,
|
'EVENT_ALL_DAY' => (isset($events[$link_id]['all_day']) && $events[$link_id]['all_day'] == true) ? true : false,
|
||||||
'EVENT_URL' => (isset($events[$link_id]['url']) && $action != 'add') ? $events[$link_id]['url'] : '',
|
'EVENT_URL' => (isset($events[$link_id]['url']) && $action != 'add') ? $events[$link_id]['url'] : '',
|
||||||
|
|
||||||
@@ -785,4 +753,18 @@ class calendar extends module_base
|
|||||||
|
|
||||||
return $url;
|
return $url;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns timestamp from given date string
|
||||||
|
*
|
||||||
|
* @param string $date Date and time string. It can contain just the
|
||||||
|
* date or date and time info. The string should
|
||||||
|
* be in a similar format: 17.06.1990 18:06
|
||||||
|
* @return int|bool The timestamp of the given date or false if
|
||||||
|
* given daten does not match any known formats.
|
||||||
|
*/
|
||||||
|
public function date_to_time($date)
|
||||||
|
{
|
||||||
|
return strtotime($date);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
46
tests/unit/modules/calendar.php
Normal file
46
tests/unit/modules/calendar.php
Normal file
@@ -0,0 +1,46 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* @package testing
|
||||||
|
* @copyright (c) Board3 Group ( www.board3.de )
|
||||||
|
* @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License v2
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
require_once(dirname(__FILE__) . '/../../../includes/functions.php');
|
||||||
|
|
||||||
|
class phpbb_functions_simple_test extends PHPUnit_Framework_TestCase
|
||||||
|
{
|
||||||
|
public function setUp()
|
||||||
|
{
|
||||||
|
$this->path_helper = new \phpbb\path_helper(
|
||||||
|
new \phpbb\symfony_request(
|
||||||
|
new phpbb_mock_request()
|
||||||
|
),
|
||||||
|
new \phpbb\filesystem(),
|
||||||
|
$this->phpbb_root_path,
|
||||||
|
'php'
|
||||||
|
);
|
||||||
|
$this->calendar = new \board3\portal\modules\calendar(array(), null, null, null, dirname(__FILE__) . '/../../../', 'php', null, $this->path_helper);
|
||||||
|
$this->offset = strtotime('17.06.1990') - 645580800;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function data_date_to_time()
|
||||||
|
{
|
||||||
|
return array(
|
||||||
|
array(1402855200, '2014-06-15 18:00'),
|
||||||
|
array(1402855200, '15.06.2014 18:00'),
|
||||||
|
array(1402855200, '06/15/2014 6:00 PM'),
|
||||||
|
array(false, '15/06'),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider data_date_to_time
|
||||||
|
*/
|
||||||
|
public function test_date_to_time($expected, $date)
|
||||||
|
{
|
||||||
|
$this->assertEquals($expected, $this->calendar->date_to_time($date) + $this->offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user