Skip to content
Snippets Groups Projects
Commit 1b897842 authored by Tim Steiner's avatar Tim Steiner
Browse files

Generic Asset model and supporting files

parent ce831ae3
No related branches found
No related tags found
No related merge requests found
<?php
class Asset extends Nmc_Db_Table_Row
{
static public $tableClass = 'Assets';
}
?>
\ No newline at end of file
...@@ -2,17 +2,14 @@ ...@@ -2,17 +2,14 @@
class CourseGeneration extends Nmc_Db_Table_Row class CourseGeneration extends Nmc_Db_Table_Row
{ {
/*
public $request;
public $gradTieIn;
public $integratedStudies;
*/
protected $_homeCrosslisting; protected $_homeCrosslisting;
public function __construct($config = array()) public function __construct($config = array())
{ {
parent::__construct($config); parent::__construct($config);
$this->_registerRelation(
new Nmc_Db_Table_Relation_Extend(Assets::getInstance(), $this, 'assetId'));
$this->_registerRelation( $this->_registerRelation(
new Nmc_Db_Table_Relation_HasOne(CourseDetails::getInstance(), $this, 'generation')); new Nmc_Db_Table_Relation_HasOne(CourseDetails::getInstance(), $this, 'generation'));
$this->_registerRelation( $this->_registerRelation(
...@@ -89,7 +86,7 @@ class CourseGeneration extends Nmc_Db_Table_Row ...@@ -89,7 +86,7 @@ class CourseGeneration extends Nmc_Db_Table_Row
} }
$saveCourse = $this->course; $saveCourse = $this->course;
$saveCreated = $this->created; $saveCreationTime = $this->creationTime;
if($this->request instanceof Request) { if($this->request instanceof Request) {
$saveRequest = $this->request->toArray(); $saveRequest = $this->request->toArray();
} }
...@@ -101,8 +98,8 @@ class CourseGeneration extends Nmc_Db_Table_Row ...@@ -101,8 +98,8 @@ class CourseGeneration extends Nmc_Db_Table_Row
$course->save(); $course->save();
$this->course = $course->id; $this->course = $course->id;
} }
if(!$this->created) { if(!$this->creationTime) {
$this->created = time(); $this->creationTime = time();
} }
if($this->request instanceof Request) { if($this->request instanceof Request) {
...@@ -123,7 +120,7 @@ class CourseGeneration extends Nmc_Db_Table_Row ...@@ -123,7 +120,7 @@ class CourseGeneration extends Nmc_Db_Table_Row
} }
$this->course = $saveCourse; $this->course = $saveCourse;
$this->created = $saveCreated; $this->creationTime = $saveCreationTime;
if($this->request instanceof Request) { if($this->request instanceof Request) {
$this->_data['request'] = $saveRequestId; $this->_data['request'] = $saveRequestId;
$this->request->setFromArray($saveRequest); $this->request->setFromArray($saveRequest);
......
...@@ -19,11 +19,19 @@ class Request extends Nmc_Db_Table_Row ...@@ -19,11 +19,19 @@ class Request extends Nmc_Db_Table_Row
{ {
$returnValue = null; $returnValue = null;
$where = $this->_db->quoteInto('request = ?', $this->id); $select = $this->_db->select();
$order = 'created'; $select->from(CourseGenerations::getInstance()->getTableName(),
$generations = CourseGenerations::getInstance()->fetchAll($where, $order); CourseGenerations::getInstance()->getPrimaryKeyName());
if($generations->count() > 0) { $select->join(Assets::getInstance()->getTableName(),
$returnValue = $generations[0]; CourseGenerations::getInstance()->getTableName()
. '.asset_id = '
. Assets::getInstance()->getTableName() . '.'
. Assets::getInstance()->getPrimaryKeyName());
$select->where($this->_db->quoteInto('request = ?', $this->id));
$select->order('creation_time');
$generations = $this->_db->fetchCol($select);
if(count($generations) > 0) {
$returnValue = CourseGenerations::getInstance()->find($generations[0]);
} }
return $returnValue; return $returnValue;
......
<?php
class Assets extends Nmc_Db_Table
{
protected $_rowClass = 'Asset';
/**
* The one true instance
*
* @var Assets
*/
protected static $_instance = null;
/**
* Returns the one true instance
*
* @return Assets
*/
public static function getInstance($config = array())
{
if(!self::$_instance) {
self::$_instance = new Assets($config);
}
return self::$_instance;
}
}
?>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment