Skip to content

Commit

Permalink
fix deprecated functions & add php doc
Browse files Browse the repository at this point in the history
  • Loading branch information
amma35 committed Aug 8, 2018
1 parent 6d3cdd5 commit a768da9
Show file tree
Hide file tree
Showing 17 changed files with 425 additions and 163 deletions.
4 changes: 2 additions & 2 deletions front/rule.test.php
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@
} else {
$rules_id = 0;
}

if (!$rule = getItemForItemtype($sub_type)) {
$dbu = new DbUtils();
if (!$rule = $dbu->getItemForItemtype($sub_type)) {
exit;
}
$rule->checkGlobal(READ);
Expand Down
2 changes: 1 addition & 1 deletion front/typology.form.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
Html::back();

} else if (isset($_POST["purge"])) {
$typo-->check($_POST['id'], PURGE);
$typo->check($_POST['id'], PURGE);
$typo->delete($_POST, 1);
$typo->redirectToList();

Expand Down
2 changes: 1 addition & 1 deletion front/typology.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
Html::header(PluginTypologyTypology::getTypeName(2), '', "tools", "plugintypologymenu");

$typo = new PluginTypologyTypology();
if ($typo->canView() || haveRight("config", UPDATE)) {
if ($typo->canView() || Session::haveRight("config", UPDATE)) {
Search::show("PluginTypologyTypology");

} else {
Expand Down
105 changes: 64 additions & 41 deletions hook.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
--------------------------------------------------------------------------
*/

/**
* @return bool
*/
function plugin_typology_install() {
global $DB;

Expand All @@ -47,18 +50,18 @@ function plugin_typology_install() {
$query = "UPDATE `glpi_plugin_typology_typologycriterias`
SET `itemtype`='IPAddress'
WHERE `itemtype`='NetworkPort'";
$result=$DB->query($query);
$DB->query($query);

$query = "UPDATE `glpi_plugin_typology_typologycriteriadefinitions`
SET `field`='name;glpi_ipaddresses;itemlink'
WHERE `field` LIKE '%glpi_networkports%'";
$result=$DB->query($query);
$DB->query($query);
}

if ($DB->tableExists("glpi_plugin_typology_profiles")) {

$notepad_tables = ['glpi_plugin_typology_typologies'];

$dbu = new DbUtils();
foreach ($notepad_tables as $t) {
// Migrate data
if ($DB->fieldExists($t, 'notepad')) {
Expand All @@ -69,7 +72,7 @@ function plugin_typology_install() {
foreach ($DB->request($query) as $data) {
$iq = "INSERT INTO `glpi_notepads`
(`itemtype`, `items_id`, `content`, `date`, `date_mod`)
VALUES ('".getItemTypeForTable($t)."', '".$data['id']."',
VALUES ('".$dbu->getItemTypeForTable($t)."', '".$data['id']."',
'".addslashes($data['notepad'])."', NOW(), NOW())";
$DB->queryOrDie($iq, "0.85 migrate notepad data");
}
Expand All @@ -91,6 +94,9 @@ function plugin_typology_install() {
}

// Uninstall process for plugin : need to return true if succeeded
/**
* @return bool
*/
function plugin_typology_uninstall() {
global $DB;

Expand Down Expand Up @@ -163,6 +169,9 @@ function plugin_typology_postinit() {
}

// Define dropdown relations
/**
* @return array
*/
function plugin_typology_getDatabaseRelations() {

$plugin = new Plugin();
Expand All @@ -183,6 +192,11 @@ function plugin_typology_getDatabaseRelations() {
////// SPECIFIC MODIF MASSIVE FUNCTIONS ///////

// Define actions :
/**
* @param $type
*
* @return array
*/
function plugin_typology_MassiveActions($type) {

switch ($type) {
Expand All @@ -202,6 +216,11 @@ function plugin_typology_MassiveActions($type) {
////// SEARCH FUNCTIONS ///////(){

// Define search option for types of the plugins
/**
* @param $itemtype
*
* @return array
*/
function plugin_typology_getAddSearchOptions($itemtype) {

$plugin = new Plugin();
Expand All @@ -210,49 +229,48 @@ function plugin_typology_getAddSearchOptions($itemtype) {
if ($plugin->isActivated('typology')
&& Session::haveRight("plugin_typology", READ)) {
if (in_array($itemtype, PluginTypologyTypology::getTypes(true))) {
$spot[] = [];

$spot[] = [
'id' => 4650,
'table' => 'glpi_plugin_typology_typologies',
'field' => 'name',
'name' => PluginTypologyTypology::getTypeName(1)." - ".
__('Typology\'s name', 'typology'),
'forcegroupby' =>true,
'datatype' => 'itemlink',
'massiveaction' => false,
'itemlink_type' => 'PluginTypologyTypology',
'joinparams' => ['beforejoin'
=> ['table' => 'glpi_plugin_typology_typologies_items',
'joinparams' => ['jointype' => 'itemtype_item']]]
];
$spot[] = [
'id' => 4651,
'table' => 'glpi_plugin_typology_typologies_items',
'field' => 'is_validated',
'datatype' => 'bool',
'massiveaction' => false,
'name' => PluginTypologyTypology::getTypeName(1)." - ".
__('Responding to typology\'s criteria', 'typology'),
'forcegroupby' => true,
'joinparams' => ['jointype' => 'itemtype_item']
];
$spot[] = [
'id' => 4652,
'table' => 'glpi_plugin_typology_typologies_items',
'field' => 'error',
'name' => PluginTypologyTypology::getTypeName(1)." - ".
__('Result details'),
'forcegroupby' => true,
'massiveaction' => false,
'joinparams' => ['jointype' => 'itemtype_item']
];
$sopt[4650]['table'] = 'glpi_plugin_typology_typologies';
$sopt[4650]['field'] = 'name';
$sopt[4650]['name'] = PluginTypologyTypology::getTypeName(1)." - ".
__('Typology\'s name','typology');
$sopt[4650]['forcegroupby'] = true;
$sopt[4650]['datatype'] = 'itemlink';
$sopt[4650]['massiveaction'] = false;
$sopt[4650]['itemlink_type'] = 'PluginTypologyTypology';
$sopt[4650]['joinparams'] = array('beforejoin'
=> array('table' => 'glpi_plugin_typology_typologies_items',
'joinparams' => array('jointype' => 'itemtype_item')));

$sopt[4651]['table'] = 'glpi_plugin_typology_typologies_items';
$sopt[4651]['field'] = 'is_validated';
$sopt[4651]['datatype'] = 'bool';
$sopt[4651]['massiveaction'] = false;
$sopt[4651]['name'] = PluginTypologyTypology::getTypeName(1)." - ".
__('Responding to typology\'s criteria','typology');
$sopt[4651]['forcegroupby'] = true;
$sopt[4651]['joinparams'] = array('jointype' => 'itemtype_item');

$sopt[4652]['table'] = 'glpi_plugin_typology_typologies_items';
$sopt[4652]['field'] = 'error';
$sopt[4652]['name'] = PluginTypologyTypology::getTypeName(1)." - ".
__('Result details');
$sopt[4652]['forcegroupby'] = true;
$sopt[4652]['massiveaction'] = false;
$sopt[4652]['joinparams'] = array('jointype' => 'itemtype_item');

}
}
return $sopt;
}

/**
* @param $type
* @param $ID
* @param $data
* @param $num
*
* @return \nothing|string
*/
function plugin_typology_giveItem($type, $ID, $data, $num) {

$searchopt=&Search::getOptions($type);
Expand Down Expand Up @@ -284,6 +302,11 @@ function plugin_typology_giveItem($type, $ID, $data, $num) {
}

// Do special actions for dynamic report
/**
* @param $parm
*
* @return bool
*/
function plugin_typology_dynamicReport($parm) {

// Return false if no specific display is done, then use standard display
Expand Down
18 changes: 17 additions & 1 deletion inc/menu.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,31 @@
--------------------------------------------------------------------------
*/

/**
* Class PluginTypologyMenu
*/
class PluginTypologyMenu extends CommonGLPI {
static $rightname = 'plugin_typology';

/**
* Get menu name
*
* @since 0.85
*
* @return string character menu shortcut key
**/
static function getMenuName() {
return _n('Typology', 'Typologies', 2, 'typology');
}

/**
* get menu content
*
* @since 0.85
*
* @return array array for menu
**/
static function getMenuContent() {
global $CFG_GLPI;

$menu = [];
$menu['title'] = self::getMenuName();
Expand Down
32 changes: 29 additions & 3 deletions inc/notificationtargettypology.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,33 @@
}

// Class NotificationTarget

/**
* Class PluginTypologyNotificationTargetTypology
*/
class PluginTypologyNotificationTargetTypology extends NotificationTarget {

/**
* Return main notification events for the object type
* Internal use only => should use getAllEvents
*
* @return an array which contains : event => event label
**/
function getEvents() {

return ['AlertNotValidatedTypology' => __('Elements not match with the typology', 'typology')];
}

/**
* Get all data needed for template processing
* Provides minimum information for alerts
* Can be overridden by each NotificationTartget class if needed
*
* @param string $event Event name
* @param array $options Options
*
* @return void
**/
function addDataForTemplate($event, $options = []) {
global $CFG_GLPI;

Expand All @@ -59,6 +79,7 @@ function addDataForTemplate($event, $options = []) {
$this->data['##lang.typology.itemuser##'] = __('User');
$this->data['##lang.typology.itemlocation##'] = __('Location');

$dbu = new DbUtils();
foreach ($options['items'] as $id => $item) {
$tmp = [];

Expand All @@ -72,7 +93,7 @@ function addDataForTemplate($event, $options = []) {
$item['plugin_typology_typologies_id']);
$tmp['##typology.itemurl##'] = urldecode($CFG_GLPI["url_base"]."/index.php?redirect=".
Toolbox::strtolower($item['itemtype'])."_".$item["items_id"]);
$tmp['##typology.itemuser##'] = getUserName($itemtype->fields["users_id"]);
$tmp['##typology.itemuser##'] = $dbu->getUserName($itemtype->fields["users_id"]);
$tmp['##typology.itemlocation##'] = Dropdown::getDropdownName("glpi_locations",
$itemtype->fields['locations_id']);

Expand All @@ -81,6 +102,9 @@ function addDataForTemplate($event, $options = []) {
}
}

/**
* @return array|void
*/
function getTags() {

$tags = ['typology.name' => PluginTypologyTypology::getTypeName(1),
Expand Down Expand Up @@ -122,8 +146,9 @@ public static function install() {
}

if ($templates_id) {
$dbu = new DbUtils();
$translation = new NotificationTemplateTranslation();
if (!countElementsInTable($translation->getTable(), "`notificationtemplates_id`='$templates_id'")) {
if (!$dbu->countElementsInTable($translation->getTable(), "`notificationtemplates_id`='$templates_id'")) {
$tmp['notificationtemplates_id'] = $templates_id;
$tmp['language'] = '';
$tmp['subject'] = '##typology.action## : ##typology.entity##';
Expand Down Expand Up @@ -166,8 +191,9 @@ public static function install() {
];
$notification = new Notification();
$notificationtemplate = new Notification_NotificationTemplate();
$dbu = new DbUtils();
foreach ($notifs as $label => $name) {
if (!countElementsInTable("glpi_notifications", "`itemtype`='PluginTypologyTypology' AND `event`='$name'")) {
if (!$dbu->countElementsInTable("glpi_notifications", "`itemtype`='PluginTypologyTypology' AND `event`='$name'")) {
$tmp = [
'name' => $label,
'entities_id' => 0,
Expand Down
36 changes: 35 additions & 1 deletion inc/profile.class.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,26 @@
die("Sorry. You can't access directly to this file");
}

/**
* Class PluginTypologyProfile
*/
class PluginTypologyProfile extends CommonDBTM {

static $rightname = "profile";

/**
* Get Tab Name used for itemtype
*
* NB : Only called for existing object
* Must check right on what will be displayed + template
*
* @since 0.83
*
* @param CommonGLPI $item Item on which the tab need to be displayed
* @param boolean $withtemplate is a template object ? (default 0)
*
* @return string tab name
**/
public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {

if ($item->getType()=='Profile'
Expand All @@ -44,8 +60,18 @@ public function getTabNameForItem(CommonGLPI $item, $withtemplate = 0) {
return '';
}

/**
* show Tab content
*
* @since 0.83
*
* @param CommonGLPI $item Item on which the tab need to be displayed
* @param integer $tabnum tab number (default 1)
* @param boolean $withtemplate is a template object ? (default 0)
*
* @return boolean
**/
public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $withtemplate = 0) {
global $CFG_GLPI;

if ($item->getType()=='Profile') {
$ID = $item->getID();
Expand All @@ -58,6 +84,9 @@ public static function displayTabContentForItem(CommonGLPI $item, $tabnum = 1, $
return true;
}

/**
* @param $ID
*/
static function createFirstAccess($ID) {
//85
self::addDefaultProfileInfos($ID,
Expand Down Expand Up @@ -126,6 +155,11 @@ function showForm($profiles_id = 0, $openform = true, $closeform = true) {
echo "</div>";
}

/**
* @param bool $all
*
* @return array
*/
static function getAllRights($all = false) {
$rights = [
['itemtype' => 'PluginTypologyTypology',
Expand Down
Loading

0 comments on commit a768da9

Please sign in to comment.