Skip to content

Commit ff12913

Browse files
authored
fix: Prevent error when classname is null (#798)
1 parent 188f5eb commit ff12913

File tree

1 file changed

+73
-64
lines changed

1 file changed

+73
-64
lines changed

templates/injection.class.tpl

Lines changed: 73 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -2,77 +2,86 @@
22

33
class %%CLASSNAME%%Injection extends %%CLASSNAME%% implements PluginDatainjectionInjectionInterface
44
{
5-
static $rightname = 'plugin_datainjection_model';
5+
static $rightname = 'plugin_datainjection_model';
66
7-
/**
8-
* Return the table used to stor this object
9-
*
10-
* @see CommonDBTM::getTable()
11-
*
12-
* @return string
13-
**/
14-
static function getTable($classname = null) {
15-
return getTableForItemType(get_parent_class($classname));
16-
}
7+
/**
8+
* Return the table used to stor this object
9+
*
10+
* @see CommonDBTM::getTable()
11+
*
12+
* @return string
13+
**/
14+
static function getTable($classname = null) {
15+
if ($classname === null) {
16+
return '';
17+
}
18+
$parent_class = get_parent_class($classname);
1719

18-
static function getTypeName($nb = 0) {
19-
return %%ITEMTYPE%%::getTypeName() . " - %%CONTAINER_NAME%%";
20-
}
20+
if ($parent_class === false) {
21+
return '';
22+
}
2123

22-
/**
23-
* Tells datainjection is the type is a primary type or not
24-
*
25-
* @return iboolean
26-
**/
27-
function isPrimaryType() {
28-
return false;
29-
}
24+
return getTableForItemType($parent_class);
25+
}
3026

31-
/**
32-
* Indicates to with other types it can be connected
33-
*
34-
* @return an array of GLPI types
35-
**/
36-
function connectedTo() {
37-
return array('%%ITEMTYPE%%');
38-
}
27+
static function getTypeName($nb = 0) {
28+
return %%ITEMTYPE%%::getTypeName() . " - %%CONTAINER_NAME%%";
29+
}
3930

40-
/**
41-
* Function which calls getSearchOptions and add more parameters specific to display
42-
*
43-
* @param string $primary_type (default '')
44-
*
45-
* @return array of search options, as defined in each commondbtm object
46-
**/
47-
function getOptions($primary_type='') {
48-
$searchoptions = PluginFieldsContainer::getAddSearchOptions('%%ITEMTYPE%%', %%CONTAINER_ID%%);
31+
/**
32+
* Tells datainjection is the type is a primary type or not
33+
*
34+
* @return iboolean
35+
**/
36+
function isPrimaryType() {
37+
return false;
38+
}
4939

50-
foreach ($searchoptions as $id => $data) {
51-
$searchoptions[$id]['injectable'] = PluginDatainjectionCommonInjectionLib::FIELD_INJECTABLE;
52-
if (!isset($searchoptions[$id]['displaytype'])) {
53-
if (isset($searchoptions[$id]['datatype'])) {
54-
$searchoptions[$id]['displaytype'] = $searchoptions[$id]['datatype'];
55-
} else {
56-
$searchoptions[$id]['displaytype'] = 'text';
40+
/**
41+
* Indicates to with other types it can be connected
42+
*
43+
* @return an array of GLPI types
44+
**/
45+
function connectedTo() {
46+
return array('%%ITEMTYPE%%');
47+
}
48+
49+
/**
50+
* Function which calls getSearchOptions and add more parameters specific to display
51+
*
52+
* @param string $primary_type (default '')
53+
*
54+
* @return array of search options, as defined in each commondbtm object
55+
**/
56+
function getOptions($primary_type='') {
57+
$searchoptions = PluginFieldsContainer::getAddSearchOptions('%%ITEMTYPE%%', %%CONTAINER_ID%%);
58+
59+
foreach ($searchoptions as $id => $data) {
60+
$searchoptions[$id]['injectable'] = PluginDatainjectionCommonInjectionLib::FIELD_INJECTABLE;
61+
if (!isset($searchoptions[$id]['displaytype'])) {
62+
if (isset($searchoptions[$id]['datatype'])) {
63+
$searchoptions[$id]['displaytype'] = $searchoptions[$id]['datatype'];
64+
} else {
65+
$searchoptions[$id]['displaytype'] = 'text';
66+
}
5767
}
58-
}
59-
}
68+
}
6069

61-
return $searchoptions;
62-
}
70+
return $searchoptions;
71+
}
6372

64-
/**
65-
* Standard method to add an object into glpi
66-
*
67-
* @param $values array fields to add into glpi
68-
* @param $options array options used during creation
69-
*
70-
* @return array of IDs of newly created objects:
71-
* for example array(Computer=>1, Networkport=>10)
72-
**/
73-
function addOrUpdateObject($values=array(), $options=array()) {
74-
$lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options);
75-
$lib->processAddOrUpdate();
76-
return $lib->getInjectionResults();
77-
}
73+
/**
74+
* Standard method to add an object into glpi
75+
*
76+
* @param $values array fields to add into glpi
77+
* @param $options array options used during creation
78+
*
79+
* @return array of IDs of newly created objects:
80+
* for example array(Computer=>1, Networkport=>10)
81+
**/
82+
function addOrUpdateObject($values=array(), $options=array()) {
83+
$lib = new PluginDatainjectionCommonInjectionLib($this, $values, $options);
84+
$lib->processAddOrUpdate();
85+
return $lib->getInjectionResults();
86+
}
7887
}

0 commit comments

Comments
 (0)