Skip to content

Commit

Permalink
fix: Prevent error when classname is null (#798)
Browse files Browse the repository at this point in the history
  • Loading branch information
Rom1-B authored Jun 25, 2024
1 parent 188f5eb commit ff12913
Showing 1 changed file with 73 additions and 64 deletions.
137 changes: 73 additions & 64 deletions templates/injection.class.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,77 +2,86 @@

class %%CLASSNAME%%Injection extends %%CLASSNAME%% implements PluginDatainjectionInjectionInterface
{
static $rightname = 'plugin_datainjection_model';
static $rightname = 'plugin_datainjection_model';
/**
* Return the table used to stor this object
*
* @see CommonDBTM::getTable()
*
* @return string
**/
static function getTable($classname = null) {
return getTableForItemType(get_parent_class($classname));
}
/**
* Return the table used to stor this object
*
* @see CommonDBTM::getTable()
*
* @return string
**/
static function getTable($classname = null) {
if ($classname === null) {
return '';
}
$parent_class = get_parent_class($classname);

static function getTypeName($nb = 0) {
return %%ITEMTYPE%%::getTypeName() . " - %%CONTAINER_NAME%%";
}
if ($parent_class === false) {
return '';
}

/**
* Tells datainjection is the type is a primary type or not
*
* @return iboolean
**/
function isPrimaryType() {
return false;
}
return getTableForItemType($parent_class);
}

/**
* Indicates to with other types it can be connected
*
* @return an array of GLPI types
**/
function connectedTo() {
return array('%%ITEMTYPE%%');
}
static function getTypeName($nb = 0) {
return %%ITEMTYPE%%::getTypeName() . " - %%CONTAINER_NAME%%";
}

/**
* Function which calls getSearchOptions and add more parameters specific to display
*
* @param string $primary_type (default '')
*
* @return array of search options, as defined in each commondbtm object
**/
function getOptions($primary_type='') {
$searchoptions = PluginFieldsContainer::getAddSearchOptions('%%ITEMTYPE%%', %%CONTAINER_ID%%);
/**
* Tells datainjection is the type is a primary type or not
*
* @return iboolean
**/
function isPrimaryType() {
return false;
}

foreach ($searchoptions as $id => $data) {
$searchoptions[$id]['injectable'] = PluginDatainjectionCommonInjectionLib::FIELD_INJECTABLE;
if (!isset($searchoptions[$id]['displaytype'])) {
if (isset($searchoptions[$id]['datatype'])) {
$searchoptions[$id]['displaytype'] = $searchoptions[$id]['datatype'];
} else {
$searchoptions[$id]['displaytype'] = 'text';
/**
* Indicates to with other types it can be connected
*
* @return an array of GLPI types
**/
function connectedTo() {
return array('%%ITEMTYPE%%');
}

/**
* Function which calls getSearchOptions and add more parameters specific to display
*
* @param string $primary_type (default '')
*
* @return array of search options, as defined in each commondbtm object
**/
function getOptions($primary_type='') {
$searchoptions = PluginFieldsContainer::getAddSearchOptions('%%ITEMTYPE%%', %%CONTAINER_ID%%);
foreach ($searchoptions as $id => $data) {
$searchoptions[$id]['injectable'] = PluginDatainjectionCommonInjectionLib::FIELD_INJECTABLE;
if (!isset($searchoptions[$id]['displaytype'])) {
if (isset($searchoptions[$id]['datatype'])) {
$searchoptions[$id]['displaytype'] = $searchoptions[$id]['datatype'];
} else {
$searchoptions[$id]['displaytype'] = 'text';
}
}
}
}
}

return $searchoptions;
}
return $searchoptions;
}

/**
* Standard method to add an object into glpi
*
* @param $values array fields to add into glpi
* @param $options array options used during creation
*
* @return array of IDs of newly created objects:
* for example array(Computer=>1, Networkport=>10)
**/
function addOrUpdateObject($values=array(), $options=array()) {
$lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options);
$lib->processAddOrUpdate();
return $lib->getInjectionResults();
}
/**
* Standard method to add an object into glpi
*
* @param $values array fields to add into glpi
* @param $options array options used during creation
*
* @return array of IDs of newly created objects:
* for example array(Computer=>1, Networkport=>10)
**/
function addOrUpdateObject($values=array(), $options=array()) {
$lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options);
$lib->processAddOrUpdate();
return $lib->getInjectionResults();
}
}

0 comments on commit ff12913

Please sign in to comment.