Tinebase_Mode_Tree_Node_Filter - added acl_node filter property
[tine20] / tine20 / Tinebase / Model / Tree / Node / Filter.php
1 <?php
2 /**
3  * Tine 2.0
4  * 
5  * @package     Tinebase
6  * @subpackage  Filter
7  * @license     http://www.gnu.org/licenses/agpl.html AGPL Version 3
8  * @author      Lars Kneschke <l.kneschke@metaways.de>
9  * @copyright   Copyright (c) 2010-2017 Metaways Infosystems GmbH (http://www.metaways.de)
10  */
11
12 /**
13  * tree node filter class
14  * 
15  * @package     Tinebase
16  * @subpackage  Filter
17  */
18 class Tinebase_Model_Tree_Node_Filter extends Tinebase_Model_Filter_GrantsFilterGroup
19 {
20     /**
21      * @var string class name of this filter group
22      *      this is needed to overcome the static late binding
23      *      limitation in php < 5.3
24      */
25     protected $_className = 'Tinebase_Model_Tree_Node_Filter';
26     
27     /**
28      * @var string application of this filter group
29      */
30     protected $_applicationName = 'Tinebase';
31     
32     /**
33      * @var string name of model this filter group is designed for
34      */
35     protected $_modelName = 'Tinebase_Model_Tree_Node';
36
37     /**
38      * @var string acl table name
39      */
40     protected $_aclTableName = 'tree_node_acl';
41
42     /**
43      * @var string acl record column for join with acl table
44      */
45     protected $_aclIdColumn = 'acl_node';
46
47     /**
48      * @var array filter model fieldName => definition
49      */
50     protected $_filterModel = array(
51         'query'                 => array(
52             'filter' => 'Tinebase_Model_Filter_Query', 
53             'options' => array('fields' => array('name', 'content', 'description'))
54         ),
55         'id'                    => array('filter' => 'Tinebase_Model_Filter_Id'),
56         'path'                  => array('filter' => 'Tinebase_Model_Tree_Node_PathFilter'),
57         'parent_id'             => array('filter' => 'Tinebase_Model_Filter_Text'),
58         'name'                  => array('filter' => 'Tinebase_Model_Filter_Text'),
59         'object_id'             => array('filter' => 'Tinebase_Model_Filter_Text'),
60         'acl_node'              => array('filter' => 'Tinebase_Model_Filter_Text'),
61     // tree_fileobjects table
62         'last_modified_time'    => array(
63             'filter' => 'Tinebase_Model_Filter_Date',
64             'options' => array('tablename' => 'tree_fileobjects')
65         ),
66         'deleted_time'          => array(
67             'filter' => 'Tinebase_Model_Filter_DateTime',
68             'options' => array('tablename' => 'tree_fileobjects')
69         ),
70         'creation_time'         => array(
71             'filter' => 'Tinebase_Model_Filter_Date',
72             'options' => array('tablename' => 'tree_fileobjects')
73         ),
74         'last_modified_by'      => array(
75             'filter' => 'Tinebase_Model_Filter_User',
76             'options' => array('tablename' => 'tree_fileobjects'
77         )),
78         'created_by'            => array(
79             'filter' => 'Tinebase_Model_Filter_User',
80             'options' => array('tablename' => 'tree_fileobjects')
81         ),
82         'type'                  => array(
83             'filter' => 'Tinebase_Model_Filter_Text', 
84             'options' => array('tablename' => 'tree_fileobjects')
85         ),
86         'contenttype'           => array(
87             'filter' => 'Tinebase_Model_Filter_Text',
88             'options' => array('tablename' => 'tree_fileobjects')
89         ),
90         'description'           => array(
91             'filter' => 'Tinebase_Model_Filter_FullText',
92             'options' => array('tablename' => 'tree_fileobjects')
93         ),
94     // tree_filerevisions table
95         'size'                  => array(
96             'filter' => 'Tinebase_Model_Filter_Int',
97             'options' => array('tablename' => 'tree_filerevisions')
98         ),
99     // recursive search
100         'recursive'             => array(
101             'filter' => 'Tinebase_Model_Filter_Bool'
102         ),
103         'tag'                   => array('filter' => 'Tinebase_Model_Filter_Tag', 'options' => array(
104             'idProperty' => 'tree_nodes.id',
105             'applicationName' => 'Tinebase',
106         )),
107     // fulltext search
108         'content'               => array(
109             'filter'                => 'Tinebase_Model_Filter_ExternalFullText',
110             'options'               => array(
111                 'idProperty'            => 'object_id',
112             )
113         ),
114         'isIndexed'             => array(
115             'filter'                => 'Tinebase_Model_Tree_Node_IsIndexedFilter',
116         ),
117         'is_deleted'            => array(
118             'filter'                => 'Tinebase_Model_Filter_Bool'
119         )
120     );
121
122     /**
123      * append grants acl filter
124      *
125      * @param Zend_Db_Select $select
126      * @param Tinebase_Backend_Sql_Abstract $backend
127      * @param Tinebase_Model_User $user
128      */
129     protected function _appendGrantsFilter($select, $backend, $user = null)
130     {
131         parent::_appendGrantsFilter($select, $backend, $user);
132
133         // TODO do something when acl_node = NULL?
134     }
135
136     /**
137      * return folder + parent_id filter with ignore acl
138      *
139      * @param $folderId
140      * @return Tinebase_Model_Tree_Node_Filter
141      */
142     public static function getFolderParentIdFilterIgnoringAcl($folderId)
143     {
144         return new Tinebase_Model_Tree_Node_Filter(array(
145             array(
146                 'field'     => 'parent_id',
147                 'operator'  => $folderId === null ? 'isnull' : 'equals',
148                 'value'     => $folderId
149             ), array(
150                 'field'     => 'type',
151                 'operator'  => 'equals',
152                 'value'     => Tinebase_Model_Tree_FileObject::TYPE_FOLDER
153             )
154         ), Tinebase_Model_Filter_FilterGroup::CONDITION_AND, array('ignoreAcl' => true));
155     }
156 }