Skip to content

Commit 80165f3

Browse files
authored
Merge branch 'dev' into jteitelb
2 parents 2a6f129 + 4bd40d1 commit 80165f3

20 files changed

Lines changed: 529 additions & 14175 deletions

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,3 +7,4 @@ composer.lock
77
Homestead.json
88
Homestead.yaml
99
.env
10+
npm-debug.log

app/Course.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ public function enrollments()
2222
private function _constraints($user, $assignment)
2323
{
2424
$repo_id = null;
25-
if($assignment->requiresRepository)
26-
{
25+
if ($assignment->requiresRepository) {
2726
//$path = 'repositories/'.$this->id.'/'.$assignment->id.'/'.$user->id.'/';
2827
$path = 'repositories/'.$this->slug.'/'.$assignment->slug.'/'.$user->id.'/';
2928
$name = $assignment->slug;
@@ -35,8 +34,6 @@ private function _constraints($user, $assignment)
3534
'backend' => 'git',
3635
]
3736
);
38-
//Initialize the repository
39-
$repo->repository();
4037
$repo_id = $repo->id;
4138
}
4239

@@ -49,16 +46,19 @@ private function _constraints($user, $assignment)
4946
);
5047

5148
$submission->save();
49+
//Initialize the repository
50+
$repo->repository();
5251
}
5352

