Skip to content
Permalink
Browse files

Simple Devices fix

* Simple Devices auto-numeration for new objects fix
  • Loading branch information...
sergejey committed Apr 9, 2019
1 parent 301875b commit 0129c7d96ef333c3ca76065d57f1b5d85ed7efc8
Showing with 11 additions and 3 deletions.
  1. +9 −2 modules/devices/devices.class.php
  2. +2 −1 modules/devices/devices_edit.inc.php
@@ -252,9 +252,15 @@ function getAllMethods($type)
return $methods;
}
function getNewObjectIndex($class)
function getNewObjectIndex($class, $prefix = '')
{
$objects = getObjectsByClass($class);
if ($prefix!='') {
$other_objects=SQLSelect("SELECT TITLE FROM objects WHERE TITLE LIKE '".$prefix."%'");
foreach($other_objects as $obj) {
$objects[]=$obj;
}
}
$index = 0;
$total = count($objects);
for ($i = 0; $i < $total; $i++) {
@@ -944,7 +950,8 @@ function addDevice($device_type, $options = 0)
}
if (!$rec['LINKED_OBJECT']) {
$new_object_title = ucfirst($rec['TYPE']) . $this->getNewObjectIndex($type_details['CLASS']);
$prefix=ucfirst($rec['TYPE']);
$new_object_title = $prefix . $this->getNewObjectIndex($type_details['CLASS']);
$object_id = addClassObject($type_details['CLASS'], $new_object_title, 'sdevice' . $rec['ID']);
$rec['LINKED_OBJECT'] = $new_object_title;
if (preg_match('/New device .+/', $rec['TITLE'])) {
@@ -338,7 +338,8 @@
$type_details = $this->getTypeDetails($rec['TYPE']);
if (!$rec['LINKED_OBJECT'] && $out['ADD_OBJECT']) {
$new_object_title = $out['PREFIX'] . ucfirst($rec['TYPE']) . $this->getNewObjectIndex($type_details['CLASS']);
$prefix = $out['PREFIX'] . ucfirst($rec['TYPE']);
$new_object_title = $prefix . $this->getNewObjectIndex($type_details['CLASS'],$prefix);
$object_id = addClassObject($type_details['CLASS'], $new_object_title, 'sdevice' . $rec['ID']);
$rec['LINKED_OBJECT'] = $new_object_title;
SQLUpdate('devices', $rec);

0 comments on commit 0129c7d

Please sign in to comment.
You can’t perform that action at this time.