From bca4d35ff62900f5fff7f8d4fc6911b16c3b6642 Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Tue, 14 Nov 2006 19:44:21 +0000
Subject: [PATCH] Lots of updates for primary key name changes as well as
 dynamic primary key functions.

Also contains new code for inheritting Database Row Models.
---
 .../ApprovalbodyadminController.php           |  6 +--
 application/controllers/AuthController.php    |  6 ++-
 .../controllers/ConflictController.php        | 10 ++--
 .../controllers/CourseadminController.php     |  6 +--
 application/controllers/HomeController.php    |  8 ++-
 application/controllers/TestController.php    | 11 +++-
 .../controllers/UseradminController.php       |  4 +-
 .../library/Local/Db/CourseTableMany.php      |  2 +-
 .../library/Local/Db/CourseTableOne.php       |  2 +-
 application/models/rows/ApprovalBodyRole.php  | 18 ++++++-
 application/models/rows/Asset.php             | 13 ++++-
 application/models/rows/CourseCode.php        | 12 ++---
 .../models/rows/CourseCrosslisting.php        |  5 +-
 application/models/rows/CourseGeneration.php  | 21 +++++---
 application/models/rows/Group.php             | 12 ++---
 application/models/rows/Person.php            | 18 +++++--
 application/models/rows/Request.php           |  4 +-
 application/models/rows/User.php              | 14 +++++
 application/models/tables/ActivityTypes.php   |  5 ++
 application/models/tables/ApprovalBodies.php  |  6 +++
 .../models/tables/ApprovalBodyRoles.php       | 20 ++++++-
 application/models/tables/ApprovalChains.php  |  5 ++
 application/models/tables/ApprovalLinks.php   |  5 ++
 application/models/tables/Assets.php          |  5 ++
 application/models/tables/Auth.php            |  7 +++
 .../models/tables/CourseActivities.php        | 10 +++-
 application/models/tables/CourseCodes.php     |  8 ++-
 application/models/tables/CourseCredits.php   |  7 ++-
 .../models/tables/CourseCrosslistings.php     | 28 ++++++----
 application/models/tables/CourseDetails.php   |  5 ++
 .../models/tables/CourseDfRemovals.php        |  7 ++-
 .../models/tables/CourseGenerations.php       |  7 ++-
 .../models/tables/CourseGradTieIns.php        |  5 ++
 .../models/tables/CoursePrerequisites.php     |  7 ++-
 application/models/tables/Courses.php         |  5 ++
 application/models/tables/Departments.php     |  5 ++
 application/models/tables/Files.php           |  5 ++
 .../models/tables/GroupImpliedMemberships.php | 25 ++++++---
 .../models/tables/GroupMemberships.php        |  5 ++
 application/models/tables/Groups.php          |  9 +++-
 application/models/tables/People.php          | 34 +++++++++++-
 application/models/tables/RequestFiles.php    |  7 ++-
 application/models/tables/RequestStacks.php   |  5 ++
 application/models/tables/RequestTypes.php    |  7 ++-
 application/models/tables/Requests.php        | 12 ++++-
 application/models/tables/Users.php           | 28 ++++++++++
 application/views/approval_body_admin.xhtml   | 12 ++---
 application/views/conflict.xhtml              |  6 +--
 application/views/editAddress.xhtml           |  2 +-
 application/views/edit_course.xhtml           | 24 ++++-----
 application/views/listAddress.xhtml           |  2 +-
 application/views/my_home.xhtml               | 54 +++++++++++++++++--
 application/views/user_admin.xhtml            |  8 +--
 53 files changed, 454 insertions(+), 110 deletions(-)
 create mode 100644 application/models/rows/User.php
 create mode 100644 application/models/tables/Users.php

diff --git a/application/controllers/ApprovalbodyadminController.php b/application/controllers/ApprovalbodyadminController.php
index feef3b26..655098e7 100644
--- a/application/controllers/ApprovalbodyadminController.php
+++ b/application/controllers/ApprovalbodyadminController.php
@@ -52,7 +52,7 @@ class ApprovalBodyAdminController extends Nmc_Controller_Action
 
         $out->groups = Groups::getInstance()->fetchAll();
         $out->approvalBodyRole = ApprovalBodyRoles::getInstance()->fetchNew();
-        $out->approvalBodyRole->approvalBody = $parentApprovalBody->id;
+        $out->approvalBodyRole->approvalBody = $parentApprovalBody->getPrimaryKey();
         $out->approvalBodies = ApprovalBodies::getInstance()->fetchAll();
 
         echo $out->render();
@@ -73,7 +73,7 @@ class ApprovalBodyAdminController extends Nmc_Controller_Action
         $body->save();
 
         $out = new Nmc_View();
-        $out->refresh = '/ApprovalBodyAdmin/EditBody/' . $body->id;
+        $out->refresh = '/ApprovalBodyAdmin/EditBody/' . $body->getPrimaryKey();
         echo $out->render();
     }
 
@@ -93,7 +93,7 @@ class ApprovalBodyAdminController extends Nmc_Controller_Action
         $role->save();
 
         $out = new Nmc_View();
-        $out->refresh = '/ApprovalBodyAdmin/EditRole/' . $role->id;
+        $out->refresh = '/ApprovalBodyAdmin/EditRole/' . $role->getPrimaryKey();
         echo $out->render();
     }
 }
diff --git a/application/controllers/AuthController.php b/application/controllers/AuthController.php
index 75172a04..ec852e95 100644
--- a/application/controllers/AuthController.php
+++ b/application/controllers/AuthController.php
@@ -59,7 +59,7 @@ class AuthController extends Nmc_Controller_Action
                 $user->lastName = $userInfo[0]['sn'][0];
                 $user->email = $userInfo[0]['mail'][0];
                 $user->phone = $userInfo[0]['telephonenumber'][0];
-                $user->department = $department->id;
+                $user->department = $department->getPrimaryKey();
                 $user->save();
             }
             Nmc_User::getInstance()->login($user);
@@ -81,4 +81,6 @@ class AuthController extends Nmc_Controller_Action
         echo $out->render();
     }
 
-}
\ No newline at end of file
+}
+
+?>
\ No newline at end of file
diff --git a/application/controllers/ConflictController.php b/application/controllers/ConflictController.php
index 65846a34..e0a7175d 100644
--- a/application/controllers/ConflictController.php
+++ b/application/controllers/ConflictController.php
@@ -19,12 +19,12 @@ FROM creq_course_crosslistings AS a,
      creq_course_generations AS c2,
      creq_course_codes AS d
 WHERE a.course_code = b.course_code
-  AND a.id != b.id
-  AND a.generation = c.id
+  AND a.course_crosslisting_id != b.course_crosslisting_id
+  AND a.generation = c.course_generation_id
   AND c.type = 'official'
-  AND b.generation = c2.id
+  AND b.generation = c2.course_generation_id
   AND c2.type = 'official'
-  AND a.course_code = d.id
+  AND a.course_code = d.course_code_id
 ORDER BY subject, course_number, course_letter
 EOF;
 
@@ -48,7 +48,7 @@ EOF;
 
         $allIds = array();
         foreach($dups as $dup) {
-            $allIds[] = $dup->id;
+            $allIds[] = $dup->getPrimaryKey();
         }
 
         $out = new Nmc_View();
