* * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/custom/netdiag/class/netdiagmeasurement.class.php * \ingroup netdiag * \brief Klasse für eine Messung (ein Tool-Lauf) im Diagnose-Protokoll */ require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php'; /** * Klasse NetDiagMeasurement — Ergebnis eines Tool-Laufs. * * params/result sind generisches JSON: neue Tools brauchen kein Schema-Update. */ class NetDiagMeasurement extends CommonObject { /** @var string Modul-Name */ public $module = 'netdiag'; /** @var string Element-Typ */ public $element = 'netdiagmeasurement'; /** @var string Datenbanktabelle (ohne Präfix) */ public $table_element = 'netdiag_measurement'; /** @var string Icon */ public $picto = 'fa-wave-square'; /** @var int 1 = Tabelle hat ein 'entity'-Feld */ public $ismultientitymanaged = 1; /** Ampel-Status der Messung */ const RESULT_OK = 0; const RESULT_WARN = 1; const RESULT_FAIL = 2; /** * @var array> Felddefinitionen */ public $fields = array( 'rowid' => array('type' => 'integer', 'label' => 'TechnicalID', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 1), 'entity' => array('type' => 'integer', 'label' => 'Entity', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'default' => 1, 'index' => 1, 'position' => 5), 'fk_protocol' => array('type' => 'integer', 'label' => 'Protocol', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'index' => 1, 'position' => 10), 'fk_device' => array('type' => 'integer', 'label' => 'Device', 'enabled' => 1, 'visible' => 0, 'index' => 1, 'position' => 15), 'tool' => array('type' => 'varchar(64)', 'label' => 'Tool', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'position' => 20), 'category' => array('type' => 'varchar(32)', 'label' => 'ToolCategory', 'enabled' => 1, 'visible' => 1, 'position' => 25), 'label' => array('type' => 'varchar(255)', 'label' => 'Label', 'enabled' => 1, 'visible' => 1, 'position' => 30), 'params' => array('type' => 'text', 'label' => 'Params', 'enabled' => 1, 'visible' => 0, 'position' => 40), 'result' => array('type' => 'text', 'label' => 'Result', 'enabled' => 1, 'visible' => 0, 'position' => 45), 'measure_status' => array('type' => 'smallint', 'label' => 'MeasureStatus', 'enabled' => 1, 'visible' => 1, 'notnull' => 1, 'default' => 0, 'position' => 50), 'date_measure' => array('type' => 'datetime', 'label' => 'DateMeasure', 'enabled' => 1, 'visible' => 1, 'position' => 55), 'date_creation' => array('type' => 'datetime', 'label' => 'DateCreation', 'enabled' => 1, 'visible' => 0, 'notnull' => 1, 'position' => 500), 'tms' => array('type' => 'timestamp', 'label' => 'DateModification', 'enabled' => 1, 'visible' => 0, 'notnull' => 0, 'position' => 501), ); public $rowid; public $entity; public $fk_protocol; public $fk_device; public $tool; public $category; public $label; public $params; public $result; public $measure_status; public $date_measure; public $date_creation; public $tms; /** * Konstruktor * * @param DoliDB $db Datenbank-Handler */ public function __construct(DoliDB $db) { $this->db = $db; } /** * Datensatz anlegen * * @param User $user Benutzer * @param int $notrigger 1 = Trigger unterdrücken * @return int >0 wenn OK, <=0 bei Fehler */ public function create(User $user, $notrigger = 0) { if (empty($this->date_measure)) { $this->date_measure = dol_now(); } return $this->createCommon($user, $notrigger); } /** * Datensatz laden * * @param int $id Rowid * @param string $ref Referenz * @return int >0 wenn OK, 0 wenn nicht gefunden, <0 bei Fehler */ public function fetch($id, $ref = null) { return $this->fetchCommon($id, $ref); } /** * Alle Messungen eines Protokolls laden * * @param int $fk_protocol Protokoll-Rowid * @return NetDiagMeasurement[] Liste der Messungen */ public function fetchAllByProtocol($fk_protocol) { $result = array(); $sql = "SELECT rowid FROM ".$this->db->prefix().$this->table_element; $sql .= " WHERE fk_protocol = ".((int) $fk_protocol); $sql .= " ORDER BY date_measure, rowid"; $resql = $this->db->query($sql); if ($resql) { while ($obj = $this->db->fetch_object($resql)) { $m = new self($this->db); if ($m->fetch((int) $obj->rowid) > 0) { $result[] = $m; } } } return $result; } /** * Datensatz aktualisieren * * @param User $user Benutzer * @param int $notrigger 1 = Trigger unterdrücken * @return int >0 wenn OK, <=0 bei Fehler */ public function update(User $user, $notrigger = 0) { return $this->updateCommon($user, $notrigger); } /** * Datensatz löschen * * @param User $user Benutzer * @param int $notrigger 1 = Trigger unterdrücken * @return int >0 wenn OK, <=0 bei Fehler */ public function delete(User $user, $notrigger = 0) { return $this->deleteCommon($user, $notrigger); } }