Re : Afficher progression traitement
Pour compléter j'ai mis cela dans une librairie qui contient ce helper
La table gf_status
et pour le traitement qui l'utilise
Pour compléter j'ai mis cela dans une librairie qui contient ce helper
Code PHP:
class GFHelper
{
public static function ResetStatus()
{
$db = JFactory::getDbo();
$now = new JDate();
$datecour = $now->toSQL();
$query = $db->getQuery(true);
$query->delete($db->quoteName('#__gf_status'));
$query->where($db->quoteName('time').'<'.$db->quote($datecour));
$db->setQuery($query);
$db->execute();
}
public static function SetStatusValue($value,$maxval)
{
$db = JFactory::getDbo();
$now = new JDate();
$datecour = $now->toSQL();
$expire=new JDate( date("Y-m-d H:i", strtotime($datecour)) . " +1 hour");
$expireSQL=$expire->toSQL();
$datecour = $now->toSQL();
$session = JFactory::getSession();
$session_id= $session->getId();
$query = $db->getQuery(true);
$query->select('session_id');
$query->from($db->quoteName('#__gf_status'));
$query->where('session_id='.$db->quote($session_id));
if (!$maxval) $percent=0;
else $percent=($value+1)*100/$maxval;
$db->setQuery($query);
$sessionobject=$db->loadObject();
if (!$sessionobject) {
$query = $db->getQuery(true);
$query->insert($db->quoteName('#__gf_status'))
->columns(array($db->quoteName('session_id'), $db->quoteName('time'), $db->quoteName('value')))
->values($db->quote($session_id) . ', ' . $db->quote($expireSQL) . ',' . $db->quote($percent));
// Set the query and execute the insert.
$db->setQuery($query);
$db->execute();
}
else {
$query = $db->getQuery(true);
$query->update($db->quoteName('#__gf_status'))
->set($db->quoteName('time').' = '. $db->quote($expireSQL) )
->set($db->quoteName('value').' = '. $db->quote($percent))
->where($db->quoteName('session_id').' = '.$db->quote($session_id));
// Set the query and execute the insert.
$db->setQuery($query);
$db->execute();
}
}
public static function GetStatusValue()
{
$db = JFactory::getDbo();
$session = JFactory::getSession();
$session_id= $session->getId();
$query = $db->getQuery(true);
$query->select('value');
$query->from($db->quoteName('#__gf_status'));
$query->where('session_id='.$db->quote($session_id));
$db->setQuery($query);
$sessionobject=$db->loadObject();
if ($sessionobject)
return $sessionobject->value;
else return 0;
}
et pour le traitement qui l'utilise
Code PHP:
en début
GFHelper::ResetStatus(); // pour épurer la base de données
$nbcount = sizeof($ids);
foreach ($ids as $indice=>$id)
{
GFHelper::SetStatusValue($indice,$nbcount);
.....
}
GFHelper::SetStatusValue(0,0);// a la fin du traitement
Commentaire