Skip to content

Commit

Permalink
Merge branch 'hotfix-v1.2.2'
Browse files Browse the repository at this point in the history
  • Loading branch information
taija committed Aug 8, 2019
2 parents 0e374d9 + b4a726f commit 691fe04
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 7 deletions.
11 changes: 6 additions & 5 deletions app/Http/Controllers/SubjectController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
namespace App\Http\Controllers;

use App\Models\Subject;
use App\Models\SubjectPrefix;
use App\Http\Transformers\SubjectTransformer;
use App\Http\Transformers\SubjectPrefixTransformer;
use App\Http\Controllers\Controller;
use App\Http\Serializers\CustomDataArraySerializer;
use Illuminate\Http\Request;
Expand All @@ -20,11 +22,10 @@ class SubjectController extends ApiController{
* Return all subjects
**/
public function index(Manager $fractal){
$subjects = Subject::all();

$subjects = SubjectPrefix::with('subject')->get();
$data = $subjects;
if ( !is_null($subjects) ) {
$collection = new Collection($subjects, new SubjectTransformer, self::WRAPPER);
$collection = new Collection($subjects, new SubjectPrefixTransformer, self::WRAPPER);

$fractal->setSerializer(new CustomDataArraySerializer);
$data = $fractal->createData($collection)->toArray();
Expand All @@ -38,12 +39,12 @@ public function index(Manager $fractal){
**/
public function getSubject($slug){

$subject = Subject::where('Slug', '=', $slug)->first();
$subject = SubjectPrefix::where('CoursePrefixID', '=', $slug)->first();

$data = $subject;
//handle gracefully if null
if( !is_null($subject) ) {
$item = new Item($subject, new SubjectTransformer, "subject");
$item = new Item($subject, new SubjectPrefixTransformer, "subject");

$fractal = new Manager;

Expand Down
22 changes: 22 additions & 0 deletions app/Http/Transformers/SubjectPrefixTransformer.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php namespace App\Http\Transformers;

use App\Models\SubjectPrefix;
use League\Fractal\Resource\Collection;
use League\Fractal\TransformerAbstract;

class SubjectPrefixTransformer extends TransformerAbstract {

/**
* A Fractal transformer for a subject. Defines how data for
* a subject should be output in the API.
**/

public function transform(SubjectPrefix $prefix)
{
return [
'subject' => $prefix->CoursePrefixID,
'name' => $prefix->subject->Title,
];
}

}
6 changes: 5 additions & 1 deletion app/Models/Subject.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ class Subject extends Model
protected $connection = 'cs';
protected $primaryKey = 'SubjectID';
public $timestamps = false;


public function prefixes()
{
return $this->hasMany('App\Models\SubjectPrefix', 'SubjectID');
}
}
?>
22 changes: 22 additions & 0 deletions app/Models/SubjectPrefix.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class SubjectPrefix extends Model
{
/**
* Model for course subject prefixes (many to one with Subjects)
**/
protected $table = 'SubjectsCoursePrefixes';
protected $connection = 'cs';
protected $primaryKey = 'CoursePrefixID';
public $timestamps = false;
public $incrementing = false;

public function subject()
{
return $this->belongsTo('App\Models\Subject', 'SubjectID');
}
}
2 changes: 1 addition & 1 deletion config/dataapi.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
'yearquarter_max' => 'Z999',
'timezone' => 'America/Los_Angeles',
'common_course_char' => '&',
'app_version' => '1.2.1',
'app_version' => '1.2.2',
'admin_group' => env('ADMIN_GROUP', null),
'api_internal_domain' => env('API_INTERNAL_DOMAIN', 'internal.localhost.test'),
];

0 comments on commit 691fe04

Please sign in to comment.