zenith Là-haut perché dans la pensée. | Ok alors voila le code du "model" de joomla :
Code :
- <?php
- /**
- * @version 1.0 simple ads - petites annonces $
- * @package simple_ads_-_petites_annonces
- * @copyright Copyright © 2010 - All rights reserved.
- * @license GNU/GPL
- * @author Anthony JULOU
- * @author mail ajulou@yahoo.fr
- *
- *
- **/
- /* Hagen Graf - cocoate.com */
- // Check to ensure this file is included in Joomla!
- defined('_JEXEC') or die();
- jimport('joomla.application.component.model');
- /**
- *Auto Component Auto Model
- *
- */
- class AnnoncesModelAnnonces extends JModel
- {
- var $_total = null;
- var $_pagination = null;
- /**
- * Constructeur
- * @return unknown_type
- */
- function __construct()
- {
- parent::__construct();
- global $mainframe;
- $parametrage = Util::parametrage();
- // Get the paramaters of the active menu item
- $params = & $mainframe->getParams();
- //get the number of events from database
- $limit = $mainframe->getUserStateFromRequest('com_annonces.limit', 'limit', $parametrage->nbpage, 'int');
- $limitstart = JRequest::getInt('limitstart');
- $this->setState('limit', $limit);
- $this->setState('limitstart', $limitstart);
- // Get the filter request variables
- $this->setState('filter_order', JRequest::getCmd('filter_order', 'a.constructeur', 'a.propriete1'));
- $this->setState('filter_order_dir', JRequest::getCmd('filter_order_Dir', 'ASC', 'DESC'));
- }
- /**
- * Construit la requete SQL
- * @param unknown_type $options
- * @param unknown_type $parametres
- * @return unknown_type
- */
- function _getAutoQuery( &$options, $parametres )
- {
- $db = JFactory::getDBO();
- $id = @$options['id'];
- $select = 'a.*, c.catname, c.showYear, c.showDimensions, c.showConstructor, u.name ';
- $from = '#__annonces AS a ';
- $orderby = $this->_buildCategoryOrderBy();
- $wheres[] = 'c.published =1 and a.published = 1 AND a.approuved = 1';
- $catid = @$options['categorie'];
- if ( $catid )
- $wheres[] = 'categorie = ' . (int) $catid;
- if ( $parametres->published_days && $parametres->published_days != 0 )
- $wheres [] = 'a.date > \'' . date( 'Y-m-d', strtotime("-".$parametres->published_days." day" )) .'\'';
- $query = "SELECT " . $select .
- "\n FROM " . $from .
- "\n LEFT JOIN #__annonces_categories AS c ON c.id = a.categorie".
- "\n LEFT JOIN #__users AS u ON a.vendeurId = u.id".
- "\n WHERE " . implode( "\n AND ", $wheres ).
- "\n " . $this->filterWhere().
- "\n " . $orderby;
- return $query;
- }
- /**
- *
- * @return unknown_type
- */
- function filterWhere()
- {
- $filter = JRequest::getString('filter', '', 'request');
- $filter_type = JRequest::getWord('filter_type', '', 'request');
- $where = "";
- if ($filter)
- {
- // clean filter variables
- $filter = JString::strtolower($filter);
- $filter = $this->_db->Quote( '%'.$this->_db->getEscaped( $filter, true ).'%', false );
- $filter_type = JString::strtolower($filter_type);
- $where = ' AND (';
- $where .= ' LOWER( a.objet ) LIKE '.$filter;
- $where .= ' OR LOWER( c.catname ) LIKE '.$filter;
- $where .= ' OR LOWER( a.villeObjet ) LIKE '.$filter;
- $where .= ' OR LOWER( a.description ) LIKE '.$filter;
- $where .= ' )';
- }
- return $where;
- }
- /**
- * Total nr of ads
- *
- * @access public
- * @return integer
- */
- function getTotal( $options, $parametres )
- {
- if (empty($this->_total))
- {
- $query = $this->_getAutoQuery($options, $parametres);
- $this->_total = $this->_getListCount($query);
- }
- return $this->_total;
- }
- /**
- * Method to get a pagination object for the ads
- *
- * @access public
- * @return integer
- */
- function getPagination()
- {
- if (empty($this->_pagination))
- {
- jimport('joomla.html.pagination');
- $this->_pagination = new JPagination( $this->_total, $this->getState('limitstart'), $this->getState('limit') );
- }
- return $this->_pagination;
- }
- /**
- * Construit la liste des annonces
- * @param $options
- * @param $parametres
- * @return unknown_type
- */
- function getListeAnnonces( $options=array(), $parametres )
- {
- $query = $this->_getAutoQuery( $options, $parametres );
- $result = $this->_getList( $query, $this->getState('limitstart'), $this->getState('limit') );
- return @$result;
- }
- /**
- * Build the order clause
- *
- * @access private
- * @return string
- */
- function _buildCategoryOrderBy()
- {
- $filter_order = $this->getState('filter_order');
- $filter_order_dir = $this->getState('filter_order_dir');
- $orderby = ' ORDER BY '.$filter_order.' '.$filter_order_dir;
- return $orderby;
- }
- /**
- * Cherche les colonnes a afficher
- * @param $listeAnnonces
- * @return unknown_type
- */
- function getShowColumns( $listeAnnonces )
- {
- $show = new stdclass();
- $show->showYear = false;
- $show->showDimensions = false;
- $show->showConstructor = true;
- foreach ( $listeAnnonces as $annonce )
- {
- $show->showYear |= $annonce->showYear;
- $show->showDimensions |= $annonce->showDimensions;
- }
- return $show;
- }
- /**
- * Initialise la nouvelle categorie dans l'annonce
- *
- * @param $annonce
- * @param $categorie
- * @return unknown_type
- */
- function getListCategorieLiens( $catidSelected )
- {
- if ( ! $catidSelected )
- $catidSelected = 0;
- $query = 'SELECT c.catname, c.id, COUNT(*) AS nb'
- . ' FROM #__annonces_categories c '
- . ' LEFT JOIN #__annonces a ON a.categorie = c.id'
- . ' WHERE a.published = 1 and c.published=1'
- . ' GROUP BY c.catname'
- . ' ORDER BY c.ordering'
- ;
- $this->_db->setQuery( $query );
- $listeCategorie = $this->_db->loadObjectList();
- $listeLiens = array();
- $tteCategorie = new stdclass();
- $tteCategorie->libelle = JText::_('ALLE');
- $tteCategorie->lien = 'index.php?option=com_annonces&view=annonces';
- $listeLiens[] = $tteCategorie;
- $total = 0;
- foreach ( $listeCategorie as $categorie ) {
- $uneCategorie = new stdclass();
- $uneCategorie->libelle = $categorie->catname;
- if ( $catidSelected != $categorie->id )
- $uneCategorie->lien = 'index.php?option=com_annonces&view=annonces&catid='.$categorie->id;
- else
- $uneCategorie->lien = 'index.php?option=com_annonces&view=annonces&catid='.$categorie->id;
- $uneCategorie->nbAnnonces = $categorie->nb;
- $total+=$categorie->nb;
- $listeLiens[] = $uneCategorie;
- }
- $tteCategorie->nbAnnonces = $total;
- return $listeLiens;
- }
- }
- ?>
|
et voici le code du view.html.php
Code :
- <?php
- /**
- * @version 1.0 simple ads - petites annonces $
- * @package simple_ads_-_petites_annonces
- * @copyright Copyright © 2010 - All rights reserved.
- * @license GNU/GPL
- * @author Anthony JULOU
- * @author mail ajulou@yahoo.fr
- *
- *
- **/
- /* Hagen Graf - cocoate.com - Nov. 2007 */
- jimport( 'joomla.application.component.view');
- /**
- * HTML View class for the auto Component
- */
- class AnnoncesViewAnnonces extends JView
- {
- function display($tpl = null)
- {
- global $mainframe;
- $document = & JFactory::getDocument();
- $user =& JFactory::getUser();
- $menu = & JSite::getMenu();
- $item = $menu->getActive();
- $model = &$this->getModel();
- $uri = & JFactory::getURI();
- $parametrage = Util::parametrage();
- $catid = JRequest::getInt('catid', 0);
- $lists = $this->_buildSortLists($parametrage);
- $annonces = $model->getListeAnnonces( array( 'categorie' => $catid ), $parametrage );
- $showColumns = $model->getShowColumns( $annonces );
- $total = $model->getTotal( array( 'categorie' => $catid ), $parametrage );
- $listeCategories = $model->getListCategorieLiens( $catid );
- $limitstart = JRequest::getInt('limitstart');
- $limit = $mainframe->getUserStateFromRequest('com_annonces.limit', 'limit', $parametrage->nbpage, 'int');
-
- $document->addStyleSheet($this->baseurl.'/components/com_annonces/assets/annonces.css');
- // Create the pagination object
- jimport('joomla.html.pagination');
- $pageNav = new JPagination($total, $limitstart, $limit);
-
- // fil d'ariane
- $pathway = $mainframe->getPathWay();
- if ( isset( $item ) == false )
- $pathway->addItem( JText::_("ADS" ), JRoute::_('index.php?view=annonces&view=annonces') );
- $k = 0;
- for($i = 0; $i < count( $annonces ); $i++)
- {
- $annonce =& $annonces[$i];
- //$contact->link = JRoute::_('index.php?option=com_contact&view=contact&id='.$contact->slug.'&catid='.$contact->catslug, false);
- $annonce->odd = $k;
- $annonce->count = $i;
- $userVendeur = JFactory::getUser($annonce->vendeurId);
- $annonce->vendeur = $userVendeur->name;
- $annonce->vignette_url= Image::vignetteExists( $annonce->id, 1 );
- $k = 1 - $k;
- }
- if ($lists['filter']) {
- $uri->setVar('filter', $lists['filter']);
- } else {
- $uri->delVar('filter');
- }
- $this->assign('lists', $lists);
- $this->assignRef('annonces' , $annonces);
- $this->assignRef('user' , $user);
- $this->assignRef('parametrage', $parametrage);
- $this->assignRef('listeCategories', $listeCategories );
- $this->assignRef('showColumns', $showColumns );
- $this->assign('action', $uri->toString());
- $this->assignRef('pageNav', $pageNav);
- $this->assignRef('item', $item);
- parent::display($tpl);
- }
- function _buildSortLists($parametrage)
- {
- // Table ordering values
- $filter_order = JRequest::getCmd('filter_order', 'a.propriete1');
- $filter_order_Dir = JRequest::getCmd('filter_order_Dir', 'DESC');
- $filter = JRequest::getString('filter');
- $filter_type = JRequest::getString('filter_type');
- $sortselects = array();
- $sortselects[] = JHTML::_('select.option', 'type', 'Type' );
- $sortselect = JHTML::_('select.genericlist', $sortselects, 'filter_type', 'size="1" class="inputbox"', 'value', 'text', $filter_type );
- $lists['order_Dir'] = $filter_order_Dir;
- $lists['order'] = $filter_order;
- $lists['filter'] = $filter;
- $lists['filter_type'] = $sortselect;
- return $lists;
- }
- }
- ?>
|
et enfin le code du tmpl :
Code :
- <?php
- /**
- * @version 1.0 simple ads - petites annonces $
- * @package simple_ads_-_petites_annonces
- * @copyright Copyright � 2010 - All rights reserved.
- * @license GNU/GPL
- * @author Anthony JULOU
- * @author mail ajulou@yahoo.fr
- *
- *
- **/
- /* Hagen Graf - cocoate.com - Nov. 2007 */
- defined('_JEXEC') or die('Restricted access');
- ?>
- <div class="componentheading"><?php echo JText::_( 'ADS' ); ?>
- </div>
- <div class="contentpane">
- <div style="margin-bottom:5px"><?php echo JText::_( 'INTRO_EXPLAIN' ); ?><br/>
- </div>
- <form action="<?php echo $this->action; ?>" method="post" id="adminForm">
- <?php if ( $this->parametrage->searchActive == true ) : ?>
- <div id="recherche_ads">
- <label for="filter"><?php echo JText::_('SEARCH') ?>: </label>
- <input type="text" name="filter" id="filter" value="<?php echo $this->lists['filter'];?>" class="text_area" onchange="document.getElementById('adminForm').submit();" />
- <button onclick="document.getElementById('adminForm').submit();" class="button"><?php echo JText::_( 'OK' ); ?></button>
- </div>
- <?php endif; ?>
- <div id="categorie">
- <table width="100%" cellspacing="0" cellpadding="0" border="0" align="center" style="border: 1px dotted <?php echo $this->parametrage->headerBgColor?>">
- <tr>
- <td class="sectiontableentry2"><strong><?php echo JText::_('CATEGORY')?>: </strong>
- <?php
- foreach ( $this->listeCategories as $uneCategorie ) { ?>
- <a href="<?php echo $uneCategorie->lien ?>"><?php echo $uneCategorie->libelle ?>
- (<?php echo $uneCategorie->nbAnnonces ?> )</a>-
- <?php
- }
- ?>
- </td>
- </tr>
- </table>
- </div>
- <script type="text/javascript">
- function tableOrdering( order, dir, view )
- {
- var form = document.getElementById("adminForm" );
- form.filter_order.value = order;
- form.filter_order_Dir.value = dir;
- form.submit( view );
- }
- </script>
- <?php if ( count( $this->annonces) > 0 ) { ?>
- <table width="100%" cellspacing="0" cellpadding="0" border="0" align="center" style="border: 1px dotted <?php echo $this->parametrage->headerBgColor?>">
- <tr class="sortable">
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>"> </td>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Marque', 'a.constructeur', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <?php if ( $this->showColumns->showDimensions ) : ?>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Size', 'a.longueur', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <?php endif; ?>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Cm3', 'a.propriete1', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Modèle', 'a.objet', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <?php if ( $this->showColumns->showYear ) : ?>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Year', 'a.annee', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <?php endif; ?>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Kms', 'a.propriete2', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Price', 'a.prix', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>">
- <strong>
- <?php echo JHTML::_('grid.sort', 'Stock', 'a.propriete4', $this->lists['order_Dir'], $this->lists['order'] ); ?>
- </strong>
- </td>
- <td class="sectiontableheader" style="background:<?php echo $this->parametrage->headerBgColor?>"> </td>
- </tr>
- <?php foreach ($this->annonces as $row)
- {
- ?>
- <tr class="sectiontableentry<?php echo ($row->odd +1 )?>" >
- <td><?php echo '<a href="'. JRoute::_('index.php?option=com_annonces&view=annonce&id='.$row->id.'&Itemid='. JRequest::getVar('Itemid', 1, 'get', 'int')).'">' ?><img src="<?php echo $row->vignette_url?>" alt="" /></a></td>
- <td><?php echo '<a href="'. JRoute::_('index.php?option=com_annonces&view=annonce&id='.$row->id.'&Itemid='. JRequest::getVar('Itemid', 1, 'get', 'int')).'"><strong>'. $row->constructeur .'</strong></a>'; ?>
- </td>
- <?php if ( $this->showColumns->showDimensions ) : ?>
- <td align="center">
- <?php if ( $row->showDimensions ) :?>
- L: <?php echo number_format($row->longueur, 2, '.', ' ') . ' ' . $this->parametrage->metric ?><br />
- l: <?php echo number_format($row->largeur, 2, '.', ' ') . ' ' . $this->parametrage->metric ?>
- <?php endif;?>
- </td>
- <?php endif; ?>
- <td>
- <strong><?php echo str_replace(" ", utf8_encode("\xA0" ), number_format($row->propriete1, 0, '.', '')) ?></strong>
- </td
- ><td>
- <strong><?php echo ($row->objet) ?></strong>
- </td>
- <?php if ( $this->showColumns->showYear ) : ?>
- <td>
- <strong><?php echo ( $row->showYear ? $row->annee : '') ?></strong>
- </td>
- <?php endif; ?>
- <td>
- <strong><?php echo str_replace(" ", utf8_encode("\xA0" ), number_format($row->propriete2, 0, '.', '')) ?></strong>
- </td>
- <td>
- <strong><?php echo str_replace(" ", utf8_encode("\xA0" ), number_format($row->prix, 0, '.', ' ')) .' '. $this->parametrage->currency ?></strong>
- </td>
- <td>
- <strong><FONT color="green"><?php echo ($row->propriete4) ?></FONT></strong>
- </td>
- <td>
- <div class="actionUser">
- <?php echo Util::editLink( false, $row->vendeurId, JText::_('MODIFY'), 'edit', 'edit', $row->id, 'itemid'); ?>
- <?php echo Util::editLink( false, $row->vendeurId, JText::_('DELETE'), 'annonces', 'delete', $row->id, 'itemid'); ?>
- </div>
- <?php echo '<a href="'. JRoute::_('index.php?option=com_annonces&view=annonce&id='.$row->id.'&Itemid='. JRequest::getVar('Itemid', 1, 'get', 'int')).'" class="button">'. JText::_('DETAIL') .'</a>'; ?>
- </td>
- </tr>
- <?php } ?>
- </table>
- <div class="pageslinks" >
- <?php echo $this->pageNav->getPagesLinks(); ?>
- </div>
- <input type="hidden" name="option" value="com_annonces" />
- <input type="hidden" name="filter_order" value="<?php echo $this->lists['order']; ?>" />
- <input type="hidden" name="filter_order_Dir" value="" />
- <input type="hidden" name="view" value="annonces" />
- <input type="hidden" name="task" value="<?php echo $this->task; ?>" />
- <input type="hidden" name="id" value="<?php echo $this->categorie; ?>" />
- <input type="hidden" name="Itemid" value="<?php echo $this->item->id;?>" />
- </form>
- <?php } else { ?>
- <p><strong><?php echo JText::_('NO ADS') ?></strong></p>
- <?php } ?>
- <ul>
- <li><?php echo JText::_('EXPLAIN1')?></li>
- <?php if ( $this->parametrage->published_days != 0 ) : ?>
- <li><?php echo JText::sprintf('EXPLAIN2', $this->parametrage->published_days)?></li>
- <?php endif; ?>
- </ul>
- <?php if ($this->user->id != 0 && $this->parametrage->unableSubmitAdInList == true ) : ?>
- <div align="right" style="margin-bottom:10px">
- <form action="/index.php?option=com_annonces&view=edit&Itemid=<?php echo JRequest::getVar('Itemid', 1, 'get', 'int')?>" method="post">
- <input type="submit" class="button" value="<?php echo JText::_('DEPOT') ?>" />
- </form>
- </div>
- <?php endif; ?>
- </div>
|
En fait ça classe les colonnes quand on clique sur le titre de la colonne en ASC puis quand on reclique ça classe en DESC, je n'ai pas besoin de cette fonction et elle peut être supprimée.
Message édité par zenith le 17-06-2010 à 10:37:29
|