/** * Get object parameters * * @param int $objectId * @param mixed $parameterNames * @return array */ public function getParameters($objectId, $parameterNames) { $params = parent::getParameters($objectId, $parameterNames); $params_image = array("ehi_icon_image", "ehi_vrml_image", "ehi_statusmap_image"); foreach ($params_image as $image) { if (array_key_exists($image, $params)) { $sql = "SELECT dir_name,img_path \n FROM view_img vi \n LEFT JOIN view_img_dir_relation vidr ON vi.img_id = vidr.img_img_id \n LEFT JOIN view_img_dir vid ON vid.dir_id = vidr.dir_dir_parent_id \n WHERE img_id = ?"; $res = $this->getResult($sql, array($params[$image]), "fetch"); if (is_array($res)) { $params[$image] = $res["dir_name"] . "/" . $res["img_path"]; } } } return $params; }
/** * Export data * * @param string $parameters * @return void */ public function export() { $elements = $this->object->getList("*", -1, 0); foreach ($elements as $element) { $addStr = $this->action . $this->delim . "ADD"; foreach ($this->insertParams as $param) { $addStr .= $this->delim . $element[$param]; } $addStr .= "\n"; echo $addStr; foreach ($element as $parameter => $value) { if (!in_array($parameter, $this->exportExcludedParams)) { if (!is_null($value) && $value != "") { $value = CentreonUtils::convertLineBreak($value); echo $this->action . $this->delim . "setparam" . $this->delim . $element[$this->object->getUniqueLabelField()] . $this->delim . $parameter . $this->delim . $value . "\n"; } } } } }
/** * Insert new dependency * * @param string $name * @param string $description * @param Centreon_Object $parentObj * @param string $parentString * @param Centreon_Object_Relation * @throws CentreonClapiException */ protected function insertDependency($name, $description, $parentObj, $parentString, $relationObj) { $parents = explode('|', $parentString); $parentIds = array(); foreach ($parents as $parent) { $idTab = $parentObj->getIdByParameter($parentObj->getUniqueLabelField(), array($parent)); // make sure that all parents exist if (!count($idTab)) { throw new CentreonClapiException(sprintf('Could not find %s', $parent)); } $parentIds[] = $idTab[0]; } // insert dependency $depId = $this->object->insert(array('dep_name' => $name, 'dep_description' => $description)); if (is_null($depId)) { throw new CentreonClapiException(sprintf("Could not insert dependency %s", $name)); } // insert relations foreach ($parentIds as $parentId) { $relationObj->insert($depId, $parentId); } }
/** * Delete resource from downtime * * @param string $parameters | downtime name; resource name separated by "|" character * @param Centreon_Object $object * @param string $relTable * @param string $relField */ protected function delGenericRelation($parameters, $object, $relTable, $relField) { $tmp = explode($this->delim, $parameters); if (count($tmp) != 2) { throw new CentreonClapiException('Missing parameters'); } /* init var */ $downtimeId = $this->getObjectId($tmp[0]); $resources = explode('|', $tmp[1]); /* retrieve object ids */ $objectIds = array(); foreach ($resources as $resource) { $ids = $object->getIdByParameter($object->getUniqueLabelField(), array($resource)); /* object does not exist */ if (!count($ids)) { throw new CentreonClapiException(sprintf('Unknown object named %s', $resource)); } /* checks whether or not relationship already exists */ $sql = "SELECT * FROM {$relTable} WHERE dt_id = ? AND {$relField} = ?"; $stmt = $this->db->query($sql, array($downtimeId, $ids[0])); if (!$stmt->rowCount()) { throw new CentreonClapiException(sprintf('Cannot remove relationship with %s as the relationship does not exist', $resource)); } $objectIds[] = $ids[0]; } /* delete relationship */ $sql = "DELETE FROM {$relTable} WHERE dt_id = ? AND {$relField} = ?"; foreach ($objectIds as $id) { $this->db->query($sql, array($downtimeId, $id)); } }