Commit bca4d35f authored by Tim Steiner's avatar Tim Steiner
Browse files

Lots of updates for primary key name changes as well as dynamic primary key functions.

Also contains new code for inheritting Database Row Models.
parent c298d54e
......@@ -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();
}
}
......
......@@ -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
......@@ -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();
......
......@@ -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();
}
......
......@@ -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();
......
......@@ -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";
}
}
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
<?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
......@@ -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;
}
......
......@@ -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();
}
......
<?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
*
......
......@@ -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();
......
......@@ -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()
......
......@@ -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) {
......
<?php
/**
*
* @tableClass Users
*
*/
class User extends Nmc_Db_Table_Row
{
static public $tableClass = 'Users';
// generic user model
}
\ No newline at end of file
<?php
/**
*
* @primary activity_type_id
*
*/
class ActivityTypes extends Nmc_Db_Table
{
/**
......
<?php
/**
*
* @primary approval_body_id
*
*/
class ApprovalBodies extends Nmc_Db_Table
{
protected $_rowClass = 'ApprovalBody';
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment