_session = new Zend_Session_Namespace($taskType, true); if (isset($this->_session->tasks)) { $this->_tasks = $this->_session->tasks; } if ($clear === true) { $this->clearTasks(); } } /** * Returns the task manager instance * * @param string $configname The name of the configuration file to load. * If not set we will load the config from * session if present. * @param boolean $forceLoading If set the config will be read from file. * * @return Msd_Configuration */ public static function getInstance($taskType = 'backupTasks', $clear = false) { if (null == self::$_instance) { self::$_instance = new self($taskType, $clear); } return self::$_instance; } /** * Add a task * * @param string $type Type of tasks * @param array $options Option array * * @return void */ public function addTask($type, $options = array()) { $tasks = $this->_tasks; if (empty($tasks[$type])) { $tasks[$type] = array(); } $tasks[$type][] = $options; $this->_tasks = $tasks; $this->_saveTasksToSession(); } /** * Get tasks of given type * * Returns false if type is not present in task list. * * @param string $type * * @return array|false */ public function getTasks($type = '') { if ($type > '') { if (!isset($this->_tasks[$type])) { return false; } return $this->_tasks[$type]; } return $this->_tasks; } /** * Reset tasks array * * @return void */ public function clearTasks() { $this->_tasks = array(); $this->_saveTasksToSession(); } /** * Remove the first task of the given type * * @param string $type * * @return void */ public function removeActualTask($type) { $tasks = $this->getTasks($type); print_r($tasks); if ($tasks === false) { return; } if (empty($tasks)) { // no task of that type left - remove type unset($this->_tasks[$type]); } unset($tasks[0]); //rebuild index sort($tasks); $this->_tasks[$type] = $tasks; $this->_saveTasksToSession(); } /** * Return the first task of given type or false if there is none. * * @param $type The type of the task to get. * * @return array|false */ public function getActualTask($type) { $tasks = $this->getTasks($type); if (isset($tasks[0])) { return $tasks[0]; }; return false; } /** * Save task list to session * * @return void */ private function _saveTasksToSession() { $this->_session->tasks = $this->_tasks; } }