014 - Create a module listing the latest article written for each author

Google's Highly Open Participation Program tries to get young students into Open Source and Joomla! specifically. Everyone is welcome, there are not limits. You can be a coder, documenter, tester, translator to help out. Jump in and start helping!
Locked
benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

014 - Create a module listing the latest article written for each author

Post by benhiller » Thu Nov 29, 2007 9:58 pm

Hello, I have claimed task 14, which to code a module that will display the latest article each author has written. The complete description is:
One line summary
Create a module listing the latest article written for each author.

Describe the task.
Create a module modeled after mod_mostread that lists the names of each
author, along with a link to their latest article.

Resources:
    * /modules/mod_mostread

Skills Needed
    * Ability to install XAMPP, download and install Joomla! on a localhost
using default data.
    * Familiarity with Joomla!
    * Knowledge of PHP
    * Knowledge of MySQL

Difficulty
Advanced.

Work Product
A functioning Joomla! v 1.5 module packaged for installation.

Licensing
All code must be created using the GNU General Public License version 2.
http://www.gnu.org/licenses/old-license ... .html#SEC4

Documentation written for this task must be made available under the
Joomla! Electronic Documentation License.

Extra Credit (Optional)
Register as a developer at joomlacode.org and create a project for your module.

Time Limit
4 weeks.
You can see it on Google Code here.

I have experience with PHP and MySQL from Senate Seeker. My friend coded the site initially, however I served as a co-administrator and through that experience I have learned a lot about PHP and MySQL. I look forward to completing this task and hopefully others.

Claimed Nov 28 Due Dec 26

Google Task

[me=AmyStephen]Changed subject slightly for sorting all threads to match against Google resource  :)[/me]
Last edited by AmyStephen on Thu Dec 20, 2007 2:06 am, edited 1 time in total.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 14 - Create a module listing the latest article written for each author

Post by AmyStephen » Thu Nov 29, 2007 10:40 pm

Welcome to Joomla! Thanks for joining the GHOP contest. I am confident that your work will be put to good use by many all over the world. We are looking for someone to help mentor this task. Soon, they will respond in this thread, introducing themselves to you.

Anytime you have questions or need assistance, do not hesitate to ask. Have fun and good luck in the contest!
Amy :)

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7897
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: 14 - Create a module listing the latest article written for each author

Post by mcsmom » Thu Nov 29, 2007 11:00 pm

Cool site!
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: 14 - Create a module listing the latest article written for each author

Post by kdevine » Thu Nov 29, 2007 11:02 pm

Hello, I'm Kevin. I would be happy to be the mentor for this one.


benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Wed Dec 05, 2007 3:00 am

I've begun work on the module. So far, I have created a simple module that shows the latest article for each user, but I have a few questions. My module is not very customizable, what sort of parameters should I allow the user to set? Also, for the comments at the top of the files, I wasn't sure what I should fill out, and what I should put in some fields, such as @package. I was not sure how to link to the latest article for each user. I looked at mod_mostread and it seems like I will need a much more complex SQL query to do this. Also, please point out anything else I should do differently.

Thanks!
You do not have the required permissions to view the files attached to this post.

kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: 014 - Create a module listing the latest article written for each author

Post by kdevine » Thu Dec 06, 2007 3:19 pm

This is a very good start, you're almost there. The install worked perfectly for me and I was able to create and publish an instance of the module on my site without any problems. Here are some answers to your questions and my comments and ideas for how to improve this.

Parameters:
Consider allowing a range of user types (gid). You could possibly do this in you author query by changing it to:
gid >=
On my install of Joomla 1.5 with sample data all articles were created by the super administrator so no results are returned by your module. Also consider making the gid parameter a select drop down with the group names to make this more user friendly.

Maybe a date range so the module displays all new articles published in the past week/month/year? The module is currently selecting all published articles.

Doc Comment Tags:
@version - is typically the current version number of your software and the date the file was last modified (mostly auto generated when checked out of a repository)
@package - you can give the name of your module
@copyright - your own name
@license- GNU/GPL

You should also add a Doc Comment to your classes and a Block Comment to your methods to give a description of what they are for, what params the method accepts and what it returns.

Also consider commenting areas of your code to explain why you made certain decisions. It not only forces you to think through why you have done things the way you have but also helps other developers (and you if it has been a while) understand the code or even figure out ways to improve it.

