Ejemplo n.º 1
0
 /**
  * During resource or employment transfer
  *
  * @static
  * @param $ID
  * @param $entity
  * @return ID|int|the
  */
 static function transfer($ID, $entity)
 {
     global $DB;
     if ($ID > 0) {
         // Not already transfer
         // Search init item
         $query = "SELECT *\n                   FROM `glpi_plugin_resources_professions`\n                   WHERE `id` = '{$ID}'";
         if ($result = $DB->query($query)) {
             if ($DB->numrows($result)) {
                 $data = $DB->fetch_assoc($result);
                 $data = Toolbox::addslashes_deep($data);
                 $input['name'] = $data['name'];
                 $input['entities_id'] = $entity;
                 $temp = new self();
                 $newID = $temp->getID($input);
                 if ($newID < 0) {
                     $newID = $temp->import($input);
                 }
                 //transfer of the linked line
                 $line = PluginResourcesProfessionLine::transfer($temp->fields["plugin_resources_professionlines_id"], $entity);
                 if ($line > 0) {
                     $values["id"] = $newID;
                     $values["plugin_resources_professionlines_id"] = $line;
                     $temp->update($values);
                 }
                 //transfer of the linked category
                 $category = PluginResourcesProfessionCategory::transfer($temp->fields["plugin_resources_professioncategories_id"], $entity);
                 if ($category > 0) {
                     $values["id"] = $newID;
                     $values["plugin_resources_professioncategories_id"] = $category;
                     $temp->update($values);
                 }
                 return $newID;
             }
         }
     }
     return 0;
 }