bonjour
je vous livre ici un model d'item
je cherche à récupérer dans une fonction le id de cet item pour l'intégrer dans une requête sql
comment appeler le id dans ma fonction, voir à la fin du fichier function batid
merci LJ
je vous livre ici un model d'item
je cherche à récupérer dans une fonction le id de cet item pour l'intégrer dans une requête sql
comment appeler le id dans ma fonction, voir à la fin du fichier function batid
merci LJ
Code PHP:
<?php
// Check to ensure this file is included in Joomla!
defined('_JEXEC') or die( 'Restricted access' );
jimport('joomla.application.component.model');
require_once(JPATH_ADMIN_BATENERGIE .DS.'classes'.DS.'jmodel.item.php');
/**
* Batenergie Component Batenergieitem Model
*
* @package Joomla
* @subpackage Batenergie
*
*/
class BatenergieModelBatenergieitem extends BatenergieModelItem
{
var $_name_plur = 'batenergie';
var $params;
/**
* Constructor
*
*/
function __construct()
{
parent::__construct();
$this->_modes = array_merge($this->_modes, array(''));
}
/**
* Method to initialise the batenergieitem data
*
* @access private
* @return boolean True on success
*/
function _initData()
{
if (empty($this->_data))
{
//Default values shown in the form for new item creation
$data = new stdClass();
$data->id = 0;
$data->attribs = null;
$data->author = null;
$data->name = null;
$data->adresse = null;
$data->commune = null;
$data->image = null;
$data->date = null;
$data->publish = null;
$data->equipement = JRequest::getVar('filter_equipement', $this->getState('filter.equipement'));
$data->type = null;
$data->year = null;
$data->surface = null;
$data->volume = null;
$data->puissance = null;
$data->puissancelec = null;
$data->message = null;
$data->travaux = null;
$data->description = null;
$data->synthese = null;
$this->_data = $data;
return (boolean) $this->_data;
}
return true;
}
/**
* Method to auto-populate the model state.
*
* Note. Calling getState in this method will result in recursion.
*
* @return void
* @since 1.6
*/
protected function populateState($ordering = null, $direction = null)
{
// Initialise variables.
$app = JFactory::getApplication();
$session = JFactory::getSession();
if ($filter_equipement = $app->getUserState($this->context.'.filter.equipement'))
$this->setState('filter.equipement', $filter_equipement, null, 'varchar');
if ($search_search = $app->getUserState($this->context.'.search.search'))
$this->setState('search.search', $search_search, null, 'varchar');
parent::populateState();
}
/**
* Method to build a the query string for the Batenergieitem
*
* @access public
* @return integer
*/
function _buildQuery()
{
if (isset($this->_active['predefined']))
switch($this->_active['predefined'])
{
case 'batiment': return $this->_buildQuery_batiment(); break;
}
$query = 'SELECT a.*'
. $this->_buildQuerySelect()
. ' FROM `#__batenergie` AS a'
. $this->_buildQueryJoin()
. $this->_buildQueryWhere()
. '';
return $query;
}
function _buildQuery_batiment()
{
$query = 'SELECT a.*'
. ' , _author_.username AS `_author_username`'
. ' , _author_.email AS `_author_email`'
. ' , _author_.usertype AS `_author_usertype`'
. $this->_buildQuerySelect()
. ' FROM `#__batenergie` AS a'
. ' LEFT JOIN `#__users` AS _author_ ON _author_.id = a.author'
. $this->_buildQueryJoin()
. $this->_buildQueryWhere()
. '';
return $query;
}
function _buildQueryWhere($where = array())
{
$app = JFactory::getApplication();
$acl = BatenergieHelper::getAcl();
$where[] = 'a.id = '.(int) $this->_id;
return parent::_buildQueryWhere($where);
}
/**
* Method to update batenergieitem in mass
*
* @access public
* @return boolean True on success
*/
function update($cids, $data)
{
foreach($cids as $cid)
{
if ($cid == 0)
continue;
$data['id'] = $cid;
if (!$this->save($data))
return false;
}
return true;
}
/**
* Method to save the batenergieitem
*
* @access public
* @return boolean True on success
*/
function save($data)
{
$row = $this->getTable();
//Convert data from a stdClass
if (get_class($data) == 'stdClass')
$data = JArrayHelper::fromObject($data);
//Current id if unspecified
if ($data['id'] != null)
$id = $data['id'];
else if (($this->_id != null) && ($this->_id > 0))
$id = $this->_id;
//Load the current object, in order to process an update
if (isset($id))
$row->load($id);
//Some security checks
$acl = BatenergieHelper::getAcl();
//Secure the published tag if not allowed to change
if (isset($data['publish']) && !$acl->get('core.edit.state'))
unset($data['publish']);
//Secure the author key if not allowed to change
if (isset($data['author']) && !$acl->get('core.edit'))
unset($data['author']);
// Bind the form fields to the batenergie table
$ignore = array();
if (!$row->bind($data, $ignore)) {
JError::raiseWarning(1000, $this->_db->getErrorMsg());
return false;
}
// Make sure the batenergie table is valid
if (!$row->check()) {
JError::raiseWarning(1000, $this->_db->getErrorMsg());
return false;
}
// Store the batenergie table to the database
if (!$row->store()) {
JError::raiseWarning(1000, $this->_db->getErrorMsg());
return false;
}
$this->_id = $row->id;
$this->_data = $row;
return true;
}
/**
* Method to delete a batenergieitem
*
* @access public
* @return boolean True on success
*/
function delete($cid = array())
{
$result = false;
if (count( $cid ))
{
JArrayHelper::toInteger($cid);
$cids = implode( ',', $cid );
$query = 'DELETE FROM `#__batenergie`'
. ' WHERE id IN ( '.$cids.' )';
$this->_db->setQuery( $query );
if(!$this->_db->query()) {
JError::raiseWarning(1000, $this->_db->getErrorMsg());
return false;
}
}
return true;
}
/**
* Method to (un)publish a batenergieitem
*
* @access public
* @return boolean True on success
*/
function publish($cid = array(), $publish = 1)
{
$user = JFactory::getUser();
if (count( $cid ))
{
JArrayHelper::toInteger($cid);
$cids = implode( ',', $cid );
$query = 'UPDATE #__batenergie'
. ' SET `publish` = '.(int) $publish
. ' WHERE id IN ( '.$cids.' )';
$this->_db->setQuery( $query );
if (!$this->_db->query()) {
JError::raiseWarning(1000, $this->_db->getErrorMsg());
return false;
}
}
return true;
}
/**
* Method to Convert the parameter fields into objects.
*
* @access public
* @return void
*/
protected function populateParams()
{
parent::populateParams();
if (!isset($this->_data))
return;
$item = $this->_data;
$acl = BatenergieHelper::getAcl();
$isAuthor = ($item->author == JFactory::getUser()->id);
if ($acl->get('core.edit.state')
|| (bool)$item->publish
|| ($acl->get('core.view.own') && $isAuthor))
$item->params->set('access-view', true);
if ($acl->get('core.edit')
|| ($acl->get('core.edit.own') && $isAuthor))
$item->params->set('access-edit', true);
if ($acl->get('core.delete')
|| ($acl->get('core.delete.own') && $isAuthor))
$item->params->set('access-delete', true);
}
function batid()
{
$batid = $this->_id;
// je souhaite utiliser ce batid dans la requête sql qui suit, mais cette écriture ne marche pas
$database =& JFactory::getDBO() ;
$database->setQuery( "SELECT SUM(dpe10)
FROM #__bate
WHERE id='$batid'
" );
if (!$database->query()) {
echo $database->stderr();
return false;
}
Commentaire