summaryrefslogtreecommitdiff
path: root/htdocs/src/Category.inc.php
diff options
context:
space:
mode:
Diffstat (limited to 'htdocs/src/Category.inc.php')
-rw-r--r--htdocs/src/Category.inc.php86
1 files changed, 86 insertions, 0 deletions
diff --git a/htdocs/src/Category.inc.php b/htdocs/src/Category.inc.php
new file mode 100644
index 0000000..edc0303
--- /dev/null
+++ b/htdocs/src/Category.inc.php
@@ -0,0 +1,86 @@
+<?php
+
+/* Foursquare Community Site
+ *
+ * Copyright (C) 2011 Foursquare Church.
+ *
+ * Developers: Jesse Morgan <jmorgan@foursquarestaff.com>
+ *
+ */
+
+require_once "base.inc.php";
+
+class Category {
+ private $info;
+
+
+ public function __construct($info=null) {
+ $this->info = $info;
+ }
+
+ public static function getCategories() {
+ $db = getDatabase();
+
+ $query = "SELECT * FROM category ORDER BY name";
+
+ $rows = $db->fetchAssocRows($query);
+
+ $result = array();
+ foreach ($rows as $row) {
+ $result[$row['shortname']] = $row['name'];
+ }
+
+ return $result;
+ }
+
+ public static function getById($id) {
+ $where = "id='$id'";
+
+ return Category::getCategory($where);
+ }
+
+ public static function getByShortname($shortname) {
+ $where = "shortname='$shortname'";
+
+ return Category::getCategory($where);
+ }
+
+ private static function getCategory($where) {
+ $query = "SELECT * FROM category WHERE $where";
+
+ $db = getDatabase();
+
+ $row = $db->fetchAssocRow($query);
+
+ if ($row) {
+ $category = new Category();
+ $category->info = $row;
+
+ return $category;
+
+ } else {
+ return false;
+ }
+ }
+
+ public function save() {
+ $db = getDatabase();
+
+ // TODO: Implement Save
+ }
+
+ public function getId() {
+ return $this->info['id'];
+ }
+
+ public function getName() {
+ return htmlspecialchars($this->info['name']);
+ }
+
+ public function getShortname() {
+ return htmlspecialchars($this->info['shortname']);
+ }
+}
+
+?>
+