Link:
Take a look at mod_latestnews helper.php lines 86, 87, and 107. This will give you an idea of how to build the link to the article. Basically you are trying to build a friendly URL if possible.

My Comments:
Unused variable $ouput at line 23 of helper.php
Query for authors:
gid needs to be converted from a string to an integer. You can use Type Casting for this.

Query for content:
Study the query built by the getList method of mod_newsflash because it is a little less complicated than latestnews but will give you a better idea of how you need to construct your query. Right now you are selecting all published articles created by a specific user but you need to also check the access level of the article against the access level of the current user, and the publish-up and publish-down dates. Consider ordering the results by the article order. And remember to make sure any variable that needs to be an integer in your query is indeed an integer.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Sat Dec 08, 2007 4:23 am

Ben -

Is there anything we can do to help you with your task? A quick update on your progress would be appreciated. Also, to let you know, we added about 20 more cool development tasks. You are free to take another task when this one has been completed.

Thanks!
Amy :)

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Sat Dec 08, 2007 5:51 pm

I revised the module, and I was able to fix most of the issues. I did have a few questions though.

Parameters:
It now uses "gid >="
I tried changing the parameter so it would show a drop down of the group names, but what I tried didn't work. I tried extending mosParameters, which is a method I found online, you can see the code (commented out) in mod_latestarticlebyauthor.php. Is there a new method or am I doing something incorrect?

Also, I added a drop down so the admin can choose between selecting articles published in the last week/month/year, but it is not very flexible. I think it does what you wanted it to do though, right? Is there a way to embed a calendar in the parameters, or the current solution ok?

Doc Comment Tags:
I have added proper Doc Comments, and block comments in some parts of the code.

Link and Content query:
I looked at the other modules and I believe that mine now correctly queries and links to the articles

Your Comments:
I removed the unused $output, and I now typecast anything in the query that needs to be an integer to an integer.


[EDIT] Oops, I just realized that I mis-read what you meant about a date-range. In the attachment, the date-range just changes what is selected in the query. I will edit it to make it so that it shows either the latest or all posts from last week/month/year.
You do not have the required permissions to view the files attached to this post.
Last edited by benhiller on Sat Dec 08, 2007 8:04 pm, edited 1 time in total.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Sun Dec 09, 2007 5:20 am

That query is really thought-provoking, isn't it?  :P

This is a tough task. I've looked at several other modules, tonight. This one is considerably more challenging. Hope you enjoy it. I think it's fun!

Odd thoughts:

1. Group - probably doesn't make sense to a novice end user 

Suggest you either, consider Kevin's idea:
On my install of Joomla 1.5 with sample data all articles were created by the super administrator so no results are returned by your module. Also consider making the gid parameter a select drop down with the group names to make this more user friendly.
Or, perhaps even add an option buttons for each group:

Include Super Administrator Articles? Yes No
Include Administrator Articles? Yes No
Include Publisher Articles? Yes No
Include Editor Articles? Yes No
Include Author Articles? Yes No

2. Consider adding a section and category text box for inclusion. (ex. like mos_latestnews)

3. Query is executed by a.ordering. I think a.created in descending order will get you the latest written article.

4. The list of users that feeds your foreach loop should be in alphabetical order by name, instead of uid order.

5. Initialize your local parameter $oldtest in helper.

6. Clean out the commented out class in mod_latestarticlebyauthor.php

Get it ready for lots and lots of use. This is a good social networking module.

You are doing good. It is so late and I want to give feedback to as many as possible, so, I failed to do something very important, and that is to point out all the good. So, EVERYTHING ELSE ROCKS!

Thanks for your contributions to the Joomla! community,
Amy :)

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Sun Dec 09, 2007 7:29 am

I really enjoyed this task. :) At first, I thought it would be a pretty simple module, it was definitely more complex than I expected, but in a good way.

1. I went with the radio buttons option, so now a user can choose which group's articles will be shown.
2. I added a section and category parameter, so users can choose which sections/categories are displayed.
3. The query is now sorted by a.created.
4. I sort the authors by name now, so it will be in alphabetical order.
5. $oldtest was a typo, I meant $oldest, which I have fixed now.
6. Since I am using the radio buttons instead of a drop-down, I removed the commented-out code.

