Profile::cleanProfile PHP Method

cleanProfile() public method

Unset unused rights for helpdesk
public cleanProfile ( )
    function cleanProfile()
    {
        if ($this->fields["interface"] == "helpdesk") {
            foreach ($this->fields as $key => $val) {
                if (!in_array($key, self::$common_fields) && !in_array($key, self::$helpdesk_rights)) {
                    unset($this->fields[$key]);
                }
            }
        }
        // decode array
        if (isset($this->fields["helpdesk_item_type"]) && !is_array($this->fields["helpdesk_item_type"])) {
            $this->fields["helpdesk_item_type"] = importArrayFromDB($this->fields["helpdesk_item_type"]);
        }
        // Empty/NULL case
        if (!isset($this->fields["helpdesk_item_type"]) || !is_array($this->fields["helpdesk_item_type"])) {
            $this->fields["helpdesk_item_type"] = array();
        }
        // Decode status array
        $fields_to_decode = array('ticket_status', 'problem_status', 'change_status');
        foreach ($fields_to_decode as $val) {
            if (isset($this->fields[$val]) && !is_array($this->fields[$val])) {
                $this->fields[$val] = importArrayFromDB($this->fields[$val]);
                // Need to be an array not a null value
                if (is_null($this->fields[$val])) {
                    $this->fields[$val] = array();
                }
            }
        }
    }

Usage Example

コード例 #1
0
/**
 * Change active profile to the $ID one. Update glpiactiveprofile session variable.
 *
 * @param $ID : ID of the new profile
 *
 * @return Nothing
**/
function changeProfile($ID)
{
    if (isset($_SESSION['glpiprofiles'][$ID]) && count($_SESSION['glpiprofiles'][$ID]['entities'])) {
        $profile = new Profile();
        if ($profile->getFromDB($ID)) {
            $profile->cleanProfile();
            $data = $profile->fields;
            $data['entities'] = $_SESSION['glpiprofiles'][$ID]['entities'];
            $_SESSION['glpiactiveprofile'] = $data;
            $_SESSION['glpiactiveentities'] = array();
            Search::resetSaveSearch();
            $active_entity_done = false;
            // Try to load default entity if it is a root entity
            foreach ($data['entities'] as $key => $val) {
                if ($val['id'] == $_SESSION["glpidefault_entity"]) {
                    if (changeActiveEntities($val['id'], $val['is_recursive'])) {
                        $active_entity_done = true;
                    }
                }
            }
            if (!$active_entity_done) {
                // Try to load default entity
                if (!changeActiveEntities($_SESSION["glpidefault_entity"], true)) {
                    // Load all entities
                    changeActiveEntities("all");
                }
            }
            doHook("change_profile");
        }
    }
    // Clean specific datas
    if (isset($_SESSION['glpi_faqcategories'])) {
        unset($_SESSION['glpi_faqcategories']);
    }
}
All Usage Examples Of Profile::cleanProfile