Bug: UserGroup Filter #376

Closed
opened 2019-02-12 09:41:26 +00:00 by tonypartridge · 12 comments
tonypartridge commented 2019-02-12 09:41:26 +00:00 (Migrated from github.com)

Latest release.

Add a field for user groups say 'Primary Type' Select and set show as filter. When viewing in the frontend it's just rendering the ID's in the filter and not the ID as val and name as text.

Latest release. Add a field for user groups say 'Primary Type' Select and set show as filter. When viewing in the frontend it's just rendering the ID's in the filter and not the ID as val and name as text.
peterpetrov commented 2019-02-12 09:46:56 +00:00 (Migrated from github.com)

Hey Tony, are you viewing it in a list view in the front end or you are talking about something completely different? If you could send some more details please?

Hey Tony, are you viewing it in a list view in the front end or you are talking about something completely different? If you could send some more details please?
tonypartridge commented 2019-02-12 09:47:57 +00:00 (Migrated from github.com)

I'm in the backend, looking at the code you have re-written a custom method to get the usergroup filter, but at just loading the column. I'm checking it now and will do a PR.

I'm in the backend, looking at the code you have re-written a custom method to get the usergroup filter, but at just loading the column. I'm checking it now and will do a PR.
tonypartridge commented 2019-02-12 10:08:46 +00:00 (Migrated from github.com)

Ok I'm not quite sure how you are building the group selects but here is getTheUsergroup_one and getTheUsergroup_two. I've fixed getTheUsergroup_one for instance:


	protected function getTheUsergroup_oneSelections()
	{
		// Get a db connection.
		$db = JFactory::getDbo();

		// Create a new query object.
		$query = $db->getQuery(true);

		// Select the text.
		$query->select($db->quoteName('g.usergroup_one', 'id'));
		$query->select($db->quoteName('ug.title','title'));
		$query->from($db->quoteName('#__listmanagement_user', 'g'));
		$query->join('LEFT', $db->quoteName('#__usergroups', 'ug') . ' ON (' . $db->quoteName('g.usergroup_one') . ' = ' . $db->quoteName('ug.id') . ')');
		$query->group($db->quoteName('ug.id'));
		$query->order($db->quoteName('title') . ' ASC');

		// Reset the query using our newly populated query object.
		$db->setQuery($query);

		$results = $db->loadAssocList();

		if ($results)
		{
			$_filter = array();
			foreach ($results as $usergroup_one)
			{
				// Now add the usergroup_one and its text to the options array
				$_filter[] = JHtml::_('select.option', $usergroup_one['id'], $usergroup_one['title']);
			}
			return $_filter;
		}
		return false;
	}

	protected function getTheUsergroup_twoSelections()
	{
		// Get a db connection.
		$db = JFactory::getDbo();

		// Create a new query object.
		$query = $db->getQuery(true);

		// Select the text.
		$query->select($db->quoteName('usergroup_two'));
		$query->from($db->quoteName('#__listmanagement_user'));
		$query->order($db->quoteName('usergroup_two') . ' ASC');

		// Reset the query using our newly populated query object.
		$db->setQuery($query);

		$results = $db->loadColumn();

		if ($results)
		{
			$results = array_unique($results);
			$_filter = array();
			foreach ($results as $usergroup_two)
			{
				// Now add the usergroup_two and its text to the options array
				$_filter[] = JHtml::_('select.option', $usergroup_two, $usergroup_two);
			}
			return $_filter;
		}
		return false;
	}
Ok I'm not quite sure how you are building the group selects but here is getTheUsergroup_one and getTheUsergroup_two. I've fixed getTheUsergroup_one for instance: ``` protected function getTheUsergroup_oneSelections() { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Select the text. $query->select($db->quoteName('g.usergroup_one', 'id')); $query->select($db->quoteName('ug.title','title')); $query->from($db->quoteName('#__listmanagement_user', 'g')); $query->join('LEFT', $db->quoteName('#__usergroups', 'ug') . ' ON (' . $db->quoteName('g.usergroup_one') . ' = ' . $db->quoteName('ug.id') . ')'); $query->group($db->quoteName('ug.id')); $query->order($db->quoteName('title') . ' ASC'); // Reset the query using our newly populated query object. $db->setQuery($query); $results = $db->loadAssocList(); if ($results) { $_filter = array(); foreach ($results as $usergroup_one) { // Now add the usergroup_one and its text to the options array $_filter[] = JHtml::_('select.option', $usergroup_one['id'], $usergroup_one['title']); } return $_filter; } return false; } protected function getTheUsergroup_twoSelections() { // Get a db connection. $db = JFactory::getDbo(); // Create a new query object. $query = $db->getQuery(true); // Select the text. $query->select($db->quoteName('usergroup_two')); $query->from($db->quoteName('#__listmanagement_user')); $query->order($db->quoteName('usergroup_two') . ' ASC'); // Reset the query using our newly populated query object. $db->setQuery($query); $results = $db->loadColumn(); if ($results) { $results = array_unique($results); $_filter = array(); foreach ($results as $usergroup_two) { // Now add the usergroup_two and its text to the options array $_filter[] = JHtml::_('select.option', $usergroup_two, $usergroup_two); } return $_filter; } return false; } ```
tonypartridge commented 2019-02-12 10:16:08 +00:00 (Migrated from github.com)