Also, I fixed the date range, so now it will show either the latest item by an author, or all the author's items from the last week/month/year.
I hope that this current version is good. Thank you both for the help!
You do not have the required permissions to view the files attached to this post.

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Mon Dec 10, 2007 10:59 pm

I see that the icon next to this topic was changed to an exclamation point. Does that mean that the module is up for final review? Exciting!  :)

User avatar
mcsmom
Joomla! Exemplar
Joomla! Exemplar
Posts: 7897
Joined: Thu Aug 18, 2005 8:43 pm
Location: New York
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by mcsmom » Tue Dec 11, 2007 9:34 pm

Well, what do you think? Do you want final review or are you still looking for general feedback?
So we must fix our vision not merely on the negative expulsion of war, but upon the positive affirmation of peace. MLK 1964.
http://officialjoomlabook.com Get it at http://www.joomla.org/joomla-press-official-books.html Buy a book, support Joomla!.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Tue Dec 11, 2007 11:28 pm

Ben -

I can't get it to return any results. I can see all the fabulous new code - just nothing other than the heading.

I've tried a number of options. Am on a brand new install (from the SVN).
  • Articles from one year ago
  • Section ID and Category ID have nothing (although there have been values there).
  • All groups turned on.
Also, I wanted to mention a wish list item.

Consider offerings choices to format the output differently:
Name: Article
Username: Article
Article by Name
Article by Username
Name
Username
You don't have to do that, it's just a suggestion. I plan to use this module and I want the format Article by Name. Made me realize there will be different ways people want this.

Let me know what I did wrong - or - make a quick fix and I'll try to look at it, again, tonight.

Thanks!
Amy :)

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Wed Dec 12, 2007 10:18 pm

I just tried installing the module on a fresh install of Joomla with the sample data, and the module worked fine. I am using the latest version (1.5RC3) of Joomla on a Mac (if that matters?)

I also tried using the SVN build of Joomla, and it did not work on that. However, I tried adding the Latest News module in the SVN build, and it did not show any stories either. I am basing my SQL query on the Latest News module, so perhaps there is a change that has to be made for the SVN build? I will try looking at the SVN changelog, to see if there are any tips there. Edit: Nope, didn't see anything.
Last edited by benhiller on Wed Dec 12, 2007 10:26 pm, edited 1 time in total.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Thu Dec 13, 2007 12:29 am

Yea, I was using a "fresh" SVN copy. I'll try later tonight when I get home. I will also try the nightly download.

Thanks for your efforts and patience.
Amy :)

kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: 014 - Create a module listing the latest article written for each author

Post by kdevine » Fri Dec 14, 2007 12:48 am

Seems to work ok on the latest build.

Looking at the code though, you could definitely do some refactoring.

For example:
If you added a limit to your articles query you wouldn't need that first if statement at line 116.

And gosh, building the group condition could really be condensed. You're on the right track but try matching the method used for building the category or section condition. You could build an array of possible choices using range, an array of chosen groups with one hard coded default, and then implode the intersection of the two. I wrote it out and it condenses your code by at least 16 lines.

Those are things that really stood out for me.

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Fri Dec 14, 2007 1:23 am

I changed the code, so the section that makes the group part of the query is now more efficient.

Also, I was able to limit the query so I could remove the if statement at line 116. Thank you for pointing these things out.

Since you reported that it worked, I would like my code to go up for final review.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Sun Dec 16, 2007 6:43 pm

Ben - where is your latest extension? I am happy to look at it if you will post it. Sorry for the delay.  :P

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Sun Dec 16, 2007 8:04 pm

Sorry, I forgot to include it in my post. Here it is.
You do not have the required permissions to view the files attached to this post.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Mon Dec 17, 2007 2:30 pm

It isn't printing the title of the article, anymore, or the link (obviously).
Latest Article by Author

    * Administrator
    * Amy Stephen
Sorry!
Amy :)

kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: 014 - Create a module listing the latest article written for each author

Post by kdevine » Mon Dec 17, 2007 9:26 pm

Ben, I took another look at the code and I still have one problem with the query you are using to get the articles. I think the WEEK interval you are trying to use for the date range is only compatible with MySQL 5+. You should consider changing your SQL to make it compatible with MySQL 4.

The minimum requirement for Joomla is MySQL 3.23.x but that might be a little too strict. You should be fine with MySQL 4.

