diff --git a/administrator/components/com_users/models/forms/filter_users.xml b/administrator/components/com_users/models/forms/filter_users.xml index f719e3be70a51..991e94cfbf521 100644 --- a/administrator/components/com_users/models/forms/filter_users.xml +++ b/administrator/components/com_users/models/forms/filter_users.xml @@ -35,6 +35,15 @@ > + + + setState('filter.state', $this->getUserStateFromRequest($this->context . '.filter.state', 'filter_state', '', 'cmd')); $this->setState('filter.group_id', $this->getUserStateFromRequest($this->context . '.filter.group_id', 'filter_group_id', null, 'int')); $this->setState('filter.range', $this->getUserStateFromRequest($this->context . '.filter.range', 'filter_range', '', 'cmd')); + $this->setState( + 'filter.lastvisitrange', $this->getUserStateFromRequest($this->context . '.filter.lastvisitrange', 'filter_lastvisitrange', '', 'cmd') + ); $groups = json_decode(base64_decode($app->input->get('groups', '', 'BASE64'))); @@ -368,59 +372,48 @@ protected function getListQuery() // Apply the range filter. if ($range) { - // Get UTC for now. - $dNow = new JDate; - $dStart = clone $dNow; + $dates = $this->buildDateRange($range); - switch ($range) + if ($dates['dNow'] === false) + { + $query->where( + $db->qn('a.registerDate') . ' < ' . $db->quote($dates['dStart']->format('Y-m-d H:i:s')) + ); + } + else { - case 'past_week': - $dStart->modify('-7 day'); - break; - - case 'past_1month': - $dStart->modify('-1 month'); - break; - - case 'past_3month': - $dStart->modify('-3 month'); - break; - - case 'past_6month': - $dStart->modify('-6 month'); - break; - - case 'post_year': - case 'past_year': - $dStart->modify('-1 year'); - break; - - case 'today': - // Ranges that need to align with local 'days' need special treatment. - $app = JFactory::getApplication(); - $offset = $app->get('offset'); - - // Reset the start time to be the beginning of today, local time. - $dStart = new JDate('now', $offset); - $dStart->setTime(0, 0, 0); - - // Now change the timezone back to UTC. - $tz = new DateTimeZone('GMT'); - $dStart->setTimezone($tz); - break; + $query->where( + $db->qn('a.registerDate') . ' >= ' . $db->quote($dates['dStart']->format('Y-m-d H:i:s')) . + ' AND ' . $db->qn('a.registerDate') . ' <= ' . $db->quote($dates['dNow']->format('Y-m-d H:i:s')) + ); } + } + + // Add filter for registration ranges select list + $lastvisitrange = $this->getState('filter.lastvisitrange'); - if ($range == 'post_year') + // Apply the range filter. + if ($lastvisitrange) + { + $dates = $this->buildDateRange($lastvisitrange); + + if (is_string($dates['dStart'])) + { + $query->where( + $db->qn('a.lastvisitDate') . ' = ' . $db->quote($dates['dStart']) + ); + } + elseif ($dates['dNow'] === false) { $query->where( - $db->qn('a.registerDate') . ' < ' . $db->quote($dStart->format('Y-m-d H:i:s')) + $db->qn('a.lastvisitDate') . ' < ' . $db->quote($dates['dStart']->format('Y-m-d H:i:s')) ); } else { $query->where( - $db->qn('a.registerDate') . ' >= ' . $db->quote($dStart->format('Y-m-d H:i:s')) . - ' AND ' . $db->qn('a.registerDate') . ' <= ' . $db->quote($dNow->format('Y-m-d H:i:s')) + $db->qn('a.lastvisitDate') . ' >= ' . $db->quote($dates['dStart']->format('Y-m-d H:i:s')) . + ' AND ' . $db->qn('a.lastvisitDate') . ' <= ' . $db->quote($dates['dNow']->format('Y-m-d H:i:s')) ); } } @@ -439,6 +432,67 @@ protected function getListQuery() return $query; } + /** + * Construct the date range to filter on. + * + * @param string $range The textual range to construct the filter for. + * + * @return string The date range to filter on. + * + * @since 3.6.0 + */ + private function buildDateRange($range) + { + // Get UTC for now. + $dNow = new JDate; + $dStart = clone $dNow; + + switch ($range) + { + case 'past_week': + $dStart->modify('-7 day'); + break; + + case 'past_1month': + $dStart->modify('-1 month'); + break; + + case 'past_3month': + $dStart->modify('-3 month'); + break; + + case 'past_6month': + $dStart->modify('-6 month'); + break; + + case 'post_year': + $dNow = false; + case 'past_year': + $dStart->modify('-1 year'); + break; + + case 'today': + // Ranges that need to align with local 'days' need special treatment. + $app = JFactory::getApplication(); + $offset = $app->get('offset'); + + // Reset the start time to be the beginning of today, local time. + $dStart = new JDate('now', $offset); + $dStart->setTime(0, 0, 0); + + // Now change the timezone back to UTC. + $tz = new DateTimeZone('GMT'); + $dStart->setTimezone($tz); + break; + case 'never': + $dNow = false; + $dStart = $this->_db->getNullDate(); + break; + } + + return array('dNow' => $dNow, 'dStart' => $dStart); + } + /** * SQL server change * diff --git a/administrator/language/en-GB/en-GB.com_users.ini b/administrator/language/en-GB/en-GB.com_users.ini index 71582a004ce0c..57e0b9e685c95 100644 --- a/administrator/language/en-GB/en-GB.com_users.ini +++ b/administrator/language/en-GB/en-GB.com_users.ini @@ -6,6 +6,8 @@ COM_CATEGORIES_CATEGORY_ADD_TITLE="User Notes: New Category" COM_CATEGORIES_CATEGORY_EDIT_TITLE="User Notes: Edit Category" COM_USERS_OPTION_FILTER_DATE="- Select Registration Date -" +COM_USERS_OPTION_FILTER_LAST_VISIT_DATE="- Select Last Visit Date -" +COM_USERS_OPTION_RANGE_NEVER="never" COM_USERS_OPTION_RANGE_PAST_1MONTH="in the last month" COM_USERS_OPTION_RANGE_PAST_3MONTH="in the last 3 months" COM_USERS_OPTION_RANGE_PAST_6MONTH="in the last 6 months" diff --git a/administrator/templates/hathor/html/com_users/users/default.php b/administrator/templates/hathor/html/com_users/users/default.php index f19cc08f88332..16587f5bf4674 100644 --- a/administrator/templates/hathor/html/com_users/users/default.php +++ b/administrator/templates/hathor/html/com_users/users/default.php @@ -65,6 +65,14 @@ state->get('filter.group_id'));?> + + + diff --git a/libraries/cms/form/field/lastvisitdaterange.php b/libraries/cms/form/field/lastvisitdaterange.php new file mode 100644 index 0000000000000..be58a3ea28377 --- /dev/null +++ b/libraries/cms/form/field/lastvisitdaterange.php @@ -0,0 +1,51 @@ +type = 'LastvisitDateRange'; + + // Load the required language + $lang = JFactory::getLanguage(); + $lang->load('com_users', JPATH_ADMINISTRATOR); + + // Set the pre-defined options + $this->predefinedOptions = array( + 'today' => 'COM_USERS_OPTION_RANGE_TODAY', + 'past_week' => 'COM_USERS_OPTION_RANGE_PAST_WEEK', + 'past_1month' => 'COM_USERS_OPTION_RANGE_PAST_1MONTH', + 'past_3month' => 'COM_USERS_OPTION_RANGE_PAST_3MONTH', + 'past_6month' => 'COM_USERS_OPTION_RANGE_PAST_6MONTH', + 'past_year' => 'COM_USERS_OPTION_RANGE_PAST_YEAR', + 'post_year' => 'COM_USERS_OPTION_RANGE_POST_YEAR', + 'never' => 'COM_USERS_OPTION_RANGE_NEVER', + ); + } +}