NotificationTarget::updateTargets PHP Method

updateTargets() static public method

static public updateTargets ( $input )
$input
    static function updateTargets($input)
    {
        $type = "";
        $action = "";
        $target = self::getInstanceByType($input['itemtype']);
        if (!isset($input['notifications_id'])) {
            return;
        }
        $targets = getAllDatasFromTable('glpi_notificationtargets', 'notifications_id = ' . $input['notifications_id']);
        $actives = array();
        if (count($targets)) {
            foreach ($targets as $data) {
                $actives[$data['type'] . '_' . $data['items_id']] = $data['type'] . '_' . $data['items_id'];
            }
        }
        // Be sure to have items once
        $actives = array_unique($actives);
        if (isset($input['_targets']) && count($input['_targets'])) {
            // Be sure to have items once
            $input['_targets'] = array_unique($input['_targets']);
            foreach ($input['_targets'] as $val) {
                // Add if not set
                if (!isset($actives[$val])) {
                    list($type, $items_id) = explode("_", $val);
                    $tmp = array();
                    $tmp['items_id'] = $items_id;
                    $tmp['type'] = $type;
                    $tmp['notifications_id'] = $input['notifications_id'];
                    $target->add($tmp);
                }
                unset($actives[$val]);
            }
        }
        // Drop others
        if (count($actives)) {
            foreach ($actives as $val) {
                list($type, $items_id) = explode("_", $val);
                if ($target->getFromDBForTarget($input['notifications_id'], $type, $items_id)) {
                    $target->delete(array('id' => $target->getID()));
                }
            }
        }
    }

Usage Example

based on GLPI - Gestionnaire Libre de Parc Informatique
Copyright (C) 2003-2014 by the INDEPNET Development Team.

-------------------------------------------------------------------------

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/>.
--------------------------------------------------------------------------
*/
/** @file
* @brief
*/
include '../inc/includes.php';
Session::checkCentralAccess();
NotificationTarget::updateTargets($_POST);
Html::back();