summaryrefslogtreecommitdiff
path: root/htdocs/src/UserIterator.inc.php
diff options
context:
space:
mode:
authorJesse Morgan <jesse@jesterpm.net>2011-06-02 16:17:25 -0700
committerJesse Morgan <jesse@jesterpm.net ; true>2011-06-02 16:17:25 -0700
commitf08eb1640388e1f067102a22ec40c30f263d92c6 (patch)
treea73f2d21cff6427b9619e7072fc90a228bd7dc78 /htdocs/src/UserIterator.inc.php
parent91feef607687b1262a949835cffd850cdd819846 (diff)
Added user management
Diffstat (limited to 'htdocs/src/UserIterator.inc.php')
-rw-r--r--htdocs/src/UserIterator.inc.php83
1 files changed, 83 insertions, 0 deletions
diff --git a/htdocs/src/UserIterator.inc.php b/htdocs/src/UserIterator.inc.php
new file mode 100644
index 0000000..2f8fef2
--- /dev/null
+++ b/htdocs/src/UserIterator.inc.php
@@ -0,0 +1,83 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class UserIterator implements Iterator {
+ private $where;
+ private $rows;
+ private $position;
+ private $order;
+ private $limit;
+
+ public function __construct() {
+ $this->where = array();
+ $this->rows = array();
+ $this->position = 0;
+ $this->order = "name asc";
+ $this->limit = 0;
+ }
+
+ public function filterNotify($notify) {
+ $sqlnotify = $notify ? '1' : '0';
+ $this->where[] = "notify='$sqlnotify'";
+ }
+
+ public function orderBy($order) {
+ $this->order = $order;
+ }
+
+ public function limit($limit) {
+ $this->limit = $limit;
+ }
+
+ public function rewind() {
+ $this->position = 0;
+ }
+
+ public function current() {
+ return new User($this->rows[$this->position]);
+ }
+
+ public function key() {
+ return $this->rows[$this->position]['id'];
+ }
+
+ public function next() {
+ ++$this->position;
+ }
+
+ public function valid() {
+ return isset($this->rows[$this->position]);
+ }
+
+ public function query() {
+ $query = "SELECT * FROM user";
+
+ if (count($this->where) > 0) {
+ $where = join(' AND ', $this->where);
+ $query .= " WHERE $where";
+ }
+
+ $query .= " ORDER BY ". $this->order;
+
+ if ($this->limit != 0) {
+ $query .= " LIMIT ". $this->limit;
+ }
+
+ $db = getDatabase();
+
+ $this->rows = $db->fetchAssocRows($query);
+ $this->position = 0;
+ }
+}
+
+?>
+