1: <?php
2: /**
3: * This class provides the Horde specific implementation of the LoginTasks
4: * backend.
5: *
6: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
7: *
8: * See the enclosed file COPYING for license information (LGPL). If you
9: * did not receive this file, see http://www.horde.org/licenses/lgpl21.
10: *
11: * @author Michael Slusarz <slusarz@horde.org>
12: * @author Gunnar Wrobel <wrobel@pardus.de>
13: * @category Horde
14: * @package Core
15: */
16: class Horde_Core_LoginTasks_Backend_Horde extends Horde_LoginTasks_Backend
17: {
18: /**
19: * The Horde application that is currently active.
20: *
21: * @var string
22: */
23: private $_app;
24:
25: /**
26: * Constructor.
27: *
28: * @param string $app The currently active Horde application.
29: */
30: public function __construct($app)
31: {
32: $this->_app = $app;
33: }
34:
35: /**
36: * Retrieve a cached tasklist if it exists.
37: *
38: * @return Horde_LoginTasks_Tasklist|boolean The cached task list or
39: * false if no task list was
40: * cached.
41: */
42: public function getTasklistFromCache()
43: {
44: return $GLOBALS['session']->get('horde', 'logintasks/' . $this->_app);
45: }
46:
47: /**
48: * Store a login tasklist in the cache.
49: *
50: * @param Horde_LoginTasks_Tasklist|boolean $tasklist The tasklist to be
51: * stored.
52: */
53: public function storeTasklistInCache($tasklist)
54: {
55: $GLOBALS['session']->set('horde', 'logintasks/' . $this->_app, $tasklist);
56: }
57:
58: /**
59: * Get the class names of the task classes that need to be performed.
60: *
61: * @return array An array of class names.
62: */
63: public function getTasks()
64: {
65: $tasks = array();
66:
67: foreach (array_merge($GLOBALS['registry']->getAppDrivers($this->_app, 'LoginTasks_SystemTask'), $GLOBALS['registry']->getAppDrivers($this->_app, 'LoginTasks_Task')) as $val) {
68: $tasks[$val] = $this->_app;
69: }
70:
71: return $tasks;
72: }
73:
74: /**
75: * Get the information about the last time the tasks were run. Array keys
76: * are app names, values are last run timestamps. Special key '_once'
77: * contains list of ONCE tasks previously run.
78: *
79: * @return array The information about the last time the tasks were run.
80: */
81: public function getLastRun()
82: {
83: $lasttask_pref = @unserialize($GLOBALS['prefs']->getValue('last_logintasks'));
84:
85: return is_array($lasttask_pref)
86: ? $lasttask_pref
87: : array();
88: }
89:
90: /**
91: * Store the information about the last time the tasks were run.
92: *
93: * @param array $last The information about the last time the tasks were
94: * run.
95: */
96: public function setLastRun(array $last)
97: {
98: $GLOBALS['prefs']->setValue('last_logintasks', serialize($last));
99: }
100:
101: /**
102: * Mark the current time as time the login tasks were run for the last
103: * time.
104: */
105: public function markLastRun()
106: {
107: $lasttasks = $this->getLastRun();
108: $lasttasks[$this->_app] = time();
109: $this->setLastRun($lasttasks);
110: }
111:
112: /**
113: * Redirect to the given URL.
114: *
115: * @param Horde_Url|string $url The URL to redirect to.
116: */
117: public function redirect($url)
118: {
119: $url = new Horde_Url($url);
120: $url->redirect();
121: }
122:
123: /**
124: * Return the URL of the login tasks view.
125: *
126: * @return string The URL of the login tasks view.
127: */
128: public function getLoginTasksUrl()
129: {
130: return Horde::getServiceLink('logintasks', $this->_app);
131: }
132:
133: }
134: