Skip to content

Commit

Permalink
Fix filter on contact
Browse files Browse the repository at this point in the history
  • Loading branch information
eldy committed Dec 17, 2024
1 parent 8813d79 commit 3fa0b65
Showing 1 changed file with 31 additions and 5 deletions.
36 changes: 31 additions & 5 deletions htdocs/societe/class/api_contacts.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,6 @@ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100,

$sql = "SELECT t.rowid";
$sql .= " FROM ".MAIN_DB_PREFIX."socpeople as t";
if ($category > 0) {
$sql .= ", ".MAIN_DB_PREFIX."categorie_contact as c";
}
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople_extrafields as te ON te.fk_object = t.rowid";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON t.fk_soc = s.rowid";
$sql .= ' WHERE t.entity IN ('.getEntity('contact').')';
Expand All @@ -213,8 +210,37 @@ public function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100,
}
// Select contacts of given category
if ($category > 0) {
$sql .= " AND c.fk_categorie = ".((int) $category);
$sql .= " AND c.fk_socpeople = t.rowid ";
// Search Contact Categories
$searchCategoryContactList = $category ? array($category) : array();
$searchCategoryContactOperator = 0;
// Search for tag/category ($searchCategoryContactList is an array of ID)
if (!empty($searchCategoryContactList)) {
$searchCategoryContactSqlList = array();
$listofcategoryid = '';
foreach ($searchCategoryContactList as $searchCategoryContact) {
if (intval($searchCategoryContact) == -2) {
$searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE t.rowid = ck.fk_socpeople)";
} elseif (intval($searchCategoryContact) > 0) {
if ($searchCategoryContactOperator == 0) {

Check failure on line 224 in htdocs/societe/class/api_contacts.class.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Loose comparison using == between 0 and 0 will always evaluate to true.
$searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE t.rowid = ck.fk_socpeople AND ck.fk_categorie = ".((int) $searchCategoryContact).")";
} else {
$listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact);

Check failure on line 227 in htdocs/societe/class/api_contacts.class.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Ternary operator condition is always false.
}
}
}
if ($listofcategoryid) {

Check failure on line 231 in htdocs/societe/class/api_contacts.class.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

If condition is always false.
$searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE t.rowid = ck.fk_socpeople AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
}
if ($searchCategoryContactOperator == 1) {

Check failure on line 234 in htdocs/societe/class/api_contacts.class.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Loose comparison using == between 0 and 1 will always evaluate to false.
if (!empty($searchCategoryContactSqlList)) {
$sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")";
}
} else {
if (!empty($searchCategoryContactSqlList)) {
$sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")";
}
}
}
}

// Add sql filters
Expand Down

0 comments on commit 3fa0b65

Please sign in to comment.