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