http://help.joomla.org/content/view/1938/302/
http://dev.mysql.com/doc/refman/4.1/en/ ... n_date-add

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Tue Dec 18, 2007 3:18 am

I revised the module again.

kdevine: I believe the SQL is now compatible with MySQL 4, and also possibly MySQL 3.23.x. Instead of using the WEEK interval I just use the DAY interval.

AmyStephen: I am sorry, but I am unable to reproduce that bug. What settings do you have the module on and what version of Joomla are you using?

I attached the latest revision.
You do not have the required permissions to view the files attached to this post.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Tue Dec 18, 2007 1:55 pm

OK - it worked this time! It correctly pulls each author - and grabs their last article.

The way it's formatted, though, with the last article as a list of one item beneath the author's name, it's really crowded in the left column,  a location many will want to use it in. If I were to use module, I'd have to hack the code to output it the way I needed it or I'd have to add template overrides to override the format. Those skills are beyond most end users. I think there will be many differnt ways people want to use this output. Again, I'd recommend offering at least few different options.

You could add a module parameter to use either: a) username or b) author/author alias as the name. (Author alias should be substituted as Author, when used.)

Then, offer a few output options so it's more flexible for your user:
  • Name: Article (Ben Hiller: GHOP)
  • Article by Name (GHOP by Ben Hiller)
  • Name (linked to article) (Ben Hiller)
I would continue to use list output - just not two lists since there is never more than one article. But, using a list - and allowing the CSS hooks, as you have, is good.

Again, this is a great module that helps transform Joomla! into a multiblogging/social networking framework. It's a module I plan to use.

Kevin - thanks for your guidance. I am learning from you, as well.

Amy :)

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Wed Dec 19, 2007 4:07 am

I revised the module again. I believe it now does what you wanted it to do.

AmyStephen: I am glad that it worked! :) I added in two parameters. One to choose between using the author's name or username, and the other to choose the format type. I tested all of the outputs and they work correctly.

Also, thank you both for all of your advice. It helped me out a lot with this module. Also, since I am now getting pretty close to the time limit and since the module has all of the requested features and works properly, I would like to submit this module for final review.

Thanks,
Ben
You do not have the required permissions to view the files attached to this post.

AmyStephen
Joomla! Champion
Joomla! Champion
Posts: 7018
Joined: Wed Nov 22, 2006 3:35 pm
Location: Nebraska
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by AmyStephen » Wed Dec 19, 2007 6:32 am

Perfect!  8) That is some beautiful code, too!

Absolutely accept this as final.

Kevin? I'll send a note out and try to get a 2nd review ASAP.

Very, very fine work. Nice piece!
Amy :)

kdevine
Joomla! Enthusiast
Joomla! Enthusiast
Posts: 200
Joined: Thu Mar 02, 2006 8:38 pm
Location: Baltimore, MD

Re: 014 - Create a module listing the latest article written for each author

Post by kdevine » Wed Dec 19, 2007 12:58 pm

Absolutely, final review. Ben, you have done a great job. Congratulations.

User avatar
ianmac
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4784
Joined: Sat Sep 24, 2005 11:01 pm
Location: Toronto, Canada

Re: 014 - Create a module listing the latest article written for each author

Post by ianmac » Wed Dec 19, 2007 1:44 pm

Sorry...  one thing if I might...

Due to a bug in Apple OS/X there is some extra files in your zip file.  See http://floatingsun.net/2007/02/07/whats ... -zip-files for more information.  If you clean your zip file then we will mark the task as closed and release you to try another one!

Ian

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Wed Dec 19, 2007 11:04 pm

I am glad you all liked the module!  ;D

I made the appropriate fix to the module. Also, I will now upload it to Google Code and to the other Joomla site.

Thank you for the opportunity to work on this task.
You do not have the required permissions to view the files attached to this post.

benhiller
Joomla! Apprentice
Joomla! Apprentice
Posts: 20
Joined: Thu Nov 29, 2007 9:46 pm
Location: NJ, USA
Contact:

Re: 014 - Create a module listing the latest article written for each author

Post by benhiller » Thu Dec 20, 2007 11:08 pm

Sorry, I promise this will be my last post here. I just wanted to say that I created the project on JoomlaCode and anyone who wants to use the module can download it from there: http://joomlacode.org/gf/project/latestarticle/

Enjoy!


Locked

Return to “Google's Highly Open Participation Contest”