<?php

Lib::loadClass('UserProfile');

/**
 * User Bookmark
 * $_SESSION['USER_PROFILE'][section][key] = val;
 */
class UserBookmarks {

	private $_sesKey = 'UserBookmarksList';

	public function __construct() {
		UserProfile::load();
	}

	public static function getInstance() {
		$userBookmarks = new UserBookmarks();
		return $userBookmarks;
	}

	public function getBookmarks() {
		$bookmarks = array();
		if (!empty($_SESSION['USER_PROFILE'][$this->_sesKey])) {
			$bookmarks = $_SESSION['USER_PROFILE'][$this->_sesKey];
		}
		return $bookmarks;
	}

	/*
	 * Add bookmark
	 */
	public function addBookmark($zasobID) {
		if (!array_key_exists($zasobID, $_SESSION['USER_PROFILE'][$this->_sesKey])) {
			$_SESSION['USER_PROFILE'][$this->_sesKey][$zasobID] = '';
		}
	}

	public function changeBookmark($zasobID, $cls) {
		$_SESSION['USER_PROFILE'][$this->_sesKey][$zasobID] = $cls;
	}

	public function hasBookmark($zasobID) {
		return array_key_exists($zasobID, $_SESSION['USER_PROFILE'][$this->_sesKey]);
	}

	public function removeBookmark($zasobID) {
		$bookmarks = array();
		foreach ($_SESSION['USER_PROFILE'][$this->_sesKey] as $kZasobID => $vClass) {
			if ($kZasobID == $zasobID) continue;
			$bookmarks[$kZasobID]= $vClass;
		}
		$_SESSION['USER_PROFILE'][$this->_sesKey] = $bookmarks;
	}

}
