[ Index ]

PHP Cross Reference of Joomla 1.5.26 DE

title

Body

[close]

/components/com_contact/models/ -> category.php (source)

   1  <?php
   2  /**
   3   * @version        $Id: category.php 14401 2010-01-26 14:10:00Z louis $
   4   * @package        Joomla
   5   * @subpackage    Contact
   6   * @copyright    Copyright (C) 2005 - 2010 Open Source Matters. All rights reserved.
   7   * @license        GNU/GPL, see LICENSE.php
   8   * Joomla! is free software. This version may have been modified pursuant to the
   9   * GNU General Public License, and as distributed it includes or is derivative
  10   * of works licensed under the GNU General Public License or other free or open
  11   * source software licenses. See COPYRIGHT.php for copyright notices and
  12   * details.
  13   */
  14  
  15  // Check to ensure this file is included in Joomla!
  16  defined('_JEXEC') or die( 'Restricted access' );
  17  
  18  jimport('joomla.application.component.model');
  19  
  20  /**
  21   * @package        Joomla
  22   * @subpackage    Contact
  23   */
  24  class ContactModelCategory extends JModel
  25  {
  26      /**
  27       * Builds the query to select contact categories
  28       * @param array
  29       * @return string
  30       * @access protected
  31       */
  32  	function _getCatgoriesQuery( &$options )
  33      {
  34          // TODO: Cache on the fingerprint of the arguments
  35          $db        =& JFactory::getDBO();
  36          $aid    = @$options['aid'];
  37  
  38          $wheres[] = 'a.published = 1';
  39          $wheres[] = 'cc.section = ' . $db->Quote( 'com_contact_details' );
  40          $wheres[] = 'cc.published = 1';
  41  
  42          if ($aid !== null)
  43          {
  44              $wheres[] = 'a.access <= ' . (int) $aid;
  45              $wheres[] = 'cc.access <= ' . (int) $aid;
  46          }
  47  
  48          $groupBy    = 'cc.id';
  49          $orderBy    = 'cc.ordering' ;
  50  
  51          /*
  52           * Query to retrieve all categories that belong under the contacts
  53           * section and that are published.
  54           */
  55          $query = 'SELECT cc.*, COUNT( a.id ) AS numlinks, a.id as cid'.
  56                  ' FROM #__categories AS cc'.
  57                  ' LEFT JOIN #__contact_details AS a ON a.catid = cc.id'.
  58                  ' WHERE ' . implode( ' AND ', $wheres ) .
  59                  ' GROUP BY ' . $groupBy .
  60                  ' ORDER BY ' . $orderBy;
  61  
  62          //echo $query;
  63          return $query;
  64      }
  65  
  66      /**
  67       * Builds the query to select contact items
  68       * @param array
  69       * @return string
  70       * @access protected
  71       */
  72  	function _getContactsQuery( &$options )
  73      {
  74          // TODO: Cache on the fingerprint of the arguments
  75          $db            =& JFactory::getDBO();
  76          $aid        = @$options['aid'];
  77          $catId        = @$options['category_id'];
  78          $groupBy    = @$options['group by'];
  79          $orderBy    = @$options['order by'];
  80  
  81          $select = 'cd.*, ' .
  82                  'cc.name AS category_name, cc.description AS category_description, cc.image AS category_image,'.
  83                  ' CASE WHEN CHAR_LENGTH(cd.alias) THEN CONCAT_WS(\':\', cd.id, cd.alias) ELSE cd.id END as slug, '.
  84                  ' CASE WHEN CHAR_LENGTH(cc.alias) THEN CONCAT_WS(\':\', cc.id, cc.alias) ELSE cc.id END as catslug ';
  85          $from    = '#__contact_details AS cd';
  86  
  87          $joins[] = 'INNER JOIN #__categories AS cc on cd.catid = cc.id';
  88  
  89          if ($catId)
  90          {
  91              $wheres[] = 'cd.catid = ' . (int) $catId;
  92          }
  93          $wheres[] = 'cc.published = 1';
  94          $wheres[] = 'cd.published = 1';
  95  
  96          if ($aid !== null)
  97          {
  98              $wheres[] = 'cc.access <= ' . (int) $aid;
  99              $wheres[] = 'cd.access <= ' . (int) $aid;
 100          }
 101  
 102          /*
 103           * Query to retrieve all categories that belong under the contacts
 104           * section and that are published.
 105           */
 106          $query = 'SELECT ' . $select .
 107                  ' FROM ' . $from .
 108                  ' ' . implode ( ' ', $joins ) .
 109                  ' WHERE ' . implode( ' AND ', $wheres ) .
 110                  ($groupBy ? ' GROUP BY ' . $groupBy : '').
 111                  ($orderBy ? ' ORDER BY ' . $orderBy : '');
 112  
 113          return $query;
 114      }
 115  
 116      /**
 117       * Gets a list of categories
 118       * @param array
 119       * @return array
 120       */
 121  	function getCategories( $options=array() )
 122      {
 123          $query    = $this->_getCatgoriesQuery( $options );
 124          return $this->_getList( $query, @$options['limitstart'], @$options['limit'] );
 125      }
 126  
 127      /**
 128       * Gets the count of the categories for the given options
 129       * @param array
 130       * @return int
 131       */
 132  	function getCategoryCount( $options=array() )
 133      {
 134          $query    = $this->_getCatgoriesQuery( $options );
 135          return $this->_getListCount( $query );
 136      }
 137  
 138      /**
 139       * Gets a list of categories
 140       * @param array
 141       * @return array
 142       */
 143  	function getContacts( $options=array() )
 144      {
 145          $query    = $this->_getContactsQuery( $options );
 146          return $this->_getList( $query, @$options['limitstart'], @$options['limit'] );
 147      }
 148  
 149      /**
 150       * Gets the count of the categories for the given options
 151       * @param array
 152       * @return int
 153       */
 154  	function getContactCount( $options=array() )
 155      {
 156          $query    = $this->_getContactsQuery( $options );
 157          return $this->_getListCount( $query );
 158      }
 159  }


Generated: Wed Mar 28 15:54:07 2012 Cross-referenced by PHPXref 0.7.1