tbh could change it to getObjectList instead of array but it;s whatever you prefer.

tbh could change it to getObjectList instead of array but it;s whatever you prefer.
tonypartridge commented 2019-02-12 12:02:29 +00:00 (Migrated from github.com)

Furthermore, text value is not show in backend lists.

Also, batch actions are 'Filtered' rather than 'All usergroups'

Furthermore, text value is not show in backend lists. Also, batch actions are 'Filtered' rather than 'All usergroups'

Hi @tonypartridge this is correct, I mean yes the user groups are not yet correctly displayed in the admin list view, nor is the filter working as expected.

We can try to resolve this, I think I left this undone due to other features more pressing at the time (I mean way back when I worked on that area). But the wires are there 👍 I will need to take a closer look, give me a few days and I will get back to you.

Hi @tonypartridge this is correct, I mean yes the user groups are not yet correctly displayed in the admin list view, nor is the filter working as expected. We can try to resolve this, I think I left this undone due to other features more pressing at the time (I mean way back when I worked on that area). But the wires are there :+1: I will need to take a closer look, give me a few days and I will get back to you.
tonypartridge commented 2019-02-25 10:24:17 +00:00 (Migrated from github.com)

Thanks! Another bug....

When generating the frontend view of the backend view, usergroup fields and using the usergroup field I get two usergroup fields as a.usergroup AS usergroup a.usergroup doesn't exist. It would be for me a.school for instance.

Thanks! Another bug.... When generating the frontend view of the backend view, usergroup fields and using the usergroup field I get two usergroup fields as a.usergroup AS usergroup a.usergroup doesn't exist. It would be for me a.school for instance.

At the time of the implementation I acted on the limited history mapping (integration) relationship of Joomla, that only allowed for one usergroup field per table/view can you confirm that this has changed?

At the time of the implementation I acted on the limited history mapping (integration) relationship of Joomla, that only allowed for one usergroup field per table/view can you confirm that this has changed?

Or was that for categories.. hmmm I will have to check. But I know there was a reason... it was a few years ago so I will also need to take a look at that. Reality is often these limitations were due to the nature of an unimportant features to me at the time I build that area of JCB. So if it is a bug or just me not implementing it fully remains to be seen.

Or was that for categories.. hmmm I will have to check. But I know there was a reason... it was a few years ago so I will also need to take a look at that. Reality is often these limitations were due to the nature of an unimportant features to me at the time I build that area of JCB. So if it is a bug or just me not implementing it fully remains to be seen.
tonypartridge commented 2019-02-26 20:54:11 +00:00 (Migrated from github.com)

Well we are including a usergroup field option within a table, the row stores the id. We should be able to filter based on the selected group. It's not controlling access in anyway at all.

The reason being in this scenario is we are preventing data duplication, the Usergroups have been setup for each usergroup so the client wants to say 'Group 1, Group 2' but they do not control filtering just for data purposes.

Well we are including a usergroup field option within a table, the row stores the id. We should be able to filter based on the selected group. It's not controlling access in anyway at all. The reason being in this scenario is we are preventing data duplication, the Usergroups have been setup for each usergroup so the client wants to say 'Group 1, Group 2' but they do not control filtering just for data purposes.

Would you be willing to share your admin view, attached to the demo component as a JCB package so I can be sure to be looking at the same implementation? You can remove any fields you feel are irrelevant, but be sure to leave more then just the usergroups.

Would you be willing to share your admin view, attached to the demo component as a **JCB package** so I can be sure to be looking at the same implementation? You can remove any fields you feel are irrelevant, but be sure to leave more then just the usergroups.
tonypartridge commented 2019-02-26 21:48:18 +00:00 (Migrated from github.com)

Ok I have this fixed with:

