connection Database connection object protected $table; ///< string Prefs table name protected $user_id; ///< string User ID protected $workspaces = array(); ///< array Associative workspaces array protected $ws; ///< string Current workspace /** Object constructor. Retrieves user prefs and puts them in $workspaces array. Local (user) prefs have a highest priority than global prefs. @param core dcCore dcCore object @param user_id string User ID */ public function __construct($core,$user_id) { $this->con =& $core->con; $this->table = $core->prefix.'pref'; $this->user_id =& $user_id; //~ $this->loadPrefs(); } /** Retrieves all workspaces (and their prefs) from database, with one query. */ public function loadPrefs() { $strReq = 'SELECT user_id, pref_id, pref_value, '. 'pref_type, pref_label, pref_ws '. 'FROM '.$this->table.' '. "WHERE user_id = '".$this->con->escape($this->user_id)."' ". 'OR user_id IS NULL '. 'ORDER BY pref_ws ASC, pref_id ASC'; try { $rs = $this->con->select($strReq); } catch (Exception $e) { trigger_error(__('Unable to retrieve workspaces:').' '.$this->con->error(), E_USER_ERROR); throw $e; } /* Prevent empty tables (install phase, for instance) */ if ($rs->isEmpty()) { return; } do { $ws = trim($rs->f('pref_ws')); if (!$rs->isStart()) { // we have to go up 1 step, since workspaces construction performs a fetch() // at very first time $rs->movePrev(); } $this->workspaces[$ws] = new dcWorkspace($GLOBALS['core'], $this->user_id, $ws,$rs); } while(!$rs->isStart()); } /** Create a new workspace. If the workspace already exists, return it without modification. @param ws string Workspace name @return dcWorkspace The workspace created */ public function addWorkspace($ws) { if (!array_key_exists($ws, $this->workspaces)) { $this->workspaces[$ws] = new dcWorkspace($GLOBALS['core'], $this->user_id, $ws); } return $this->workspaces[$ws]; } /** Returns full workspace with all prefs pertaining to it. @param ws string Workspace name @return dcWorkspace */ public function get($ws) { if (array_key_exists($ws, $this->workspaces)) { return $this->workspaces[$ws]; } return null; } /** Magic __get method. @copydoc ::get */ public function __get($n) { return $this->get($n); } /** Returns $workspaces property content. @return array */ public function dumpWorkspaces() { return $this->workspaces; } } ?>