Closed marcodings closed 8 years ago
OK, this is promising but I need to shape it a bit better. I don't like uncached static methods because they ultimately make testing a pain in the rear. Next week I'm on vacation, but I'll try to get it merged before mid-August :)
enjoy your vacation..
Hm, the more I'm looking at it the more issues with it I find.
Hard-coding user IDs and group names (or even view access levels) is very site-specific and has no place in the metadata.xml
file. It makes more sense for such limits to be part of your component.
You can modify the sidebar menu on the fly, e.g. as we're doing in Akeeba Subs (if you ignore the tree structure we're basically telling FOF which views to render in the submenu). In your component's Toolbar you can simply override renderSubmenu
, call getMyViews
and then filter out the views you don't want. Or do a custom presentation of select views like we do in Akeeba Subs. Or even limit views by user ID, group, view access level etc. This is why Toolbar is overridable.
Furthermore, a few comments regarding coding issues and coding style I spotted:
FOF30\Platform\PlatformInterface
(declaration) and FOF30\Platform\Joomla\Platform
(implementation), then accessed as $this->container->platform->....
if (!is_string($groupNames) && !is_array($groupNames))
{
throw new InvalidArgumentException('$groupNames should be passed as array or string');
}
$groupNamesArr = (array) $groupNames;
if (is_string($groupNames))
{
// Convert a lone string into an array
$groupNamesArr = empty($groupNames) ? array() : array($groupNames);
}
throw
. Execution terminates at throw
. PHP does not offer a mechanism for resuming after an exception is thrown (and most developers agree this is a good thing, leading to much less sloppy code)You don't need to coalesce WHERE statements to join them by OR
as long as all of your WHERE statements are going to be separated by ORs. Example
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query
->select($db->quoteName('id'))
->from($db->quoteName('#__usergroups'));
foreach ($groupNamesArr as $name)
{
$query->where($db->qn('title') . ' LIKE ' . $db->q($name), 'OR');
}
Overall I am not going to merge this PR since it's a feature that doesn't belong to the framework.
2nd time is a charm.. Display menuitems in sidebar based on "group title" or "user id". Extend the definition of meta metadata.xml, if no viewaccess is defined, item is shown. If viewmetadata is specified, current users settings are tested against it and only displayed if the user matches