savedsearch.inc.php
3.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
<?php
require_once(KT_LIB_DIR . '/ktentity.inc');
/**
* Saved searches allow for common searches to be saved.
*
* There are two main purposes - saving search setup time for users, and
* creating conditions on documents that will determine if someone has
* permission on the document or if a workflow process can continue.
*/
class KTSavedSearch extends KTEntity {
/**
* Human-understandable name for the search.
*
* Only unique in combination with iUserId.
*/
var $sName;
/**
* Unique name to look up or add a search from a plugin.
*/
var $sNamespace;
/**
* Whether the search is a user-saved search or a document
* condition.
*/
var $bIsCondition = false;
/**
* Determines if the search is complete already, or if it needs
* certain fields to be filled in. (XXX: Not implemented yet)
*/
var $bIsComplete = true;
/**
* Which user saved this search. If no user is given, it is a
* system-wide search.
*/
var $iUserId;
/**
* The saved search in an array. This is serialised before it is
* written into the database.
*/
var $aSearch;
// {{{ KTEntity setup
var $_aFieldToSelect = array(
"iId" => "id",
"sName" => "name",
"sNamespace" => "namespace",
"bIsCondition" => "is_condition",
"bIsComplete" => "is_complete",
"iUserId" => "user_id",
"aSearch" => "search",
);
var $_bUsePearError = true;
function _table () {
global $default;
return $default->saved_searches_table;
}
function _fieldValues () {
$aRet = parent::_fieldValues();
$aRet['search'] = base64_encode(serialize($aRet['search']));
return $aRet;
}
function load($iId) {
$res = parent::load($iId);
if (PEAR::isError($res)) {
return $res;
}
$this->aSearch = unserialize(base64_decode($this->aSearch));
return $res;
}
// }}}
function getId() { return $this->iId; }
function getName() { return $this->sName; }
function getNamespace() { return $this->sNamespace; }
function getIsCondition() { return $this->bIsCondition; }
function getIsComplete() { return $this->bIsComplete; }
function getUserId() { return $this->iUserId; }
function getSearch() { return $this->aSearch; }
function setId($iId) { $this->iId = $iId; }
function setName($sName) { $this->sName = $sName; }
function setNamespace($sNamespace) { $this->sNamespace = $sNamespace; }
function setIsCondition($bIsCondition) { $this->bIsCondition = $bIsCondition; }
function setIsComplete($bIsComplete) { $this->bIsComplete = $bIsComplete; }
function setUserId($iUserId) { $this->iUserId = $iUserId; }
function setSearch($aSearch) { $this->aSearch = $aSearch; }
function &createFromArray($aValues) {
return KTEntityUtil::createFromArray('KTSavedSearch', $aValues);
}
function &getByNamespace($sNamespace) {
return KTEntityUtil::getBy('KTSavedSearch', 'namespace', $sNamespace);
}
function &get($iId) {
return KTEntityUtil::get('KTSavedSearch', $iId);
}
function &getList($sWhereClause = null) {
return KTEntityUtil::getList2('KTSavedSearch', $sWhereClause);
}
function &getSearches() {
return KTEntityUtil::getByDict('KTSavedSearch', array(
'is_condition' => false,
), array(
'multi' => true,
));
}
function &getConditions() {
return KTEntityUtil::getByDict('KTSavedSearch', array(
'is_condition' => true,
), array(
'multi' => true,
));
}
function &getSystemSearches($sWhereClause = null) {
return KTEntityUtil::getByDict('KTSavedSearch', array(
'is_condition' => false,
'user_id' => null,
), array(
'multi' => true,
'noneok' => true,
));
}
}