Fix: move sql in dao class

This commit is contained in:
Regis Houssin 2011-06-19 15:10:32 +00:00
parent a00d389ea0
commit 36223de560
2 changed files with 109 additions and 72 deletions

View File

@ -82,6 +82,8 @@ class ActionComm extends CommonObject
var $icalname; var $icalname;
var $icalcolor; var $icalcolor;
var $actions=array();
/** /**
* Constructor * Constructor
@ -243,7 +245,7 @@ class ActionComm extends CommonObject
$sql.= " a.priority, a.fulldayevent, a.location,"; $sql.= " a.priority, a.fulldayevent, a.location,";
$sql.= " c.id as type_id, c.code as type_code, c.libelle,"; $sql.= " c.id as type_id, c.code as type_code, c.libelle,";
$sql.= " s.nom as socname,"; $sql.= " s.nom as socname,";
$sql.= " u.firstname, u.name"; $sql.= " u.firstname, u.name as lastname";
$sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)"; $sql.= " FROM (".MAIN_DB_PREFIX."c_actioncomm as c, ".MAIN_DB_PREFIX."actioncomm as a)";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as u on u.rowid = a.fk_user_author";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on s.rowid = a.fk_soc";
@ -277,6 +279,8 @@ class ActionComm extends CommonObject
$this->percentage = $obj->percentage; $this->percentage = $obj->percentage;
$this->author->id = $obj->fk_user_author; $this->author->id = $obj->fk_user_author;
$this->author->firstname = $obj->firstname;
$this->author->lastname = $obj->lastname;
$this->usermod->id = $obj->fk_user_mod; $this->usermod->id = $obj->fk_user_mod;
$this->usertodo->id = $obj->fk_user_action; $this->usertodo->id = $obj->fk_user_action;
@ -385,6 +389,50 @@ class ActionComm extends CommonObject
} }
} }
/**
* Load all objects with filters
* @param socid Filter by thirdparty
* @param filter Other filter
*/
function getActions($socid=0, $fk_element=0, $elementtype='', $filter='')
{
global $conf, $langs;
$sql = "SELECT a.id";
$sql.= " FROM ".MAIN_DB_PREFIX."actioncomm as a";
$sql.= " WHERE a.entity = ".$conf->entity;
if ($socid) $sql.= " AND a.fk_soc = ".$socid;
if ($elementtype!='')
{
if ($elementtype == 'project') $sql.= ' AND a.fk_project = '.$fk_element;
else $sql.= " AND a.fk_element = ".$fk_element." AND a.elementtype = '".$elementtype."'";
}
if ($filter) $sql.= $filter;
dol_syslog("ActionComm::fetchAll sql=".$sql);
$resql=$this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
if ($num)
{
for($i=0;$i<$num;$i++)
{
$obj = $this->db->fetch_object($resql);
$this->fetch($obj->id);
$this->actions[$i] = $this;
}
}
$this->db->free($resql);
return 1;
}
else
{
$this->error=$this->db->lasterror();
return -1;
}
}
/** /**
* Load indicators for dashboard (this->nbtodo and this->nbtodolate) * Load indicators for dashboard (this->nbtodo and this->nbtodolate)

View File

@ -104,19 +104,12 @@ class FormActions
global $langs,$conf,$user; global $langs,$conf,$user;
global $bc; global $bc;
$sql = 'SELECT a.id, a.datep as da, a.label, a.note,'; require_once(DOL_DOCUMENT_ROOT."/comm/action/class/actioncomm.class.php");
$sql.= ' u.login';
$sql.= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a, '.MAIN_DB_PREFIX.'user as u';
$sql.= ' WHERE a.fk_user_author = u.rowid';
if ($socid) $sql .= ' AND a.fk_soc = '.$socid;
if ($typeelement == 'project') $sql.= ' AND a.fk_project = '.$object->id;
else $sql.= " AND a.fk_element = ".$object->id." AND a.elementtype = '".$typeelement."'";
dol_syslog("FormActions::showactions sql=".$sql); $actioncomm = new ActionComm($this->db);
$resql = $this->db->query($sql); $actioncomm->getActions($socid, $object->id, $typeelement);
if ($resql)
{ $num = count($actioncomm->actions);
$num = $this->db->num_rows($resql);
if ($num) if ($num)
{ {
if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill'); if ($typeelement == 'invoice') $title=$langs->trans('ActionsOnBill');
@ -129,34 +122,30 @@ class FormActions
print_titre($title); print_titre($title);
$i = 0; $total = 0; $var=true; $total = 0; $var=true;
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr '.$bc[$var].'><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Date').'</td><td>'.$langs->trans('Action').'</td><td>'.$langs->trans('By').'</td></tr>'; print '<tr '.$bc[$var].'><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Date').'</td><td>'.$langs->trans('Action').'</td><td>'.$langs->trans('By').'</td></tr>';
print "\n"; print "\n";
while ($i < $num) foreach($actioncomm->actions as $action)
{ {
$objp = $this->db->fetch_object($resql);
$var=!$var; $var=!$var;
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$objp->id.'">'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.'</a></td>'; print '<td>'.$action->getNomUrl(1).'</td>';
print '<td>'.dol_print_date($this->db->jdate($objp->da),'day').'</td>'; print '<td>'.dol_print_date($action->datep,'day').'</td>';
print '<td title="'.dol_escape_htmltag($objp->label).'">'.dol_trunc($objp->label,32).'</td>'; print '<td title="'.dol_escape_htmltag($action->label).'">'.dol_trunc($action->label,32).'</td>';
print '<td>'.$objp->login.'</td>'; $userstatic = new User($this->db);
$userstatic->id = $action->author->id;
$userstatic->prenom = $action->author->firstname;
$userstatic->nom = $action->author->lastname;
print '<td>'.$userstatic->getNomUrl(1).'</td>';
print '</tr>'; print '</tr>';
$i++;
} }
print '</table>'; print '</table>';
} }
return $num; return $num;
} }
else
{
dol_print_error($this->db);
return -1;
}
}
/** /**