Skip to content

Commit

Permalink
#1434 [Control] add: public control history
Browse files Browse the repository at this point in the history
  • Loading branch information
Théo David committed Aug 10, 2023
1 parent 9f26358 commit 18c0da4
Show file tree
Hide file tree
Showing 10 changed files with 449 additions and 90 deletions.
40 changes: 39 additions & 1 deletion class/actions_digiquali.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,26 @@ public function printCommonFooter($parameters)
jQuery('.fichecenter').last().after(<?php echo json_encode($out) ; ?>)
</script>
<?php
}
} elseif ($parameters['currentcontext'] == 'globalcard') {
if (preg_match('/productlotcard/', $parameters['context'])) {

$productLot = new ProductLot($this->db);
$productLot->fetch(GETPOST('id'));
$objectB64 = $productLot->array_options['options_control_history_link'];
$publicControlInterfaceUrl = dol_buildpath('custom/digiquali/public/control/public_control_history.php?track_id=' . $objectB64, 3);

$out = '<a target="_blank" href="'. $publicControlInterfaceUrl .'"><div class="butAction">';
$out .= $langs->trans('ShowObjectControlHistory');
$out .= '</div></a>';

?>
<script>
$('[class*=extras_control_history_link]').html(<?php echo json_encode($out) ?>);
</script>
<?php
}

}

if (!$error) {
$this->results = array('myreturn' => 999);
Expand All @@ -278,6 +297,25 @@ public function printCommonFooter($parameters)
}
}

public function formObjectOptions($parameters, $object, $options) {
global $langs, $user;

if ($parameters['currentcontext'] == 'globalcard' && preg_match('/productlotcard/', $parameters['context'])) {
$objectData = [
'type' => $object->element,
'id' => $object->id
];

$objectDataJson = json_encode($objectData);
$objectDataB64 = base64_encode($objectDataJson);

if (dol_strlen($object)->array_options['options_control_history_link'] == 0 ) {
$object->array_options['options_control_history_link'] = $objectDataB64;
$object->update($user, 1);
}
}
}

/**
* Overloading the redirectAfterConnection function : replacing the parent's function with the one below
*
Expand Down
84 changes: 84 additions & 0 deletions class/control.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,90 @@ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset =
}
}


/**
* Load list of objects in memory from the database.
*
* @param string $sortorder Sort Order
* @param string $sortfield Sort field
* @param int $limit limit
* @param int $offset Offset
* @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...)
* @param string $filtermode Filter mode (AND or OR)
* @return array|int int <0 if KO, array of pages if OK
*/
public function fetchAllWithLeftJoin($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND', $fetchCategories = false, $leftJoin = '')
{
dol_syslog(__METHOD__, LOG_DEBUG);

$records = array();

$sql = 'SELECT ';
$sql .= $this->getFieldList('t');
$sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t';
if (isModEnabled('categorie') && $fetchCategories) {
require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
$sql .= Categorie::getFilterJoinQuery('control', 't.rowid');
}
if (dol_strlen($leftJoin)) {
$sql .= ' ' . $leftJoin;
}
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) $sql .= ' WHERE t.entity IN (' . getEntity($this->table_element) . ')';
else $sql .= ' WHERE 1 = 1';

// Manage filter
$sqlwhere = array();
if (count($filter) > 0) {
foreach ($filter as $key => $value) {
if ($key == 't.rowid') {
$sqlwhere[] = $key . '=' . $value;
} elseif (in_array($this->fields[$key]['type'], array('date', 'datetime', 'timestamp'))) {
$sqlwhere[] = $key . ' = \'' . $this->db->idate($value) . '\'';
} elseif ($key == 'customsql') {
$sqlwhere[] = $value;
} elseif (strpos($value, '%') === false) {
$sqlwhere[] = $key . ' IN (' . $this->db->sanitize($this->db->escape($value)) . ')';
} else {
$sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\'';
}
}
}
if (count($sqlwhere) > 0) {
$sql .= ' AND (' . implode(' ' . $filtermode . ' ', $sqlwhere) . ')';
}

if ( ! empty($sortfield)) {
$sql .= $this->db->order($sortfield, $sortorder);
}
if ( ! empty($limit)) {
$sql .= ' ' . $this->db->plimit($limit, $offset);
}

$resql = $this->db->query($sql);
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
while ($i < ($limit ? min($limit, $num) : $num)) {
$obj = $this->db->fetch_object($resql);

$record = new self($this->db);
$record->setVarsFromFetchObj($obj);

$records[$record->id] = $record;

$i++;
}
$this->db->free($resql);

return $records;
} else {
$this->errors[] = 'Error ' . $this->db->lasterror();
dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR);

return -1;
}
}

