Skip to content

Commit

Permalink
Merge pull request #3 from mjansenDatabay/feature-dateduration-for-ma…
Browse files Browse the repository at this point in the history
…ilfilter

Feature: Allow empty start or end for \ilDateDurationInputGUI
  • Loading branch information
mjansenDatabay authored Sep 20, 2018
2 parents a77e8c6 + b4c210f commit 6ff1dd9
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 51 deletions.
135 changes: 88 additions & 47 deletions Services/Form/classes/class.ilDateDurationInputGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ class ilDateDurationInputGUI extends ilSubEnabledFormPropertyGUI implements ilTa
protected $toggle_fulltime = false;
protected $toggle_fulltime_txt = '';
protected $toggle_fulltime_checked = false;


protected $allowOpenIntervals = false;

/**
* Constructor
*
Expand Down Expand Up @@ -243,14 +245,28 @@ public function getMinuteStepSize()
public function setValueByArray($a_values)
{
$incoming = $a_values[$this->getPostVar()];
if(is_array($incoming))
{
$format = $incoming['tgl'] ? 0 : $this->getDatePickerTimeFormat();
$this->toggle_fulltime_checked = (bool) $incoming['tgl'];
$this->setStart(ilCalendarUtil::parseIncomingDate($incoming["start"], $format));
$this->setEnd(ilCalendarUtil::parseIncomingDate($incoming["end"], $format));
if (is_array($incoming)) {
$format = $incoming['tgl'] ? 0 : $this->getDatePickerTimeFormat();
$this->toggle_fulltime_checked = (bool)$incoming['tgl'];

if ($this->openIntervalsAllowed()) {
if (is_string($incoming['start']) && trim($incoming['start']) !== '') {
$this->setStart(ilCalendarUtil::parseIncomingDate($incoming["start"], $format));
} else {
$this->setStart(new ilDate(null, IL_CAL_UNIX));
}

if (is_string($incoming['end']) && trim($incoming['end']) !== '') {
$this->setEnd(ilCalendarUtil::parseIncomingDate($incoming["end"], $format));
} else {
$this->setEnd(new ilDate(null, IL_CAL_UNIX));
}
} else {
$this->setStart(ilCalendarUtil::parseIncomingDate($incoming["start"], $format));
$this->setEnd(ilCalendarUtil::parseIncomingDate($incoming["end"], $format));
}
}

foreach($this->getSubItems() as $item)
{
$item->setValueByArray($a_values);
Expand Down Expand Up @@ -288,37 +304,41 @@ public function checkInput()
// always done to make sure there are no obsolete values left
$this->setStart(null);
$this->setEnd(null);

$valid_start = false;
if(trim($start))
{
if (trim($start)) {
$parsed = ilCalendarUtil::parseIncomingDate($start, $format);
if($parsed)
{
if ($parsed) {
$this->setStart($parsed);
$valid_start = true;
}
}
else if(!$this->getRequired() && !trim($end))
{
$valid_start = true;
}
} else {
if (!$this->getRequired() && !trim($end)) {
$valid_start = true;
} else {
if ($this->openIntervalsAllowed() && !strlen(trim($start))) {
$valid_start = true;
}
}
}

$valid_end = false;
if(trim($end))
{
$parsed = ilCalendarUtil::parseIncomingDate($end, $format);
if($parsed)
{

$valid_end = false;
if (trim($end)) {
$parsed = ilCalendarUtil::parseIncomingDate($end, $format);
if ($parsed) {
$this->setEnd($parsed);
$valid_end = true;
}
}
else if(!$this->getRequired() && !trim($start))
{
$valid_end = true;
}
} else {
if (!$this->getRequired() && !trim($start)) {
$valid_end = true;
} else {
if ($this->openIntervalsAllowed() && !strlen(trim($end))) {
$valid_end = true;
}
}
}

if($this->getStartYear())
{
if($valid_start &&
Expand All @@ -342,29 +362,34 @@ public function checkInput()
{
$valid = false;
}

if(!$valid)
{

if ($this->openIntervalsAllowed()) {
if (!$this->getStart()) {
$_POST[$this->getPostVar()]["start"] = null;
}

if (!$this->getEnd()) {
$_POST[$this->getPostVar()]["end"] = null;
}
$valid = true;
} elseif (!$valid) {
$this->invalid_input_start = $start;
$this->invalid_input_end = $end;

$_POST[$this->getPostVar()]["start"] = null;
$_POST[$this->getPostVar()]["end"] = null;

$this->setAlert($lng->txt("form_msg_wrong_date"));
}
else
{
if(
} else {
if (
!$this->getStart() ||
!$this->getEnd()
)
{
) {
$_POST[$this->getPostVar()]["start"] = null;
$_POST[$this->getPostVar()]["end"] = null;
}
}

if($valid)
{
$valid = $this->checkSubItemsInput();
Expand Down Expand Up @@ -483,8 +508,8 @@ public function render()


// values
$date_value = htmlspecialchars($this->invalid_input_start);

$date_value = htmlspecialchars($this->invalid_input_start);
if(!$date_value &&
$this->getStart())
{
Expand Down Expand Up @@ -560,16 +585,32 @@ public function setValue($value)
$this->setEnd(new ilDateTime($value['end'], IL_CAL_UNIX));
}
}

public function hideSubForm()
{
if($this->invalid_input_start ||
$this->invalid_input_end)
{
return false;
}

return ((!$this->getStart() || $this->getStart()->isNull()) &&
(!$this->getEnd() || $this->getEnd()->isNull()));
}

/**
* @return bool
*/
public function openIntervalsAllowed(): bool
{
return $this->allowOpenIntervals;
}

/**
* @param bool $allowOpenInterval
*/
public function setAllowOpenIntervals(bool $allowOpenInterval)
{
$this->allowOpenIntervals = $allowOpenInterval;
}
}
8 changes: 4 additions & 4 deletions Services/Mail/classes/class.ilMailBoxQuery.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,16 @@ public static function _getMailBoxListData()
if (isset(self::$filter['period']) && is_array(self::$filter['period'])) {
$dateFilterParts = [];

if (null !== $filter['period']['start']) {
if (null !== self::$filter['period']['start']) {
$dateFilterParts[] = 'send_time >= ' . $DIC->database()->quote(
date('Y-m-d H:i:s', self::$filter['period']['start']),
(new \DateTimeImmutable('@' . self::$filter['period']['start']))->format('Y-m-d 00:00:00'),
'timestamp'
);
}

if (null !== $filter['period']['end']) {
if (null !== self::$filter['period']['end']) {
$dateFilterParts[] = 'send_time <= ' . $DIC->database()->quote(
date('Y-m-d H:i:s', self::$filter['period']['end']),
(new \DateTimeImmutable('@' . self::$filter['period']['end']))->format('Y-m-d 23:59:59'),
'timestamp'
);
}
Expand Down
1 change: 1 addition & 0 deletions Services/Mail/classes/class.ilMailFolderTableGUI.php
Original file line number Diff line number Diff line change
Expand Up @@ -755,6 +755,7 @@ public function initFilter()
}

$duration = new \ilDateDurationInputGUI($this->lng->txt('mail_filter_period'), 'period');
$duration->setAllowOpenIntervals(true);
$duration->setStartText($this->lng->txt('mail_filter_period_from'));
$duration->setEndText($this->lng->txt('mail_filter_period_until'));
$duration->setStart(new ilDateTime(null, IL_CAL_UNIX));
Expand Down

0 comments on commit 6ff1dd9

Please sign in to comment.