Skip to content

Commit

Permalink
fix filters and add log
Browse files Browse the repository at this point in the history
  • Loading branch information
stonebuzz committed Jan 29, 2024
1 parent 86e02c2 commit 408a591
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 34 deletions.
7 changes: 5 additions & 2 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use GlpiPlugin\Deploy\Package_Action;
use GlpiPlugin\Deploy\Package_Check;
use GlpiPlugin\Deploy\Package_File;
use GlpiPlugin\Deploy\Package_Job;
use GlpiPlugin\Deploy\Package_Target;
use GlpiPlugin\Deploy\Profile;
use GlpiPlugin\Deploy\Repository;
Expand Down Expand Up @@ -44,11 +45,12 @@ function plugin_deploy_install()
$version = plugin_version_deploy();
$migration = new Migration($version['version']);

Package::install($migration);
Package_Action::install($migration);
Package_Check::install($migration);
Package_File::install($migration);
Package::install($migration);
Package_Target::install($migration);
Package_Job::install($migration);
Profile::install($migration);
Repository::install($migration);
Group::install($migration);
Expand All @@ -67,8 +69,9 @@ function plugin_deploy_uninstall()
{
$migration = new Migration(PLUGIN_DEPLOY_VERSION);

Package_Target::uninstall($migration);
Package::uninstall($migration);
Package_Job::install($migration);
Package_Target::uninstall($migration);
Profile::uninstall($migration);
Repository::uninstall($migration);
Group::uninstall($migration);
Expand Down
48 changes: 18 additions & 30 deletions src/Package_Job.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use DBmysqlIterator;
use Glpi\Application\View\TemplateRenderer;
use Migration;
use Search;

class Package_Job extends CommonDBTM
{
Expand Down Expand Up @@ -140,39 +139,28 @@ public static function getPackageAgents(Package $package): array
return $agent_list;
}

public static function convertFilterForSql(array $filter)
public static function convertFilterForSql(array $filters)
{
$sql_filter = [];
if (isset($filter) && count($filter) > 1) {
$sql_filter = [
'OR' => []
];
if (count($filter) > 2) {
if (isset($filter['status'])) {
$sql_filter['OR'][] = [
'status' => $filter['status']
];
}
if (isset($filter['agents_id'])) {
$sql_filter['AND'][] = [
'agents_id' => $filter['agents_id']
];
}
} else {
if (isset($filter['status'])) {
$sql_filter['OR'][] = [
'status' => $filter['status']
];
}
if (isset($filter['agents_id'])) {
$sql_filter['OR'][] = [
'agents_id' => $filter['agents_id']
];
}

$sql_filters = [];
$like_filters = [
'log',
];
foreach ($like_filters as $filter_key) {
if (strlen(($filters[$filter_key] ?? ""))) {
$sql_filters[$filter_key] = ['LIKE', '%' . $filters[$filter_key] . '%'];
}
}

return $sql_filter;
if (isset($filters['agents_id']) && !empty($filters['agents_id'])) {
$sql_filters['agents_id'] = $filters['agents_id'];
}

if (isset($filters['status']) && !empty($filters['status'])) {
$sql_filters['status'] = $filters['status'];
}

return $sql_filters;
}

public static function showForPackage(Package $package)
Expand Down
6 changes: 4 additions & 2 deletions templates/package/job.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
{% endfor %}
</select>
</td>
<td></td>
<td>
<input type="text" class="form-control" name="filters[log]" value="{{ filters['log'] }}">
</td>
<td></td>
<td></td>
<td></td>
Expand Down Expand Up @@ -86,4 +88,4 @@
$(function() {
$('.agents-filter-select-multiple').select2();
});
</script>
</script>

0 comments on commit 408a591

Please sign in to comment.