/**
* Set draft status.
*
Expand Down
7 changes: 5 additions & 2 deletions core/modules/modDigiQuali.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,9 @@ public function __construct($db)
'controlcard',
'publiccontrol',
'publicsurvey',
'digiqualiadmindocuments'
'digiqualiadmindocuments',
'globalcard',
'productlotcard'
],
// Set this to 1 if features of module are opened to external users
'moduleforexternal' => 0,
Expand Down Expand Up @@ -635,7 +637,8 @@ public function init($options = ''): int
$linkableObject = new $className($this->db);
$tableElement = $linkableObject->table_element;

$extraFields->addExtraField('qc_frequency', 'QcFrequency', 'int', 100, 10, $tableElement, 0, 0, '', 'a:1:{s:7:"options";a:1:{s:0:"";N;}}', 1, '', '1', '','',0, 'digiquali@digiquali', '$conf->digiquali->enabled');
$extraFields->addExtraField('qc_frequency', 'QcFrequency', 'int', 100, 10, $tableElement, 0, 0, '', 'a:1:{s:7:"options";a:1:{s:0:"";N;}}', 1, '', '1', '','',0, 'digiquali@digiquali', '$conf->digiquali->enabled');
$extraFields->addExtraField('control_history_link', 'ControlHistoryLink', 'varchar', 100, 255, $tableElement, 0, 0, '', '', 0, '', '1', '','',0, 'digiquali@digiquali', '$conf->digiquali->enabled');
}
}

Expand Down
85 changes: 85 additions & 0 deletions core/tpl/digiquali_public_control.tpl.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<div class="signature-container" style="max-width: 1000px;">
<div class="wpeo-gridlayout grid-2">
<div style="display: flex; justify-content: center; align-items: center;"><?php echo saturne_show_medias_linked('digiquali', $conf->digiquali->multidir_output[$conf->entity] . '/' . $object->element . '/'. $object->ref . '/photos/', 'small', '', 0, 0, 0, 200, 200, 0, 0, 0, $object->element . '/'. $object->ref . '/photos/', $object, 'photo', 0, 0,0, 1); ?></div>
<div class="informations">
<div style="margin-bottom: 10px"><strong><?php echo $object->getNomUrl(1, 'nolink'); ?></strong></div>
<div class="wpeo-table table-flex">
<div class="table-row">
<div class="table-cell"><?php echo '<i class="far fa-check-circle"></i> ' . $langs->trans('Verdict'); ?></div>
<?php
$verdictColor = $object->verdict == 1 ? 'green' : ($object->verdict == 2 ? 'red' : 'grey');
?>
<div class="table-cell table-end"><?php print '<div class="wpeo-button button-'. $verdictColor .'">' . $object->fields['verdict']['arrayofkeyval'][(!empty($object->verdict)) ?: 3] . '</div>'; ?></div>
</div>
<div class="table-row">
<div class="wpeo-table table-cell table-full">
<?php
foreach ($elementArray as $linkableObjectType => $linkableObject) {
if ($linkableObject['conf'] > 0 && (!empty($object->linkedObjectsIds[$linkableObject['link_name']]))) {

$className = $linkableObject['className'];
$linkedObject = new $className($db);

$linkedObjectKey = array_key_first($object->linkedObjectsIds[$linkableObject['link_name']]);
$linkedObjectId = $object->linkedObjectsIds[$linkableObject['link_name']][$linkedObjectKey];


$result = $linkedObject->fetch($linkedObjectId);
if ($result > 0) {
$linkedObject->fetch_optionals();

$objectName = '';
$objectNameField = $linkableObject['name_field'];

if (strstr($objectNameField, ',')) {
$nameFields = explode(', ', $objectNameField);
if (is_array($nameFields) && !empty($nameFields)) {
foreach ($nameFields as $subnameField) {
$objectName .= $linkedObject->$subnameField . ' ';
}
}
} else {
$objectName = $linkedObject->$objectNameField;
}

print '<div class="table-row">';
print '<div class="table-cell table-150">';
print '<strong>';
print $langs->transnoentities($linkableObject['langs']);
print '</div>';
print '<div class="table-cell table-end">';
print $objectName . ' ' . img_picto('', $linkableObject['picto'], 'class="pictofixedwidth"');

if ($linkedObject->array_options['options_qc_frequency'] > 0) {
$objectQcFrequency = $linkedObject->array_options['options_qc_frequency'];
print '<br>';
print $langs->transnoentities('QcFrequency') . ' : ' . $objectQcFrequency;
}
print '</strong>';
print '</div>';
print '</div>';
}
}
}
?>
</div>
</div>
<div class="table-row">
<div class="table-cell table-200"><?php echo img_picto('', 'calendar', 'class="pictofixedwidth"') . $langs->trans('ControlDate'); ?></div>
<div class="table-cell table-end"><?php echo dol_print_date($object->date_creation, 'day'); ?></div>
</div>
<?php if (!empty($object->next_control_date)) : ?>
<div class="table-row">
<div class="table-cell table-300"><?php echo img_picto('', 'calendar', 'class="pictofixedwidth"') . $langs->trans('NextControlDate'); ?></div>
<div class="table-cell table-end"><?php echo dol_print_date($object->next_control_date, 'day'); ?></div>
</div>
<div class="table-row">
<div class="table-cell table-200"><?php echo img_picto('', $object->picto, 'class="pictofixedwidth"') . $langs->trans('NextControl'); ?></div>
<div class="table-cell table-75 table-end badge badge-status <?php echo ((($object->next_control_date - dol_now()) > 0) ? 'badge-status4' : 'badge-status8'); ?>"><?php echo floor(($object->next_control_date - dol_now())/(3600 * 24)) . ' ' . $langs->trans('Days'); ?></div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>

Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ public function runTrigger($action, $object, User $user, Translate $langs, Conf
$actioncomm->note_private .= $langs->trans('Status') . ' : ' . $langs->trans('Locked') . '</br>';
$actioncomm->create($user);

$qcFrequency = 0;
$actioncommID = 0;
$elementArray = get_sheet_linkable_objects();
$object->fetchObjectLinked('', '', '', 'digiquali_control', 'OR', 1, 'sourcetype', 0);
Expand Down
Loading

0 comments on commit 18c0da4

Please sign in to comment.