joomla/mod_api_40_6/helper.php

<?php
defined( '_JEXEC' ) or die( 'Restricted Access' );

class ModAPIHelper
{
   public function getRandomColor() { // return a random color
     return sprintf("#%02X%02X%02X",rand(0,255), rand(0,255), rand(0,255));
   }

   public function getUserName($gastName)  { // return user name, $gastName for name of not logged in user
        $user = JFactory::getUser();
        if ($user->id == 0)
        {
           return array($gastName, 'keine Infos');
        } else {
           return array($user->username, 'lastvisit=' . $user->lastvisitDate . ' email=' . $user->email);
        }
   }

   public function getUserContributions() { // get all articles of user
        $db = JFactory::getDBO();
        $user = JFactory::getUser();
        $id = $user->id;
        $query = "SELECT c.*, coalesce((select min(id) from jo36_menu m where m.link like concat('%article&id=', c.id, '%'))
                                      ,(select min(id) from jo36_menu where home = 1)) menu
             FROM #__content c
             WHERE created_by = $id
             ORDER BY modified DESC";

        $db->setQuery($query); 
        if ( !$db->query() ) {
             echo "<script type='text/javascript'>
                      alert('".$db->getErrorMsg()."');
                   </script>";
             return false;
          } else {
            $rows = $db->loadObjectList();
            return $rows;
          }
    }

    public function publishArticle($act,$id) { // set state to published or unpublished for article with id $id
        # --- SQL-Statement erstellen
        $sql = "UPDATE #__content SET state=";
        if ($act == "pub")
            $sql .= '1';
        elseif ($act == 'unpub')
            $sql .= '0';
        else
            return;
        $sql .= " WHERE Id = ".$id;
        # --- Datenbankabfrage ausf�hren
        $db = JFactory::getDBO();
           $db->setQuery($sql);
        if ( !$db->query() ) 
            echo "<script type='text/javascript'>
                     alert('".$db->getErrorMsg()."');
                  </script>";
    }
}   
?>