Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#1928 [Cards] add: badge on controls #1942

Open
wants to merge 2 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions class/actions_digiquali.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -419,4 +419,42 @@ public function saturneAdminObjectConst(array $parameters): int

return 0; // or return 1 to replace standard code.
}

function completeTabsHead(array $parameters) : int
{
global $langs, $conf;

if (strpos($parameters['context'], 'main') !== false) {
if (!empty($parameters['head'])) {
foreach ($parameters['head'] as $headKey => $headTab) {
if (is_array($headTab) && count($headTab) > 0) {
if (isset($headTab[2]) && $headTab[2] === 'control' && is_string($headTab[1]) && strpos($headTab[1], $langs->trans('Controls')) !== false && strpos($headTab[1], 'badge') === false) {

$matches = [];
preg_match_all('/[?&](fromid|fromtype)=([^&]+)/', $headTab[0], $matches, PREG_SET_ORDER);
foreach ($matches as $match) {
if ($match[1] === 'fromid') {
$fk_source = $match[2];
} elseif ($match[1] === 'fromtype') {
$sourcetype = $match[2];
}
}
if (empty($fk_source) || empty($sourcetype)) {
continue;
}

require_once __DIR__ . '/../class/control.class.php';
$control = new Control($this->db);

$join = ' LEFT JOIN '. MAIN_DB_PREFIX . 'element_element as project ON (project.fk_source = ' . $fk_source . ' AND project.sourcetype = "' . $sourcetype . '" AND project.targettype = "' . $control->table_element . '")';
$num = saturne_fetch_all_object_type('Control', '', '', 0, 0, ['customsql' => 't.rowid = project.fk_target'], '', '', '', '', $join, ['count' => true]);

$parameters['head'][$headKey][1] .= '<span class="badge badge-pill badge-primary marginleftonlyshort">' . $num . '</span>';
}
}
}
}
}
return 0;
}
}
5 changes: 4 additions & 1 deletion class/control.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key . '=' . $value;
} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
} elseif (isset($this->fields[$key]['type']) && in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
$sqlwhere[] = $key . ' = \'' . $this->db->idate($value) . '\'';
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
Expand Down Expand Up @@ -875,6 +875,9 @@ public function getNbControlsTagsByVerdict(): array
if (empty($control->verdict)) {
$arrayNbControlByVerdict[0]++;
} else {
if (!isset($arrayNbControlByVerdict[$control->verdict])) {
$arrayNbControlByVerdict[$control->verdict] = 0;
}
$arrayNbControlByVerdict[$control->verdict]++;
}
}
Expand Down
4 changes: 2 additions & 2 deletions class/sheet.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -483,13 +483,13 @@ public function updateQuestionsPosition(array $questionIds)

$questionIds = array_values($questionIds);
for ($position = 0; $position < count($questionIds); $position++) {
$sql = 'UPDATE '. MAIN_DB_PREFIX . 'element_element';
$sql = 'UPDATE '. MAIN_DB_PREFIX . 'element_element';
$sql .= ' SET position = ' . $position;
$sql .= ' WHERE fk_source = ' . $this->id;
$sql .= ' AND sourcetype = "digiquali_sheet"';
$sql .= ' AND fk_target = ' . $questionIds[$position];
$sql .= ' AND targettype = "digiquali_question"';
$res = $this->db->query($sql);
$res = $this->db->query($sql);

if (!$res) {
$error++;
Expand Down