info:joomla:modellivress

Ceci est une ancienne révision du document !


Changements dans le model livress (liste)

function getTotal()
  {
        // Load the content if it doesn't already exist
        if (empty($this->_total)) {
            $query = $this->_buildQuery();
            $this->_total = $this->_getListCount($query);    
        }
        return $this->_total;
  }
   function getPagination()
  {
        // Load the content if it doesn't already exist
        if (empty($this->_pagination)) {
            jimport('joomla.html.pagination');

         $total = $this->getTotal();
        $limitstart = $this->getState('limitstart');
        $limit = $this->getState('limit');

        // create the pagination object
        $this->_pagination = new JPagination($total, $limitstart, $limit);
        }
        return $this->_pagination;
  }
  
  /**
   * Items total
   * @var integer
   */
  var $_total = null;
 
  /**
   * Pagination object
   * @var object
   */
  var $_pagination = null;
   
     function __construct()
  {
        parent::__construct();
 
        global $mainframe, $option;
 
        // Get pagination request variables
        $limit = $mainframe->getUserStateFromRequest('global.list.limit', 'limit', $mainframe->getCfg('list_limit'), 'int');
        $limitstart = JRequest::getVar('limitstart', 0, '', 'int');
 
        // In case limit has been changed, adjust it
        $limitstart = ($limit != 0 ? (floor($limitstart / $limit) * $limit) : 0);
 
        $this->setState('limit', $limit);
        $this->setState('limitstart', $limitstart);
  }
  
//end main model class
 function getData()
 {
    // Lets load the data if it doesn't already exist
    if (empty( $this->_data ))
    {
       $query = $this->_buildQuery();
       $this->_data = $this->_getList( $query );
    }
    return $this->_data;
 }

attention, ici c'est plus délicat:

avant getData, changer

  function _buildQuery()
   {
      $query = ' SELECT * '
         . ' FROM #__livres '
      ;

      return $query;
   }

pour

   function _buildQuery()
   {
      #echo "filter: " .$this->filter_search;
      
      $query = ' SELECT * '
         . ' FROM #__livres ' 
   . $this->_buildQueryWhere()
         . ' ORDER BY auteur,titre'
      ;
      #echo "<hr>SQL: " .$query ."<hr>"; //tests
      return $query;
   }
   
/**
 * Builds the WHERE part of a query
 *
 * @return string Part of an SQL query
 */
function _buildQueryWhere()
{
    global $mainframe, $option; 

    // get the filter values
     $filter_search = $mainframe->getUserStateFromRequest($option.'filter_search', 'filter_search'); 

    // prepare the WHERE clause
    $where = array(); 
     // Determine search terms
    if ($filter_search = trim($filter_search))
    {
        $filter_search = JString::strtolower($filter_search);
        $db =& $this->_db;
        $filter_search = $db->getEscaped($filter_search);
        #$where[] = 'NOM1 LIKE "%'.$filter_search.'%"';

    $where[] = '
auteur LIKE "%'.$filter_search.'%" OR 
titre LIKE "%'.$filter_search.'%" OR 
support LIKE "%'.$filter_search.'%" OR 
localisation LIKE "%'.$filter_search.'%" OR 
groupe_carton LIKE "%'.$filter_search.'%" OR 
type LIKE "%'.$filter_search.'%" OR 
date LIKE "%'.$filter_search.'%" OR 
remarques LIKE "%'.$filter_search.'%" OR 
owner LIKE "%'.$filter_search.'%" OR 
datein LIKE "%'.$filter_search.'%" OR 
user_id LIKE "%'.$filter_search.'%"
    ';
    }

    // return the WHERE clause
    return (count($where)) ? ' WHERE '.implode(' AND ', $where) : '';
}
   /**
    * Retrieves the hello data
    * @return array Array of objects containing the data from the database
    */
   function getData()
   {
      // Lets load the data if it doesn't already exist
      if (empty( $this->_data ))
      {
        $query = $this->_buildQuery();
        $limitstart = $this->getState('limitstart');
        $limit = $this->getState('limit');
        $this->_data = $this->_getList($query, $limitstart, $limit);
      }

      return $this->_data;
   }
  • info/joomla/modellivress.1531899937.txt.gz
  • Dernière modification : 2018/07/18 09:45
  • de radeff