diff --git a/application/controllers/CourseadminController.php b/application/controllers/CourseadminController.php
index 9988caed..85026a3c 100644
--- a/application/controllers/CourseadminController.php
+++ b/application/controllers/CourseadminController.php
@@ -36,7 +36,7 @@ class CourseAdminController extends Nmc_Controller_Action
             if($nextCourse = $crosslisting->getNextAlphabetically()) {
                 $nextCourse = $nextCourse->getParentCourse();
                 $nextCourseLink = '/' . $nextCourse->subject . '/' . $nextCourse->courseNumber . '/' . $nextCourse->courseLetter;
-                if($nextCourse->subject != $course->subject || $nextCourse->id == $course->id) {
+                if($nextCourse->subject != $course->subject || $nextCourse->getPrimaryKey() == $course->getPrimaryKey()) {
                     foreach($nextCourse->crosslistings as $crosslisting) {
                         if($crosslisting->subject == $course->subject) {
                             $nextCourseLink = '/' . $crosslisting->subject . '/' . $crosslisting->courseNumber . '/' . $crosslisting->courseLetter;
@@ -49,7 +49,7 @@ class CourseAdminController extends Nmc_Controller_Action
             if($prevCourse = $crosslisting->getPreviousAlphabetically()) {
                 $prevCourse = $prevCourse->getParentCourse();
                 $prevCourseLink = '/' . $prevCourse->subject . '/' . $prevCourse->courseNumber . '/' . $prevCourse->courseLetter;
-                if($prevCourse->subject != $course->subject || $prevCourse->id == $course->id) {
+                if($prevCourse->subject != $course->subject || $prevCourse->getPrimaryKey() == $course->getPrimaryKey()) {
                     foreach($prevCourse->crosslistings as $crosslisting) {
                         if($crosslisting->subject == $course->subject) {
                             $prevCourseLink = '/' . $crosslisting->subject . '/' . $crosslisting->courseNumber . '/' . $crosslisting->courseLetter;
@@ -169,7 +169,7 @@ class CourseAdminController extends Nmc_Controller_Action
         $course->save();
 
         $out = new Nmc_View();
-        $out->refresh = '/courseadmin/index/' . $course->id;
+        $out->refresh = '/courseadmin/index/' . $course->getPrimaryKey();
         echo $out->render();
     }
 
diff --git a/application/controllers/HomeController.php b/application/controllers/HomeController.php
index eafda27a..1eb13d38 100644
--- a/application/controllers/HomeController.php
+++ b/application/controllers/HomeController.php
@@ -8,13 +8,17 @@ class HomeController extends Nmc_Controller_Action
         $this->_registerPlugin(new Nmc_Controller_Action_Plugin_Authorize());
     }
 
-    public function IndexAction()
+    public function indexAction()
     {
         $user = Nmc_User::getInstance()->getUser();
         $requests = Requests::getInstance()->getRequestsForUser($user);
 
+        $roles = ApprovalBodyRoles::getInstance()->fetchRolesForUser($user);
+
+
         $out = new Nmc_View();
-        $out->requests = $requests;
+        $out->roles = $roles;
+        $out->myRequests = $requests;
         $out->page = 'my_home';
 
         echo $out->render();
diff --git a/application/controllers/TestController.php b/application/controllers/TestController.php
index 94716656..9bad73ce 100644
--- a/application/controllers/TestController.php
+++ b/application/controllers/TestController.php
@@ -5,12 +5,19 @@ class TestController extends Nmc_Controller_Action
     public function __construct()
     {
         //$this->_registerPlugin(new Nmc_Controller_Action_Plugin_Authorize());
-        $this->_registerPlugin(new Nmc_Controller_Action_Plugin_Test());
+        //$this->_registerPlugin(new Nmc_Controller_Action_Plugin_Test());
     }
 
     public function indexAction()
     {
-        $foo = new Nmc_XMPP_Core();
+        header('Content-type: text/plain');
+        $test = Test::getInstance();
+        $rows = $test->fetchAll();
+        foreach($rows as $row) {
+            echo 'Creation time: ' . $row->creationTime . "\n";
+            echo 'Modification time: ' . $row->modifiedTime . "\n";
+            echo 'Asset ID: ' . $row->getAssetId() . "\n";
+        }
     }
 }
 
diff --git a/application/controllers/UseradminController.php b/application/controllers/UseradminController.php
index a6c9868f..d52ff86f 100644
--- a/application/controllers/UseradminController.php
+++ b/application/controllers/UseradminController.php
@@ -31,7 +31,7 @@ class UserAdminController extends Nmc_Controller_Action
         if($userId < 0) {
             $out->user = People::getInstance()->fetchNew();
         } else {
-            $out->user = People::getInstance()->find($userId);
+            $out->user = People::getInstance()->findByUserId($userId);
         }
         $out->groups = Groups::getInstance()->fetchAllWithoutPrimaries();
 
@@ -137,7 +137,7 @@ class UserAdminController extends Nmc_Controller_Action
             $group->addGroup($newGroup);
         }
 
-        $selectedUsers = People::getInstance()->findAll($in['users']);
+        $selectedUsers = People::getInstance()->findByUserId($in['users']);
         $currentUsers = $group->getUsers(false);
 
         $removedUsers = $currentUsers->getRowsNotInCommonWith($selectedUsers);
diff --git a/application/library/Local/Db/CourseTableMany.php b/application/library/Local/Db/CourseTableMany.php
index 9cc737b9..7a9fb893 100644
--- a/application/library/Local/Db/CourseTableMany.php
+++ b/application/library/Local/Db/CourseTableMany.php
@@ -5,7 +5,7 @@ abstract class Local_Db_CourseTableMany extends Nmc_Db_Table
     public function fetchByGeneration(CourseGeneration $generation)
     {
         $where = array();
-        $where[] = $this->_db->quoteInto('generation = ?', $generation->id);
+        $where[] = $this->_db->quoteInto('generation = ?', $generation->getPrimaryKey());
         $where = implode(' AND ', $where);
 
         return $this->fetchAll($where);
diff --git a/application/library/Local/Db/CourseTableOne.php b/application/library/Local/Db/CourseTableOne.php
index 1d74f9c9..08ddad07 100644
--- a/application/library/Local/Db/CourseTableOne.php
+++ b/application/library/Local/Db/CourseTableOne.php
@@ -5,7 +5,7 @@ abstract class Local_Db_CourseTableOne extends Nmc_Db_Table
     public function fetchByGeneration(CourseGeneration $generation)
     {
         $where = array();
-        $where[] = $this->_db->quoteInto('generation = ?', $generation->id);
+        $where[] = $this->_db->quoteInto('generation = ?', $generation->getPrimaryKey());
         $where = implode(' AND ', $where);
 
         return $this->fetchRow($where);
diff --git a/application/models/rows/ApprovalBodyRole.php b/application/models/rows/ApprovalBodyRole.php
index 7a352607..e2afea9a 100644
--- a/application/models/rows/ApprovalBodyRole.php
+++ b/application/models/rows/ApprovalBodyRole.php
@@ -6,14 +6,28 @@ class ApprovalBodyRole extends Nmc_Db_Table_Row
     {
         parent::__construct($config);
         $this->_registerRelation(
-            new Nmc_Db_Table_Relation_HasOne(
+            new Nmc_Db_Table_Relation_Extend(
                 Groups::getInstance(),
                 $this,
                 'group',
-                'roleGroup'
+                'roleGroup',
+                false
             )
         );
     }
+
+    /**
+     * Return a rowset of requests pending for this role
+     *
+     * @return Nmc_Db_Table_Rowset
+     */
+    public function getRequests()
+    {
+        // If this is the "root" role
+        if($this->getPrimaryKey() == 1) {
+            return Requests::getInstance()->fetchAll();
+        }
+    }
 }
 
 ?>
\ No newline at end of file
diff --git a/application/models/rows/Asset.php b/application/models/rows/Asset.php
index a72b4c9f..ea3aabdf 100644
--- a/application/models/rows/Asset.php
+++ b/application/models/rows/Asset.php
@@ -1,10 +1,16 @@
 <?php
 
+/**
+ * Row class for the asset table
+ *
+ * @tableClass Assets
+ *
+ */
 class Asset extends Nmc_Db_Table_Row
 {
     static public $tableClass = 'Assets';
 
-    public function _save()
+    protected function _save()
     {
         if(!$this->creationTime) {
             $this->creationTime = time();
@@ -14,6 +20,11 @@ class Asset extends Nmc_Db_Table_Row
 
         parent::_save();
     }
+
+    public function getAssetId()
+    {
+        return $this->getPrimaryKey();
+    }
 }
 
 ?>
\ No newline at end of file
diff --git a/application/models/rows/CourseCode.php b/application/models/rows/CourseCode.php
index b3b85d9e..08ecfeee 100644
--- a/application/models/rows/CourseCode.php
+++ b/application/models/rows/CourseCode.php
@@ -20,7 +20,7 @@ class CourseCode extends Nmc_Db_Table_Row
         $where = implode(' AND ', $where);
 
         $row = $this->_table->fetchRow($where, $order);
-        if($row->id) {
+        if($row->getPrimaryKey()) {
             return $row;
         }
 
@@ -30,7 +30,7 @@ class CourseCode extends Nmc_Db_Table_Row
         $where = implode(' AND ', $where);
 
         $row = $this->_table->fetchRow($where, $order);
-        if($row->id) {
+        if($row->getPrimaryKey()) {
             return $row;
         }
 
@@ -39,7 +39,7 @@ class CourseCode extends Nmc_Db_Table_Row
         $where = implode(' AND ', $where);
 
         $row = $this->_table->fetchRow($where, $order);
-        if($row->id) {
+        if($row->getPrimaryKey()) {
             return $row;
         }
 
@@ -65,7 +65,7 @@ class CourseCode extends Nmc_Db_Table_Row
         $where = implode(' AND ', $where);
 
         $row = $this->_table->fetchRow($where, $order);
-        if($row->id) {
+        if($row instanceof Nmc_Db_Table_Row && $row->getPrimaryKey()) {
             return $row;
         }
 
@@ -75,7 +75,7 @@ class CourseCode extends Nmc_Db_Table_Row
         $where = implode(' AND ', $where);
 
         $row = $this->_table->fetchRow($where, $order);
-        if($row->id) {
+        if($row->getPrimaryKey()) {
             return $row;
         }
 
@@ -84,7 +84,7 @@ class CourseCode extends Nmc_Db_Table_Row
         $where = implode(' AND ', $where);
 
         $row = $this->_table->fetchRow($where, $order);
-        if($row->id) {
+        if($row->getPrimaryKey()) {
             return $row;
         }
 
diff --git a/application/models/rows/CourseCrosslisting.php b/application/models/rows/CourseCrosslisting.php
index 8f3f848c..d6cad6d0 100644
--- a/application/models/rows/CourseCrosslisting.php
+++ b/application/models/rows/CourseCrosslisting.php
@@ -11,8 +11,9 @@ class CourseCrosslisting extends Nmc_Db_Table_Row
     public function __construct($config = array())
     {
         parent::__construct($config);
+        $primaryKeyName = CourseCodes::getInstance()->getPrimaryKeyName(true);
         $courseCode = CourseCodes::getInstance()->find($this->courseCode);
-        if($courseCode->id) {
+        if($courseCode->$primaryKeyName) {
             $this->_subject = $courseCode->subject;
             $this->_courseNumber = $courseCode->courseNumber;
             $this->_courseLetter = $courseCode->courseLetter;
@@ -58,7 +59,7 @@ class CourseCrosslisting extends Nmc_Db_Table_Row
         );
         $courseCode->integratedStudies = $this->_integratedStudies;
         $courseCode->save();
-        $this->courseCode = $courseCode->id;
+        $this->courseCode = $courseCode->getPrimaryKey();
         parent::_save();
     }
 
diff --git a/application/models/rows/CourseGeneration.php b/application/models/rows/CourseGeneration.php
index 1f2361e2..117acb18 100644
--- a/application/models/rows/CourseGeneration.php
+++ b/application/models/rows/CourseGeneration.php
@@ -1,6 +1,12 @@
 <?php
 
-class CourseGeneration extends Nmc_Db_Table_Row
+/**
+ *
+ * @tableClass CourseGenerations
+ * @foreignKey assetId
+ *
+ */
+class CourseGeneration extends Asset
 {
     protected $_homeCrosslisting;
 
@@ -8,8 +14,6 @@ class CourseGeneration extends Nmc_Db_Table_Row
     {
         parent::__construct($config);
 
-        $this->_registerRelation(
-            new Nmc_Db_Table_Relation_Extend(Assets::getInstance(), $this, 'assetId'));
         $this->_registerRelation(
             new Nmc_Db_Table_Relation_HasOne(CourseDetails::getInstance(), $this, 'generation'));
         $this->_registerRelation(
@@ -30,7 +34,7 @@ class CourseGeneration extends Nmc_Db_Table_Row
 
     public function _clone()
     {
-        $parentId = $this->id;
+        $parentId = $this->getPrimaryKey();
 
         // duplicate parent record
         parent::_clone();
@@ -96,7 +100,7 @@ class CourseGeneration extends Nmc_Db_Table_Row
             if(!$this->course) {
                 $course = Courses::getInstance()->fetchNew();
                 $course->save();
-                $this->course = $course->id;
+                $this->course = $course->getPrimaryKey();
             }
             if(!$this->creationTime) {
                 $this->creationTime = time();
@@ -104,7 +108,7 @@ class CourseGeneration extends Nmc_Db_Table_Row
 
             if($this->request instanceof Request) {
                 $this->request->save();
-                $this->_data['request'] = $this->request->id;
+                $this->_data['request'] = $this->request->getPrimaryKey();
             }
 
             $this->_setHomeCrosslisting($this->_homeCrosslisting);
@@ -129,6 +133,11 @@ class CourseGeneration extends Nmc_Db_Table_Row
         }
     }
 
+    public function getAssetId()
+    {
+        return $this->assetId;
+    }
+
     /**
      * Returns a reference to the home crosslist
      *
diff --git a/application/models/rows/Group.php b/application/models/rows/Group.php
index 2f745a38..6bd0f865 100644
--- a/application/models/rows/Group.php
+++ b/application/models/rows/Group.php
@@ -18,13 +18,13 @@ class Group extends Nmc_Db_Table_Row
         }
     }
 
-    public function addUser(Person $user)
+    public function addUser($user)
     {
         $childGroup = Groups::getInstance()->find($user->primaryGroup);
         $this->addGroup($childGroup);
     }
 
-    public function removeUser(Person $user)
+    public function removeUser($user)
     {
         $childGroup = Groups::getInstance()->find($user->primaryGroup);
         $this->removeGroup($childGroup);
@@ -33,8 +33,8 @@ class Group extends Nmc_Db_Table_Row
     public function addGroup(Group $group)
     {
         $membership = GroupMemberships::getInstance()->fetchNew();
-        $membership->parentGroup = $this->id;
-        $membership->childGroup = $group->id;
+        $membership->parentGroup = $this->getPrimaryKey();
+        $membership->childGroup = $group->getPrimaryKey();
         $membership->type = $this->type;
         $membership->save();
     }
@@ -42,8 +42,8 @@ class Group extends Nmc_Db_Table_Row
     public function removeGroup(Group $group)
     {
         $where = array();
-        $where[] = $this->_db->quoteInto('parent_group = ?', $this->id);
-        $where[] = $this->_db->quoteInto('child_group = ?', $group->id);
+        $where[] = $this->_db->quoteInto('parent_group = ?', $this->getPrimaryKey());
+        $where[] = $this->_db->quoteInto('child_group = ?', $group->getPrimaryKey());
         $where = implode(' AND ', $where);
         $membership = GroupMemberships::getInstance()->fetchRow($where);
         $membership->delete();
diff --git a/application/models/rows/Person.php b/application/models/rows/Person.php
index 44cb735c..de13ad86 100644
--- a/application/models/rows/Person.php
+++ b/application/models/rows/Person.php
@@ -2,9 +2,21 @@
 
 Zend::loadInterface('Nmc_Model_UserInterface');
 
-class Person extends Nmc_Db_Table_Row implements Nmc_Model_UserInterface
+/**
+ *
+ * @foreignKey userId
+ * @tableClass People
+ *
+ */
+class Person extends User
+             implements Nmc_Model_UserInterface
 {
 
+    public function __construct($config = array())
+    {
+        parent::__construct($config);
+    }
+
     public function _save()
     {
         if(!$this->primaryGroup) {
@@ -12,7 +24,7 @@ class Person extends Nmc_Db_Table_Row implements Nmc_Model_UserInterface
             $primaryGroup->type = 1;
             $primaryGroup->name = $this->userName;
             $primaryGroup->save();
-            $this->primaryGroup = $primaryGroup->id;
+            $this->primaryGroup = $primaryGroup->getPrimaryKey();
         }
 
         return parent::_save();
@@ -20,7 +32,7 @@ class Person extends Nmc_Db_Table_Row implements Nmc_Model_UserInterface
 
     public function getId()
     {
-        return $this->id;
+        return $this->getPrimaryKey();
     }
 
     public function getUserName()
diff --git a/application/models/rows/Request.php b/application/models/rows/Request.php
index 91f16e46..5df0ce0b 100644
--- a/application/models/rows/Request.php
+++ b/application/models/rows/Request.php
@@ -18,6 +18,8 @@ class Request extends Nmc_Db_Table_Row
     public function getCourseGeneration()
     {
         $returnValue = null;
+        $primaryKey = $this->_table->getPrimaryKeyName();
+        $primaryKey = Nmc_Db_Inflector::getInstance()->camelize($primaryKey);
 
         $select = $this->_db->select();
         $select->from(CourseGenerations::getInstance()->getTableName(),
@@ -27,7 +29,7 @@ class Request extends Nmc_Db_Table_Row
                       . '.asset_id = '
                       . Assets::getInstance()->getTableName() . '.'
                       . Assets::getInstance()->getPrimaryKeyName());
-        $select->where($this->_db->quoteInto('request = ?', $this->id));
+        $select->where($this->_db->quoteInto('request = ?', $this->$primaryKey));
         $select->order('creation_time');
         $generations = $this->_db->fetchCol($select);
         if(count($generations) > 0) {
diff --git a/application/models/rows/User.php b/application/models/rows/User.php
new file mode 100644
index 00000000..c47ddb84
--- /dev/null
+++ b/application/models/rows/User.php
@@ -0,0 +1,14 @@
+<?php
+
+
+/**
+ *
+ * @tableClass Users
+ *
+ */
+class User extends Nmc_Db_Table_Row
+{
+    static public $tableClass = 'Users';
+
+    // generic user model
+}
\ No newline at end of file
diff --git a/application/models/tables/ActivityTypes.php b/application/models/tables/ActivityTypes.php
index 6b4e35cf..2f85f3ce 100644
--- a/application/models/tables/ActivityTypes.php
+++ b/application/models/tables/ActivityTypes.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary activity_type_id
+ *
+ */
 class ActivityTypes extends Nmc_Db_Table
 {
     /**
diff --git a/application/models/tables/ApprovalBodies.php b/application/models/tables/ApprovalBodies.php
index 897e9204..40410d5a 100644
--- a/application/models/tables/ApprovalBodies.php
+++ b/application/models/tables/ApprovalBodies.php
@@ -1,5 +1,11 @@
 <?php
 
+
+/**
+ *
+ * @primary approval_body_id
+ *
+ */
 class ApprovalBodies extends Nmc_Db_Table
 {
     protected $_rowClass = 'ApprovalBody';
diff --git a/application/models/tables/ApprovalBodyRoles.php b/application/models/tables/ApprovalBodyRoles.php
index c4f48af0..468e7639 100644
--- a/application/models/tables/ApprovalBodyRoles.php
+++ b/application/models/tables/ApprovalBodyRoles.php
@@ -1,8 +1,13 @@
 <?php
 
+/**
+ *
+ * @rowClass ApprovalBodyRole
+ * @primary approval_body_role_id
+ *
+ */
 class ApprovalBodyRoles extends Nmc_Db_Table
 {
-    protected $_className = 'ApprovalBodyRole';
 
     /**
      * The one true instance
@@ -24,6 +29,19 @@ class ApprovalBodyRoles extends Nmc_Db_Table
         return self::$_instance;
     }
 
+    public function fetchRolesForUser(User $user)
+    {
+        $groups = GroupImpliedMemberships::getInstance()->fetchGroupsByUser($user);
+
+        $groupIds = array();
+        foreach($groups as $group) {
+            $groupIds[] = $group->getPrimaryKey();
+        }
+
+        $db = $this->_db;
+        $where = $db->quoteInto('`group` IN(?)', $groupIds);
+        return $this->fetchAll($where);
+    }
 }
 
 ?>
\ No newline at end of file
diff --git a/application/models/tables/ApprovalChains.php b/application/models/tables/ApprovalChains.php
index 974cc347..92dfee50 100644
--- a/application/models/tables/ApprovalChains.php
+++ b/application/models/tables/ApprovalChains.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary approval_chain_id
+ *
+ */
 class ApprovalChains extends Nmc_Db_Table {}
 
 ?>
\ No newline at end of file
diff --git a/application/models/tables/ApprovalLinks.php b/application/models/tables/ApprovalLinks.php
index 1ef35557..d58c522a 100644
--- a/application/models/tables/ApprovalLinks.php
+++ b/application/models/tables/ApprovalLinks.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary approval_link_id
+ *
+ */
 class ApprovalLinks extends Nmc_Db_Table {}
 
 ?>
\ No newline at end of file
diff --git a/application/models/tables/Assets.php b/application/models/tables/Assets.php
index 5fe66a7f..71a01989 100644
--- a/application/models/tables/Assets.php
+++ b/application/models/tables/Assets.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary asset_id
+ *
+ */
 class Assets extends Nmc_Db_Table
 {
     protected $_rowClass = 'Asset';
diff --git a/application/models/tables/Auth.php b/application/models/tables/Auth.php
index c5489d3e..51ca2027 100644
--- a/application/models/tables/Auth.php
+++ b/application/models/tables/Auth.php
@@ -1,5 +1,12 @@
 <?php
 
+
+/**
+ *
+ * @table auth
+ * @primary auth_id
+ *
+ */
 class Auth extends Zend_Db_Table
 {
 
diff --git a/application/models/tables/CourseActivities.php b/application/models/tables/CourseActivities.php
index 97097ddd..a716e035 100644
--- a/application/models/tables/CourseActivities.php
+++ b/application/models/tables/CourseActivities.php
@@ -1,5 +1,11 @@
 <?php
 
+
+/**
+ *
+ * @primary course_activity_id
+ *
+ */
 class CourseActivities extends Local_Db_CourseTableMany
 {
     protected static $_instance;
@@ -24,7 +30,7 @@ class CourseActivities extends Local_Db_CourseTableMany
         $me = self::getInstance();
         $config = array('db'    => $me->_db,
                         'table' => $me,
-                        'data'  => array('course_generation' => $course->id));
+                        'data'  => array('course_generation' => $course->getPrimaryKey()));
         $newRecord = new CourseActivity($config);
         return $newRecord;
     }
@@ -45,7 +51,7 @@ class CourseActivities extends Local_Db_CourseTableMany
                           . $activityTableName . '.short_name');
 
             $select->where($where);
-            $select->order($activityTableName . '.id');
+            $select->order($activityTableName . '.' . $activityPrimary);
             $select->limit($count, $offset);
             $resultData = $this->_db->fetchAll($select);
             $config = array();
diff --git a/application/models/tables/CourseCodes.php b/application/models/tables/CourseCodes.php
index a8821ab0..b9b98ae7 100644
--- a/application/models/tables/CourseCodes.php
+++ b/application/models/tables/CourseCodes.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_code_id
+ *
+ */
 class CourseCodes extends Nmc_Db_Table
 {
 
@@ -42,7 +47,8 @@ class CourseCodes extends Nmc_Db_Table
         $where = implode(' AND ', $where);
 
         $result = $this->fetchRow($where);
-        if(! $result->id) {
+        $primaryKeyName = $this->getPrimaryKeyName(true);
+        if(! $result->$primaryKeyName) {
             $result = $this->fetchNew();
             $result->subject = $subject;
             $result->courseNumber = $number;
diff --git a/application/models/tables/CourseCredits.php b/application/models/tables/CourseCredits.php
index b04f554c..e2309866 100644
--- a/application/models/tables/CourseCredits.php
+++ b/application/models/tables/CourseCredits.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_credit_id
+ *
+ */
 class CourseCredits extends Local_Db_CourseTableMany
 {
     protected static $_instance;
@@ -24,7 +29,7 @@ class CourseCredits extends Local_Db_CourseTableMany
         $me = self::getInstance();
         $config = array('db'    => $me->_db,
                         'table' => $me,
-                        'data'  => array('course_generation' => $course->id));
+                        'data'  => array('course_generation' => $course->getPrimaryKey()));
         $newRecord = new CourseCredit($config);
         return $newRecord;
     }
diff --git a/application/models/tables/CourseCrosslistings.php b/application/models/tables/CourseCrosslistings.php
index 7db60529..f36debd2 100644
--- a/application/models/tables/CourseCrosslistings.php
+++ b/application/models/tables/CourseCrosslistings.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_crosslisting_id
+ *
+ */
 class CourseCrosslistings extends Local_Db_CourseTableMany
 {
     protected static $_instance;
@@ -32,15 +37,20 @@ class CourseCrosslistings extends Local_Db_CourseTableMany
         $me = self::getInstance();
         $db = $me->getAdapter();
 
+        $courseCrosslistingsPrimaryKeyName = $me->getPrimaryKeyName();
+        $courseCodePrimaryKeyName = CourseCodes::getInstance()->getPrimaryKeyName();
+        $courseGenerationsPrimaryKeyName = CourseGenerations::getInstance()->getPrimaryKeyName();
+        $assetsPrimaryKeyName = Assets::getInstance()->getPrimaryKeyName();
+
         $select = $db->select();
         $select->from('creq_course_codes');
         $select->join('creq_course_crosslistings',
-                      'creq_course_codes.id = creq_course_crosslistings.course_code',
-                      'id');
+                      'creq_course_codes.' . $courseCodePrimaryKeyName . ' = creq_course_crosslistings.course_code',
+                      $courseCrosslistingsPrimaryKeyName);
         $select->join('creq_course_generations',
-                      'creq_course_crosslistings.generation = creq_course_generations.id');
+                      'creq_course_crosslistings.generation = creq_course_generations.' . $courseGenerationsPrimaryKeyName);
         $select->join('creq_assets',
-                      'creq_course_generations.asset_id = creq_assets.id');
+                      'creq_course_generations.asset_id = creq_assets.' . $assetsPrimaryKeyName);
         $select->where('creq_course_generations.type = "official"');
         $select->where($db->quoteInto('subject = ?', $subject));
         $select->where($db->quoteInto('course_number = ?', $number));
@@ -48,10 +58,10 @@ class CourseCrosslistings extends Local_Db_CourseTableMany
         $select->order('creation_time DESC');
 
         $row = $db->fetchRow($select);
-        $result = $me->find($row['id']);
+        $result = $me->find($row[$courseCrosslistingsPrimaryKeyName]);
 
 
-        if($result->id == '') {
+        if($result instanceof Nmc_Db_Table_Row && $result->getPrimaryKey() == '') {
             return null;
         } else {
             return $result;
@@ -66,7 +76,7 @@ class CourseCrosslistings extends Local_Db_CourseTableMany
         $where = $db->quoteInto('course_code = ?', $courseCodeId);
         $self->fetchRow($where);
 
-        if($result->id == '') {
+        if($result->getPrimaryKey() == '') {
             return null;
         } else {
             return $result;
@@ -78,7 +88,7 @@ class CourseCrosslistings extends Local_Db_CourseTableMany
         $me = self::getInstance();
         $config = array('db'    => $me->_db,
                         'table' => $me,
-                        'data'  => array('parent_course' => $course->id));
+                        'data'  => array('parent_course' => $course->getPrimaryKey()));
         $newRecord = new CourseCrosslisting($config);
         return $newRecord;
     }
@@ -120,5 +130,3 @@ class CourseCrosslistings extends Local_Db_CourseTableMany
         return $rowset;
     }
 }
-
-?>
\ No newline at end of file
diff --git a/application/models/tables/CourseDetails.php b/application/models/tables/CourseDetails.php
index a0debddc..dd41fa88 100644
--- a/application/models/tables/CourseDetails.php
+++ b/application/models/tables/CourseDetails.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_detail_id
+ *
+ */
 class CourseDetails extends Local_Db_CourseTableOne
 {
     protected static $_instance;
diff --git a/application/models/tables/CourseDfRemovals.php b/application/models/tables/CourseDfRemovals.php
index 3eba430e..5ee9df10 100644
--- a/application/models/tables/CourseDfRemovals.php
+++ b/application/models/tables/CourseDfRemovals.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_df_removal_id
+ *
+ */
 class CourseDfRemovals extends Local_Db_CourseTableMany
 {
     protected static $_instance;
@@ -24,7 +29,7 @@ class CourseDfRemovals extends Local_Db_CourseTableMany
         $me = self::getInstance();
         $config = array('db'    => $me->_db,
                         'table' => $me,
-                        'data'  => array('course_generation_passed' => $course->id));
+                        'data'  => array('course_generation_passed' => $course->getPrimaryKey()));
         $newRecord = new CourseCredit($config);
         return $newRecord;
     }
diff --git a/application/models/tables/CourseGenerations.php b/application/models/tables/CourseGenerations.php
index 0be83841..2a292428 100644
--- a/application/models/tables/CourseGenerations.php
+++ b/application/models/tables/CourseGenerations.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_generation_id
+ *
+ */
 class CourseGenerations extends Nmc_Db_Table
 {
     protected static $_instance;
@@ -33,7 +38,7 @@ class CourseGenerations extends Nmc_Db_Table
         $me = CourseGenerations::getInstance();
 
         $row = CourseCrosslistings::fetchBySubjectNumberLetter($subject, $number, $letter);
-        if(!$row->id) {
+        if(!$row->getPrimaryKey()) {
             return null;
         }
 
diff --git a/application/models/tables/CourseGradTieIns.php b/application/models/tables/CourseGradTieIns.php
index cda84a48..b070beee 100644
--- a/application/models/tables/CourseGradTieIns.php
+++ b/application/models/tables/CourseGradTieIns.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_grad_tie_in_id
+ *
+ */
 class CourseGradTieIns extends Local_Db_CourseTableOne
 {
     protected static $_instance;
diff --git a/application/models/tables/CoursePrerequisites.php b/application/models/tables/CoursePrerequisites.php
index 88b445f2..2f523f1d 100644
--- a/application/models/tables/CoursePrerequisites.php
+++ b/application/models/tables/CoursePrerequisites.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_prerequisite_id
+ *
+ */
 class CoursePrerequisites extends Local_Db_CourseTableMany
 {
     protected static $_instance;
@@ -24,7 +29,7 @@ class CoursePrerequisites extends Local_Db_CourseTableMany
         $me = self::getInstance();
         $config = array('db'    => $me->_db,
                         'table' => $me,
-                        'data'  => array('parent_course' => $course->id));
+                        'data'  => array('parent_course' => $course->getPrimaryKey()));
         $newRecord = new CourseCredit($config);
         return $newRecord;
     }
diff --git a/application/models/tables/Courses.php b/application/models/tables/Courses.php
index 023d9ee4..25e6cf0a 100644
--- a/application/models/tables/Courses.php
+++ b/application/models/tables/Courses.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary course_id
+ *
+ */
 class Courses extends Nmc_Db_Table
 {
     protected static $_instance;
diff --git a/application/models/tables/Departments.php b/application/models/tables/Departments.php
index 0f7a6245..fdcb8946 100644
--- a/application/models/tables/Departments.php
+++ b/application/models/tables/Departments.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary department_id
+ *
+ */
 class Departments extends Nmc_Db_Table
 {
 
diff --git a/application/models/tables/Files.php b/application/models/tables/Files.php
index ef978925..b754daa5 100644
--- a/application/models/tables/Files.php
+++ b/application/models/tables/Files.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * file_id
+ *
+ */
 class Files extends Nmc_Db_Table
 {
     static protected $_instance;
diff --git a/application/models/tables/GroupImpliedMemberships.php b/application/models/tables/GroupImpliedMemberships.php
index 50f2db9b..ccb83b4d 100644
--- a/application/models/tables/GroupImpliedMemberships.php
+++ b/application/models/tables/GroupImpliedMemberships.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary group_implied_membership_id
+ *
+ */
 class GroupImpliedMemberships extends Nmc_Db_Table
 {
     protected $_rowClass = 'GroupImpliedMembership';
@@ -50,7 +55,7 @@ class GroupImpliedMemberships extends Nmc_Db_Table
     {
         $db = $this->_db;
         $where = array();
-        $where[] = $db->quoteInto('child_group = ?', $group->id);
+        $where[] = $db->quoteInto('child_group = ?', $group->getPrimaryKey());
         if(!$implied && $explicit) {
             $where[] = "explicit = 'yes'";
         } else if($implied && !$explicit) {
@@ -68,7 +73,8 @@ class GroupImpliedMemberships extends Nmc_Db_Table
         }
 
         $groupIds[] = -1;
-        $where = $db->quoteInto('id IN(?)', $groupIds);
+        $groupPrimaryKeyName = Groups::getInstance()->getPrimaryKeyName();
+        $where = $db->quoteInto('`' . $groupPrimaryKeyName . '` IN(?)', $groupIds);
         $groups = Groups::getInstance()->fetchAllWithoutPrimaries($where);
         return $groups;
     }
@@ -85,7 +91,7 @@ class GroupImpliedMemberships extends Nmc_Db_Table
     {
         $db = $this->_db;
         $where = array();
-        $where[] = $db->quoteInto('parent_group = ?', $group->id);
+        $where[] = $db->quoteInto('parent_group = ?', $group->getPrimaryKey());
         if(!$implied && $explicit) {
             $where[] = "explicit = 'yes'";
         } else if($implied && !$explicit) {
@@ -118,11 +124,16 @@ class GroupImpliedMemberships extends Nmc_Db_Table
      */
     public function fetchUsersByParentGroup(Group $group, $implied = true, $explicit = true)
     {
+        $usersTable = Users::getInstance();
+        $usersTableInfo = $usersTable->info();
+        $usersTableName = $usersTableInfo['name'];
+        $usersTablePrimary = $usersTableInfo['primary'];
+
         $select = $this->_db->select();
-        $select->from('creq_people', 'id');
+        $select->from($usersTableName, $usersTablePrimary);
         $select->join($this->_name,
-                      'creq_people.primary_group = ' . $this->_name . '.child_group');
-        $select->where($this->_db->quoteInto('parent_group = ?', $group->id));
+                      $usersTableName . '.primary_group = ' . $this->_name . '.child_group');
+        $select->where($this->_db->quoteInto('parent_group = ?', $group->getPrimaryKey()));
         if(!$implied && $explicit) {
             $select->where("explicit = 'yes'");
         } else if($implied && !$explicit) {
@@ -135,7 +146,7 @@ class GroupImpliedMemberships extends Nmc_Db_Table
 
         $userIds[] = -1;
         $where = $this->_db->quoteInto('id IN(?)', $userIds);
-        $users = People::getInstance()->fetchAll($where);
+        $users = Users::getInstance()->fetchAll($where);
         return $users;
     }
 }
diff --git a/application/models/tables/GroupMemberships.php b/application/models/tables/GroupMemberships.php
index 6c0f809c..43d587f8 100644
--- a/application/models/tables/GroupMemberships.php
+++ b/application/models/tables/GroupMemberships.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary group_membership_id
+ *
+ */
 class GroupMemberships extends Nmc_Db_Table
 {
     protected static $_instance = null;
diff --git a/application/models/tables/Groups.php b/application/models/tables/Groups.php
index 1f8a954f..02996805 100644
--- a/application/models/tables/Groups.php
+++ b/application/models/tables/Groups.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary group_id
+ *
+ */
 class Groups extends Nmc_Db_Table
 {
     protected $_rowClass = 'Group';
@@ -41,13 +46,13 @@ class Groups extends Nmc_Db_Table
     {
         $db = $this->_db;
         $select = $db->select();
-        $userTableInfo = People::getInstance()->info();
+        $userTableInfo = Users::getInstance()->info();
         $userTableName = $userTableInfo['name'];
         $select->from($userTableName, 'primary_group');
         $select->distinct();
         $primaryGroupIds = $db->fetchCol($select);
 
-        $extra_where = $db->quoteInto($this->_name . '.id NOT IN(?)', $primaryGroupIds);
+        $extra_where = $db->quoteInto($this->_name . '.' . $this->_primary . ' NOT IN(?)', $primaryGroupIds);
         if($where) {
             $where .= ' AND ';
         }
diff --git a/application/models/tables/People.php b/application/models/tables/People.php
index 299bcc10..c684b193 100644
--- a/application/models/tables/People.php
+++ b/application/models/tables/People.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary person_id
+ *
+ */
 class People extends Nmc_Db_Table
 {
     static private $_instance;
@@ -29,9 +34,36 @@ class People extends Nmc_Db_Table
     static public function findByUserName($userName)
     {
         $me = self::getInstance();
-        $where = $me->_getDefaultAdapter()->quoteInto('user_name=?', $userName);
+        $db = $me->_getDefaultAdapter();
+        $inflector = new Zend_Db_Inflector();
+
+        $usersTable = Users::getInstance();
+        $usersPrimaryKey = $usersTable->getPrimaryKeyName();
+        $usersPrimaryKey = $inflector->camelize($usersPrimaryKey);
+
+
+        $where = $db->quoteInto('user_name=?', $userName);
+        $user = $usersTable->fetchRow($where);
+
+        $where = $db->quoteInto('user_id=?', $user->$usersPrimaryKey);
         return $me->fetchRow($where);
     }
+
+    public function findByUser(User $user)
+    {
+        return $this->findByUserId($user->getPrimaryKey());
+    }
+
+    public function findByUserId($userId)
+    {
+        if(is_array($userId)) {
+            $where = $this->_db->quoteInto('user_id IN (?)', $userId);
+            return $this->fetchAll($where);
+        } else {
+            $where = $this->_db->quoteInto('user_id=?', $userId);
+            return $this->fetchRow($where);
+        }
+    }
 }
 
 ?>
\ No newline at end of file
diff --git a/application/models/tables/RequestFiles.php b/application/models/tables/RequestFiles.php
index 352d7bb9..c65f2d8f 100644
--- a/application/models/tables/RequestFiles.php
+++ b/application/models/tables/RequestFiles.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary request_file_id
+ *
+ */
 class RequestFiles extends Nmc_Db_Table
 {
     static protected $_instance;
@@ -15,7 +20,7 @@ class RequestFiles extends Nmc_Db_Table
 
     public function getByRequest(Request $request)
     {
-        $where = $this->getAdapter()->quoteInto('request = ?', $request->id);
+        $where = $this->getAdapter()->quoteInto('request = ?', $request->getPrimaryKey());
         return $this->fetchAll($where);
     }
 }
diff --git a/application/models/tables/RequestStacks.php b/application/models/tables/RequestStacks.php
index ec466847..1b583107 100644
--- a/application/models/tables/RequestStacks.php
+++ b/application/models/tables/RequestStacks.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary request_stack_id
+ *
+ */
 class RequestStacks extends Nmc_Db_Table {}
 
 ?>
\ No newline at end of file
diff --git a/application/models/tables/RequestTypes.php b/application/models/tables/RequestTypes.php
index b277de24..60c081a2 100644
--- a/application/models/tables/RequestTypes.php
+++ b/application/models/tables/RequestTypes.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary request_type_id
+ *
+ */
 class RequestTypes extends Nmc_Db_Table
 {
     private static $_instance;
@@ -10,7 +15,7 @@ class RequestTypes extends Nmc_Db_Table
         parent::__construct($config);
         $contents = $this->fetchAll();
         foreach($contents as $row) {
-            $this->_map[$row->name] = $row->id;
+            $this->_map[$row->name] = $row->getPrimaryKey();
         }
     }
 
diff --git a/application/models/tables/Requests.php b/application/models/tables/Requests.php
index 460a46a9..f669f12e 100644
--- a/application/models/tables/Requests.php
+++ b/application/models/tables/Requests.php
@@ -1,5 +1,10 @@
 <?php
 
+/**
+ *
+ * @primary request_id
+ *
+ */
 class Requests extends Nmc_Db_Table {
 
     protected static $_instance;
@@ -20,7 +25,12 @@ class Requests extends Nmc_Db_Table {
 
     public function getRequestsForUser(Person $user)
     {
-        $where = $this->_db->quoteInto('owner = ?', $user->id);
+        $usersTable = Users::getInstance();
+        $usersPrimaryKey = $usersTable->getPrimaryKeyName();
+        $inflector = new Zend_Db_Inflector();
+        $usersPrimaryKey = $inflector->camelize($usersPrimaryKey);
+
+        $where = $this->_db->quoteInto('owner = ?', $user->$usersPrimaryKey);
         $requests = $this->fetchAll($where);
         return $requests;
     }
diff --git a/application/models/tables/Users.php b/application/models/tables/Users.php
new file mode 100644
index 00000000..117f2fd6
--- /dev/null
+++ b/application/models/tables/Users.php
@@ -0,0 +1,28 @@
+<?php
+
+/**
+ *
+ * @primary user_id
+ *
+ */
+class Users extends Nmc_Db_Table
+{
+    static private $_instance;
+    protected $_rowClass = 'User';
+
+    /**
+     * Return the one true instance
+     *
+     * @param array $config
+     * @return Users
+     */
+    static public function getInstance($config = array())
+    {
+        if(!self::$_instance) {
+            self::$_instance = new Users($config);
+        }
+        return self::$_instance;
+    }
+}
+
+?>
\ No newline at end of file
diff --git a/application/views/approval_body_admin.xhtml b/application/views/approval_body_admin.xhtml
index b6b28baf..e7e6dd5c 100644
--- a/application/views/approval_body_admin.xhtml
+++ b/application/views/approval_body_admin.xhtml
@@ -3,18 +3,18 @@
     <ul>
         <?php foreach($this->approvalBodies as $approvalBody) { ?>
         <li>
-            <a href="/ApprovalBodyAdmin/EditBody/<?php echo $approvalBody->id; ?>">
+            <a href="/ApprovalBodyAdmin/EditBody/<?php echo $approvalBody->getPrimaryKey(); ?>">
                 <?php echo $approvalBody->name; ?>
             </a>
             <ul>
                 <li>
-                    <a href="/ApprovalBodyAdmin/AddRole/<?php echo $approvalBody->id; ?>">
+                    <a href="/ApprovalBodyAdmin/AddRole/<?php echo $approvalBody->getPrimaryKey(); ?>">
                         --Add New Role--
                     </a>
                 </li>
                 <?php foreach($approvalBody->roles as $role) { ?>
                 <li>
-                    <a href="/ApprovalbodyAdmin/EditRole/<?php echo $role->id; ?>">
+                    <a href="/ApprovalbodyAdmin/EditRole/<?php echo $role->getPrimaryKey(); ?>">
                         <?php echo $role->name; ?>
                     </a>
                 </li>
@@ -28,7 +28,7 @@
 <?php if($this->approvalBody) { ?>
 <div id="edit_user" class="edit_pane">
     <h2>Editing Approval Body: <?php echo $this->approvalBody->name; ?></h2>
-    <form action="/ApprovalBodyAdmin/EditBodyPost/<?php echo $this->approvalBody->id; ?>" method="post">
+    <form action="/ApprovalBodyAdmin/EditBodyPost/<?php echo $this->approvalBody->getPrimaryKey(); ?>" method="post">
         <label for="name">Name:</label>
         <?php echo $this->formText('name',
                                    $this->approvalBody->name,
@@ -45,8 +45,8 @@
 <?php if($this->approvalBodyRole) { ?>
 <div id="edit_user" class="edit_pane">
     <h2>Editing Approval Body Role: <?php echo $this->approvalBodyRole->name; ?></h2>
-    <?php if($this->approvalBodyRole->id) { ?>
-    <form action="/ApprovalBodyAdmin/EditRolePost/<?php echo $this->approvalBodyRole->id; ?>" method="post">
+    <?php if($this->approvalBodyRole->getPrimaryKey()) { ?>
+    <form action="/ApprovalBodyAdmin/EditRolePost/<?php echo $this->approvalBodyRole->getPrimaryKey(); ?>" method="post">
     <?php } else { ?>
     <form action="/ApprovalBodyAdmin/EditRolePost/-<?php echo $this->approvalBodyRole->approvalBody; ?>" method="post">
     <?php } ?>
diff --git a/application/views/conflict.xhtml b/application/views/conflict.xhtml
index a8cbd43c..13b0ffdb 100644
--- a/application/views/conflict.xhtml
+++ b/application/views/conflict.xhtml
@@ -9,11 +9,11 @@
 
 <ul id="selections">
     <?php foreach($this->dups as $dup) { ?>
-    <li id="<?php echo $dup->id; ?>">
+    <li id="<?php echo $dup->getPrimaryKey(); ?>">
         <?php __bulletinPreview($dup); ?>
         <div class="choices">
-            <a class="delete" href="/conflict/remove/<?php echo $dup->id; ?>">Delete</a>
-            <a class="edit" href="/CourseAdmin/index/<?php echo $dup->id; ?>">Edit</a>
+            <a class="delete" href="/conflict/remove/<?php echo $dup->getPrimaryKey(); ?>">Delete</a>
+            <a class="edit" href="/CourseAdmin/index/<?php echo $dup->getPrimaryKey(); ?>">Edit</a>
         </div>
     </li>
     <?php } ?>
diff --git a/application/views/editAddress.xhtml b/application/views/editAddress.xhtml
index c64f937f..17a26a04 100644
--- a/application/views/editAddress.xhtml
+++ b/application/views/editAddress.xhtml
@@ -1,5 +1,5 @@
 <form action="/testform/save" method="post">
-    <input type="hidden" name="id" value="<?php echo $this->record->id; ?>" />
+    <input type="hidden" name="id" value="<?php echo $this->record->getPrimaryKey(); ?>" />
     First Name:<br />
     <input type="text" name="firstName" value="<?php echo $this->record->firstName; ?>" /><br />
     Last Name:<br />
diff --git a/application/views/edit_course.xhtml b/application/views/edit_course.xhtml
index 21a932df..becb35a2 100644
--- a/application/views/edit_course.xhtml
+++ b/application/views/edit_course.xhtml
@@ -3,7 +3,7 @@
 
 <form action="/courseadmin/updatecourse/<?php echo implode('/', $this->uriParams); ?>" method="post">
 
-<input type="hidden" name="courseId" value="<?php echo $this->course->id; ?>" />
+<input type="hidden" name="courseId" value="<?php echo $this->course->getPrimaryKey(); ?>" />
 
 <h2>Main Details</h2>
 <fieldset>
@@ -403,17 +403,17 @@
     <?php foreach($this->course->dfRemovals as $key => $dfRemoval) { ?>
     <tr>
         <td>
-            <input type="text" name="crosslistings[<?php echo $dfRemoval->id; ?>][subject]" value="<?php echo $crosslisting->subject; ?>" />
+            <input type="text" name="crosslistings[<?php echo $dfRemoval->getPrimaryKey(); ?>][subject]" value="<?php echo $crosslisting->subject; ?>" />
         </td>
         <td>
-            <input type="text" name="crosslistings[<?php echo $dfRemoval->id; ?>][courseNumber]" value="<?php echo $crosslisting->courseNumber; ?>" />
+            <input type="text" name="crosslistings[<?php echo $dfRemoval->getPrimaryKey(); ?>][courseNumber]" value="<?php echo $crosslisting->courseNumber; ?>" />
         </td>
         <td>
-            <input type="text" name="crosslistings[<?php echo $dfRemoval->id; ?>][courseLetter]" value="<?php echo $crosslisting->courseLetter; ?>" />
+            <input type="text" name="crosslistings[<?php echo $dfRemoval->getPrimaryKey(); ?>][courseLetter]" value="<?php echo $crosslisting->courseLetter; ?>" />
         </td>
         <td>
-            <input type="hidden" name="dfRemovals[<?php echo $dfRemoval->id; ?>][delete]" value="no" />
-            <input type="checkbox" name="dfRemovals[<?php echo $dfRemoval->id; ?>][delete]" value="yes" />
+            <input type="hidden" name="dfRemovals[<?php echo $dfRemoval->getPrimaryKey(); ?>][delete]" value="no" />
+            <input type="checkbox" name="dfRemovals[<?php echo $dfRemoval->getPrimaryKey(); ?>][delete]" value="yes" />
         </td>
     </tr>
     <?php } ?>
@@ -432,17 +432,17 @@
     <?php foreach($this->course->prerequisites as $key => $prerequisite) { ?>
     <tr>
         <td>
-            <input type="text" name="crosslistings[<?php echo $prerequisite->id; ?>][subject]" value="<?php echo $crosslisting->subject; ?>" />
+            <input type="text" name="crosslistings[<?php echo $prerequisite->getPrimaryKey(); ?>][subject]" value="<?php echo $crosslisting->subject; ?>" />
         </td>
         <td>
-            <input type="text" name="crosslistings[<?php echo $prerequisite->id; ?>][courseNumber]" value="<?php echo $crosslisting->courseNumber; ?>" />
+            <input type="text" name="crosslistings[<?php echo $prerequisite->getPrimaryKey(); ?>][courseNumber]" value="<?php echo $crosslisting->courseNumber; ?>" />
         </td>
         <td>
-            <input type="text" name="crosslistings[<?php echo $prerequisite->id; ?>][courseLetter]" value="<?php echo $crosslisting->courseLetter; ?>" />
+            <input type="text" name="crosslistings[<?php echo $prerequisite->getPrimaryKey(); ?>][courseLetter]" value="<?php echo $crosslisting->courseLetter; ?>" />
         </td>
         <td>
-            <input type="hidden" name="prerequisites[<?php echo $prerequisite->id; ?>][delete]" value="no" />
-            <input type="checkbox" name="prerequisites[<?php echo $prerequisite->id; ?>][delete]" value="yes" />
+            <input type="hidden" name="prerequisites[<?php echo $prerequisite->getPrimaryKey(); ?>][delete]" value="no" />
+            <input type="checkbox" name="prerequisites[<?php echo $prerequisite->getPrimaryKey(); ?>][delete]" value="yes" />
         </td>
     </tr>
     <?php } ?>
@@ -452,7 +452,7 @@
 
 </form>
 
-<form id="delete_course" method="post" action="/CourseAdmin/DeleteCourse/<?php echo $this->course->id; ?>">
+<form id="delete_course" method="post" action="/CourseAdmin/DeleteCourse/<?php echo $this->course->getPrimaryKey(); ?>">
     <label>
         Enable Delete
         <input type="checkbox" id="enable_delete" />
diff --git a/application/views/listAddress.xhtml b/application/views/listAddress.xhtml
index 19df2d2c..faabdc8b 100644
--- a/application/views/listAddress.xhtml
+++ b/application/views/listAddress.xhtml
@@ -13,7 +13,7 @@
         <td><?php echo $record->phone; ?></td>
         <td><?php echo $record->address; ?></td>
         <td><?php echo $record->zip; ?></td>
-        <td><a href="/testform/edit/<?php echo $record->id; ?>">Edit</a></td>
+        <td><a href="/testform/edit/<?php echo $record->getPrimaryKey(); ?>">Edit</a></td>
     </tr>
     <?php } ?>
 </table>
\ No newline at end of file
diff --git a/application/views/my_home.xhtml b/application/views/my_home.xhtml
index eb13f35d..1631d1d8 100644
--- a/application/views/my_home.xhtml
+++ b/application/views/my_home.xhtml
@@ -17,12 +17,12 @@
         <div class="tr"></div>
         <div class="tl">
             <h2>Activity</h2>
-            <h3><em>Curent Roll:</em> Instructor</h3>
+            <h3><em>Curent Roll:</em> Yourself</h3>
         </div>
         <div class="bl"></div>
     </div>
     <div class="content">
-        <?php if($this->requests->count() == 0) { ?>
+        <?php if($this->myRequests->count() == 0) { ?>
         <h2>You currently have no requests.</h2>
         <?php } else { ?>
         <table class="course_list">
@@ -36,7 +36,7 @@
             </tr>
             <?php
             $row = 0;
-            foreach($this->requests as $request) {
+            foreach($this->myRequests as $request) {
                 $course = $request->getCourseGeneration();
             ?>
             <tr <?php echo (++$row % 2 ? 'class="odd"' : ''); ?>>
@@ -47,7 +47,7 @@
                 <td><?php echo $request->type; ?></td>
                 <td><select><option>Submission</option></select></td>
                 <td>
-                    <a href="/NewRequest/Load/<?php echo $request->id; ?>">
+                    <a href="/NewRequest/Load/<?php echo $request->getPrimaryKey(); ?>">
                         View/Edit
                     </a>
                 </td>
@@ -56,6 +56,52 @@
         </table>
         <?php } ?>
     </div>
+
+    <?php foreach($this->roles as $role) { ?>
+    <div class="box_shadow_2">
+        <div class="tr"></div>
+        <div class="tl">
+            <h2>Activity</h2>
+            <h3><em>Curent Roll:</em> <?php echo $role->name; ?></h3>
+        </div>
+        <div class="bl"></div>
+    </div>
+    <div class="content">
+        <?php if($role->getRequests()->count() == 0) { ?>
+        <h2>This role currently has no requests.</h2>
+        <?php } else { ?>
+        <table class="course_list">
+            <tr>
+                <th id="check">&#160;</th>
+                <th id="course">Course</th>
+                <th id="college">College</th>
+                <th id="type">Type</th>
+                <th id="status">Status</th>
+                <th id="view_edit">View/Edit</th>
+            </tr>
+            <?php
+            $row = 0;
+            foreach($role->getRequests() as $request) {
+                $course = $request->getCourseGeneration();
+            ?>
+            <tr <?php echo (++$row % 2 ? 'class="odd"' : ''); ?>>
+                <td><input type="checkbox" /></td>
+                <td><?php echo $request->getCourseGeneration()->subject . ' '
+                             . $request->getCourseGeneration()->courseNumber; ?></td>
+                <td>NONC</td>
+                <td><?php echo $request->type; ?></td>
+                <td><select><option>Submission</option></select></td>
+                <td>
+                    <a href="/NewRequest/Load/<?php echo $request->getPrimaryKey(); ?>">
+                        View/Edit
+                    </a>
+                </td>
+            </tr>
+            <?php } ?>
+        </table>
+        <?php } ?>
+    </div>
+    <?php } ?>
 </div>
 
 
diff --git a/application/views/user_admin.xhtml b/application/views/user_admin.xhtml
index 51d5c12c..957cef65 100644
--- a/application/views/user_admin.xhtml
+++ b/application/views/user_admin.xhtml
@@ -1,13 +1,13 @@
 <?php function list_group(Group $group, $depth = 0) { ?>
 <h3>
-    <a href="/UserAdmin/EditGroup/<?php echo $group->id; ?>">
+    <a href="/UserAdmin/EditGroup/<?php echo $group->getPrimaryKey(); ?>">
         <?php echo $group->name; ?>
     </a>
 </h3>
 <ul>
     <?php foreach($group->getUsers(false) as $user) { ?>
     <li>
-        <a href="/UserAdmin/EditUser/<?php echo $user->id; ?>">
+        <a href="/UserAdmin/EditUser/<?php echo $user->getPrimaryKey(); ?>">
             <?php echo $user->userName; ?>
         </a>
     </li>
@@ -40,7 +40,7 @@
 <?php if($this->user) { ?>
 <div id="edit_user" class="edit_pane">
     <h2>Editing User: <?php echo $this->user->userName; ?></h2>
-    <form action="/UserAdmin/EditUser/<?php echo $this->user->id; ?>" method="post">
+    <form action="/UserAdmin/EditUser/<?php echo $this->user->getPrimaryKey(); ?>" method="post">
         <label for="firstName">First Name:</label>
         <?php echo $this->formText('firstName',
                                    $this->user->firstName,
@@ -62,7 +62,7 @@
 <?php if($this->group) { ?>
 <div id="edit_group" class="edit_pane">
     <h2>Editing Group: <?php echo $this->group->name; ?></h2>
-    <form action="/UserAdmin/EditGroup/<?php echo $this->group->id; ?>" method="post">
+    <form action="/UserAdmin/EditGroup/<?php echo $this->group->getPrimaryKey(); ?>" method="post">
         <label for="delete">
             Delete: <?php echo $this->formCheckBox('delete', null, array('id' => 'delete')); ?>
         </label>
-- 
GitLab