elseif ($filter['type'] != 'category' && !ComponentbuilderHelper::checkArray($filter['custom']))
				{
					$translation = false;
					if (isset($this->selectionTranslationFixBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->selectionTranslationFixBuilder[$viewName_list]) && array_key_exists($filter['code'], $this->selectionTranslationFixBuilder[$viewName_list]))
					{
						$translation = true;
					}
					$function[] = PHP_EOL . $this->_t(1) . "protected function getThe" . $filter['function'] . "Selections()";
					$function[] = $this->_t(1) . "{";
					$function[] = $this->_t(2) . "//" . $this->setLine(__LINE__) . " Get a db connection.";
					$function[] = $this->_t(2) . "\$db = JFactory::getDbo();";
					$function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Create a new query object.";
					$function[] = $this->_t(2) . "\$query = \$db->getQuery(true);";

					// check if usergroup as we change to an object query
                    if ($filter['type'] === 'usergroup') {
                        $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Select the text.";
                        $function[] = $this->_t(2) . "\$query->select(\$db->quoteName('g." . $filter['code'] . "', 'id'));";
                        $function[] = $this->_t(2) . "\$query->select(\$db->quoteName('ug.title', 'title'));";
                        $function[] = $this->_t(2) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $filter['database'] . "', 'g'));";
                        $function[] = $this->_t(2) . "\$query->join('LEFT', \$db->quoteName('#__usergroups', 'ug') . ' ON (' . (\$db->quoteName('g." . $filter['code'] . "') . ' = ' . \$db->quoteName('ug.id') . ')'));";
                        $function[] = $this->_t(2) . "\$query->order(\$db->quoteName('title') . ' ASC');";
                        $function[] = $this->_t(2) . "\$query->group(\$db->quoteName('ug.id'));";
                        $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object.";
                        $function[] = $this->_t(2) . "\$db->setQuery(\$query);";
                        $function[] = PHP_EOL . $this->_t(2) . "\$results = \$db->loadObjectList();";
                    } else {
                        $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Select the text.";
                        $function[] = $this->_t(2) . "\$query->select(\$db->quoteName('" . $filter['code'] . "'));";
                        $function[] = $this->_t(2) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $filter['database'] . "'));";
                        $function[] = $this->_t(2) . "\$query->order(\$db->quoteName('" . $filter['code'] . "') . ' ASC');";
                        $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object.";
                        $function[] = $this->_t(2) . "\$db->setQuery(\$query);";
                        $function[] = PHP_EOL . $this->_t(2) . "\$results = \$db->loadColumn();";
                    }


					$function[] = PHP_EOL . $this->_t(2) . "if (\$results)";
					$function[] = $this->_t(2) . "{";

					// check if translated value is used
					if ($translation)
					{
						$function[] = $this->_t(3) . "//" . $this->setLine(__LINE__) . " get model";
						$function[] = $this->_t(3) . "\$model = \$this->getModel();";
					}
					$function[] = $this->_t(3) . "\$results = array_unique(\$results);";
					$function[] = $this->_t(3) . "\$_filter = array();";
					$function[] = $this->_t(3) . "foreach (\$results as \$" . $filter['code'] . ")";
					$function[] = $this->_t(3) . "{";


					// check if translated vlaue is used
					if ($translation)
					{
						$function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Translate the " . $filter['code'] . " selection";
						$function[] = $this->_t(4) . "\$text = \$model->selectionTranslation(\$" . $filter['code'] . ",'" . $filter['code'] . "');";
						$function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array";
						$function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . ", JText:" . ":_(\$text));";
					}
					elseif ($filter['type'] === 'user')
					{
						$function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array";
						$function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . ", JFactory::getUser(\$" . $filter['code'] . ")->name);";
					}
					else if ($filter['type'] === 'usergroup')
					{
						$function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array";
						$function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . "->id, \$" . $filter['code'] . "->title);";
					}
					else
					{
						$function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array";
						$function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . ", \$" . $filter['code'] . ");";
					}
					$function[] = $this->_t(3) . "}";
					$function[] = $this->_t(3) . "return \$_filter;";
					$function[] = $this->_t(2) . "}";
					$function[] = $this->_t(2) . "return false;";
					$function[] = $this->_t(1) . "}";

in admin/helpers/complier/e_interpretation.php

I have tried doing a PR but having issues with line endings, can you confirm what system you are developing on and what line endings you are using?

Thanks

Ok I have this fixed with: ``` elseif ($filter['type'] != 'category' && !ComponentbuilderHelper::checkArray($filter['custom'])) { $translation = false; if (isset($this->selectionTranslationFixBuilder[$viewName_list]) && ComponentbuilderHelper::checkArray($this->selectionTranslationFixBuilder[$viewName_list]) && array_key_exists($filter['code'], $this->selectionTranslationFixBuilder[$viewName_list])) { $translation = true; } $function[] = PHP_EOL . $this->_t(1) . "protected function getThe" . $filter['function'] . "Selections()"; $function[] = $this->_t(1) . "{"; $function[] = $this->_t(2) . "//" . $this->setLine(__LINE__) . " Get a db connection."; $function[] = $this->_t(2) . "\$db = JFactory::getDbo();"; $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Create a new query object."; $function[] = $this->_t(2) . "\$query = \$db->getQuery(true);"; // check if usergroup as we change to an object query if ($filter['type'] === 'usergroup') { $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Select the text."; $function[] = $this->_t(2) . "\$query->select(\$db->quoteName('g." . $filter['code'] . "', 'id'));"; $function[] = $this->_t(2) . "\$query->select(\$db->quoteName('ug.title', 'title'));"; $function[] = $this->_t(2) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $filter['database'] . "', 'g'));"; $function[] = $this->_t(2) . "\$query->join('LEFT', \$db->quoteName('#__usergroups', 'ug') . ' ON (' . (\$db->quoteName('g." . $filter['code'] . "') . ' = ' . \$db->quoteName('ug.id') . ')'));"; $function[] = $this->_t(2) . "\$query->order(\$db->quoteName('title') . ' ASC');"; $function[] = $this->_t(2) . "\$query->group(\$db->quoteName('ug.id'));"; $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object."; $function[] = $this->_t(2) . "\$db->setQuery(\$query);"; $function[] = PHP_EOL . $this->_t(2) . "\$results = \$db->loadObjectList();"; } else { $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Select the text."; $function[] = $this->_t(2) . "\$query->select(\$db->quoteName('" . $filter['code'] . "'));"; $function[] = $this->_t(2) . "\$query->from(\$db->quoteName('#__" . $component . "_" . $filter['database'] . "'));"; $function[] = $this->_t(2) . "\$query->order(\$db->quoteName('" . $filter['code'] . "') . ' ASC');"; $function[] = PHP_EOL . $this->_t(2) . "//" . $this->setLine(__LINE__) . " Reset the query using our newly populated query object."; $function[] = $this->_t(2) . "\$db->setQuery(\$query);"; $function[] = PHP_EOL . $this->_t(2) . "\$results = \$db->loadColumn();"; } $function[] = PHP_EOL . $this->_t(2) . "if (\$results)"; $function[] = $this->_t(2) . "{"; // check if translated value is used if ($translation) { $function[] = $this->_t(3) . "//" . $this->setLine(__LINE__) . " get model"; $function[] = $this->_t(3) . "\$model = \$this->getModel();"; } $function[] = $this->_t(3) . "\$results = array_unique(\$results);"; $function[] = $this->_t(3) . "\$_filter = array();"; $function[] = $this->_t(3) . "foreach (\$results as \$" . $filter['code'] . ")"; $function[] = $this->_t(3) . "{"; // check if translated vlaue is used if ($translation) { $function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Translate the " . $filter['code'] . " selection"; $function[] = $this->_t(4) . "\$text = \$model->selectionTranslation(\$" . $filter['code'] . ",'" . $filter['code'] . "');"; $function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array"; $function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . ", JText:" . ":_(\$text));"; } elseif ($filter['type'] === 'user') { $function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array"; $function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . ", JFactory::getUser(\$" . $filter['code'] . ")->name);"; } else if ($filter['type'] === 'usergroup') { $function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array"; $function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . "->id, \$" . $filter['code'] . "->title);"; } else { $function[] = $this->_t(4) . "//" . $this->setLine(__LINE__) . " Now add the " . $filter['code'] . " and its text to the options array"; $function[] = $this->_t(4) . "\$_filter[] = JHtml::_('select.option', \$" . $filter['code'] . ", \$" . $filter['code'] . ");"; } $function[] = $this->_t(3) . "}"; $function[] = $this->_t(3) . "return \$_filter;"; $function[] = $this->_t(2) . "}"; $function[] = $this->_t(2) . "return false;"; $function[] = $this->_t(1) . "}"; ``` in admin/helpers/complier/e_interpretation.php I have tried doing a PR but having issues with line endings, can you confirm what system you are developing on and what line endings you are using? Thanks
Sign in to join this conversation.
No Milestone
No project
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: joomla/Component-Builder#376
No description provided.