1: <?php
2: /**
3: * The base functionality of the tasklists handler.
4: *
5: * See the enclosed file COPYING for license information (GPL). If you
6: * did not receive this file, see http://www.horde.org/licenses/gpl.
7: *
8: * @author Gunnar Wrobel <wrobel@pardus.de>
9: * @package Nag
10: */
11: abstract class Nag_Tasklists_Base
12: {
13: /**
14: * The share backend.
15: *
16: * @var Horde_Share_Base
17: */
18: protected $shares;
19:
20: /**
21: * The current user.
22: *
23: * @var string
24: */
25: protected $user;
26:
27: /**
28: * Additional parameters for the tasklist handling.
29: *
30: * @var array
31: */
32: protected $params;
33:
34: /**
35: * Constructor.
36: *
37: * @param Horde_Share_Base $shares The share backend.
38: * @param string $user The current user.
39: * @param array $params Additional parameters.
40: */
41: public function __construct($shares, $user, $params)
42: {
43: $this->shares = $shares;
44: $this->user = $user;
45: $this->params = $params;
46: }
47:
48: /**
49: * Ensure the share system has a default tasklist share for the current user
50: * if the default share feature is activated.
51: *
52: * @return string|NULL The id of the new default share or NULL if no share
53: * was created.
54: */
55: public function ensureDefaultShare()
56: {
57: /* If the user doesn't own a task list, create one. */
58: if (!empty($this->params['auto_create']) && $this->user &&
59: !count(Nag::listTasklists(true))) {
60: $share = $this->shares->newShare(
61: $this->user,
62: strval(new Horde_Support_Randomid()),
63: $this->getDefaultShareName()
64: );
65: $this->shares->addShare($share);
66: return $share->getName();
67: }
68: }
69:
70: /**
71: * Return the name of the default share.
72: *
73: * @return string The name of a default share.
74: */
75: abstract protected function getDefaultShareName();
76: }