. */ /* * ***************************Includes********************************* */ require_once __DIR__ . '/../../core/php/core.inc.php'; /* Translate system scan core/template/dashboard files and set them in i18n all under "core\/template\/widgets.html" path -> translate::exec($string, 'core/template/widgets.html'); */ class cmd { /* * *************************Attributs****************************** */ protected $id; protected $logicalId; protected $generic_type; protected $eqType; protected $name; protected $order; protected $type; protected $subType; protected $eqLogic_id; protected $isHistorized = 0; protected $unite = ''; protected $configuration; protected $template; protected $display; protected $value = null; protected $isVisible = 1; protected $alert; protected $_collectDate = ''; protected $_valueDate = ''; /** @var eqLogic */ protected $_eqLogic = null; protected $_needRefreshWidget; protected $_needRefreshAlert; /** @var bool */ protected $_changed = false; protected static $_templateArray = array(); protected static $_unite_conversion = array( 's' => array(60, 's', 'min', 'h'), 'W' => array(1000, 'W', 'kW', 'MW'), 'Wh' => array(1000, 'Wh', 'kWh', 'MWh'), 'io' => array(1024, 'io', 'Kio', 'Mio', 'Gio', 'Tio'), 'o' => array(1000, 'o', 'Ko', 'Mo', 'Go', 'To'), 'o/s' => array(1000, 'o/s', 'Ko/s', 'Mo/s', 'Go/s', 'To/s'), 'Bps' => array(1000, 'Bps', 'Kbps', 'Mbps', 'Gbps', 'Tbps'), 'Hz' => array(1000, 'Hz', 'kHz', 'MHz', 'GHz'), 'l' => array(1000, 'l', 'm3') ); /* * ***********************Méthodes statiques*************************** */ private static function cast($_inputs, $_eqLogic = null) { if (is_object($_inputs) && class_exists($_inputs->getEqType() . 'Cmd')) { if ($_eqLogic !== null) { $_inputs->_eqLogic = $_eqLogic; } $return = cast($_inputs, $_inputs->getEqType() . 'Cmd'); if (method_exists($return, 'decrypt')) { $return->decrypt(); } return $return; } if (is_array($_inputs)) { $return = array(); foreach ($_inputs as $input) { if ($_eqLogic !== null) { $input->_eqLogic = $_eqLogic; } $return[] = self::cast($input); } return $return; } return $_inputs; } /** * @param int|string $_id the id of the command * @return void|cmd void if $_id is not valid else the cmd */ public static function byId($_id) { if ($_id == '') { return; } $values = array( 'id' => $_id, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE id=:id'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } /** * @param array $_ids * @return void|array void if $_ids is not valid else an array of cmd */ public static function byIds($_ids) { if (!is_array($_ids) || count($_ids) == 0) { return; } $in = trim(preg_replace('/[, ]{2,}/m', ',', implode(',', $_ids)), ','); if (!empty($in)) { $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE id IN (' . $in . ')'; return self::cast(DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } } /** * @return array */ public static function all() { $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd ORDER BY id'; return self::cast(DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function isHistorized($_state = true) { $values = array( 'isHistorized' => ($_state) ? 1 : 0 ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE isHistorized=:isHistorized ORDER BY id'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function allHistoryCmd() { $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id INNER JOIN object ob ON el.object_id=ob.id WHERE isHistorized=1 AND type=\'info\''; $sql .= ' ORDER BY ob.position,ob.name,el.name,c.name'; $result1 = self::cast(DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id WHERE el.object_id IS NULL AND isHistorized=1 AND type=\'info\''; $sql .= ' ORDER BY el.name,c.name'; $result2 = self::cast(DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); return array_merge($result1, $result2); } /** * * @param int|array $_eqLogic_id * @param string $_type ['action'|'info'] * @param bool $_visible * @param eqLogic $_eqLogic * @param bool $_has_generic_type * @return array */ public static function byEqLogicId($_eqLogic_id, $_type = null, $_visible = null, $_eqLogic = null, $_has_generic_type = null) { $values = array(); if (is_array($_eqLogic_id)) { $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE eqLogic_id IN (' . trim(preg_replace('/[, ]{2,}/m', ',', implode(',', $_eqLogic_id)), ',') . ')'; } else { $values = array( 'eqLogic_id' => $_eqLogic_id, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE eqLogic_id=:eqLogic_id'; } if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND `type`=:type'; } if ($_visible !== null) { $sql .= ' AND `isVisible`=1'; } if ($_has_generic_type) { $sql .= ' AND `generic_type` IS NOT NULL'; } $sql .= ' ORDER BY `order`,`name`'; if (is_object($_eqLogic) && class_exists($_eqLogic->getEqType_name() . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, $_eqLogic->getEqType_name() . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__), $_eqLogic); } /** * * @param string $_logical_id * @param string $_type ['action'|'info'] * @return array */ public static function byLogicalId($_logical_id, $_type = null) { $values = array( 'logicalId' => $_logical_id, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE logicalId=:logicalId'; if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND `type`=:type'; } $sql .= ' ORDER BY `order`'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } /** * * @param string|array $_generic_type * @param int $_eqLogic_id * @param boolean $_one * @return cmd|array first cmd if $_one is true otherwise an array of all cmd */ public static function byGenericType($_generic_type, $_eqLogic_id = null, $_one = false) { if (is_array($_generic_type)) { $in = ''; foreach ($_generic_type as $value) { $in .= "'" . $value . "',"; } $values = array(); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE generic_type IN (' . trim(preg_replace('/[, ]{2,}/m', ',', $in), ',') . ')'; } else { $values = array( 'generic_type' => $_generic_type, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE generic_type=:generic_type'; } if ($_eqLogic_id !== null) { $values['eqLogic_id'] = $_eqLogic_id; $sql .= ' AND `eqLogic_id`=:eqLogic_id'; } $sql .= ' ORDER BY `order`'; if ($_one) { return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } /** * Search a command on eqType, logicalId, generic_type or name * * @param string $_search the needle * @return array */ public static function searchByString($_search) { $values = array( 'search' => '%' . $_search . '%' ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE eqType LIKE :search or logicalId LIKE :search or generic_type LIKE :search or name LIKE :search'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } /** * * @param string|array $_configuration * @param string $_eqType * @return array */ public static function searchConfiguration($_configuration, $_eqType = null) { if (!is_array($_configuration)) { $values = array( 'configuration' => '%' . $_configuration . '%', ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE configuration LIKE :configuration'; } else { $values = array( 'configuration' => '%' . $_configuration[0] . '%', ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE configuration LIKE :configuration'; for ($i = 1; $i < count($_configuration); $i++) { $values['configuration' . $i] = '%' . $_configuration[$i] . '%'; $sql .= ' OR configuration LIKE :configuration' . $i; } } if ($_eqType !== null) { $values['eqType'] = $_eqType; $sql .= ' AND eqType=:eqType '; } $sql .= ' ORDER BY name'; if ($_eqType != null && class_exists($_eqType . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, $_eqType . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function searchDisplay($_display, $_eqType = null) { if (!is_array($_display)) { $values = array( 'display' => '%' . $_display . '%', ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE display LIKE :display'; } else { $values = array( 'display' => '%' . $_display[0] . '%', ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE display LIKE :display'; for ($i = 1; $i < count($_display); $i++) { $values['display' . $i] = '%' . $_display[$i] . '%'; $sql .= ' OR display LIKE :display' . $i; } } if ($_eqType !== null) { $values['eqType'] = $_eqType; $sql .= ' AND eqType=:eqType '; } $sql .= ' ORDER BY name'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function searchConfigurationEqLogic($_eqLogic_id, $_configuration, $_type = null) { $values = array( 'configuration' => '%' . $_configuration . '%', 'eqLogic_id' => $_eqLogic_id, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE eqLogic_id=:eqLogic_id'; if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND type=:type '; } $sql .= ' AND configuration LIKE :configuration'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function searchTemplate($_template, $_eqType = null, $_type = null, $_subtype = null) { $values = array( 'template' => '%' . $_template . '%', ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE template LIKE :template'; if ($_eqType !== null) { $values['eqType'] = $_eqType; $sql .= ' AND eqType=:eqType '; } if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND type=:type '; } if ($_subtype !== null) { $values['subType'] = $_subtype; $sql .= ' AND subType=:subType '; } $sql .= ' ORDER BY name'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function byEqLogicIdAndLogicalId($_eqLogic_id, $_logicalId, $_multiple = false, $_type = null, $_eqLogic = null) { $values = array( 'eqLogic_id' => $_eqLogic_id, 'logicalId' => $_logicalId, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE eqLogic_id=:eqLogic_id AND logicalId=:logicalId'; if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND type=:type'; } $sql .= ' ORDER BY `order`'; if ($_multiple) { if (is_object($_eqLogic) && class_exists($_eqLogic->getEqType_name() . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, $_eqLogic->getEqType_name() . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } if (is_object($_eqLogic) && class_exists($_eqLogic->getEqType_name() . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, $_eqLogic->getEqType_name() . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } public static function byEqLogicIdAndGenericType($_eqLogic_id, $_generic_type, $_multiple = false, $_type = null, $_eqLogic = null) { $values = array( 'eqLogic_id' => $_eqLogic_id, 'generic_type' => $_generic_type, ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE eqLogic_id=:eqLogic_id AND generic_type=:generic_type'; if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND type=:type'; } if ($_multiple) { if (is_object($_eqLogic) && class_exists($_eqLogic->getEqType_name() . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, $_eqLogic->getEqType_name() . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } if (is_object($_eqLogic) && class_exists($_eqLogic->getEqType_name() . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, $_eqLogic->getEqType_name() . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } public static function byGenericTypeObjectId($_generic_type, $_object_id = null, $_type = null) { $values = array( 'generic_type' => $_generic_type ); $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE generic_type=:generic_type'; if ($_object_id && $_object_id != '-1') { if (!is_numeric($_object_id)) { $object = jeeObject::byName($_object_id); if (!is_object($object)) return array(); $_object_id = $object->getId(); } $eqLogics = eqLogic::byObjectId($_object_id); $eqLogicIds = array(); foreach ($eqLogics as $eqLogic) { array_push($eqLogicIds, $eqLogic->getId()); } $eqLogicIds = implode(',', $eqLogicIds); if (empty($eqLogicIds)) { return; } $sql .= ' AND eqLogic_id IN (' . $eqLogicIds . ')'; } if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND type=:type'; } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function byValue($_value, $_type = null, $_onlyEnable = false) { $values = array( 'value' => $_value, 'search' => '%#' . $_value . '#%', ); if (strpos($_value, 'variable(') !== false) { $values['search'] = '%#' . $_value . '%'; } if ($_onlyEnable) { $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id WHERE ( value=:value OR value LIKE :search) AND el.isEnable=1 AND c.id!=:value'; if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND c.type=:type '; } } else { $sql = 'SELECT ' . DB::buildField(__CLASS__) . ' FROM cmd WHERE ( value=:value OR value LIKE :search) AND id!=:value'; if ($_type !== null) { $values['type'] = $_type; $sql .= ' AND type=:type '; } } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function byTypeEqLogicNameCmdName($_eqType_name, $_eqLogic_name, $_cmd_name) { $values = array( 'eqType_name' => $_eqType_name, 'eqLogic_name' => $_eqLogic_name, 'cmd_name' => $_cmd_name, ); $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id WHERE c.name=:cmd_name AND el.name=:eqLogic_name AND el.eqType_name=:eqType_name'; if ($_eqType_name != null && class_exists($_eqType_name . 'Cmd')) { return DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, $_eqType_name . 'Cmd'); } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } public static function byEqLogicIdCmdName($_eqLogic_id, $_cmd_name) { $values = array( 'eqLogic_id' => $_eqLogic_id, 'cmd_name' => $_cmd_name, ); $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c WHERE c.name=:cmd_name AND c.eqLogic_id=:eqLogic_id'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } public static function byObjectNameEqLogicNameCmdName($_object_name, $_eqLogic_name, $_cmd_name) { $values = array( 'eqLogic_name' => $_eqLogic_name, 'cmd_name' => (html_entity_decode($_cmd_name) != '') ? html_entity_decode($_cmd_name) : $_cmd_name, ); if ($_object_name == __('Aucun', __FILE__)) { $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id WHERE c.name=:cmd_name AND el.name=:eqLogic_name AND el.object_id IS NULL'; } else { $values['object_name'] = $_object_name; $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id INNER JOIN object ob ON el.object_id=ob.id WHERE c.name=:cmd_name AND el.name=:eqLogic_name AND ob.name=:object_name'; } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } public static function byObjectNameCmdName($_object_name, $_cmd_name) { $values = array( 'object_name' => $_object_name, 'cmd_name' => $_cmd_name, ); $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c INNER JOIN eqLogic el ON c.eqLogic_id=el.id INNER JOIN object ob ON el.object_id=ob.id WHERE c.name=:cmd_name AND ob.name=:object_name'; return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ROW, PDO::FETCH_CLASS, __CLASS__)); } public static function byTypeSubType($_type, $_subType = '') { $values = array( 'type' => $_type, ); $sql = 'SELECT ' . DB::buildField(__CLASS__, 'c') . ' FROM cmd c WHERE c.type=:type'; if ($_subType != '') { $values['subtype'] = $_subType; $sql .= ' AND c.subtype=:subtype'; } return self::cast(DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL, PDO::FETCH_CLASS, __CLASS__)); } public static function cmdToHumanReadable($_input) { if (is_object($_input)) { $reflections = array(); $uuid = spl_object_hash($_input); if (!isset($reflections[$uuid])) { $reflections[$uuid] = new ReflectionClass($_input); } $reflection = $reflections[$uuid]; $properties = $reflection->getProperties(); foreach ($properties as $property) { $property->setAccessible(true); $value = $property->getValue($_input); $property->setValue($_input, self::cmdToHumanReadable($value)); $property->setAccessible(false); } return $_input; } if (is_array($_input)) { return json_decode(self::cmdToHumanReadable(json_encode($_input)), true); } $replace = array(); preg_match_all("/#([0-9]*)#/", $_input, $matches); if (count($matches[1]) == 0) { return $_input; } $cmds = self::byIds($matches[1]); if (is_array($cmds) && count($cmds) > 0) { foreach ($cmds as $cmd) { if (isset($replace['#' . $cmd->getId() . '#'])) { continue; } $replace['#' . $cmd->getId() . '#'] = '#' . $cmd->getHumanName() . '#'; } } return str_replace(array_keys($replace), $replace, $_input); } public static function humanReadableToCmd($_input) { $isJson = false; if (is_json($_input)) { $isJson = true; $_input = json_decode($_input, true); } if (is_object($_input)) { $reflections = array(); $uuid = spl_object_hash($_input); if (!isset($reflections[$uuid])) { $reflections[$uuid] = new ReflectionClass($_input); } $reflection = $reflections[$uuid]; $properties = $reflection->getProperties(); foreach ($properties as $property) { $property->setAccessible(true); $value = $property->getValue($_input); $property->setValue($_input, self::humanReadableToCmd($value)); $property->setAccessible(false); } return $_input; } if (is_array($_input)) { foreach ($_input as $key => $value) { $_input[$key] = self::humanReadableToCmd($value); } if ($isJson) { return json_encode($_input, JSON_UNESCAPED_UNICODE); } return $_input; } if (is_int($_input) || is_bool($_input) || is_null($_input)) { return $_input; } $replace = array(); preg_match_all("/#\[([^#]*)\]\[([^#]*)\]\[([^#]*)\]#/", $_input, $matches); if (count($matches) == 4) { $countMatches = count($matches[0]); for ($i = 0; $i < $countMatches; $i++) { if (isset($replace[$matches[0][$i]])) { continue; } if (isset($matches[1][$i]) && isset($matches[2][$i]) && isset($matches[3][$i])) { $cmd = self::byObjectNameEqLogicNameCmdName($matches[1][$i], $matches[2][$i], $matches[3][$i]); if (is_object($cmd)) { $replace[$matches[0][$i]] = '#' . $cmd->getId() . '#'; } } } } return str_replace(array_keys($replace), $replace, $_input); } public static function byString($_string) { $cmd = self::byId(str_replace('#', '', self::humanReadableToCmd($_string))); if (!is_object($cmd)) { throw new Exception($GLOBALS['JEEDOM_SCLOG_TEXT']['unfoundCmd']['txt'] . ' : ' . $_string . ' => ' . self::humanReadableToCmd($_string)); } return $cmd; } public static function cmdToValue($_input, $_quote = false) { if (config::byKey('expression::autoQuote', 'core', 1) == 0) { $_quote = false; } if (is_object($_input)) { $reflections = array(); $uuid = spl_object_hash($_input); if (!isset($reflections[$uuid])) { $reflections[$uuid] = new ReflectionClass($_input); } $reflection = $reflections[$uuid]; $properties = $reflection->getProperties(); foreach ($properties as $property) { $property->setAccessible(true); $value = $property->getValue($_input); $property->setValue($_input, self::cmdToValue($value, $_quote)); $property->setAccessible(false); } return $_input; } if (is_array($_input)) { foreach ($_input as $key => $value) { $_input[$key] = self::cmdToValue($value, $_quote); } return $_input; } $json = is_json($_input); $replace = array(); preg_match_all("/#([0-9]*)#/", $_input, $matches); foreach ($matches[1] as $cmd_id) { if (isset($replace['#' . $cmd_id . '#'])) { continue; } $cache = cache::byKey('cmdCacheAttr' . $cmd_id)->getValue(); if (utils::getJsonAttr($cache, 'value', null) !== null) { $collectDate = utils::getJsonAttr($cache, 'collectDate', date('Y-m-d H:i:s')); $valueDate = utils::getJsonAttr($cache, 'valueDate', date('Y-m-d H:i:s')); $cmd_value = utils::getJsonAttr($cache, 'value', ''); } else { $cmd = self::byId($cmd_id); if (!is_object($cmd) || $cmd->getType() != 'info') { continue; } $cmd_value = $cmd->execCmd(null, true, $_quote); $collectDate = $cmd->getCollectDate(); $valueDate = $cmd->getValueDate(); } if ($_quote && (substr_count($cmd_value, '.') > 1 || strpos($cmd_value, ' ') !== false || preg_match("/[a-zA-Z#]/", $cmd_value) || $cmd_value === '')) { $cmd_value = '"' . trim($cmd_value, '"') . '"'; } if (!$json) { $replace['"#' . $cmd_id . '#"'] = $cmd_value; $replace['#' . $cmd_id . '#'] = $cmd_value; $replace['#collectDate' . $cmd_id . '#'] = $collectDate; $replace['#valueDate' . $cmd_id . '#'] = $valueDate; } else { $replace['#' . $cmd_id . '#'] = trim(json_encode($cmd_value), '"'); $replace['#valueDate' . $cmd_id . '#'] = trim(json_encode($valueDate), '"'); $replace['#collectDate' . $cmd_id . '#'] = trim(json_encode($collectDate), '"'); } } return str_replace(array_keys($replace), $replace, $_input); } public static function allType() { $sql = 'SELECT distinct(type) as type FROM cmd'; return DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); } public static function allSubType($_type = '') { $values = array(); $sql = 'SELECT distinct(subType) as subtype'; if ($_type != '') { $values['type'] = $_type; $sql .= ' WHERE type=:type'; } $sql .= ' FROM cmd'; return DB::Prepare($sql, $values, DB::FETCH_TYPE_ALL); } public static function allUnite() { $sql = 'SELECT distinct(unite) as unite FROM cmd'; return DB::Prepare($sql, array(), DB::FETCH_TYPE_ALL); } public static function convertColor($_color) { $colors = config::byKey('convertColor'); if (isset($colors[$_color])) { return $colors[$_color]; } throw new Exception(__('Impossible de traduire la couleur en code hexadécimal :', __FILE__) . $_color); } public static function availableWidget($_version) { global $JEEDOM_INTERNAL_CONFIG; $return = array(); $path = __DIR__ . '/../../data/customTemplates/' . $_version; if (file_exists($path)) { $files = ls($path, 'cmd.*', false, array('files', 'quiet')); foreach ($files as $file) { $informations = explode('.', $file); if (count($informations) < 4) { continue; } if (stripos($informations[3], 'tmpl') !== false) { continue; } if (!isset($return[$informations[1]])) { $return[$informations[1]] = array(); } if (!isset($return[$informations[1]][$informations[2]])) { $return[$informations[1]][$informations[2]] = array(); } if (isset($informations[3])) { $return[$informations[1]][$informations[2]][$informations[3]] = array('name' => $informations[3], 'location' => 'customtemp', 'type' => 'custom'); } } } foreach ($JEEDOM_INTERNAL_CONFIG['cmd']['widgets'] as $type => $data1) { foreach ($data1 as $subtype => $data2) { foreach ($data2 as $name => $data3) { if (!isset($return[$type])) { $return[$type] = array(); } if (!isset($return[$type][$subtype])) { $return[$type][$subtype] = array(); } $return[$type][$subtype][$name] = array('name' => $name, 'location' => 'core', 'type' => 'template'); } } } foreach (plugin::listPlugin(true, false, false) as $plugin) { $path = __DIR__ . '/../../plugins/' . $plugin->getId() . '/core/template/' . $_version; if (file_exists($path)) { $files = ls($path, 'cmd.*', false, array('files', 'quiet')); foreach ($files as $file) { $informations = explode('.', $file); if (count($informations) < 4) { continue; } if (stripos($informations[3], 'tmpl') !== false) { continue; } if (!isset($return[$informations[1]])) { $return[$informations[1]] = array(); } if (!isset($return[$informations[1]][$informations[2]])) { $return[$informations[1]][$informations[2]] = array(); } if (isset($informations[3])) { $return[$informations[1]][$informations[2]][$informations[3]] = array('name' => $informations[3], 'location' => $plugin->getId(), 'type' => $plugin->getId()); } } } if (!method_exists($plugin->getId(), 'templateWidget')) { continue; } $plugin_id = $plugin->getId(); foreach (($plugin_id::templateWidget()) as $type => $data1) { foreach ($data1 as $subtype => $data2) { foreach ($data2 as $name => $data3) { if (!isset($return[$type])) { $return[$type] = array(); } if (!isset($return[$type][$subtype])) { $return[$type][$subtype] = array(); } $return[$type][$subtype][$plugin->getId() . '::' . $name] = array('name' => $name, 'location' => $plugin->getId(), 'type' => 'plugin'); } } } } foreach ((widgets::all()) as $widgets) { if (!isset($return[$widgets->getType()])) { $return[$widgets->getType()] = array(); } if (!isset($return[$widgets->getType()][$widgets->getSubtype()])) { $return[$widgets->getType()][$widgets->getSubtype()] = array(); } $return[$widgets->getType()][$widgets->getSubtype()][$widgets->getName()] = array('name' => $widgets->getName(), 'location' => 'custom', 'type' => 'custom'); } $path = __DIR__ . '/../template/' . $_version; $files = ls($path, 'cmd.*', false, array('files', 'quiet')); foreach ($files as $file) { $informations = explode('.', $file); if (count($informations) < 4) { continue; } if (stripos($informations[3], 'tmpl') !== false) { continue; } if (!isset($return[$informations[1]])) { $return[$informations[1]] = array(); } if (!isset($return[$informations[1]][$informations[2]])) { $return[$informations[1]][$informations[2]] = array(); } if (isset($informations[3])) { $return[$informations[1]][$informations[2]][$informations[3]] = array('name' => $informations[3], 'location' => 'core', 'type' => 'core'); } } return $return; } public static function getSelectOptionsByTypeAndSubtype($_type = false, $_subtype = false, $_version = 'dashboard', $_availWidgets = false) { if ($_type === false || $_subtype === false) { throw new Exception(__('Type ou sous-type de commande invalide', __FILE__)); } if (!$_availWidgets) { $_availWidgets = self::availableWidget($_version); } $display = ''; if (is_array($_availWidgets[$_type]) && is_array($_availWidgets[$_type][$_subtype]) && count($_availWidgets[$_type][$_subtype]) > 0) { $types = array(); foreach ($_availWidgets[$_type][$_subtype] as $key => $info) { if (isset($info['type'])) { $info['key'] = $key; if (!isset($types[$info['type']])) { $types[$info['type']][0] = $info; } else { array_push($types[$info['type']], $info); } } } ksort($types); foreach ($types as $type) { usort($type, function ($a, $b) { return strcmp($a['name'], $b['name']); }); foreach ($type as $key => $widget) { if ($widget['name'] == 'default' || $widget['name'] == 'core::default') { continue; } if ($key == 0) { $display .= ''; } if (isset($widget['location']) && $widget['location'] != 'core' && $widget['location'] != 'custom') { $display .= ''; } else { $display .= ''; } } $display .= ''; } return $display; } } public static function returnState($_options) { $cmd = cmd::byId($_options['cmd_id']); if (is_object($cmd)) { $cmd->event($cmd->getConfiguration('returnStateValue', 0)); } } public static function deadCmd() { $return = array(); foreach ((cmd::all()) as $cmd) { if ($cmd->getConfiguration('core::cmd::noDeadAnalyze', 0) == 1) { continue; } if (is_array($cmd->getConfiguration('actionCheckCmd', ''))) { foreach ($cmd->getConfiguration('actionCheckCmd', '') as $actionCmd) { if ($actionCmd['cmd'] != '' && strpos($actionCmd['cmd'], '#') !== false) { if (!cmd::byId(str_replace('#', '', $actionCmd['cmd']))) { $return[] = array('detail' => 'Commande ' . $cmd->getName() . ' de ' . $cmd->getEqLogic()->getName() . ' (' . $cmd->getEqLogic()->getEqType_name() . ')', 'help' => 'Action sur valeur', 'who' => $actionCmd['cmd']); } } } } if (is_array($cmd->getConfiguration('jeedomPostExecCmd', ''))) { foreach ($cmd->getConfiguration('jeedomPostExecCmd', '') as $actionCmd) { if ($actionCmd['cmd'] != '' && strpos($actionCmd['cmd'], '#') !== false) { if (!cmd::byId(str_replace('#', '', $actionCmd['cmd']))) { $return[] = array('detail' => 'Commande ' . $cmd->getName() . ' de ' . $cmd->getEqLogic()->getName() . ' (' . $cmd->getEqLogic()->getEqType_name() . ')', 'help' => 'Post Exécution', 'who' => $actionCmd['cmd']); } } } } if (is_array($cmd->getConfiguration('jeedomPreExecCmd', ''))) { foreach ($cmd->getConfiguration('jeedomPreExecCmd', '') as $actionCmd) { if ($actionCmd['cmd'] != '' && strpos($actionCmd['cmd'], '#') !== false) { if (!cmd::byId(str_replace('#', '', $actionCmd['cmd']))) { $return[] = array('detail' => 'Commande ' . $cmd->getName() . ' de ' . $cmd->getEqLogic()->getName() . ' (' . $cmd->getEqLogic()->getEqType_name() . ')', 'help' => 'Pré Exécution', 'who' => $actionCmd['cmd']); } } } } } return $return; } public static function cmdAlert($_options) { $cmd = cmd::byId($_options['cmd_id']); if (!is_object($cmd)) { return; } $cmd->executeAlertCmdAction(); } /* * *********************Méthodes d'instance************************* */ public function formatValue($_value, $_quote = false) { if (is_array($_value) || is_object($_value)) { return ''; } if ($_value === null) { $_value = 0; } if (trim($_value) == '' && $_value !== false && $_value !== 0) { if ($this->getSubType() == 'numeric') { return 0; } if ($this->getSubType() == 'binary') { return 0; } return ''; } $_value = trim(trim($_value), '"'); if (@strpos(strtolower($_value), 'error::') !== false) { return $_value; } if ($this->getType() == 'info') { if ($this->getSubType() == 'numeric') { // Handle comma instead of period in a float value $_value = floatval(str_replace(',', '.', $_value)); } $calc = $this->getConfiguration('calculValueOffset'); if ($calc != '') { try { if (preg_match("/[a-zA-Z#]/", $_value)) { // Value is not just a number $calc = str_replace('#value#', '"' . $_value . '"', str_replace('\'#value#\'', '#value#', str_replace('"#value#"', '#value#', $calc))); } else { // Value is a number $calc = str_replace('#value#', $_value, $calc); } $_value = jeedom::evaluateExpression($calc); } catch (Exception $ex) { } catch (Error $ex) { } } switch ($this->getSubType()) { case 'string': case 'other': if ($_quote) { return '"' . $_value . '"'; } return $_value; case 'binary': if ($_value === true || $_value === 1) { // Handle literal values $binary = true; } elseif ((is_numeric(intval($_value)) && intval($_value) >= 1)) { // Handle number and numeric string $binary = true; } elseif (in_array(strtolower($_value), array('on', 'true', 'high', 'enable', 'enabled', 'online'))) { // Handle common string boolean values $binary = true; } else { // Handle everything else as false $binary = false; } // Return int value negated according to invertBinary configuration return intval($binary xor boolval($this->getConfiguration('invertBinary', false))); case 'numeric': if ($this->getConfiguration('historizeRound') !== '' && is_numeric($this->getConfiguration('historizeRound')) && $this->getConfiguration('historizeRound') >= 0) { if (!is_numeric($_value)) { log::add('cmd', 'error', __('La formule de calcul doit retourner une valeur numérique 33333333333333 uniquement : ', __FILE__) . $this->getHumanName() . ' => ' . $_value); $_value = (float) (str_replace(',', '.', $_value)); } $_value = round($_value, $this->getConfiguration('historizeRound')); } if ($_value > $this->getConfiguration('maxValue', $_value)) { $_value = $this->getConfiguration('maxValue', $_value); } if ($_value < $this->getConfiguration('minValue', $_value)) { $_value = $this->getConfiguration('minValue', $_value); } return floatval($_value); } } return $_value; } public function getLastValue() { return $this->getConfiguration('lastCmdValue', null); } public function dontRemoveCmd() { return false; } public function getTableName() { return 'cmd'; } public function save($_direct = false) { if ($this->getName() == '') { throw new Exception(__('Le nom de la commande ne peut pas être vide :', __FILE__) . print_r($this, true)); } if ($this->getType() == '') { throw new Exception($this->getHumanName() . ' ' . __('Le type de la commande ne peut pas être vide :', __FILE__) . print_r($this, true)); } if ($this->getSubType() == '') { throw new Exception($this->getHumanName() . ' ' . __('Le sous-type de la commande ne peut pas être vide :', __FILE__) . print_r($this, true)); } if ($this->getEqLogic_id() == '') { throw new Exception($this->getHumanName() . ' ' . __('Vous ne pouvez pas créer une commande sans la rattacher à un équipement', __FILE__)); } if ($this->getConfiguration('maxValue') != '' && $this->getConfiguration('minValue') != '' && $this->getConfiguration('minValue') > $this->getConfiguration('maxValue')) { throw new Exception($this->getHumanName() . ' ' . __('La valeur minimum de la commande ne peut être supérieure à la valeur maximum', __FILE__)); } if ($this->getEqType() == '') { $this->setEqType($this->getEqLogic()->getEqType_name()); } if ($this->getDisplay('generic_type') != '' && $this->getGeneric_type() == '') { $this->setGeneric_type($this->getDisplay('generic_type')); $this->setDisplay('generic_type', null); } if ($this->getTemplate('dashboard', '') == '') { $this->setTemplate('dashboard', 'core::default'); } if ($this->getTemplate('mobile', '') == '') { $this->setTemplate('mobile', 'core::default'); } if ($this->getType() == 'action' && $this->getIsHistorized() == 1) { $this->setIsHistorized(0); } if ($this->getIsHistorized() == 0 && $this->getType() == 'info' && $this->getSubType() != 'string') { $this->setDisplay('showStatsOnmobile', 0); $this->setDisplay('showStatsOndashboard', 0); } if ($this->getType() == 'action') { $this->setDisplay('showStatsOnmobile', null); $this->setDisplay('showStatsOndashboard', null); } DB::save($this, $_direct); if ($this->_needRefreshWidget) { $this->_needRefreshWidget = false; $eqLogic = $this->getEqLogic(); if (is_object($eqLogic)) { $eqLogic->refreshWidget(); } } if ($this->_needRefreshAlert && $this->getType() == 'info') { $value = $this->execCmd(); $level = $this->checkAlertLevel($value); if ($level != $this->getCache('alertLevel')) { $this->actionAlertLevel($level, $value); } } return true; } public function refresh() { DB::refresh($this); } public function remove() { viewData::removeByTypeLinkId('cmd', $this->getId()); dataStore::removeByTypeLinkId('cmd', $this->getId()); $eqLogic = $this->getEqLogic(); if (is_object($eqLogic)) { $eqLogic->setStatus(array( 'warning' => 0, 'danger' => 0, )); } $this->emptyHistory(); cache::delete('cmdCacheAttr' . $this->getId()); cache::delete('cmd' . $this->getId()); jeedom::addRemoveHistory(array('id' => $this->getId(), 'name' => $this->getHumanName(), 'date' => date('Y-m-d H:i:s'), 'type' => 'cmd')); return DB::remove($this); } public function execute($_options = array()) { return false; } private function pre_postExecCmd($_values = array(), $_type = 'jeedomPreExecCmd') { if (!is_array($this->getConfiguration($_type)) || count($this->getConfiguration($_type)) == 0) { return; } $message = ''; switch ($_type) { case 'jeedomPreExecCmd': $message = '. ' . __('Sur preExec de la commande', __FILE__); break; case 'jeedomPostExecCmd': $message = '. ' . __('Sur postExec de la commande', __FILE__); break; } foreach ($this->getConfiguration($_type) as $action) { try { $options = array(); if (isset($action['options'])) { $options = $action['options']; } if (is_array($_values) && count($_values) > 0) { foreach ($_values as $key => $value) { foreach ($options as &$option) { if (!is_array($option)) { $option = str_replace('#' . $key . '#', $value, $option); } } } $options['source'] = $this->getHumanName(); } scenarioExpression::createAndExec('action', $action['cmd'], $options); } catch (Exception $e) { log::add('cmd', 'error', __('Erreur lors de l\'exécution de', __FILE__) . ' ' . $action['cmd'] . ': ' . $message . '. ' . $this->getHumanName() . __('Détails :', __FILE__) . ' ' . log::exception($e)); } } } public function preExecCmd($_values = array()) { if (isset($_values['user_login'])) { $this->setCache('lastExecutionUser', $_values['user_login']); } else { $this->setCache('lastExecutionUser', 'system'); } $this->pre_postExecCmd($_values, 'jeedomPreExecCmd'); } public function postExecCmd($_values = array()) { $this->pre_postExecCmd($_values, 'jeedomPostExecCmd'); } public function isAlreadyInStateAllow() { if ($this->getConfiguration('alreadyInState') == 'deny') { return false; } if ($this->getConfiguration('alreadyInState') == '' && config::byKey('cmd::allowCheckState') == 0) { return false; } if ($this->getType() != 'action') { return false; } $cmdValue = $this->getCmdValue(); if (!is_object($cmdValue)) { return false; } if ($cmdValue->getCache('lastAction') != '' && strtotime($cmdValue->getCache('lastAction')) > strtotime($cmdValue->getCache('valueDate'))) { return false; } return true; } public function alreadyInState($_options) { if ($this->getSubType() == 'message') { return false; } $cmdValue = $this->getCmdValue(); $value = $cmdValue->execCmd(); switch ($this->getSubType()) { case 'other': switch ($cmdValue->getSubtype()) { case 'binary': if (strtolower($this->getName()) == 'on' && $value == 1) { return true; } if (strtolower($this->getName()) == 'off' && $value == 0) { return true; } break; case 'string': if (strtolower($this->getName()) == $value) { return true; } break; } break; case 'slider': if ($_options['slider'] == $value) { return true; } } return false; } /** * * @param null|string $_options * @param bool $_sendNodeJsEvent * @param bool $_quote * @return void|string * @throws Exception */ public function execCmd($_options = null, $_sendNodeJsEvent = false, $_quote = false) { if ($this->getType() == 'info') { $state = $this->getCache(array('collectDate', 'valueDate', 'value', 'usage')); if (isset($state['collectDate'])) { $this->setCollectDate($state['collectDate']); } else { $this->setCollectDate(date('Y-m-d H:i:s')); } if (isset($state['valueDate'])) { $this->setValueDate($state['valueDate']); } else { $this->setValueDate($this->getCollectDate()); } return $state['value']; } $eqLogic = $this->getEqLogic(); if (!is_object($eqLogic) || $eqLogic->getIsEnable() != 1) { throw new Exception($GLOBALS['JEEDOM_SCLOG_TEXT']['disableEqNoExecCmd']['txt'] . $this->getHumanName()); } try { if ($_options !== null && $_options !== '') { $options = self::cmdToValue($_options); if (is_json($_options)) { $options = json_decode($_options, true); } } else { $options = null; } if (isset($options['color'])) { $options['color'] = str_replace('"', '', $options['color']); } if ($this->getSubType() == 'color' && isset($options['color']) && substr($options['color'], 0, 1) != '#') { $options['color'] = cmd::convertColor($options['color']); } if ($this->getSubType() == 'slider' && isset($options['slider']) && $this->getConfiguration('calculValueOffset') != '') { $options['slider'] = jeedom::evaluateExpression(str_replace('#value#', $options['slider'], $this->getConfiguration('calculValueOffset'))); } if ($this->getConfiguration('timeline::enable')) { $timeline = new timeline(); $timeline->setType('cmd'); $timeline->setSubtype('action'); $timeline->setLink_id($this->getId()); $timeline->setFolder($this->getConfiguration('timeline::folder')); $timeline->setName($this->getHumanName(true, true)); $timeline->save(); } if ($this->isAlreadyInStateAllow() && $this->alreadyInState($options)) { if (is_array($options) && ((count($options) > 1 && isset($options['uid'])) || count($options) > 0)) { log::add('event', 'info', $GLOBALS['JEEDOM_SCLOG_TEXT']['execCmd']['txt'] . $this->getHumanName() . ' ' . __('avec les paramètres', __FILE__) . ' ' . json_encode($options) . ' ' . __('(ignorée)', __FILE__)); } else { log::add('event', 'info', $GLOBALS['JEEDOM_SCLOG_TEXT']['execCmd']['txt'] . $this->getHumanName() . ' ' . __('(ignorée)', __FILE__)); } return; } if (is_array($options) && ((count($options) > 1 && isset($options['uid'])) || count($options) > 0)) { log::add('event', 'info', $GLOBALS['JEEDOM_SCLOG_TEXT']['execCmd']['txt'] . $this->getHumanName() . ' ' . __('avec les paramètres', __FILE__) . ' ' . json_encode($options)); } else { log::add('event', 'info', $GLOBALS['JEEDOM_SCLOG_TEXT']['execCmd']['txt'] . $this->getHumanName()); } $this->preExecCmd($options); $value = $this->formatValue($this->execute($options), $_quote); $cmdValue = $this->getCmdValue(); if (is_object($cmdValue)) { $cmdValue->setCache('lastAction', date('Y-m-d H:i:s')); } $this->postExecCmd($options); $usage = $this->getCache(array('usage::automation', 'usage::ui')); if (isset($_options['user_login'])) { $usage['usage::ui'] = ($usage['usage::ui'] === '') ? 0 : $usage['usage::ui']; $this->setCache('usage::ui', $usage['usage::ui'] + 1); } else { $usage['usage::automation'] = ($usage['usage::automation'] === '') ? 0 : $usage['usage::automation']; $this->setCache('usage::automation', $usage['usage::automation'] + 1); } } catch (Exception $e) { $type = $eqLogic->getEqType_name(); if (config::byKey('numberOfTryBeforeEqLogicDisable') > 0 && $eqLogic->getConfiguration('nerverFail') != 1) { $numberTryWithoutSuccess = $eqLogic->getStatus('numberTryWithoutSuccess', 0); $eqLogic->setStatus('numberTryWithoutSuccess', $numberTryWithoutSuccess); if ($numberTryWithoutSuccess >= config::byKey('numberOfTryBeforeEqLogicDisable')) { $message = __('Désactivation de', __FILE__) . ' ' . $eqLogic->getName() . ' ' . __('car il n\'a pas répondu ou mal répondu lors des 3 derniers essais', __FILE__); $action = '' . __('Equipement', __FILE__) . ''; message::add($type, $message, $action); $eqLogic->setIsEnable(0); $eqLogic->save(); } } log::add($type, 'error', __('Erreur exécution de la commande', __FILE__) . ' ' . $this->getHumanName() . ' : ' . log::exception($e)); throw $e; } if ($options !== null && $this->getValue() == '') { if (isset($options['slider'])) { $this->setConfiguration('lastCmdValue', $options['slider']); $this->save(); } if (isset($options['color'])) { $this->setConfiguration('lastCmdValue', $options['color']); $this->save(); } } if ($this->getConfiguration('updateCmdId') != '') { $cmd = cmd::byId($this->getConfiguration('updateCmdId')); if (is_object($cmd)) { $value = $this->getConfiguration('updateCmdToValue'); switch ($this->getSubType()) { case 'slider': $value = str_replace('#slider#', $options['slider'], $value); break; case 'color': $value = str_replace('#color#', $options['color'], $value); break; case 'select': $value = str_replace('#select#', $options['select'], $value); break; case 'message': $value = str_replace('#message#', $options['message'], $value); break; } $cmd->event($value); } } return $value; } // Used by modals eqLogic.dashboard.edit and cmd.configure public function getWidgetsSelectOptions($_version = 'dashboard', $_availWidgets = false) { if (!$_availWidgets) { $_availWidgets = self::availableWidget($_version); } if ($this->getTemplate($_version) == 'default') { $this->setTemplate($_version, 'core::default'); $this->save(true); } $display = ''; return $display .= self::getSelectOptionsByTypeAndSubtype($this->getType(), $this->getSubType(), $_version, $_availWidgets); } public function getGenericTypeSelectOptions() { $display = ''; $groups = array(); foreach ((config::getGenericTypes(false)['byType']) as $key => $info) { if (strtolower($this->getType()) != strtolower($info['type'])) { continue; } if (isset($info['subtype']) && !in_array($this->getSubType(), $info['subtype'])) { continue; } $info['key'] = $key; if (!isset($groups[$info['family']])) { $groups[$info['family']][0] = $info; } else { array_push($groups[$info['family']], $info); } } ksort($groups); $optgroup = ''; foreach ($groups as $group) { usort($group, function ($a, $b) { return strcmp($a['name'], $b['name']); }); foreach ($group as $key => $info) { if ($key == 0) { $optgroup .= ''; } $name = $info['name']; $optgroup .= ''; } $optgroup .= ''; } if ($optgroup != '') $display .= $optgroup; return $display; } public function getWidgetHelp($_version = 'dashboard', $_widgetName = '') { $widget = $this->getWidgetTemplateCode($_version, false, $_widgetName); $widgetCode = $widget['template']; $isCorewidget = $widget['isCoreWidget']; if (strpos($widgetCode, '') !== false) { $widgetHelp = explode('', $widgetCode)[0]; $widgetHelp = explode('