From 0ea3509c98845ffb0cba6d3fe4711870e68f0ab7 Mon Sep 17 00:00:00 2001
From: Tim Steiner <tsteiner2@unl.edu>
Date: Mon, 11 Dec 2006 18:47:05 +0000
Subject: [PATCH] Updates to view parent and child course generations

---
 .../controllers/CourseadminController.php     |  3 +++
 application/models/rows/CourseGeneration.php  | 15 +++++++++++
 application/models/rows/Request.php           |  5 ++--
 .../models/tables/CourseGenerations.php       |  7 ++++++
 application/views/edit_course.xhtml           | 25 +++++++++++++++++--
 5 files changed, 50 insertions(+), 5 deletions(-)

diff --git a/application/controllers/CourseadminController.php b/application/controllers/CourseadminController.php
index 85026a3c..2db404af 100644
--- a/application/controllers/CourseadminController.php
+++ b/application/controllers/CourseadminController.php
@@ -63,6 +63,7 @@ class CourseAdminController extends Nmc_Controller_Action
             $out->assign('nextCourseLink', $nextCourseLink);
 
         }
+
         $creditsSingleValues = array();
         foreach($course->credits as $credit) {
             if($credit->type == 1) {
@@ -81,6 +82,8 @@ class CourseAdminController extends Nmc_Controller_Action
 
         $out->assign('page', 'edit_course');
         $out->assign('course', $course);
+        $out->assign('parentGeneration', $course->getParentGeneration());
+        $out->assign('childGenerations', $course->getChildGenerations());
         $out->assign('uriParams', $uriParams);
         echo $out->render();
     }
diff --git a/application/models/rows/CourseGeneration.php b/application/models/rows/CourseGeneration.php
index 117acb18..04107f34 100644
--- a/application/models/rows/CourseGeneration.php
+++ b/application/models/rows/CourseGeneration.php
@@ -138,6 +138,21 @@ class CourseGeneration extends Asset
         return $this->assetId;
     }
 
+    public function getParentGeneration()
+    {
+        if(!$this->parent) {
+            return null;
+        }
+
+        $parentGeneration = CourseGenerations::getInstance()->find($this->parent);
+        return $parentGeneration;
+    }
+
+    public function getChildGenerations()
+    {
+        return CourseGenerations::getInstance()->fetchWithParentGeneration($this);
+    }
+
     /**
      * Returns a reference to the home crosslist
      *
diff --git a/application/models/rows/Request.php b/application/models/rows/Request.php
index 5df0ce0b..831ab20d 100644
--- a/application/models/rows/Request.php
+++ b/application/models/rows/Request.php
@@ -18,8 +18,6 @@ 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(),
@@ -29,8 +27,9 @@ class Request extends Nmc_Db_Table_Row
                       . '.asset_id = '
                       . Assets::getInstance()->getTableName() . '.'
                       . Assets::getInstance()->getPrimaryKeyName());
-        $select->where($this->_db->quoteInto('request = ?', $this->$primaryKey));
+        $select->where($this->_db->quoteInto('request = ?', $this->getPrimaryKey()));
         $select->order('creation_time');
+
         $generations = $this->_db->fetchCol($select);
         if(count($generations) > 0) {
             $returnValue = CourseGenerations::getInstance()->find($generations[0]);
diff --git a/application/models/tables/CourseGenerations.php b/application/models/tables/CourseGenerations.php
index 2a292428..9410c3a9 100644
--- a/application/models/tables/CourseGenerations.php
+++ b/application/models/tables/CourseGenerations.php
@@ -137,6 +137,13 @@ class CourseGenerations extends Nmc_Db_Table
         //print_r($newRecord->credits);
         return $newRecord;
     }
+
+    public function fetchWithParentGeneration(CourseGeneration $parentGeneration)
+    {
+        $where = $this->_db->quoteInto('parent=?', $parentGeneration->getPrimaryKey());
+        $childGenerations = $this->fetchAll($where);
+        return $childGenerations;
+    }
 }
 
 ?>
\ No newline at end of file
diff --git a/application/views/edit_course.xhtml b/application/views/edit_course.xhtml
index becb35a2..ff0f2bf7 100644
--- a/application/views/edit_course.xhtml
+++ b/application/views/edit_course.xhtml
@@ -1,6 +1,27 @@
-<a href="/courseadmin/index<?php echo $this->prevCourseLink; ?>">Previous</a>
-<a href="/courseadmin/index<?php echo $this->nextCourseLink; ?>">Next</a>
+<h1>Navigation</h1>
+<div>
+    <b>Alphabetical: </b>
+    <a href="/courseadmin/index<?php echo $this->prevCourseLink; ?>">Previous</a>
+    <a href="/courseadmin/index<?php echo $this->nextCourseLink; ?>">Next</a>
+</div>
 
+<?php if ($this->parentGeneration || $this->childGenerations->count() > 0) { ?>
+<div>
+    <b>Generational:</b>
+    <?php if ($this->parentGeneration) { ?>
+    <a href="/CourseAdmin/index/<?php echo $this->parentGeneration->getPrimaryKey();?>">Parent</a>
+    <?php } ?>
+
+    <?php if ($this->childGenerations->count() > 0) { ?>
+    Children:
+    <?php $i = 0; foreach ($this->childGenerations as $childGeneration) { $i++; ?>
+    <a href="/CourseAdmin/index/<?php echo $childGeneration->getPrimaryKey();?>"><?php echo $i; ?></a>
+    <?php } ?>
+    <?php } ?>
+</div>
+<?php } ?>
+
+<h1>Edit Course</h1>
 <form action="/courseadmin/updatecourse/<?php echo implode('/', $this->uriParams); ?>" method="post">
 
 <input type="hidden" name="courseId" value="<?php echo $this->course->getPrimaryKey(); ?>" />
-- 
GitLab