Virginia Web Designers: Joomla, Drupal, Open-Source, CSS, and PHP Northern Virginia / Maryland / Washington DC web designers

22Jun/101

Client login for Joomla 1.5 banner component

For the longest time I have been frustrated that the standard banner component doesn’t let banner clients login and view theirbanner statistics. I had been using OpenX but it is a resource hog and is really overkill when all I want is to be able to show a client how many clicks they’ve had so far. I don’t want them to just take my word for it.

Well, after trying out various solutions besides OpenX, I thought to myself 2 hours ago, “why can’t I just use Contact field in thebanner client area and enter a Joomla username, and then write a custom model for com_banners to display the statistics if the current Joomla user is the same as the one listed as the contact for a client?”

So that’s what I did. It is actually two queries. #1 checks the current username and selects all clients with that username (should be just one .. I limited it to one in the query), and selects the correct cid (client id). #2 selects all active banners for a given cid and spits them out, showing the banner, clicks, impressions, and CTR. I also added in some custom HTML to display a PayPal button … ideally this should be done in a View, not a Model, but the Banners component doesn’t seem to follow the MVC structure 100% so I didn’t either.

I did have to modify a few other files. Here are my modifications – this is on Joomla 1.5.18 but should work for any 1.5 release.

It’s as easy as 1-2-3;

1.

/components/com_banners/controller.php:

Add this after the end of function click():

2.

/components/com_banners/bannerstats.php
This is a new file – containing this code:

3.

/components/com_banners/models/bannerstats.php

This is a new file containing this code:

You can then create a link in the User Menu pointing to index.php?option=com_banners&task=bannerstats.

It will detect the current logged-in user’s username, check the “contact” field of the banner clients, and select the active banners for that client. Needless to say, the contact field should contain that person’s username and nothing else, or it will not work.

In the future maybe there can be a special field allowing us to choose a username or enter one, instead of using the Contact field which is not really meant for that. I had considered making this a separate component, but it is really something I would like to see become part of the regular com_banners component.

Feedback is welcome – as far as I can tell this is secure and works, but others may have a better idea about that.

Comments (1) Trackbacks (0)
  1. Thanks!
    I was looking for something like this without something to complex.
    Just a FYI…I would put the code in a textarea field …it make for better copy/paste.


Leave a comment

(required)

Spam Protection by WP-SpamFree

No trackbacks yet.