- Added Filtering
[activemongo.git] / sample / user.php
blobe99fc347d259f40e7a3272dc99475a19970d7ed7
1 <?php
3 class Users Extends ActiveMongo
5 public $username;
6 public $password;
7 public $uid;
9 function my_selector()
11 /* Get collection */
12 $col = $this->_getCollection();
14 /* Build our request */
15 $res = $col->find(array('uid' => array('$gt' => 5, '$lt' => 10)));
16 $res->sort(array('uid' => -1));
18 /* Give to ActiveMongo our Cursor */
19 $this->setCursor($res);
21 /* You must return 'this' for easy iteration */
22 return $this;
25 function username_filter(&$value, $past_value)
27 if ($past_value != null && $value != $past_value) {
28 throw new FilterException("You cannot change the username");
29 } else {
30 if (strlen($value) < 5) {
31 throw new FilterException("Name too short");
34 return true;
37 function password_filter(&$value, &$past_value)
39 if (strlen($value) < 5) {
40 throw new FilterException("Password is too sort");
42 $value = sha1($value);
43 return true;
46 function setup()
48 $this->_getCollection()->ensureIndex(array('uid' => 1), array('unique' => true, 'background' => true));