54-
// Register a user for a course
55-
//TODO: Extend this to allow collections
53+
/* Register a user for a course
54+
/ TODO: Extend this to allow collections
55+
*/
5656
public function register(User $user, $role)
5757
{
5858
$this->enrollments()->attach($user->id, ['role' => $role]);
5959

6060
//We must also add submissions for a student
61-
if($role == 'student') {
61+
if ($role == 'student') {
6262
$assignments = $this->assignments()->get();
6363
foreach ($assignments as $assignment) {
6464
$this->_constraints($user, $assignment);

app/Http/Controllers/CourseController.php

Lines changed: 68 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
namespace App\Http\Controllers;
44

55
use App\Course;
6+
use App\Assignment;
7+
use Illuminate\Support\Facades\DB;
68
use Illuminate\Http\Request;
79

810
class CourseController extends Controller
@@ -24,8 +26,12 @@ public function __construct()
2426
*/
2527
public function show(Course $course)
2628
{
29+
$assignments = DB::table('assignments')->select('id', 'name', 'due', 'similarity')->where('course_id', $course->id)->get();
30+
2731
$courseID = $course->name;
28-
return view('courses.show', compact('courseID'));
32+
$slug = $course->slug;
33+
34+
return view('courses.show', compact('courseID', 'slug'), ['assignments' => $assignments]);
2935
}
3036

3137
/**
@@ -35,19 +41,78 @@ public function show(Course $course)
3541
*/
3642
public function showRegistration()
3743
{
38-
return view('courses.courseregistration');
44+
return view('courses.register');
45+
}
46+
47+
/**
48+
* Show the course settings page
49+
*
50+
* @return
51+
*/
52+
public function enroll(Course $course)
53+
{
54+
$users = DB::table('users')->select('id', 'name', 'email')->get();
55+
$courses = DB::table('courses')->select('slug')->get();
56+
57+
return view('courses.enroll', ['users' => $users], ['course' => $course]);
58+
}
59+
60+
/**
61+
* Save data from settings page into database
62+
*
63+
* @return
64+
*/
65+
public function storeSettings()
66+
{
67+
3968
}
4069

70+
/**
71+
* Stores the course registration information into the database
72+
*
73+
* @return redirection to the new course page
74+
*/
4175
public function store(Request $request)
4276
{
4377
// validate the input before storing it into the database
78+
$this->validate($request,[
79+
'courseName' => 'required',
80+
'courseSemester' => 'required',
81+
'courseSection' => 'required'
82+
]);
83+
84+
// if any of the fields are null, bring them back to the registration page (did not select an option)
85+
if($request->courseName == null || $request->courseSemester == null || $request->courseSection == null) {
86+
return back()->withInput();
87+
}
88+
89+
// create slug
90+
$slug = $request->courseName . '_' . $request->courseSemester . '_' . $request->courseSection;
4491

4592
// sanitize the slug
4693

4794
//store data into the database
4895
$c = new Course;
4996
$c->name = $request->courseName;
50-
$c->slug = $request->courseID;
97+
$c->slug = $slug;
5198
$c->save();
99+
100+
return redirect()->action('CourseController@show', $c);
101+
}
102+
103+
/**
104+
* Shows the assignments for a specified course on the course page
105+
*
106+
*
107+
*/
108+
public function displayAssignments() {
109+
110+
$assignments = DB::table('assignments')->pluck('name');
111+
112+
foreach($assignments as $assignment)
113+
echo $assignment;
114+
115+
116+
return view('courses.show', ['assignments' => $assignments]);
52117
}
53118
}

app/Repository.php

Lines changed: 75 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
use App\VersionControl\VersionControl;
77
use GitElephant\Repository as GitRepository;
88
use Illuminate\Support\Facades\Storage;
9+
use Illuminate\FileSystem\FileSystem;
910

1011
class Repository extends Model
1112
{
@@ -16,15 +17,82 @@ protected function absolutePath()
1617
return app()->storagePath().'/app/'.$this->path;
1718
}
1819

20+
protected function init()
21+
{
22+
$submission = Submission::where('repository_id', $this->id)->get()[0];
23+
$assignment = Assignment::where('id', $submission->assignment_id)->get()[0];
24+
$fs = new FileSystem();
25+
26+
$laravelStorage = app()->storagePath();
27+
$userId = $submission->user_id;
28+
$assignmentId = $submission->assignment_id;
29+
$repositoryPath = $this->absolutePath();
30+
$hookPath = $this->path.'.git/hooks/';
31+
32+
//First create the user's repository and init a git repo.
33+
Storage::makeDirectory($this->path);
34+
$this->repo = GitRepository::open($this->absolutePath());
35+
$this->repo->init();
36+
//
37+
$assignmentPath = realpath($repositoryPath . "../");
38+
$assignmentPathRel = $this->path.'/../';
39+
40+
//Obtain the template for a repository environment.
41+
$env = Storage::get('templates/environment.php');
42+
43+
//We're starting to tie repositories directly to an assignment.
44+
//It should be broken up into a generic repository and
45+
//an AssignmentRepository.
46+
47+
48+
$parameters = [
49+
'__LARAVEL_STORAGE__' => $laravelStorage,
50+
'__LARAVEL_DIR__' => __DIR__,
51+
'__STUDENT_ID__' => $userId,
52+
'__ASSIGNMENT_ID__' => $assignmentId,
53+
'__SUBMISSION_DIR__' => $repositoryPath,
54+
'__ASSIGNMENT_DIR__' => $assignmentPath,
55+
];
56+
57+
foreach ($parameters as $key => $value) {
58+
$env = str_replace($key, $value, $env);
59+
}
60+
61+
62+
63+
/*GIT Repo config*/
64+
$file = Storage::get('templates/config');
65+
$configPath = $this->path.'.git/';
66+
Storage::put($configPath.'config', $file);
67+
68+
/*Git Environment*/
69+
Storage::put($hookPath.'environment.php', $env);
70+
71+
/*Post-update Hook*/
72+
$file = Storage::get('templates/post-update');
73+
Storage::put($hookPath.'post-update', $file);
74+
$fs->chmod($this->absolutePath().'/.git/hooks/post-update', 0755);
75+
/*post-commit hook*/
76+
$file = Storage::get('templates/post-commit');
77+
Storage::put($hookPath.'post-commit', $file);
78+
$fs->chmod($this->absolutePath().'/.git/hooks/post-commit', 0755);
79+
80+
/*Assignment config*/
81+
/*Currently this gets overwritten each time a repository is created*/
82+
Storage::makeDirectory($assignmentPathRel.'/.config/');
83+
$file = Storage::get('templates/hooks.php');
84+
Storage::put($assignmentPathRel.'/.config/hooks.php', $file);
85+
$fs->chmod($assignmentPath . '/.config/hooks.php', 0755);
86+
87+
88+
$this->initialized = true;
89+
}
90+
1991
public function repository()
2092
{
2193
//Lazy initialization
2294
if (!$this->initialized) {
23-
Storage::makeDirectory($this->path);
24-
$this->repo = GitRepository::open($this->absolutePath());
25-
$this->repo->init();
26-
27-
$this->initialized = true;
95+
$this->init();
2896
}
2997

3098
if (is_null($this->repo)) {
@@ -35,7 +103,8 @@ public function repository()
35103
}
36104

37105

38-
public function commit($message) {
106+
public function commit($message)
107+
{
39108
//Prehooks should be placed here.
40109
$this->repository()->commit($message, true);
41110
//Posthooks should be placed here.

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"php": ">=5.6.4",
99
"laravel/framework": "5.4.*",
1010
"laravel/tinker": "~1.0",
11-
"cypresslab/gitelephant-bundle": "dev-master",
11+
"cypresslab/gitelephant-bundle": "dev-master"
1212
},
1313
"require-dev": {
1414
"fzaninotto/faker": "~1.4",

0 commit comments

Comments
 (0)