<?php

class core_menuconfig extends module {

    public $_get_vars = ['act', 'id'];

    public function _ajax_addToFav() {
        global $auth;
        if ($auth->is_login() == false) return 'not loginned';
        if (!$this->id) return 'no id';

        $curFavorites = (array)json_decode($auth->user_obj->get('favorite_menu'), true);

        $curFavorites = array_merge($curFavorites, [$this->id]);

        $auth->user_obj->set('favorite_menu', json_encode($curFavorites));
        $auth->user_obj->save();

        return 'ok';
    }

    public function _ajax_delFromFav() {
        global $auth;
        if ($auth->is_login() == false) return 'not loginned';
        if (!$this->id) return 'no id';

        $curFavorites = (array)json_decode($auth->user_obj->get('favorite_menu'), true);

        $curFavorites = array_diff($curFavorites, [$this->id]);
        $auth->user_obj->set('favorite_menu', json_encode($curFavorites));
        $auth->user_obj->save();
        return 'ok';
    }

}

?>