mirror of
https://github.com/pluginsGLPI/example.git
synced 2025-05-04 18:08:42 +02:00
Add CommonDBChild inherited class sample
git-svn-id: https://forge.glpi-project.org/svn/example/trunk@204 349b9182-4a13-0410-896f-e5e9767dd1b3
This commit is contained in:
parent
5fadd64292
commit
c3b401049c
@ -72,7 +72,7 @@ avec l'une des ressources techniques
|
||||
--- Dépendances (uniquement testé avec ces configurations)
|
||||
*************************************************************************************************************
|
||||
|
||||
1) Apache 1.3.>6 avec PHP 4 ou PHP 5
|
||||
1) Apache 1.3.>6 avec PHP 5.3.0
|
||||
2) MySQL 4.2 et supérieures
|
||||
3) Javascript activé
|
||||
|
||||
|
102
inc/child.class.php
Normal file
102
inc/child.class.php
Normal file
@ -0,0 +1,102 @@
|
||||
<?php
|
||||
/*
|
||||
* @version $Id: HEADER 15930 2011-10-25 10:47:55Z jmd $
|
||||
-------------------------------------------------------------------------
|
||||
GLPI - Gestionnaire Libre de Parc Informatique
|
||||
Copyright (C) 2003-2011 by the INDEPNET Development Team.
|
||||
|
||||
http://indepnet.net/ http://glpi-project.org
|
||||
-------------------------------------------------------------------------
|
||||
|
||||
LICENSE
|
||||
|
||||
This file is part of GLPI.
|
||||
|
||||
GLPI is free software; you can redistribute it and/or modify
|
||||
it under the terms of the GNU General Public License as published by
|
||||
the Free Software Foundation; either version 2 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
GLPI is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU General Public License
|
||||
along with GLPI. If not, see <http://www.gnu.org/licenses/>.
|
||||
--------------------------------------------------------------------------
|
||||
*/
|
||||
|
||||
// ----------------------------------------------------------------------
|
||||
// Original Author of file:
|
||||
// Purpose of file:
|
||||
// ----------------------------------------------------------------------
|
||||
|
||||
// Sample of class that inherit from CommonDBChild. The behaviour of CommonRelation is similar.
|
||||
// The main evolution introduced by 0.84 version of GLPI is a stronger control and log of
|
||||
// interactions. We suggest you to refer to the header of CommonDBConnexity class to see these
|
||||
// enhancements.
|
||||
// For CommonDBRelation, the variable are quiet equivalent, but they use _1 and _2 for each side
|
||||
// parent
|
||||
class PluginExampleChild extends CommonDBChild {
|
||||
|
||||
// A child rely on an item. If $itemtype=='itemtype', then that is a variable item.
|
||||
static public $itemtype = 'itemtype';
|
||||
static public $items_id = 'items_id';
|
||||
|
||||
|
||||
// With 0.84, you have to specify each right (create, view, update and delete), because
|
||||
// CommonDBChild(s) and CommonDBRelation(s) mainly depend on the rights on the parent item
|
||||
// All these methods rely on parent:can*. Two attributs are usefull :
|
||||
// * $checkParentRights: define what to check regarding the parent :
|
||||
// - CommonDBConnexity::DONT_CHECK_ITEM_RIGHTS don't eaven relly on parents rights
|
||||
// - CommonDBConnexity::HAVE_VIEW_RIGHT_ON_ITEM view right on the item is enough
|
||||
// - CommonDBConnexity::HAVE_SAME_RIGHT_ON_ITEM we must have at least update right
|
||||
// on the item
|
||||
// * $mustBeAttached: some CommonDBChild can be free, without any parent.
|
||||
static function canCreate() {
|
||||
|
||||
return (Session::haveRight('internet', 'w')
|
||||
&& parent::canCreate());
|
||||
}
|
||||
|
||||
|
||||
static function canView() {
|
||||
|
||||
return (Session::haveRight('internet', 'r')
|
||||
&& parent::canView());
|
||||
}
|
||||
|
||||
|
||||
static function canUpdate() {
|
||||
|
||||
return (Session::haveRight('internet', 'w')
|
||||
&& parent::canUpdate());
|
||||
}
|
||||
|
||||
|
||||
static function canDelete() {
|
||||
|
||||
return (Session::haveRight('internet', 'w')
|
||||
&& parent::canDelete());
|
||||
}
|
||||
|
||||
|
||||
// By default, post_addItem, post_updateItem and post_deleteFromDB are defined.
|
||||
// They define the history to add to the parents
|
||||
// This method define the name to set inside the history of the parent.
|
||||
// All these methods use $log_history_add, $log_history_update and $log_history_delete to
|
||||
// define the level of log (Log::HISTORY_ADD_DEVICE, Log::HISTORY_UPDATE_DEVICE ...)
|
||||
function getHistoryName_for_item($case) {
|
||||
}
|
||||
|
||||
// CommonDBChild also check if we can add or updatethe item regarding the new item
|
||||
// ($input[static::$itemtype] and $input[static::$items_id]).
|
||||
// But don't forget to call parent::prepareInputForAdd()
|
||||
function prepareInputForAdd($input) {
|
||||
// My preparation on $input
|
||||
return parent::prepareInputForAdd($input);
|
||||
}
|
||||
|
||||
}
|
||||
?>
|
Loading…
x
Reference in New Issue
Block a user