Fix Usergroup filter #382

Merged
tonypartridge merged 1 commits from staging into staging 2019-03-09 22:33:50 +00:00
tonypartridge commented 2019-02-26 22:45:12 +00:00 (Migrated from github.com)

This PR will fix the usergroup filter this section of code has been changed:

                {
                    $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) . "}";
				}

I am struggling to get line endings right against your repo for some reason? currently set to CRLF.

This PR will fix the usergroup filter this section of code has been changed: ``` { $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) . "}"; } ``` I am struggling to get line endings right against your repo for some reason? currently set to CRLF.

I can't merge this request there is like crazy amount of lines changed. What editor are you using?

Can you not just pull the staging branch and then change just the lines above, and make a pull request with those, instead of auto formatting of the whole file in your IDE?

I can't merge this request there is like crazy amount of lines changed. What editor are you using? Can you not just pull the staging branch and then change just the lines above, and make a pull request with those, instead of auto formatting of the whole file in your IDE?

I am working on Ubuntu, Netbeans.

I am working on Ubuntu, Netbeans.
tonypartridge commented 2019-02-27 11:51:50 +00:00 (Migrated from github.com)

It's a line ending change, just using phpstorm. But it depends what system
you are developing on as to how you have stored them in JCB Github. Can you
confirm how they are stored?

My editor hasn't reformatted the file.

It's a line ending change, just using phpstorm. But it depends what system you are developing on as to how you have stored them in JCB Github. Can you confirm how they are stored? My editor hasn't reformatted the file.

So just to confirm I am on a pure Linux box, and so all files are saved on a UNIX file system. That is also my weakness I have never done development on Windows or any other... just Linux.

So can you try again?

So just to confirm I am on a pure Linux box, and so all files are saved on a UNIX file system. That is also my weakness I have never done development on Windows or any other... just Linux. So can you try again?
tonypartridge commented 2019-02-27 12:14:03 +00:00 (Migrated from github.com)

Ok so you are likely using LR, I saved are CRLF for cross compatibility.

I’m on Linux too, so will change it and do it again soon.

Ok so you are likely using LR, I saved are CRLF for cross compatibility. I’m on Linux too, so will change it and do it again soon.
pjdevries commented 2019-03-01 09:37:29 +00:00 (Migrated from github.com)

From what I can see, line endings are not consistent across the whole project. For instance: script.php in the root folder has LF line endings, wheras componentbuilder.php in the site folder has CRLF line endings.

From what I can see, line endings are not consistent across the whole project. For instance: `script.php` in the root folder has LF line endings, wheras `componentbuilder.php` in the site folder has CRLF line endings.
tonypartridge commented 2019-03-01 09:54:31 +00:00 (Migrated from github.com)

@Llewellynvdm can you please update the projects line endings?

https://help.github.com/en/articles/dealing-with-line-endings

So you can have cross platform / user help.

@Llewellynvdm can you please update the projects line endings? https://help.github.com/en/articles/dealing-with-line-endings So you can have cross platform / user help.
pjdevries commented 2019-03-01 10:21:47 +00:00 (Migrated from github.com)

And if you're like me and find the Github help somewhat confusing, this might be another good place to have a look:

https://git-scm.com/book/it/v2/Customizing-Git-Git-Configuration#_code_core_autocrlf_code

And if you're like me and find the Github help somewhat confusing, this might be another good place to have a look: [https://git-scm.com/book/it/v2/Customizing-Git-Git-Configuration#_code_core_autocrlf_code](https://git-scm.com/book/it/v2/Customizing-Git-Git-Configuration#_code_core_autocrlf_code)

Okay we have an issue here, firstly the script.php file is auto generated, and in the compiler we are using PHP_EOL which means depending on what platform you compile the line-ending will change.

At the moment this pull request is dealing with the groups selecting filter and therefore not the place to resolve line endings.

So we can move this issue to its own place, yet to merge this pull request I need you to just push the update of the lines in question, and not change the whole file's line-endings.

Okay we have an issue here, firstly the script.php file is auto generated, and in the compiler we are using `PHP_EOL` which means depending on what platform you compile the line-ending will change. At the moment this pull request is dealing with the groups selecting filter and therefore not the place to resolve line endings. So we can move this issue to its own place, yet to merge this pull request I need you to just push the update of the lines in question, and not change the whole file's line-endings.

I can add the code, but then your contribution will be "unseen" I would like to give you the open door to actually contribute code. So I am giving this a few more days hoping to get a updated pull-request that only targets the code in question.

Secondly the current staging branch has moved, and so you will need to update your repo with the upstream.

I can add the code, but then your contribution will be "unseen" I would like to give you the open door to actually contribute code. So I am giving this a few more days hoping to get a updated pull-request that only targets the code in question. Secondly the current staging branch has moved, and so you will need to update your repo with the upstream.
tonypartridge commented 2019-03-07 09:24:06 +00:00 (Migrated from github.com)

There you go! Used my mac in the end. Need to figure what GIT is going on ubuntu to my files!

There you go! Used my mac in the end. Need to figure what GIT is going on ubuntu to my files!

Okay I will pull this down and run some test. Thanks!

Okay I will pull this down and run some test. Thanks!
Sign in to join this conversation.
No reviewers
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#382
No description provided.