Skip to content

Commit

Permalink
more work
Browse files Browse the repository at this point in the history
  • Loading branch information
cconard96 committed Jun 13, 2023
1 parent 561150a commit 5b50583
Show file tree
Hide file tree
Showing 8 changed files with 370 additions and 213 deletions.
14 changes: 12 additions & 2 deletions src/CommonITILObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -10494,10 +10494,20 @@ protected function processRules(int $condition, array &$input, int $entid = -1):
}
}

public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta = false): ?array
public static function getSQLDefaultSelectCriteria(string $itemtype): ?array
{
return null;
}

public static function getSQLSelectCriteria(string $itemtype, SearchOption $opt, bool $meta = false, string $meta_type = ''): ?array
{
return null;
}

public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta, callable $fn_append_with_search): ?array
{
// Only handle core ITIL objects here
if (!in_array($opt['table'], [Ticket::getTable(), Change::getTable(), Problem::getTable()], true)) {
if (!in_array($itemtype, [Ticket::class, Change::class, Problem::class], true)) {
return null;
}

Expand Down
25 changes: 24 additions & 1 deletion src/Entity.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,14 @@
use Glpi\DBAL\QueryFunction;
use Glpi\Event;
use Glpi\Plugin\Hooks;
use Glpi\Search\AdvancedSearchInterface;
use Glpi\Search\SearchEngine;
use Glpi\Search\SearchOption;

/**
* Entity class
*/
class Entity extends CommonTreeDropdown
class Entity extends CommonTreeDropdown implements AdvancedSearchInterface
{
use Glpi\Features\Clonable;
use MapGeolocation;
Expand Down Expand Up @@ -4409,4 +4412,24 @@ public static function badgeCompletenameLinkById(int $entity_id): ?string
}
return null;
}

public static function getSQLDefaultSelectCriteria(string $itemtype): ?array
{
global $DB;
$itemtable = SearchEngine::getOrigTableName($itemtype);
return [
"{$itemtable}.id AS entities_id",
new QueryExpression($DB::quoteValue('1') . ' AS ' . $DB::quoteName('is_recursive')),
];
}

public static function getSQLSelectCriteria(string $itemtype, SearchOption $opt, bool $meta = false, string $meta_type = ''): ?array
{
return null;
}

public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta, callable $fn_append_with_search): ?array
{
return null;
}
}
24 changes: 21 additions & 3 deletions src/FieldUnicity.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,13 @@
* ---------------------------------------------------------------------
*/

use Glpi\Search\AdvancedSearchInterface;
use Glpi\Search\SearchOption;

/**
* FieldUnicity Class
**/
class FieldUnicity extends CommonDropdown
class FieldUnicity extends CommonDropdown implements AdvancedSearchInterface
{
// From CommonDBTM
public $dohistory = true;
Expand Down Expand Up @@ -642,7 +645,6 @@ public static function showDoubles(FieldUnicity $unicity)
echo "</table>";
}


/**
* Display debug information for current object
**/
Expand All @@ -663,9 +665,25 @@ public function showDebug()
NotificationEvent::debugEvent($this, $params);
}


public static function getIcon()
{
return "ti ti-fingerprint";
}

public static function getSQLDefaultSelectCriteria(string $itemtype): ?array
{
return [
'glpi_fieldunicities.itemtype AS ITEMTYPE'
];
}

public static function getSQLSelectCriteria(string $itemtype, SearchOption $opt, bool $meta = false, string $meta_type = ''): ?array
{
return null;
}

public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta, callable $fn_append_with_search): ?array
{
return null;
}
}
74 changes: 73 additions & 1 deletion src/Group.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,13 @@

use Glpi\Application\View\TemplateRenderer;
use Glpi\DBAL\QuerySubQuery;
use Glpi\Search\AdvancedSearchInterface;
use Glpi\Search\SearchOption;

/**
* Group class
**/
class Group extends CommonTreeDropdown
class Group extends CommonTreeDropdown implements AdvancedSearchInterface
{
public $dohistory = true;

Expand Down Expand Up @@ -1192,4 +1194,74 @@ public static function updateLastGroupChange()
Session::loadGroups();
}
}

public static function getSQLDefaultSelectCriteria(string $itemtype): ?array
{
return null;
}

public static function getSQLSelectCriteria(string $itemtype, SearchOption $opt, bool $meta = false, string $meta_type = ''): ?array
{
return null;
}

public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta, callable $fn_append_with_search): ?array
{
$table = $opt->getTableReference($itemtype, $meta);
$field = $opt['field'];
if ($field === 'completename') {
if ($val === 'mygroups') {
switch ($searchtype) {
case 'equals':
if (count($_SESSION['glpigroups']) === 0) {
return [];
}
return [
"$table.id" => $_SESSION['glpigroups']
];

case 'notequals':
if (count($_SESSION['glpigroups']) === 0) {
return [];
}
return [
"$table.id" => ['NOT IN', $_SESSION['glpigroups']]
];

case 'under':
if (count($_SESSION['glpigroups']) === 0) {
return [];
}
$groups = $_SESSION['glpigroups'];
foreach ($_SESSION['glpigroups'] as $g) {
$groups += getSonsOf($opt['table'], $g);
}
$groups = array_unique($groups);
return [
"$table.id" => $groups
];

case 'notunder':
if (count($_SESSION['glpigroups']) === 0) {
return [];
}
$groups = $_SESSION['glpigroups'];
foreach ($_SESSION['glpigroups'] as $g) {
$groups += getSonsOf($opt['table'], $g);
}
$groups = array_unique($groups);
return [
"$table.id" => ['NOT IN', $groups]
];

case 'empty':
$criteria = [];
$fn_append_with_search($criteria, "$table.id");
return $criteria;
}
}
}

return null;
}
}
29 changes: 25 additions & 4 deletions src/Search/AdvancedSearchInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,37 @@

namespace Glpi\Search;

use Glpi\DBAL\QueryFunction;

interface AdvancedSearchInterface
{
/**
* @param class-string<\CommonDBTM> $itemtype
* @return array|null
*/
public static function getSQLDefaultSelectCriteria(string $itemtype): ?array;

/**
* @param class-string<\CommonDBTM> $itemtype
* @param SearchOption $opt
* @param bool $nott
* @param string $searchtype
* @param mixed $val
* @param bool $meta
* @param string $meta_type
* @return array|null
*/
public static function getSQLSelectCriteria(string $itemtype, SearchOption $opt, bool $meta = false, string $meta_type = ''): ?array;

/**
* This method is called on the class that the search option belongs to (based on the table).
* It can return an array of criteria to handle the search option in a non-standard way, or return null to indicate it wasn't handled at all.
* @param class-string<\CommonDBTM> $itemtype The main itemtype being searched on
* @param SearchOption $opt The search option being handled
* @param bool $nott Whether the search option is negated
* @param string $searchtype The search type (e.g. 'contains')
* @param mixed $val The value to search for
* @param bool $meta Whether the search option is for a meta field
* @param callable $fn_append_with_search A helper function to append a criterion to a criteria array in a standardized way
* @phpstan-param callable(array &$criteria, string|QueryFunction $value): void $fn_append_with_search
* @return array|null
*/
public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta = false): ?array;
public static function getSQLWhereCriteria(string $itemtype, SearchOption $opt, bool $nott, string $searchtype, mixed $val, bool $meta, callable $fn_append_with_search): ?array;
}
Loading

0 comments on commit 5b50583

Please sign in to comment.