1: <?php
2: /**
3: * Copyright 2010-2014 Horde LLC (http://www.horde.org/)
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: * @category Horde
9: * @copyright 2010-2014 Horde LLC
10: * @license http://www.horde.org/licenses/gpl GPL
11: * @package IMP
12: */
13:
14: /**
15: * Abstract framework for a search query element.
16: *
17: * @author Michael Slusarz <slusarz@horde.org>
18: * @category Horde
19: * @copyright 2010-2014 Horde LLC
20: * @license http://www.horde.org/licenses/gpl GPL
21: * @package IMP
22: */
23: abstract class IMP_Search_Element implements Serializable
24: {
25: /* Serialized version. */
26: const VERSION = 1;
27:
28: /**
29: * Allow NOT search on this element?
30: *
31: * @var boolean
32: */
33: public $not = true;
34:
35: /**
36: * Data for this element.
37: *
38: * @var object
39: */
40: protected $_data;
41:
42: /**
43: * Adds the current query item to the query object.
44: *
45: * @param string $mbox The mailbox to create
46: * the query for.
47: * @param Horde_Imap_Client_Search_Query $queryob The query object.
48: *
49: * @return Horde_Imap_Client_Search_Query The altered query object.
50: */
51: abstract public function createQuery($mbox, $queryob);
52:
53: /**
54: * Return search query text representation.
55: *
56: * @return array The textual description of this search element.
57: */
58: abstract public function queryText();
59:
60: /**
61: * Returns the criteria data for the element.
62: *
63: * @return object The criteria (see each class for the available
64: * properties).
65: */
66: public function getCriteria()
67: {
68: return $this->_data;
69: }
70:
71: /* Serializable methods. */
72:
73: /**
74: * Serialization.
75: *
76: * @return string Serialized data.
77: */
78: public function serialize()
79: {
80: return json_encode(array(
81: self::VERSION,
82: $this->_data
83: ));
84: }
85:
86: /**
87: * Unserialization.
88: *
89: * @param string $data Serialized data.
90: *
91: * @throws Exception
92: */
93: public function unserialize($data)
94: {
95: $data = json_decode($data);
96: if (!is_array($data) ||
97: !isset($data[0]) ||
98: ($data[0] != self::VERSION)) {
99: throw new Exception('Cache version change');
100: }
101:
102: $this->_data = $data[1];
103: }
104:
105: }
106: