0
Welcome Guest! Login
0 items Join Now

ROCKETTHEME IS CLOSING ON JUNE 30, 2025. As a thank-you to our community, enjoy 50% off all themes with the promo code THANKYOU before we shut down. Read our Farewell Blog Post for more details.

Counter for user posts (Solution by Adamck)

    • filmzone's Avatar
    • filmzone
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0
    • Clerk with the Belgian Christian Union

    Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • Is there anyone of you guys, who knows about a module or component (even a plugin perhaps), that can show a list of articles per user?

      the idea is this :

      on my website I let users post their own movie-descriptions with pix etc. The one that has most descriptions posted at the end of a certain periode, will win a movie on dvd. But I hate going back and forth in the admin-backend to count the articles they have posted for that period (in that category). For now there are only a dozen or so users doing this, but their number is growing and I wouldn't want to have to check for an hour, just to know who got the most of them...

      any ideas, thoughts?
    • Last Edit: 14 years 7 months ago by filmzone.
    • Adamck's Avatar
    • Adamck
    • Elite Rocketeer
    • Posts: 546
    • Thanks: 2
    • Web Developer, IT Assistant, Graphics design, App Developer

    Re: Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • I created a custom_php module (its an extension, see link)
      www.fijiwebdesign.com/portfolio/joomla-php-module-mod_php.html
      Make sure you get the Joomla 1.5 version.

      Then add
       
      <?php    
           $db =& JFactory::getDBO();
           $db->setQuery("SELECT jos_users.username, COUNT(*) AS 'TOTAL' FROM jos_content INNER JOIN jos_users ON jos_content.created_by = jos_users.id GROUP BY created_by");
           $rows1 = $db->loadObjectList();
           echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'>";
           echo "<tr><td><strong>User</strong></td><td><strong>Descriptions</strong></td></tr>";
           foreach ($rows1 as $row)
           {
      ?>
          <tr>
          <td><?php echo $row->username; ?></td><td><?php echo $row->TOTAL; ?></td>
          </tr>
      <?php
       } 
       echo "</table>";
       ?>
       

      This will display each users username and their total articles created by them.
      You may want to add a little to the sql query if you want to remove replies or un-published items etc...
      Should work ok tho!
      Let me know how that works out for you 8)
    • Kiss my RSS
    • filmzone's Avatar
    • filmzone
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0
    • Clerk with the Belgian Christian Union

    Re: Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • Hi Adamck, first off : a huge thanks for your support. I have used your module for a long time now, but at the moment I only did to paste html chunks into my website...

      since I'm a total noob to php, could you tell me how to limit the results to a certain category and certain period only?

      for example :

      all articles posted by users (per user) in category "X" from monday to sunday of last week...
    • Adamck's Avatar
    • Adamck
    • Elite Rocketeer
    • Posts: 546
    • Thanks: 2
    • Web Developer, IT Assistant, Graphics design, App Developer

    Re: Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • Its not PHP you need for filtering the info, its SQL (mySQL)
      If you look at you mysql database you will see jos_content
      Within this you will see all the fields that make up an article, within this their is catid which determains which category each item is in.

      So to limit the results to a certain category you would do:
      SELECT jos_users.username, COUNT(*) AS 'TOTAL' FROM jos_content INNER JOIN jos_users ON jos_content.created_by = jos_users.id WHERE catid = '3' GROUP BY created_by

      here i selected all items in category 3 (catid = '3') (look at jos_categories to find the category ID you want)

      to add the dates aswel you would futher the query and mix it up with PHP to get the date from last week.
      It would be easier here to have 2 input boxes for dates (so you can select any date range via a form).
      I will play about with the date thing when i get chance, but have a try yourself as i cannot do everything for you or you will never learn!
    • Kiss my RSS
    • Adamck's Avatar
    • Adamck
    • Elite Rocketeer
    • Posts: 546
    • Thanks: 2
    • Web Developer, IT Assistant, Graphics design, App Developer

    Re: Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • Im far too nice to people!
      <?php   
          $from = JRequest::getVar('from');
          $to = JRequest::getVar('to');
          $option = JRequest::getVar('option');
          $view = JRequest::getVar('view');
          $id = JRequest::getVar('id');
          $Itemid = JRequest::getVar('Itemid');
          if (isset($from)) {
          $db =& JFactory::getDBO();
          $db->setQuery("SELECT jos_users.username, COUNT(*) AS 'TOTAL' FROM jos_content INNER JOIN jos_users ON jos_content.created_by = jos_users.id WHERE catid = '34' AND created >= '" .$from. "' AND created <= '" .$to. "' GROUP BY created_by");
          $rows1 = $db->loadObjectList();
          echo "<table width='100%' border='0' cellspacing='2' cellpadding='2'>";
          echo "<tr><td><strong>User</strong></td><td><strong>Descriptions</strong></td></tr>";
          foreach ($rows1 as $row)
          {
      ?>
         <tr>
         <td><?php echo $row->username; ?></td><td><?php echo $row->TOTAL; ?></td>
         </tr>
      <?php
       }
       echo "</table>";
       } else {
      ?>
      <form id="form1" name="form1" method="get" action="index.php">
      <input type="hidden" name="option" value="<?php echo $option; ?>" />
      <input type="hidden" name="view" value="<?php echo $view; ?>" />
      <input type="hidden" name="id" value="<?php echo $id; ?>" />
      <input type="hidden" name="Itemid" value="<?php echo $Itemid; ?>" />
      <table>
      <tr>
      <td>
          From:
      </td>
      <td>
          <input type="text" name="from" id="from" />
      </td>
      </tr>
      <tr>
      <td>
          To:
      </td>
      <td>
          <input type="text" name="to" id="to" />
      </td>
      </tr>
      </table>
      <input type="submit" value="Submit" />
      </form>
      <?php
       }
       ?>

      This is ending up big enough to be an extension in itself!

      That code will display 2 input boxes (see pics attached)
      Enter the dates in YYYY-MM-DD format.
      Make sure you set the catid in the query to the category you wanted the results from.
      Full out BOTH of the boxes or it will error.

      This is a little rough, but it works (tested it on my own site) to improve you could add some error catching and you could add the joomla calendar javascript for selecting dates.
      Ad.
    • Kiss my RSS
    • filmzone's Avatar
    • filmzone
    • Jr. Rocketeer
    • Posts: 22
    • Thanks: 0
    • Clerk with the Belgian Christian Union

    Re: Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • Adamck, I don't know how to thank you, this is just best service anyone could wish for, even for a paid supportdesk this would be top notch!
      You are the best!!!
    • Adamck's Avatar
    • Adamck
    • Elite Rocketeer
    • Posts: 546
    • Thanks: 2
    • Web Developer, IT Assistant, Graphics design, App Developer

    Re: Counter for user posts (Solution by Adamck)

    Posted 14 years 7 months ago
    • No worries dude, I'm not even a RT member of staff lol.
      Just my good deed for the day!
      Now go and learn SQL you will need it!
    • Kiss my RSS

Time to create page: 0.082 seconds