Arbit - project tracking

PHPillow - PHP CouchDB connector

Browse source code

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

Type
text/plain text/plain
Last Author
kore
Version
161
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: 161 $
22 3 kore * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
23 1 kore */
24 kore
25 kore /**
26 kore * Document representing the groups
27 kore *
28 kore * @package Core
29 4 kore * @version $Revision: 161 $
30 3 kore * @license http://www.gnu.org/licenses/lgpl-3.0.txt LGPL
31 1 kore */
32 4 kore class phpillowGroupDocument extends phpillowDocument
33 1 kore {
34 kore /**
35 kore * Document type, may be a string matching the regular expression:
36 kore * (^[a-zA-Z0-9_]+$)
37 159 kore *
38 1 kore * @var string
39 kore */
40 kore protected static $type = 'group';
41 kore
42 kore /**
43 kore * List of required properties. For each required property, which is not
44 kore * set, a validation exception will be thrown on save.
45 159 kore *
46 1 kore * @var array
47 kore */
48 kore protected $requiredProperties = array(
49 kore 'name',
50 kore );
51 kore
52 kore /**
53 159 kore * Indicates whether to keep old revisions of this document or not.
54 1 kore *
55 kore * @var bool
56 kore */
57 kore protected $versioned = false;
58 kore
59 kore /**
60 kore * Construct new book document
61 159 kore *
62 1 kore * Construct new book document and set its property validators.
63 159 kore *
64 1 kore * @return void
65 kore */
66 94 kore public function __construct()
67 1 kore {
68 kore $this->properties = array(
69 3 kore 'name' => new phpillowRegexpValidator( '(^[\x21-\x7e]+$)i' ),
70 kore 'description' => new phpillowTextValidator(),
71 kore 'users' => new phpillowArrayValidator(),
72 161 kore 'userDocs' => new phpillowDocumentArrayValidator( 'phpillowUserDocument' ),
73 3 kore 'permissions' => new phpillowArrayValidator(),
74 1 kore );
75 kore
76 kore parent::__construct();
77 kore }
78 kore
79 kore /**
80 kore * Get ID from document
81 kore *
82 kore * The ID normally should be calculated on some meaningful / unique
83 151 seldaek * property for the current type of documents. The returned string should
84 1 kore * not be too long and should not contain multibyte characters.
85 41 kore *
86 kore * You can return null instead of an ID string, to trigger the ID
87 kore * autogeneration.
88 159 kore *
89 41 kore * @return mixed
90 1 kore */
91 kore protected function generateId()
92 kore {
93 kore return $this->stringToId( $this->storage->name );
94 kore }
95 94 kore
96 kore /**
97 kore * Return document type name
98 kore *
99 kore * This method is required to be implemented to return the document type
100 kore * for PHP versions lower then 5.2. When only using PHP 5.3 and higher you
101 kore * might just implement a method which does "return static:$type" in a base
102 kore * class.
103 159 kore *
104 94 kore * @return void
105 kore */
106 kore protected function getType()
107 kore {
108 kore return self::$type;
109 kore }
110 kore
111 kore /**
112 kore * Create a new instance of the document class
113 kore *
114 kore * Create a new instance of the statically called document class.
115 kore * Implementing this method should only be required when using PHP 5.2 and
116 kore * lower, otherwise the class can be determined using LSB.
117 kore *
118 kore * Do not pass a parameter to this method, this is only used to maintain
119 kore * the called class information for PHP 5.2 and lower.
120 kore *
121 kore * @param mixed $docType
122 159 kore * @return phpillowDocument
123 94 kore */
124 kore public static function createNew( $docType = null )
125 kore {
126 kore return parent::createNew( $docType === null ? __CLASS__ : $docType );
127 kore }
128 1 kore }
129 kore