Développement

Comment développer un composant, un module , un plugin avec Joomla.

Composant ImagesZoom

Note utilisateur:  / 1
<?php
/**
 * This file is part of Budgef - Joomla! extension for family budget
 * 
 * @copyright   Copyright (C) 2012 phptoolbox.net. All rights reserved.
 * @license     GNU/GPL, see LICENSE.php
 * Budgef is free software. This version may have been modified pursuant to the
 * GNU General Public License, and as distributed it includes or is derivative
 * of works licensed under the GNU General Public License or other free or open
 * source software licenses.
 * 
 */
// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );
jimport('joomla.application.component.model');
/**
 * gallery gallery Model
 *
 * @package    Joomla.Tutorials
 * @subpackage Components
 */
class imageszoomModelGallery extends JModel
{
    var $_error = '';
    var $_id;
    var $_lastId = 0;
    var $row;
  /**
   * Constructor that retrieves the ID from the request
   *
   * @access  public
   * @return  void
   */
  function __construct()
  {
    parent::__construct();
    $array = JRequest::getVar('cid',  0, '', 'array');
    $this->setId((int)$array[0]);
  }
    function getId()
    {
        //First loooking for new insertion
        if ($this->_lastId > 0) {
            return $this->_lastId ;
        }
        
        $cid = $this->getCid();
        
        if (empty($cid[0])) {
            //try to see id
            return JRequest::getInt('id', 0);
        }
        
        return $cid[0] ;
    }
    
