1: <?php
2: /**
3: * This file contains various to-do classes.
4: *
5: * @package Core
6: * @subpackage Backend
7: * @author Unknown
8: * @copyright four for business AG <www.4fb.de>
9: * @license http://www.contenido.org/license/LIZENZ.txt
10: * @link http://www.4fb.de
11: * @link http://www.contenido.org
12: */
13:
14: defined('CON_FRAMEWORK') || die('Illegal call: Missing framework initialization - request aborted.');
15:
16: /**
17: * This class uses the communication collection to serve a special collection
18: * for to-do entries.
19: *
20: * @package Core
21: * @subpackage GenericDB_Model
22: */
23: class TODOCollection extends cApiCommunicationCollection {
24: /**
25: * Constructor to create an instance of this class.
26: *
27: * @throws cInvalidArgumentException
28: */
29: public function __construct() {
30: parent::__construct();
31: $this->_setItemClass('TODOItem');
32: }
33:
34: /**
35: * Selects all entries from the database.
36: * Objects are loaded using their primary key.
37: *
38: * @param string $where [optional]
39: * Specifies the where clause.
40: * @param string $group_by [optional]
41: * Specifies the group by clause.
42: * @param string $order_by [optional]
43: * Specifies the order by clause.
44: * @param string $limit [optional]
45: * Specifies the limit by clause.
46: *
47: * @return bool
48: * True on success, otherwise false
49: *
50: * @throws cDbException
51: */
52: public function select($where = '', $group_by = '', $order_by = '', $limit = '') {
53: if ($where == '') {
54: $where = "comtype='todo'";
55: } else {
56: $where .= " AND comtype='todo'";
57: }
58:
59: return parent::select($where, $group_by, $order_by, $limit);
60: }
61:
62: /**
63: * Creates a new communication item
64: *
65: * @param string $itemtype
66: * @param int $itemid
67: * @param int|string $reminderdate
68: * if not given as timestamp it is expected to be a string
69: * using the English date format
70: * @param string $subject
71: * @param string $content
72: * @param string $notimail
73: * @param string $notibackend
74: * @param string $recipient
75: *
76: * @return cApiCommunication
77: *
78: * @throws cDbException
79: * @throws cException
80: * @throws cInvalidArgumentException
81: */
82: public function createItem($itemtype, $itemid, $reminderdate, $subject, $content, $notimail, $notibackend, $recipient) {
83: $item = parent::create();
84:
85: $item->set('comtype', 'todo');
86: $item->set('subject', $subject);
87: $item->set('message', $content);
88: $item->set('recipient', $recipient);
89: $item->store();
90:
91: if ($notimail === true) {
92: $notimail = 1;
93: }
94:
95: // Is the date passed as string?
96: if (!is_numeric($reminderdate)) {
97: // Convert to timestamp
98: $reminderdate = strtotime($reminderdate);
99: }
100:
101: $item->setProperty('todo', 'reminderdate', $reminderdate);
102: $item->setProperty('todo', 'itemtype', $itemtype);
103: $item->setProperty('todo', 'itemid', $itemid);
104: $item->setProperty('todo', 'emailnoti', $notimail);
105: $item->setProperty('todo', 'backendnoti', $notibackend);
106: $item->setProperty('todo', 'status', 'new');
107: $item->setProperty('todo', 'priority', 'medium');
108: $item->setProperty('todo', 'progress', '0');
109:
110: return $item;
111: }
112:
113: /**
114: *
115: * @return array
116: */
117: public function getStatusTypes() {
118: return array(
119: 'new' => i18n('New'),
120: 'progress' => i18n('In progress'),
121: 'done' => i18n('Done'),
122: 'waiting' => i18n('Waiting for action'),
123: 'deferred' => i18n('Deferred')
124: );
125: }
126:
127: /**
128: *
129: * @return array
130: */
131: public function getPriorityTypes() {
132: return array(
133: 'low' => i18n('Low'),
134: 'medium' => i18n('Medium'),
135: 'high' => i18n('High'),
136: 'immediately' => i18n('Immediately')
137: );
138: }
139: }
140:
141: /**
142: * This class uses the communication collection to serve a special collection
143: * for to-do entries.
144: *
145: * @package Core
146: * @subpackage GenericDB_Model
147: */
148: class TODOItem extends cApiCommunication
149: {
150: /**
151: * Sets a custom property.
152: *
153: * @see Item::setProperty()
154: *
155: * @param string $type
156: * Specifies the type
157: * @param string $name
158: * Specifies the name
159: * @param mixed $value
160: * Specifies the value
161: * @param int $client [optional]
162: * unused (should be "Id of client to set property for")
163: *
164: * @return bool
165: *
166: * @throws cDbException
167: * @throws cException
168: * @throws cInvalidArgumentException
169: */
170: public function setProperty($type, $name, $value, $client = 0) {
171: if ($type == 'todo' && $name == 'emailnoti') {
172: if ($value) {
173: parent::setProperty('todo', 'emailnoti-sent', false);
174: $value = true;
175: } else {
176: $value = false;
177: }
178: }
179:
180: return parent::setProperty($type, $name, $value);
181: }
182: }
183:
184: /**
185: * This class uses the link GUI class to serve a special link for to-do entries.
186: *
187: * @package Core
188: * @subpackage GUI
189: */
190: class TODOLink extends cHTMLLink {
191:
192: /**
193: * Constructor to create an instance of this class.
194: *
195: * @param string $itemtype
196: * @param int $itemid
197: * @param string $subject
198: * @param string $message
199: */
200: public function __construct($itemtype, $itemid, $subject, $message) {
201: global $sess;
202: parent::__construct();
203:
204: $subject = urlencode($subject);
205: $message = urlencode($message);
206:
207: $this->setEvent('click', 'javascript:window.open(' . "'" . $sess->url("main.php?subject=$subject&message=$message&area=todo&frame=1&itemtype=$itemtype&itemid=$itemid") . "', 'todo', 'scrollbars=yes,resizable=yes,height=350,width=625');");
208: $this->setEvent('mouseover', "this.style.cursor='pointer'");
209:
210: $img = new cHTMLImage('images/but_setreminder.gif');
211: $img->setClass("vAlignMiddle tableElement");
212:
213: $img->setAlt(i18n('Set reminder / add to todo list'));
214: $this->setLink('#');
215: $this->setContent($img->render());
216: $this->setAlt(i18n('Set reminder / add to todo list'));
217: }
218: }
219: