本文整理汇总了PHP中Monitor::getFromDB方法的典型用法代码示例。如果您正苦于以下问题:PHP Monitor::getFromDB方法的具体用法?PHP Monitor::getFromDB怎么用?PHP Monitor::getFromDB使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Monitor
的用法示例。
在下文中一共展示了Monitor::getFromDB方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importMonitor
//.........这里部分代码省略.........
if ($cfg_ocs["import_monitor"] == 1) {
//Config says : manage monitors as global
//check if monitors already exists in GLPI
$mon["is_global"] = 1;
$query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `name` = '" . $mon["name"] . "'\n AND `is_global` = '1'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) > 0) {
//Periph is already in GLPI
//Do not import anything just get periph ID for link
$id_monitor = $DB->result($result_search, 0, "id");
} else {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
} else {
if ($cfg_ocs["import_monitor"] >= 2) {
//Config says : manage monitors as single units
//Import all monitors as non global.
$mon["is_global"] = 0;
// Try to find a monitor with the same serial.
if (!empty($mon["serial"])) {
$query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `serial` LIKE '%" . $mon["serial"] . "%'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
//Monitor founded
$id_monitor = $DB->result($result_search, 0, "id");
}
}
//Search by serial failed, search by name
if ($cfg_ocs["import_monitor"] == 2 && !$id_monitor) {
//Try to find a monitor with no serial, the same name and not already connected.
if (!empty($mon["name"])) {
$query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
$id_monitor = $DB->result($result_search, 0, "id");
}
}
}
if (!$id_monitor) {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
}
}
// ($cfg_ocs["import_monitor"] >= 2)
if ($id_monitor) {
//Import unique : Disconnect monitor on other computer done in Connect function
$connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0));
$already_processed[] = $id_monitor;
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$old = new Monitor();
if ($old->getFromDB($id_monitor)) {
if ($old->fields["is_deleted"]) {
$input["is_deleted"] = 0;
}
if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
if (empty($old->fields["name"]) && !empty($mon["name"])) {
$input["name"] = $mon["name"];
}
if (empty($old->fields["serial"]) && !empty($mon["serial"])) {
$input["serial"] = $mon["serial"];
}
if (count($input)) {
$input["id"] = $id_monitor;
$input['entities_id'] = $entity;
$m->update($input);
}
}
}
} else {
$already_processed[] = $id;
}
}
// end foreach
if ($cfg_ocs["import_monitor"] <= 2 || $checkserial) {
//Look for all monitors, not locked, not linked to the computer anymore
$query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Monitor'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'";
if (!empty($already_processed)) {
$query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")";
}
foreach ($DB->request($query) as $data) {
//Delete all connexions
$conn->delete(array('id' => $data['id'], '_ocsservers_id' => $ocsservers_id), true);
}
}
}
}
}
示例2: importMonitor
//.........这里部分代码省略.........
if ($cfg_ocs["import_monitor"] >= 2) {
//Config says : manage monitors as single units
//Import all monitors as non global.
$mon["is_global"] = 0;
// Try to find a monitor with the same serial.
if (!empty($mon["serial"])) {
$query = "SELECT `id`\n FROM `glpi_monitors`\n WHERE `serial` LIKE '%" . $mon["serial"] . "%'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
//Monitor founded
$id_monitor = $DB->result($result_search, 0, "id");
}
}
//Search by serial failed, search by name
if ($cfg_ocs["import_monitor"] == 2 && !$id_monitor) {
//Try to find a monitor with no serial, the same name and not already connected.
if (!empty($mon["name"])) {
$query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
$id_monitor = $DB->result($result_search, 0, "id");
}
}
}
if (!$id_monitor) {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
}
}
// ($cfg_ocs["import_monitor"] >= 2)
if ($id_monitor) {
//Import unique : Disconnect monitor on other computer done in Connect function
$connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory, 'is_dynamic' => 1, 'is_deleted' => 0));
$already_processed[] = $id_monitor;
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$old = new Monitor();
if ($old->getFromDB($id_monitor)) {
if ($old->fields["is_deleted"]) {
$input["is_deleted"] = 0;
}
if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
if (empty($old->fields["name"]) && !empty($mon["name"])) {
$input["name"] = $mon["name"];
}
if (empty($old->fields["serial"]) && !empty($mon["serial"])) {
$input["serial"] = $mon["serial"];
}
if (count($input)) {
$input["id"] = $id_monitor;
$input['entities_id'] = $entity;
$m->update($input);
}
}
}
} else {
$already_processed[] = $id;
}
// } // end foreach
// if ($cfg_ocs["import_monitor"]<=2 || $checkserial){
//Look for all monitors, not locked, not linked to the computer anymore
$query = "SELECT `id`\n FROM `glpi_computers_items`\n WHERE `itemtype`='Monitor'\n AND `computers_id`='{$computers_id}'\n AND `is_dynamic`='1'\n AND `is_deleted`='0'";
if (!empty($already_processed)) {
$query .= "AND `items_id` NOT IN (" . implode(',', $already_processed) . ")";
}
foreach ($DB->request($query) as $data) {
// Delete all connexions
//Get OCS configuration
$ocs_config = PluginOcsinventoryngOcsServer::getConfig($ocsservers_id);
//Get the management mode for this device
$mode = PluginOcsinventoryngOcsServer::getDevicesManagementMode($ocs_config, 'Monitor');
$decoConf = $ocs_config["deconnection_behavior"];
//Change status if :
// 1 : the management mode IS NOT global
// 2 : a deconnection's status have been defined
// 3 : unique with serial
if ($mode >= 2 && strlen($decoConf) > 0) {
//Delete periph from glpi
if ($decoConf == "delete") {
$query = "DELETE\n FROM `glpi_computers_items`\n WHERE `id`='" . $data['id'] . "'";
$result = $DB->query($query);
//Put periph in dustbin
} else {
if ($decoConf == "trash") {
$query = "UPDATE\n `glpi_computers_items`\n SET `is_deleted` = 1\n WHERE `id`='" . $data['id'] . "'";
$result = $DB->query($query);
}
}
}
}
}
}
}
示例3: ComputerMonitor
/**
* @test
*/
public function ComputerMonitor()
{
global $DB;
$DB->connect();
$a_dataMonit = getAllDatasFromTable("glpi_monitors");
$this->assertEquals(1, count($a_dataMonit), "Must have 1 monitor created");
$a_dataLink = getAllDatasFromTable("glpi_computers_items", "`itemtype`='Monitor'\n AND `computers_id`='1'");
$this->assertEquals(1, count($a_dataLink), "Number of monitors not right");
$a_dataLink = current($a_dataLink);
$monitor = new Monitor();
$monitor->getFromDB($a_dataLink['items_id']);
unset($monitor->fields['date_mod']);
$a_reference = array('id' => '1', 'entities_id' => '0', 'name' => 'ThinkPad Display 1280x800', 'contact' => 'ddurieux', 'contact_num' => NULL, 'users_id_tech' => '0', 'groups_id_tech' => '0', 'comment' => '', 'serial' => 'UBYVUTFYEIUI', 'otherserial' => NULL, 'size' => '0', 'have_micro' => '0', 'have_speaker' => '0', 'have_subd' => '0', 'have_bnc' => '0', 'have_dvi' => '0', 'have_pivot' => '0', 'have_hdmi' => '0', 'have_displayport' => '0', 'locations_id' => '0', 'monitortypes_id' => '0', 'monitormodels_id' => '0', 'manufacturers_id' => '2', 'is_global' => '0', 'is_deleted' => '0', 'is_template' => '0', 'template_name' => NULL, 'users_id' => '0', 'groups_id' => '0', 'states_id' => '0', 'ticket_tco' => '0.0000', 'is_dynamic' => '0');
$this->assertEquals($a_reference, $monitor->fields);
}
示例4: updatePeripherals
//.........这里部分代码省略.........
$query = "SELECT `glpi_monitors`.`id`\n FROM `glpi_monitors`\n LEFT JOIN `glpi_computers_items`\n ON (`glpi_computers_items`.`itemtype`='Monitor'\n AND `glpi_computers_items`.`items_id`\n =`glpi_monitors`.`id`)\n WHERE `serial` = ''\n AND `name` = '" . $mon["name"] . "'\n AND `is_global` = '0'\n AND `entities_id` = '{$entity}'\n AND `glpi_computers_items`.`computers_id` IS NULL";
$result_search = $DB->query($query);
if ($DB->numrows($result_search) == 1) {
$id_monitor = $DB->result($result_search, 0, "id");
}
}
}
if (!$id_monitor) {
$input = $mon;
if ($cfg_ocs["states_id_default"] > 0) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
$input["entities_id"] = $entity;
$id_monitor = $m->add($input);
}
}
}
// ($cfg_ocs["import_monitor"] >= 2)
if ($id_monitor) {
//Import unique : Disconnect monitor on other computer done in Connect function
$conn = new Computer_Item();
$connID = $conn->add(array('computers_id' => $computers_id, 'itemtype' => 'Monitor', 'items_id' => $id_monitor, '_no_history' => !$dohistory));
if (!in_array(self::IMPORT_TAG_070, $import_periph)) {
self::addToOcsArray($computers_id, array(0 => self::IMPORT_TAG_070), "import_monitor");
}
if ($connID > 0) {
// sanity check - Add can fail
self::addToOcsArray($computers_id, array($connID => $checkMonitor), "import_monitor");
}
$count_monitor++;
//Update column "is_deleted" set value to 0 and set status to default
$input = array();
$old = new Monitor();
if ($old->getFromDB($id_monitor)) {
if ($old->fields["is_deleted"]) {
$input["is_deleted"] = 0;
}
if ($cfg_ocs["states_id_default"] > 0 && $old->fields["states_id"] != $cfg_ocs["states_id_default"]) {
$input["states_id"] = $cfg_ocs["states_id_default"];
}
if (empty($old->fields["name"]) && !empty($mon["name"])) {
$input["name"] = $mon["name"];
}
if (empty($old->fields["serial"]) && !empty($mon["serial"])) {
$input["serial"] = $mon["serial"];
}
if (count($input)) {
$input["id"] = $id_monitor;
$input['entities_id'] = $entity;
$m->update($input);
}
}
}
} else {
// found in array
unset($import_periph[$id]);
}
}
// end foreach
}
if (in_array(self::IMPORT_TAG_070, $import_periph)) {
//unset the version Tag
unset($import_periph[0]);
}
}
break;