    function getCid()
    {
        $cid = JRequest::getVar( 'cid', array(0), '', 'array' );
        JArrayHelper::toInteger( $cid, array(0) );
        return $cid ;
    }
  /**
   * Method to set the gallery identifier
   *
   * @access  public
   * @param  int gallery identifier
   * @return  void
   */
  function setId($id)
  {
    // Set id and wipe data
    $this->_id    = $id;
    $this->_data  = null;
  }
    function setTableName( $tableName )
    {
        $tables = array(
                'gallery',
            );
            
        if( !in_array( $tableName, $tables ) ){
                
                JError::raiseWarning( 200, 'table name : ' . $tableName . ' doesn\'t exists' );
                return false;
        }
        
        $this->_currentTableName =  $tableName ;
        
        
        return $this->_currentTableName ;
    }
function &getRow()
{
   $table =& $this->getTable();
   $table->load( $this->getId() );
   return $table;
}
function checkout()
{
  $code = E_ERROR;
  $fichier = 'gallery.php';
  try {
       $row = & $this->getRow();
       // retrieve item identifier from getId()
       $itemId = $this->getId();
       // the user to test checkout with, could be any other user you want
       $user = JFactory::getUser();
 
       // load the item's data so we'll know with what item were dealing with
       if (!$row->load($itemId)) {
          throw new imageszoomException($row->getError(),0,$code, $fichier, 125);
        }
       // check out the item
       if ($row->checkout($user->id)) {
          JFactory::getApplication()->enqueueMessage( JText::_( 'CHECKOUT' ).' (Id : '.$itemId.')', 'Message' );
       } else {
          throw new imageszoomException($row->getError(),0,$code, $fichier, 130);
   }
   } catch (imageszoomException $e){
         $resul = $e->__toString();
         JFactory::getApplication()->enqueueMessage( JText::_( $resul ), 'error' );
         return false;
   }
   return true ;
}
function checkin()
{
  $code = E_ERROR;
  $fichier = 'gallery.php';
  try {
      // retrieve item identifier from getId()
      $itemId = $this->getId();
      // the user to test checkout with, could be any other user you want
      $user = JFactory::getUser();
      $row = & $this->getRow();
      // load the item's data so we'll know with what item were dealing with
      if (!$row->load($itemId)) {
         throw new imageszoomException($row->getError(),0,$code, $fichier, 148);
      }
 
      // check in the item
      if (!$row->checkin()) {
         throw new imageszoomException($row->getError(),0,$code, $fichier, 153);
      }
   } catch (imageszoomException $e){
         $resul = $e->__toString();
         JFactory::getApplication()->enqueueMessage( JText::_( $resul ), 'error' );
         return false;
   }
    return true;
}
/**
* Cette fonction exécute une requète Select sur la table imageszoom_gallery.
* critères de sélection :<br>
*   - l'annee de reference ($year_reference)
*   - le code_tresorerie ($code_tresorerie)<br>
* en retour : le flux de données sélectionné ($rows)
*/
function getItems($all=false)
{
  $code = E_ERROR;
  $fichier = 'gallery.php';
  try {
  $result = array();
  $where = '';
  $mainframe = &JFactory::getApplication();
  $context = 'com_imageszoom';
  $default_limit = $mainframe->getCfg('list_limit');
  $limit          = $mainframe->getUserStateFromRequest( $context.'limit', 'limit',  $default_limit, 'int' );
  $limitstart     = $mainframe->getUserStateFromRequest( $context.'offset', 'limitstart', 0, 'int' );
  $year_gallery = $mainframe->getUserStateFromRequest( $context.'year_gallery', 'year_gallery', 0, 'int' );
  $code_gallery = $mainframe->getUserStateFromRequest( $context.'code_gallery', 'code_gallery', 0, 'int' );
###########################################################
$code_gallery = 0;
###########################################################
  $published = $mainframe->getUserStateFromRequest( $context.'published', 'published', 0, 'int' );
  $order = 'numgallery';
  $order_dir = 'asc';
   $select = 'SELECT id, numgallery, title, description, date_insert,number_images,published,checked_out' . PHP_EOL
   . 'FROM #__imageszoom_gallery ' . PHP_EOL
   . 'WHERE 1 '. PHP_EOL;
//   $where .= ' AND year_gallery = '. $year_gallery ;
   if ( $published ){
       $where .= ' AND published > 0';
   }
   $sql = $select . $where . ' ORDER BY ' . $order . ' ' . strtoupper( $order_dir ) ;
   $rows = $this->_getList( $sql , $limitstart, $limit );
   if ( $this->_db->getErrorNum() ) {
        throw new imageszoomException($this->_db->getErrorMsg(),$this->_db->getErrorNum(),$code, $fichier, 124);
     }
   $rows = $this->_getList( $sql , $limitstart, $limit );
   $result['total'] = $this->_getListCount( $sql );
   $total = $result['total'];
###################################################################
//echo "<br>88 gallery : $sql # total : $total<br><br>";
//exit();
###################################################################
   if( $all === true ){
       $result['limitstart'] = 0 ;
       $result['limit'] = 0 ;
       $result['rows'] = $this->_getList( $sql) ;
   } else {
       $result['limitstart'] = $limitstart ;
       $result['limit'] = $limit ;
       $result['rows'] = $this->_getList( $sql , $limitstart, $limit );
   }
   } catch (imageszoomException $e){
         $resul = $e->__toString();
         JFactory::getApplication()->enqueueMessage( JText::_( $resul ), 'error' );
         return false;
   }
   return $result;
}
function getItem()
{
   $result = array();
   $row =& $this->getRow();
   if($row->id == 0 ) {
      $row->published = 1;
      $row->dispo ='';
   }
   $rootURL = JURI::root();
   $result['row'] = $row;
   return $result;
}
/**
   * Method to store a record
   *
   * @access  public
   * @return  boolean  True on success
   */
  function store($data)
  {
    $session = JFactory::getSession();
    $code = E_ERROR;
    $fichier = 'gallery.php';
    try {
      if (empty( $data ))
      {
        $data  = JRequest::get('post');
      }
    $row =& $this->getTable('gallery');
    // Bind the form fields to the mvtcompte table
    if (!$row->bind($data)) {
        throw new imageszoomException($this->_db->getErrorMsg(),0,$code, $fichier, 292);
    }
    // Make sure the mvtcompte record is valid
    if ($session->get('task_ante')!='add'){
        if (!$row->check()) {
            throw new imageszoomException($this->_db->getErrorMsg(),0,$code, $fichier, 253);
        }
    }
    // Store the web link table to the database
    if (!$row->store()) {
        throw new imageszoomException($this->_db->getErrorMsg(),0,$code, $fichier, 304);
    }
    if ($session->get('task_ante')!='add'){
         if (!$this->checkin()) {
               return false;
          }
    }
   } catch (imageszoomException $e){
          $resul = $e->__toString();
          JFactory::getApplication()->enqueueMessage( JText::_( $resul ), 'error' );
         return false;
   }
    return true;
  }
  function publish( $bool )
  {
    $code = E_ERROR;
    $fichier = 'gallery.php';
      try {
          $cid = $this->getCid();
          $user   = & JFactory::getUser();
          $uid    = $user->get('id');
          $table =& $this->getTable();
        
          if ( !$table->publish( $cid, (int)$bool, $uid) ){
            throw new imageszoomException($table->getError(),0,$code, $fichier, 332);
          }
      } catch (imageszoomException $e){
          $resul = $e->__toString();
          JFactory::getApplication()->enqueueMessage( JText::_( $resul ), 'error' );
         return false;
     }
     return true;
  }
  /**
   * Method to delete record(s)
   *
   * @access  public
   * @return  boolean  True on success
   */
  function remove()
  {
      $code = E_ERROR;
      $fichier = 'gallery.php';
      try{
        $cid = $this->getCid() ;
        $cids = implode( ',', $cid );
        //only one request
        $this->_db->setQuery( 'DELETE FROM #__imageszoom_gallery WHERE id IN (' . $cids . ')' );
        
        if ( !$this->_db->query() ) {
            throw new imageszoomException($this->_db->getErrorMsg(),0,$code, $fichier, 357);
        }
   } catch (imageszoomException $e){
          $resul = $e->__toString();
          JFactory::getApplication()->enqueueMessage( JText::_( $resul ), 'error' );
         return false;
   }
        return true;
 }
  function delete()
  {
    $cids = JRequest::getVar( 'cid', array(0), 'post', 'array' );
    $row =& $this->getTable();
    if (count( $cids ))
    {
      foreach($cids as $cid)
      {
        if (!$row->delete( $cid ))
        {
          $this->setError( $row->getErrorMsg() );
          return false;
        }
      }
    }
    return true;
  }
}

 

Vous êtes ici : Accueil Développement