Arbit - project tracking

PHPillow - PHP CouchDB connector

Browse source code

File: / src/ classes/ view/ group.php

Type
text/plain text/plain
Last Author
kore
Version
159
Line Rev. Author Source
1 1 kore <?php
2 kore /**
3 2 kore * phpillow CouchDB backend
4 1 kore *
5 2 kore * This file is part of phpillow.
6 1 kore *
7 3 kore * phpillow is free software; you can redistribute it and/or modify it under
8 kore * the terms of the GNU Lesser General Public License as published by the Free
9 kore * Software Foundation; version 3 of the License.
10 1 kore *
11 3 kore * phpillow is distributed in the hope that it will be useful, but WITHOUT ANY
12 kore * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
13 kore * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
14 kore * more details.
15 1 kore *
16 3 kore * You should have received a copy of the GNU Lesser General Public License
17 kore * along with phpillow; if not, write to the Free Software Foundation, Inc., 51
18 kore * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
19 1 kore *
20 kore * @package Core
21 4 kore * @version $Revision: 159 $
22 3 kore * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
23 1 kore */
24 kore
25 kore /**
26 kore * Wrapper for group views
27 kore *
28 kore * @package Core
29 4 kore * @version $Revision: 159 $
30 3 kore * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
31 1 kore */
32 4 kore class phpillowGroupView extends phpillowView
33 1 kore {
34 kore /**
35 kore * View functions to be registered on the server
36 kore *
37 kore * @var array
38 kore */
39 kore protected $viewDefinitions = array(
40 kore // Add view for all groups indexed by their name
41 kore 'group' => 'function( doc )
42 kore {
43 kore if ( doc.type == "group" )
44 kore {
45 6 kore emit( doc.name, doc._id );
46 1 kore }
47 kore }',
48 kore // Fetch all rights of one user, which is defined by the groups a user
49 kore // belongs to.
50 kore 'user_permissions' => 'function( doc )
51 kore {
52 kore if ( doc.type == "group" )
53 kore {
54 kore for ( var i = 0; i < doc.users.length; ++i )
55 kore {
56 57 kore emit( doc.users[i], doc.permissions );
57 1 kore }
58 kore }
59 kore }',
60 31 kore // Fetch all rights of one user, which is defined by the groups a user
61 kore // belongs to.
62 kore 'user_permissions_reduced' => 'function( doc )
63 kore {
64 kore if ( doc.type == "group" )
65 kore {
66 kore for ( var i = 0; i < doc.users.length; ++i )
67 kore {
68 kore for ( var j = 0; j < doc.permissions.length; ++j )
69 kore {
70 kore emit( doc.users[i], doc.permissions[j] );
71 kore }
72 kore }
73 kore }
74 kore }',
75 1 kore );
76 kore
77 kore /**
78 31 kore * Reduce function for a view function.
79 kore *
80 kore * A reduce function may be used to aggregate / reduce the results
81 kore * calculated by a view function. See the CouchDB documentation for more
82 kore * results: @TODO: Not yet documented.
83 kore *
84 kore * Each view reduce function MUST have a view definition with the same
85 kore * name, otherwise there is nothing to reduce.
86 159 kore *
87 31 kore * @var array
88 kore */
89 kore protected $viewReduces = array(
90 kore 'user_permissions_reduced' => 'function( keys, values )
91 kore {
92 57 kore var permissions = [];
93 kore for ( var i = 0; i < values.length; ++i )
94 31 kore {
95 57 kore if ( permissions.indexOf( values[i] ) == -1 )
96 31 kore {
97 57 kore permissions.push( values[i] );
98 31 kore }
99 kore }
100 57 kore return permissions;
101 31 kore }',
102 kore );
103 kore
104 kore /**
105 94 kore * Create a new instance of the document class
106 kore *
107 kore * Create a new instance of the statically called document class.
108 kore * Implementing this method should only be required when using PHP 5.2 and
109 kore * lower, otherwise the class can be determined using LSB.
110 kore *
111 kore * Do not pass a parameter to this method, this is only used to maintain
112 kore * the called class information for PHP 5.2 and lower.
113 kore *
114 kore * @param mixed $docType
115 159 kore * @return phpillowDocument
116 94 kore */
117 kore public static function createNew( $docType = null )
118 kore {
119 kore return parent::createNew( $docType === null ? __CLASS__ : $docType );
120 kore }
121 kore
122 kore /**
123 1 kore * Get name of view
124 159 kore *
125 1 kore * Get name of view
126 159 kore *
127 1 kore * @return string
128 kore */
129 94 kore protected function getViewName()
130 1 kore {
131 kore return 'groups';
132 kore }
133 kore }
134 kore