Addshore

It's a blog

Tag: Joomla

My Joomla Component development workflow

Joomla20Symbol20Color20FLATMy first and currently only Joomla component development was for the SWA UK website. The component manages memberships, events, tickets, results and more and is a rewrite of a previous component for Joomla 1.

But in this post lets ignore what the component does and instead concentrate the development workflow that is used. After lots of research at the beginning of development I decided to ignore other  methods of developing a component and this is what I ended up coming up with.

Continue reading

Letting a Joomla component assign View Levels to Users

So I recently came across an issue with my speedy rewrite of the component that is used to power the SWA website. Here is a quick summary of the issue and how I went about fixing it!

The rewrite maintains information about users and members in tables that it has created. A User, in Joomla terms is not the same as a member of the component. Members of the component should be able to access various different menu items depending on various details of their member profile. Thus extra levels of access for users needs to be decided by the component.

Component defined view levels

At the lowest level access to menu items generally depends on what view levels a user has access to. These are stored in the ‘viewlevels’ table, so my component would need to add some view levels in order to do anything here at all.

To do this I added the following to the install.sql file for my component, meaning these 2 view levels would be added if they did not previously exist (I could probably also do this separately in PHP post installation).

Now that the view levels exist menu items can be set to require them. Lovely, except for the fact that I am not going to assign these view levels to users directly, thus right now no one can view these menu items!

Component decided view levels

As my main concern was hiding / showing menu items the logical place to start looking was in ‘mod_menu’ which creates the menus in Joomla. As the module was very small it was easy to see that the list of menu items was generated using the code below.

This method then gets a list of authorised view levels for the current user using the code below:

So of course next we look at JUser::getAuthorisedViewLevels. This method provides some level of caching so that the view levels are only retrieved once per request, meaning less DB casll. But essentially this method gets the view levels from JAccess::getAuthorisedViewLevels. So this is where need a new event!

JAccess::getAuthorisedViewLevels requests all of the view levels currently defined in Joomla as well as all of the groups that the current user is in. A quick look over everything then results in an array of view levels that are assigned to the users groups. This is where we pounce!

Just before the return of this method we add our event:

This passes off the array of view levels to subscribers of the onJAccessGetAuthorisedViewLevels event which means that extra view levels can be added according to $userId.

Note that before this event is fired the code imports all plugins of the group ‘swa’ which is where the plugin that we want to subscribe is located! Also note that the import plugin call is wrapped in an IF so that it is only ever called once, this is due to a loop as apparently the importPlugin method calls the this method again (at some point).

We can then use this event to do whatever we want. See what I did at https://github.com/SWAuk/plg_swa_viewlevels/blob/3c78b858c34f4ee5c3a303b05979191847261837/src/viewlevels.php#L19

Final thoughts

There may have been a nicer way to do this but right now I simply do not have the time!

This is a bit of a hack as we are having to change Joomla code by adding an event however it is a very maintainable hack (simply adding the trigger before a method return).

I wonder if I will ever have time to revisit this….

Right now

A Stickman

So a quick summary of everything I am working on right now:

  • MassAction is a Mediawiki extension allowing users to perform mass actions on targets on a Mediawiki site through a static page using Mediawikis inbuilt job queue that I have been working on for the past half a year or so. I look forward to releasing it to the open source world soon!
  • addwiki is a collection of Mediawiki related PHP libraries (including one for wikibase). Previous to this I developed various PHP scripts and bots for Wikipedia using other libraries and always found that they were quite badly coded and prone to doing unexpected things. Addwiki is the start of my attempt to fix that for PHP.
  • Orain (github) is a community-driven, not-for-profit wiki network that I help to keep running.
  • I am also still an active contributor to all kinds of Wikimedia projects including the wonderful Wikidata.
  • I should at some point be trying to create a very rudimentary backup script / system for Sharepoint Lists…
  • I am also currently working on a redesign of the Joomla 1 components used to power http://studentwindsurfing.co.uk/ written for Joomla 3 which should be ready in the next 6 months.

I am also still involved with:

  • Huggle (github), an antivandalism tool for use on Wikipedia and similar projects.

I could also point toward a few other things:

I also have a backlog of posts that I might try to write…

But for now lets end this post here.

© 2017 Addshore

Theme by Anders NorenUp ↑