CommonDBTM::getForeignKeyField PHP Method

getForeignKeyField() static public method

static public getForeignKeyField ( )
    static function getForeignKeyField()
    {
        if (empty($_SESSION['glpi_foreign_key_field_of'][get_called_class()])) {
            $_SESSION['glpi_foreign_key_field_of'][get_called_class()] = getForeignKeyFieldForTable(static::getTable());
        }
        return $_SESSION['glpi_foreign_key_field_of'][get_called_class()];
    }

Usage Example

 /**
  * @since version 0.85
  *
  * @see CommonDBTM::processMassiveActionsForOneItemtype()
  **/
 static function processMassiveActionsForOneItemtype(MassiveAction $ma, CommonDBTM $item, array $ids)
 {
     $input = $ma->getInput();
     switch ($ma->getAction()) {
         case 'move_under':
             if (isset($input['parent'])) {
                 $fk = $item->getForeignKeyField();
                 $parent = clone $item;
                 if (!$parent->getFromDB($input['parent'])) {
                     $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                     $ma->addMessage($parent->getErrorMessage(ERROR_NOT_FOUND));
                     return;
                 }
                 foreach ($ids as $id) {
                     if ($item->can($id, UPDATE)) {
                         // Check if parent is not a child of the original one
                         if (!in_array($parent->getID(), getSonsOf($item->getTable(), $item->getID()))) {
                             if ($item->update(array('id' => $id, $fk => $parent->getID()))) {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_OK);
                             } else {
                                 $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                                 $ma->addMessage($item->getErrorMessage(ERROR_ON_ACTION));
                             }
                         } else {
                             $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_KO);
                             $ma->addMessage($item->getErrorMessage(ERROR_COMPAT));
                         }
                     } else {
                         $ma->itemDone($item->getType(), $id, MassiveAction::ACTION_NORIGHT);
                         $ma->addMessage($item->getErrorMessage(ERROR_RIGHT));
                     }
                 }
             } else {
                 $ma->itemDone($item->getType(), $ids, MassiveAction::ACTION_KO);
                 $ma->addMessage($parent->getErrorMessage(ERROR_COMPAT));
             }
             return;
     }
     parent::processMassiveActionsForOneItemtype($ma, $item, $ids);
 }
All Usage Examples Of CommonDBTM::getForeignKeyField
CommonDBTM