/** * Returns the value of variable for the given CmdbObject * @param CmdbObject $object the object to get the value */ public function getValue(\yourCMDB\entities\CmdbObject $object) { //get ObjectController $objectController = ObjectController::create(); //get object type config $config = CmdbConfig::create(); $configObjecttype = $config->getObjectTypeConfig(); $value = $this->defaultValue; //if there is a configuration for that object type //use the content of the specified field as value $objectType = $object->getType(); if (isset($this->fieldValue[$objectType]['name'])) { $fieldname = $this->fieldValue[$objectType]['name']; $value = $object->getFieldvalue($fieldname); //check if field is an object reference (type objectref) if (preg_match('/objectref-.*/', $configObjecttype->getFieldType($objectType, $fieldname)) == 1) { try { //get referenced object $refObject = $objectController->getObject($value, "yourCMDB-exporter"); //get value of referenced field if configured if ($this->fieldValue[$objectType]['refobjectfield'] != "") { $refFieldname = $this->fieldValue[$objectType]['refobjectfield']; $value = $refObject->getFieldvalue($refFieldname); } } catch (Exception $e) { } } } //return the value return $value; }
public function addObject(\yourCMDB\entities\CmdbObject $object) { //get object information $objectType = $object->getType(); $objectId = $object->getId(); $objectStatus = $object->getStatus(); //get values of ExportVariables dummy1-dummy4 $dummy1Val = "null"; $dummy2Val = "null"; $dummy3Val = "null"; $dummy4Val = "null"; $dummy1 = $this->variables->getVariable("dummy1"); $dummy2 = $this->variables->getVariable("dummy2"); $dummy3 = $this->variables->getVariable("dummy3"); $dummy4 = $this->variables->getVariable("dummy4"); if ($dummy1 != null) { $dummy1Val = $dummy1->getValue($object); } if ($dummy2 != null) { $dummy2Val = $dummy2->getValue($object); } if ($dummy3 != null) { $dummy3Val = $dummy3->getValue($object); } if ($dummy4 != null) { $dummy4Val = $dummy4->getValue($object); } //print object information and variable values echo "exporting object {$objectId} \tof type {$objectType} \tand status {$objectStatus}. "; echo "values of variables dummy1-4: {$dummy1Val}, {$dummy2Val}, {$dummy3Val}, {$dummy4Val}.\n"; }