1: <?php
2: /**
3: * This class handles date-related search queries.
4: *
5: * Copyright 2010-2012 Horde LLC (http://www.horde.org/)
6: *
7: * See the enclosed file COPYING for license information (GPL). If you
8: * did not receive this file, see http://www.horde.org/licenses/gpl.
9: *
10: * @author Michael Slusarz <slusarz@horde.org>
11: * @category Horde
12: * @license http://www.horde.org/licenses/gpl GPL
13: * @package IMP
14: */
15: class IMP_Search_Element_Date extends IMP_Search_Element
16: {
17: /* Date types. */
18: const DATE_ON = 1;
19: const DATE_BEFORE = 2;
20: const DATE_SINCE = 3;
21:
22: /**
23: * Constructor.
24: *
25: * @param DateTime $date Date object.
26: * @param integer $type Either:
27: * <pre>
28: * IMP_Search_Element_Date::DATE_ON
29: * IMP_Search_Element_Date::DATE_BEFORE
30: * IMP_Search_Element_Date::DATE_SINCE
31: * </pre>
32: */
33: public function __construct(DateTime $date, $type)
34: {
35: /* Data element:
36: * d = (integer) UNIX timestamp.
37: * t = (integer) Type: one of the self::DATE_* constants. */
38: $this->_data = new stdClass;
39: $this->_data->d = $date->format('U');
40: $this->_data->t = $type;
41: }
42:
43: /**
44: */
45: public function createQuery($mbox, $queryob)
46: {
47: // Cast to timestamp - see PHP Bug #40171/Horde Bug #9513
48: $date = new DateTime('@' . $this->_data->d);
49: $queryob->dateSearch($date, ($this->_data->t == self::DATE_ON) ? Horde_Imap_Client_Search_Query::DATE_ON : (($this->_data->t == self::DATE_BEFORE) ? Horde_Imap_Client_Search_Query::DATE_BEFORE : Horde_Imap_Client_Search_Query::DATE_SINCE));
50:
51: return $queryob;
52: }
53:
54: /**
55: */
56: public function queryText()
57: {
58: switch ($this->_data->t) {
59: case self::DATE_ON:
60: $label = _("Date Equals");
61: break;
62:
63: case self::DATE_BEFORE:
64: $label = _("Date Until");
65: break;
66:
67: case self::DATE_SINCE:
68: $label = _("Date Since");
69: break;
70: }
71:
72: return sprintf("%s '%s'", $label, gmstrftime('%x', $this->_data->d));
73: }
74:
75: }
76: