Fix subrequest inside a loop

This commit is contained in:
Laurent Destailleur 2023-02-10 16:14:32 +01:00
parent 457e6883e2
commit 8299501800
2 changed files with 36 additions and 20 deletions

View File

@ -1354,12 +1354,13 @@ abstract class CommonObject
*
* @param int $statusoflink Status of links to get (-1=all). Not used.
* @param string $source Source of contact: 'external' or 'thirdparty' (llx_socpeople) or 'internal' (llx_user)
* @param int $list 0:Return array contains all properties, 1:Return array contains just id
* @param int $list 0:Returned array contains all properties, 1:Return array contains just id
* @param string $code Filter on this code of contact type ('SHIPPING', 'BILLING', ...)
* @param int $status Status of user or company
* @param array $arrayoftcids Array with ID of type of contacts. If we provide this, we can make a ec.fk_c_type_contact in ($arrayoftcids) to avoid link on tc table. TODO Not implemented.
* @return array|int Array of contacts, -1 if error
*/
public function liste_contact($statusoflink = -1, $source = 'external', $list = 0, $code = '', $status = -1)
public function liste_contact($statusoflink = -1, $source = 'external', $list = 0, $code = '', $status = -1, $typecontectids = array())
{
// phpcs:enable
global $langs;
@ -1401,7 +1402,7 @@ abstract class CommonObject
$sql .= " AND t.statut = ".((int) $status); // t is llx_socpeople
}
}
$sql .= " AND tc.active=1";
$sql .= " AND tc.active = 1";
if ($statusoflink >= 0) {
$sql .= " AND ec.statut = ".((int) $statusoflink);
}

View File

@ -1331,6 +1331,7 @@ while ($i < $imaxinloop) {
$userAccess = $object->restrictedProjectArea($user); // why this ?
if ($userAccess >= 0) {
// Thirdparty
$companystatic->id = $obj->socid;
$companystatic->name = $obj->name;
$companystatic->name_alias = $obj->alias;
@ -1343,6 +1344,21 @@ while ($i < $imaxinloop) {
$companystatic->town = $obj->town;
$companystatic->country_code = $obj->country_code;
// Author
$userstatic->id = $obj->fk_user_creat;
$userstatic->login = $obj->login;
$userstatic->lastname = $obj->lastname;
$userstatic->firstname = $obj->firstname;
$userstatic->email = $obj->user_email;
$userstatic->statut = $obj->user_statut;
$userstatic->entity = $obj->entity;
$userstatic->photo = $obj->photo;
$userstatic->office_phone = $obj->office_phone;
$userstatic->office_fax = $obj->office_fax;
$userstatic->user_mobile = $obj->user_mobile;
$userstatic->job = $obj->job;
$userstatic->gender = $obj->gender;
print '<tr class="oddeven">';
// Action column
@ -1496,12 +1512,25 @@ while ($i < $imaxinloop) {
if (!empty($numcontact)) {
foreach ($tab as $contactproject) {
//var_dump($contacttask);
$cid = $contactproject['id'];
if ($source == 'internal') {
$c = new User($db);
if (empty($conf->cache['user'][$cid])) {
$c = new User($db);
$c->fetch($cid);
$conf->cache['user'][$cid] = $c;
} else {
$c = $conf->cache['user'][$cid];
}
} else {
$c = new Contact($db);
if (empty($conf->cache['contact'][$cid])) {
$c = new Contact($db);
$c->fetch($cid);
$conf->cache['contact'][$cid] = $c;
} else {
$c = $conf->cache['contact'][$cid];
}
}
$c->fetch($contactproject['id']);
if (!empty($c->photo)) {
if (get_class($c) == 'User') {
print $c->getNomUrl(-2, '', 0, 0, 24, 1, '', ($ifisrt ? '' : 'notfirst'));
@ -1703,20 +1732,6 @@ while ($i < $imaxinloop) {
$totalarray['pos'][$totalarray['nbfield']] = 'p.price_booth';
}
}
// Author
$userstatic->id = $obj->fk_user_creat;
$userstatic->login = $obj->login;
$userstatic->lastname = $obj->lastname;
$userstatic->firstname = $obj->firstname;
$userstatic->email = $obj->user_email;
$userstatic->statut = $obj->user_statut;
$userstatic->entity = $obj->entity;
$userstatic->photo = $obj->photo;
$userstatic->office_phone = $obj->office_phone;
$userstatic->office_fax = $obj->office_fax;
$userstatic->user_mobile = $obj->user_mobile;
$userstatic->job = $obj->job;
$userstatic->gender = $obj->gender;
if (!empty($arrayfields['u.login']['checked'])) {
print '<td class="center tdoverflowmax150">';