Browse Source

Merge branch 'Antes-de-pushar' into Merge_gabriel_mayo

parent
commit
a21a6d27a8

+ 31
- 4
app/controllers/AnnualPlansController.php View File

@@ -1,9 +1,10 @@
1 1
 <?php
2 2
 
3 3
 use Barryvdh\DomPDF\PDF as PDF;
4
+use Response;
4 5
 use Illuminate\Support\Facades\Auth;
5 6
 use Illuminate\Support\Facades\Input;
6
-
7
+use Illuminate\Support\Facades\View;
7 8
 
8 9
 class AnnualPlansController extends \BaseController
9 10
 {
@@ -1082,16 +1083,42 @@ class AnnualPlansController extends \BaseController
1082 1083
       ->where('id', $path_id)
1083 1084
       ->first();
1084 1085
 
1085
-    Log::info("ERES TU? creo que no");
1086
+    //Log::info("ERES TU? creo que no");
1087
+
1088
+    $path = storage_path($queryToPath->path_to_pdf);
1089
+
1090
+    if ($download != "download") {
1091
+      return Response::make(file_get_contents($queryToPath->path_to_pdf), 200, [
1092
+        'Content-type' => 'application/pdf',
1093
+        'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
1094
+
1095
+      ]);
1096
+    } else {
1097
+
1098
+
1099
+      return Response::download(
1100
+        file_get_contents($queryToPath->path_to_pdf),
1101
+        200,
1102
+        [
1103
+          'Content-type' => 'application/pdf',
1104
+          'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
1086 1105
 
1106
+        ]
1107
+      );
1108
+    }
1109
+    /*
1110
+[
1111
+      'Content-type' => 'application/pdf',
1112
+      'Content-Disposition' => 'inline; filename="' . $queryToPath->path_to_pdf . '"'
1113
+    ]
1114
+    */
1087 1115
     $annualPlan = AnnualPlan::findOrFail($queryToPath->annual_plan_id);
1088 1116
 
1089 1117
     Log::info("ERES TU?");
1090 1118
 
1091
-
1119
+    //return View::make('local.managers.shared.print_annual_report', compact('annualPlan'));
1092 1120
     $pdf = $pdf->loadView('local.managers.shared.print_annual_report', compact('annualPlan'))
1093 1121
       ->setOrientation("landscape")
1094
-
1095 1122
       ->setPaper('legal', 'landscape');
1096 1123
     if ($download == "download")
1097 1124
       return $pdf->download(basename($queryToPath->path_to_pdf));

+ 68
- 1
app/controllers/CoursesController.php View File

@@ -91,10 +91,77 @@ CoursesController extends \BaseController
91 91
             ->get();
92 92
     }
93 93
 
94
-    public function create()
94
+    private function cleanInput()
95 95
     {
96
+        //$clean_input = array();
96 97
 
97 98
         $all_input = Input::all();
99
+
100
+        $all_input["name"] = trim(preg_replace('/\t+/', '', Input::get('name')));
101
+
102
+
103
+
104
+
105
+        return $all_input;
106
+    }
107
+
108
+    private function makeValidator($clean_input)
109
+    {
110
+
111
+
112
+        return Validator::make(
113
+            array(
114
+                'course_name' => $clean_input['name'],
115
+                'course_code' => $clean_input['code'],
116
+                'course_number'  => $clean_input['number'],
117
+                'course_section' => $clean_input['section'],
118
+                'program_id' => $clean_input['program'],
119
+                'professor_id' => $clean_input['professor_id'],
120
+                'semester_id' => $clean_input['semester_id'],
121
+
122
+            ),
123
+            array(
124
+                'course_name' => 'required|string',
125
+                'course_code' => 'required|string',
126
+                'course_number' => "required|string",
127
+                'course_section' => 'required|string',
128
+                'program_id' => 'required|integer',
129
+                "professor_id" => 'required|integer',
130
+                "semester_id" => "required|integer"
131
+
132
+            )
133
+
134
+        );
135
+    }
136
+
137
+
138
+    public function create()
139
+    {
140
+
141
+        //$all_input = Input::all();
142
+
143
+        // limpiar el input
144
+
145
+        $all_input = $this->cleanInput();
146
+
147
+        $validator = $this->makeValidator($all_input);
148
+
149
+        /** If validation fails */
150
+        if ($validator->fails()) {
151
+            /** Prepare error message */
152
+            $message = '<p>Error(s) creating a new Course:</p><ul>';
153
+
154
+            foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
155
+                $message .= $validationError;
156
+            }
157
+
158
+            $message .= '</ul>';
159
+
160
+            /** Send error message and old data */
161
+            Session::flash('status', 'danger');
162
+            Session::flash('message', $message);
163
+            return Redirect::to('editCourses')->withInput();
164
+        }
98 165
         $name = $all_input['name'];
99 166
         $code = $all_input['code'];
100 167
         $number = $all_input['number'];

+ 267
- 0
app/controllers/Objective2Controller.php View File

@@ -49,11 +49,68 @@ class Objective2Controller extends \BaseController
49 49
 					->where("user_id", Auth::user()->id)
50 50
 					->lists('program_id');
51 51
 		}
52
+		Log::info("bad?");
52 53
 		$objectives = $outcome->objectivesFromProgram($programs)->get();
53 54
 
54 55
 		return $objectives;
55 56
 	}
56 57
 
58
+	public function deletePCOBO()
59
+	{
60
+		$pcobo_id = Input::get('pcobo_id');
61
+		$criterion_id = Input::get('criterion_id');
62
+		//$objective_id  = Input::get('objective_id');
63
+		$outcome_id  = Input::get('outcome_id');
64
+		$program_id = Input::get('program_id');
65
+
66
+		$cri_hol_dom = DB::table('criterion_objective_outcome')
67
+			->where('objective_id', 0)
68
+			->where('criterion_id', $criterion_id)
69
+			->where('outcome_id', $outcome_id)
70
+			->first();
71
+
72
+
73
+		if (!isset($cri_hol_dom)) {
74
+			$cri_obj_out_id = DB::table('criterion_objective_outcome')->insertGetId(
75
+				array(
76
+					'objective_id' => 0,
77
+					'outcome_id' => $outcome_id,
78
+					'criterion_id' => $criterion_id
79
+				)
80
+			);
81
+		} else {
82
+			$cri_obj_out_id = $cri_hol_dom->id;
83
+			//no creo que esto pase pero
84
+
85
+			$exists_pair = DB::table("program_criterion_objective_outcome")
86
+				->where('program_id', $program_id)
87
+				->where('cri_obj_out_id', $cri_obj_out_id)
88
+				->first();
89
+
90
+			if (isset($exists_pair)) {
91
+				//se puede borrar la entrada
92
+				//porque el pareo de programa-criterio-dominio-holder ya existe, so borrar esta entrada borra duplicados. 
93
+
94
+				DB::table('program_criterion_objective_outcome')
95
+					->where('id', $pcobo_id)
96
+					->delete();
97
+				return 200;
98
+			}
99
+		}
100
+
101
+
102
+
103
+
104
+
105
+
106
+		DB::table('program_criterion_objective_outcome')
107
+			->where('id', $pcobo_id)->update(array(
108
+				'cri_obj_out_id' => $cri_obj_out_id
109
+			));
110
+
111
+		return 200;
112
+	}
113
+
57 114
 	public function isObjectiveUnique($input, $existing_Objective = NULL)
58 115
 	{
59 116
 
@@ -168,6 +225,216 @@ class Objective2Controller extends \BaseController
168 225
 		return Objective::find(Input::get('id'));
169 226
 	}
170 227
 
228
+	public function fetchProgramCriteria()
229
+	{
230
+		$outcome_id = Input::get("outcome_id");
231
+		$objective = Objective::findOrFail(Input::get('objective_id'));
232
+
233
+
234
+
235
+
236
+		$user_objective_programs_query = DB::table('objective_program');
237
+
238
+		//Si es admin o school, puede ver todos los criterios de los programas pareados
239
+		//Si es program_coordinator depende.
240
+		if (Auth::user()->role == 3) {
241
+			$user_objective_programs_query = $user_objective_programs_query
242
+				->join("program_user", 'program_user.program_id', '=', 'objective_program.program_id')
243
+				->where('user_id', Auth::user()->id);
244
+		} elseif (Auth::user()->role == 2) {
245
+			$user_objective_programs_query = $user_objective_programs_query
246
+				->join('programs', 'programs.id', '=', 'objective_program.program_id')
247
+				->where("programs.school_id", Auth::user()->school->id);
248
+		}
249
+		$program_ids = $user_objective_programs_query->where('objective_id', $objective->id)
250
+			->select('objective_program.program_id')
251
+			->lists('objective_program.program_id');
252
+
253
+		Log::info("PRogram");
254
+		//Log::info();
255
+
256
+		//$array_to_send = [];
257
+		//$array_to_send["programs"] = Program::whereIn('id', $program_ids)->with('criteria')->get();
258
+		//$array_to_send['selected_criteria'] = $objective->pairedCriteria();
259
+
260
+		//Program
261
+		return Program::whereIn('id', $program_ids)
262
+			->select(DB::raw("programs.*, {$outcome_id} as outcome_id"))
263
+
264
+			->get();
265
+	}
266
+
267
+	public function updatePCOBO()
268
+	{
269
+		//aqui entra si  cambia el viejo al nuevo
270
+
271
+		$criterion_id = Input::get('criterion_id');
272
+		$pcobo_id = Input::get("pcobo_id");
273
+		$cobo_id = Input::get("cobo_id");
274
+		$objective_id = Input::get("objective_id");
275
+		$outcome_id = Input::get("outcome_id");
276
+		$program_id = Input::get("program_id");
277
+		$old_crit = Input::get('old_crit');
278
+		$old_cobo_id = Input::get('old_cobo');
279
+		$old_pcobo_id = Input::get('old_pcobo');
280
+		$old_outcome_id = Input::get('old_outcome');
281
+
282
+
283
+
284
+
285
+
286
+		//Existe el pareo de este criterio, este dominio y este objetivo?
287
+
288
+		$existing_cobo_id = DB::table('criterion_objective_outcome')
289
+			->where('objective_id', $objective_id)
290
+			->where('outcome_id', $outcome_id)
291
+			->where('criterion_id', $criterion_id)
292
+			->first();
293
+
294
+		if (!isset($existing_cobo_id)) {
295
+			$insert_cobo_id = DB::table('criterion_objective_outcome')->insertGetId(array(
296
+				'criterion_id' => $criterion_id,
297
+				'outcome_id' => $outcome_id,
298
+				'objective_id' => $objective_id
299
+
300
+			));
301
+		} else $insert_cobo_id = $existing_cobo_id->id;
302
+
303
+		$it_exists = DB::table('program_criterion_objective_outcome')
304
+			->where('program_id', $program_id)
305
+			->where('cri_obj_out_id', $insert_cobo_id)
306
+			->first();
307
+
308
+		if (isset($it_exists)) {
309
+			return "DUPLICATE";
310
+		}
311
+
312
+		DB::table('program_criterion_objective_outcome')
313
+			->where("program_id", $program_id)
314
+			->where('cri_obj_out_id', $old_cobo_id)
315
+			->update(array(
316
+				//'program_id' => $program_id,
317
+				'cri_obj_out_id' => $insert_cobo_id
318
+			));
319
+
320
+
321
+
322
+		//now check if old criterion_objective_outcome is being used
323
+
324
+		$other_pcobo_exist = DB::table('program_criterion_objective_outcome')
325
+			->where("cri_obj_out_id", $old_cobo_id)
326
+			->first();
327
+
328
+
329
+		//si ningun otro programa tiene el pareo de este criterio con ese objetivo y ese dominio
330
+		//lo puedes borrar
331
+		if (!isset($other_pcobo_exist)) {
332
+			DB::table('criterion_objective_outcome')
333
+
334
+				->where('id', $old_cobo_id)
335
+				->delete();
336
+		}
337
+
338
+
339
+
340
+		//Ahora hay que ver que la relacion de program, crit y dominio existe.
341
+
342
+		$relationship_exists = DB::table('criterion_objective_outcome as cobo')
343
+			->join('program_criterion_objective_outcome as pcobo', 'pcobo.cri_obj_out_id', '=', 'cobo.id')
344
+			->where('criterion_id', $old_crit)
345
+			->where('outcome_id', $old_outcome_id)
346
+			->where('program_id', $program_id)
347
+			->first();
348
+
349
+		if (!isset($relationship_exists)) {
350
+			$new_cobo_id = DB::table('criterion_objective_outcome')
351
+				->insertGetId(array(
352
+					'criterion_id' => $old_crit,
353
+					'outcome_id' => $old_outcome_id,
354
+					'objective_id' => 0
355
+				));
356
+			DB::table('program_criterion_objective_outcome')
357
+				->insert(array(
358
+					'program_id' => $program_id,
359
+					'cri_obj_out_id' => $new_cobo_id
360
+				));
361
+		}
362
+
363
+
364
+
365
+
366
+
367
+
368
+
369
+
370
+
371
+		return 200;
372
+
373
+
374
+		//Aqui es insertar
375
+
376
+
377
+	}
378
+
379
+	public function insertPCOBO()
380
+	{
381
+		//aqui entra si  le da a add criterio, y escoje uno nuevo
382
+
383
+		$criterion_id = Input::get('criterion_id');
384
+		$pcobo_id = Input::get("pcobo_id");
385
+		$cobo_id = Input::get("cobo_id");
386
+		$objective_id = Input::get("objective_id");
387
+		$outcome_id = Input::get("outcome_id");
388
+		$program_id = Input::get("program_id");
389
+		Log::info(Input::all());
390
+
391
+
392
+		//doc se esta usando? ie, objetivo_id == 0?
393
+
394
+		//Existe el pareo de este criterio, este dominio y este objetivo?
395
+
396
+
397
+
398
+		$old_cobo_id = DB::table('criterion_objective_outcome')
399
+			->where('objective_id', $objective_id)
400
+			->where('outcome_id', $outcome_id)
401
+			->where('criterion_id', $criterion_id)
402
+			->first();
403
+
404
+		if (!isset($old_cobo_id)) {
405
+			$insert_cobo_id = DB::table('criterion_objective_outcome')->insertGetId(array(
406
+				'criterion_id' => $criterion_id,
407
+				'outcome_id' => $outcome_id,
408
+				'objective_id' => $objective_id
409
+
410
+			));
411
+		} else $insert_cobo_id = $old_cobo_id->id;
412
+
413
+		$it_exists = DB::table('program_criterion_objective_outcome')
414
+			->where('program_id', $program_id)
415
+			->where('cri_obj_out_id', $insert_cobo_id)
416
+			->first();
417
+
418
+		if (isset($it_exists)) {
419
+			return "DUPLICATE";
420
+		}
421
+
422
+		DB::table('program_criterion_objective_outcome')
423
+			->insert(array(
424
+				'program_id' => $program_id,
425
+				'cri_obj_out_id' => $insert_cobo_id
426
+			));
427
+
428
+
429
+
430
+		return 200;
431
+
432
+
433
+		//Aqui es insertar
434
+
435
+
436
+	}
437
+
171 438
 	public function fetchObjectiveWithTrashed()
172 439
 	{
173 440
 		$json = array();

+ 44
- 0
app/database/migrations/2022_08_30_195747_create_program_criterion_objective_outcome_id.php View File

@@ -0,0 +1,44 @@
1
+<?php
2
+
3
+use Illuminate\Database\Schema\Blueprint;
4
+use Illuminate\Database\Migrations\Migration;
5
+
6
+class CreateProgramCriterionObjectiveOutcomeId extends Migration
7
+{
8
+
9
+	/**
10
+	 * Run the migrations.
11
+	 *
12
+	 * @return void
13
+	 */
14
+	public function up()
15
+	{
16
+		Schema::create('program_criterion_objective_outcome', function (Blueprint $table) {
17
+
18
+			$table->increments('id');
19
+			$table->integer('program_id')->unsigned();
20
+			$table->integer('cri_obj_out_id')->unsigned();
21
+			$table->foreign('cri_obj_out_id')
22
+				->references('id')
23
+				->on('criterion_objective_outcome')
24
+				->onUpdate('cascade')
25
+				->onDelete('cascade');
26
+
27
+			$table->foreign('program_id')
28
+				->references('id')
29
+				->on('programs')
30
+				->onUpdate('cascade')
31
+				->onDelete('cascade');
32
+		});
33
+	}
34
+
35
+	/**
36
+	 * Reverse the migrations.
37
+	 *
38
+	 * @return void
39
+	 */
40
+	public function down()
41
+	{
42
+		Schema::drop("program_criterion_objective_outcome");
43
+	}
44
+}

+ 17
- 1
app/models/Criterion.php View File

@@ -27,7 +27,7 @@ class Criterion extends Eloquent
27 27
 
28 28
 
29 29
 
30
-	public function objectives()
30
+	public function getObjectivesAttribute()
31 31
 	{
32 32
 		return $this->belongsToMany('Objective');
33 33
 	}
@@ -38,6 +38,15 @@ class Criterion extends Eloquent
38 38
 		return $this->belongsToMany('Rubric', 'rubric_criterion');
39 39
 	}
40 40
 
41
+
42
+	public function scopeFromProgram($query, $programs)
43
+	{
44
+
45
+		return $query->join('program_criterion', 'program_criterion.criterion_id', '=', 'criteria.id')
46
+			->whereIn("program_id", "programs")
47
+			->select('criteria.*');
48
+	}
49
+
41 50
 	/**
42 51
 	 * Return the program that the criterion belongs to
43 52
 	 *
@@ -48,6 +57,13 @@ class Criterion extends Eloquent
48 57
 		return $this->belongsToMany('Program', 'program_criterion');
49 58
 	}
50 59
 
60
+	//public getPairedObjectivesAttribute(){
61
+
62
+	//	if(isset($this->from_objective)){
63
+	//		return DB::table()
64
+	//	}
65
+	//}
66
+
51 67
 
52 68
 	public function program()
53 69
 	{

+ 5
- 0
app/models/Objective.php View File

@@ -33,6 +33,11 @@ class Objective extends Eloquent
33 33
     }
34 34
 
35 35
 
36
+    //public function pairedCriteria(){
37
+
38
+    //    return Criterion::
39
+    //}
40
+
36 41
 
37 42
     public function getGroupedAnnualCourseAttribute()
38 43
     {

+ 3
- 0
app/models/Outcome.php View File

@@ -275,8 +275,11 @@ class Outcome extends Eloquent
275 275
 	public function scopeObjectivesFromProgram($query, $programs)
276 276
 	{
277 277
 		return Objective::join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
278
+			->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
278 279
 			//->join('programs', 'programs.id', '=', 'objective_program.program_id')
279 280
 			->whereIn("program_id", $programs)
281
+			->where('outcome_id', $this->id)
282
+
280 283
 			->where('objective_program.objective_id', '<>', '0')
281 284
 			->select('objectives.*')
282 285
 			->groupBy('objectives.id');

+ 40
- 1
app/models/Program.php View File

@@ -1,7 +1,17 @@
1 1
 <?php
2 2
 
3 3
 class Program extends Eloquent
4
+
5
+
4 6
 {
7
+	//use SoftDeletingTrait;
8
+	//protected $dates = ['deleted_at'];
9
+
10
+	//     protected $table = 'new_criteria';
11
+	protected $table = 'programs';
12
+
13
+
14
+	protected $appends = ["criteria"];
5 15
 	public function school()
6 16
 	{
7 17
 		return $this->belongsTo('School');
@@ -27,6 +37,23 @@ class Program extends Eloquent
27 37
 		return $this->hasMany('Student');
28 38
 	}
29 39
 
40
+	public function getCriteriaAttribute()
41
+	{
42
+
43
+		if ($this->outcome_id) {
44
+			return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
45
+				->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
46
+				->select('criteria.*', 'cobo.id as cobo_id', 'cobo.objective_id', 'cobo.outcome_id', 'cobo.criterion_id')
47
+				->addSelect('program_criterion_objective_outcome.id as pcobo_id')
48
+				->where('program_id', $this->id)
49
+				->where('outcome_id', $this->outcome_id)
50
+				->get();
51
+		}
52
+		return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
53
+			->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
54
+			->where('program_id', $this->id)
55
+			->get();
56
+	}
30 57
 	public function templates()
31 58
 	{
32 59
 		return $this->hasMany('Template');
@@ -110,7 +137,19 @@ class Program extends Eloquent
110 137
 	 */
111 138
 	public function criteria()
112 139
 	{
113
-		return $this->hasMany('Criterion');
140
+
141
+		Log::info("AQUI");
142
+		$lmao = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
143
+			->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
144
+			->where('program_id', $this->id);
145
+		//->get();
146
+
147
+
148
+		return $lmao;
149
+		$l = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
150
+			->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
151
+			->where('program_id', $this->id)->get();
152
+		//get();
114 153
 	}
115 154
 
116 155
 	// 	public function attempted_outcome($outcome_id, $semester)

+ 12
- 2
app/routes.php View File

@@ -303,6 +303,8 @@ Route::group(array('before' => 'auth|has_access'), function () {
303 303
         'uses' => 'CriteriaController@fetchAllCriterion'
304 304
     ));
305 305
 
306
+    Route::post('insertPCOBO', 'Objective2Controller@insertPCOBO');
307
+
306 308
 
307 309
     Route::get('viewFormative', array(
308 310
         'as' => 'viewFormative',
@@ -363,6 +365,9 @@ Route::group(array('before' => 'auth|has_access'), function () {
363 365
     // Show professor overview to users with courses
364 366
     Route::get('professor', 'ProfessorsController@overview');
365 367
 
368
+    // view objectives and criteria, edit criteria
369
+    Route::post('fetchCriteriaFromProgram', 'Objective2Controller@fetchProgramCriteria');
370
+
366 371
     // Assessment reports for users' courses
367 372
 
368 373
     Route::get('my-assessment-reports', 'OutcomesController@professorAssessmentReport');
@@ -376,6 +381,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
376 381
     Route::post('transformativeAction/filterTA', array('before' => 'csrf', 'uses' => 'TransformativeActionsController@filterTA'));
377 382
     Route::post('transformativeAction/objectivesFromOutcome', array('before' => 'csrf', 'uses' => 'TransformativeActionsController@objectivesFromOutcome'));
378 383
 
384
+
379 385
     /**
380 386
      * Administrator Routes
381 387
      */
@@ -536,6 +542,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
536 542
         // Print course (grouped sections) report
537 543
         Route::get('print_course/{code}/{number}/{semester_code}', 'CoursesController@print_course');
538 544
 
545
+
539 546
         // Assessment reports
540 547
         Route::get('program-assessment-report/{program_id}', 'OutcomesController@programAssessmentReport');
541 548
         Route::get('assessment-reports', 'OutcomesController@managerAssessmentReports');
@@ -547,11 +554,14 @@ Route::group(array('before' => 'auth|has_access'), function () {
547 554
         Route::post('fetchObjective', array('before' => 'csrf', 'uses' => 'ObjectivesController@fetchObjective'));
548 555
         Route::post('fetchObjectivesForCriteria', array('before' => 'csrf', 'uses' => 'ObjectivesController@fetchObjectivesForCriteria'));
549 556
 
550
-        //Objectives por Gabriel
557
+        //Objectives
551 558
         //Route::get('objective', 'Objective2Controller@edit');
552 559
         Route::post('createObjective', array('before' => 'csrf', 'uses' => 'Objective2Controller@create'));
553 560
         Route::post('updateObjective', array('before' => 'csrf', 'uses' => 'Objective2Controller@update'));
554 561
         Route::post('fetchObjectiveWithTrashed', array('before' => 'csrf', 'uses' => 'Objective2Controller@fetchObjectiveWithTrashed'));
562
+        Route::post('deletePCOBO', 'Objective2Controller@deletePCOBO');
563
+        Route::post('updatePCOBO', 'Objective2Controller@updatePCOBO');
564
+
555 565
 
556 566
         // Five year plans,
557 567
         Route::get('five-year-plans', 'FiveYearPlansController@index');
@@ -652,7 +662,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
652 662
         Route::get('learning-outcomes-criteria', 'CriteriaController@index');
653 663
         Route::get('learning-objectives-criteria', 'Objective2Controller@viewObjectives');
654 664
         Route::get('export_grades/{id}', 'CoursesController@exportGrades');
655
-        Route::get('learning-objectives-criteria', 'Objective2Controller@viewObjectives');
665
+        Route::get('template/{template}', 'TemplatesController@show');
656 666
         Route::get('compare_activities/{activity_1}/{activity_2}', 'ActivitiesController@compareActivities');
657 667
         // Assessment reports
658 668
         //Route::get('professor-assessment-report/{outcome_id}', 'OutcomesController@professorAssessmentReport');

+ 469
- 1
app/views/global/view-objectives-criteria.blade.php View File

@@ -63,6 +63,7 @@
63 63
                             <thead id="theHead">
64 64
                                 <th>Objective</th>
65 65
                                 <th>Program</th>
66
+                                <th>Match to Criteria</th>
66 67
                             </thead>
67 68
                             <tfoot>
68 69
 
@@ -83,6 +84,74 @@
83 84
         </div>
84 85
 
85 86
     </div>
87
+
88
+    
89
+
90
+    <div id="match_criteria" class="modal fade" tabindex="-1" data-objective-id="0">
91
+        <div class="modal-dialog">
92
+            <div class="modal-content">
93
+                <div class="modal-header">
94
+                    <h5 class="modal-title" id = 'match_criteria_title'></h5>
95
+                    <button type="button" class="close" data-dismiss="modal">&times;</button>
96
+                </div>
97
+                <div class="modal-body" id = "match_criteria_body">
98
+                    <p>The following criteria appear based on objective's programs and your available programs</p>
99
+
100
+                    <div class ='form-group col-md-12'>
101
+                        <label for="match_criteria_program">Program</label>
102
+                        <select id="match_criteria_program" class ='form-control selectpicker select_program' onchange="changeCriteriaDisplayed('#match_criteria_program')">
103
+                            
104
+                        </select>
105
+                    </div>
106
+                    <hr>
107
+                    <label>Criteria associated to program</label>
108
+                    <div id="program_objectives" class ='form-group col-md-12' >
109
+
110
+                    </div>
111
+
112
+                
113
+
114
+
115
+
116
+
117
+                </div>
118
+                <div class="modal-footer">
119
+                    <hr>
120
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="">Close</button>
121
+
122
+                </div>
123
+            </div>
124
+        </div>
125
+    </div>
126
+
127
+    
128
+    <div id="warning" class="modal fade" tabindex="-1" data-objective-id="0">
129
+        <div class="modal-dialog">
130
+            <div class="modal-content">
131
+                <div class="modal-header">
132
+                    <h5 class="modal-title" id = 'warning_title'></h5>
133
+                    <button type="button" class="close" data-dismiss="modal">&times;</button>
134
+                </div>
135
+                <div class="modal-body" id = "warning_body">
136
+                    
137
+
138
+                
139
+
140
+
141
+
142
+
143
+                </div>
144
+                <div class="modal-footer">
145
+                    <hr>
146
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="$('#match_criteria').data('objective-id', '0');">Cancel</button>
147
+                    <button  id='warning_delete' type="button" class="btn btn-primary" onclick = ''>Delete</button>
148
+                </div>
149
+            </div>
150
+        </div>
151
+    </div>
152
+
153
+
154
+    
86 155
     <script>
87 156
         $(document).ready(function() {
88 157
             // --------------------------------------------------------------------------
@@ -100,6 +169,8 @@
100 169
             /*
101 170
 
102 171
               */
172
+
173
+            
103 174
             function fetchObjectives(li) {
104 175
                 {
105 176
 
@@ -130,8 +201,12 @@
130 201
 
131 202
                             $.each(json, function(ind2, objective) {
132 203
                                 tr = $("<tr>");
133
-                                td_text = $("<td>").html(objective.text);
134 204
 
205
+                                //objectives
206
+                                td_text = $("<td>",{
207
+                                    'id':"objective-"+objective.id
208
+                                }).html(objective.text);
209
+                                 //programs
135 210
                                 td_programs = $("<td>");
136 211
                                 ol = $("<ol>");
137 212
 
@@ -140,10 +215,29 @@
140 215
                                     li.appendTo(ol);
141 216
                                 })
142 217
                                 ol.appendTo(td_programs);
218
+
219
+                                //link to criteria matching
220
+                                link_td = $("<td>");
221
+                                
222
+                                a = $('<a>',{
223
+                                    'onclick':'fetchCriteria(this)',
224
+                                    'data-objective-id': objective.id,
225
+                                    'data-outcome-id':id
226
+
227
+                                    
228
+                                }).html("Change Associated Criteria");
229
+
230
+                                link_td.append(a)
231
+
232
+                                
143 233
                                 tr.append(td_text);
144 234
                                 tr.append(td_programs);
235
+                                tr.append(link_td)
145 236
                                 tr.appendTo($('#table_objectives'))
146 237
 
238
+
239
+                                
240
+
147 241
                             })
148 242
                         },
149 243
                         'json'
@@ -161,6 +255,369 @@
161 255
             })
162 256
         });
163 257
 
258
+        function postDeleteCrit(criterion_id ,program_id ,outcome_id ,objective_id ,cobo_id ,pcobo_id){
259
+            
260
+            $.post(
261
+                "{{URL::action('Objective2Controller@deletePCOBO')}}",
262
+                {
263
+                    criterion_id:criterion_id,
264
+                    program_id:program_id,
265
+                    outcome_id:outcome_id,
266
+                    objective_id:objective_id,
267
+                    cobo_id:cobo_id,
268
+                    pcobo_id:pcobo_id
269
+                },
270
+                function (status){
271
+
272
+                    if(status == 200){
273
+                    $('.selected_criteria_to_delete').parent().parent().remove();
274
+                    }
275
+                    else{
276
+                        alert("something went wrong, try again later.");
277
+                    }
278
+                    
279
+                }
280
+            )
281
+        }
282
+
283
+
284
+        function createSelectForModal(options){
285
+            
286
+            div_master = $('<div>',{
287
+                'class':'removable_div'
288
+            })
289
+            div_select = $("<div>",{
290
+                'class':'form-group col-md-11',
291
+
292
+            })
293
+            select = $('<select>',{
294
+                'class':'selectpicker form-control criteria_select',
295
+                'name':'criteria[]',
296
+                'onchange':'saveChanges(this)'
297
+
298
+            }).html(options);
299
+            div_rem_button = $('<div>',
300
+                {
301
+                    'class':'col-md-1 remove-btn'
302
+                    
303
+                })
304
+            rem_button = $('<button>',{
305
+                'type':'button',
306
+                'class':'btn btn-primary',
307
+                'onclick':'deleteCriterion(this);'
308
+            }).html("<span class='glyphicon glyphicon-remove'></span>")
309
+
310
+            div_select.append(select);
311
+            div_rem_button.append(rem_button);
312
+            div_master.append(div_select);
313
+            div_master.append(div_rem_button);
314
+
315
+            return div_master;
316
+
317
+        }
318
+
319
+        function saveChanges(select){
320
+            
321
+            //Create if old-cobo doesnt exist
322
+
323
+            option = $(select).find(':selected');
324
+            
325
+            criterion_id = option.val()
326
+            if(criterion_id ==0){
327
+                return;
328
+            }
329
+            pcobo_id = option.data('pcobo-id')
330
+            cobo_id = option.data('cobo-id');
331
+            objective_id = option.data('objective-id')
332
+            outcome_id =  option.data('outcome-id');
333
+            program_id = option.data('program-id')
334
+
335
+            dict_to_send = {};
336
+   
337
+            if($(select).data('old-pcobo') ===undefined){
338
+               dict_to_send=    {
339
+                        criterion_id:criterion_id,
340
+                        pcobo_id:pcobo_id,
341
+                        cobo_id:cobo_id,
342
+                        objective_id:objective_id,
343
+                        outcome_id:outcome_id,
344
+                        program_id:program_id
345
+                    } 
346
+                url = "{{URL::action('Objective2Controller@insertPCOBO')}}";
347
+
348
+                   
349
+            }
350
+            else{
351
+
352
+                url= "{{URL::action('Objective2Controller@updatePCOBO')}}";
353
+
354
+
355
+                old_crit = $(select).data('old-criterion')
356
+                old_outcome= $(select).data('old-outcome')
357
+                old_cobo = $(select).data('old-cobo')
358
+                old_pcobo = $(select).data('old-pcobo')
359
+                dict_to_send ={
360
+                        criterion_id:criterion_id,
361
+                        pcobo_id:pcobo_id,
362
+                        cobo_id:cobo_id,
363
+                        objective_id:objective_id,
364
+                        outcome_id:outcome_id,
365
+                        program_id:program_id,
366
+                        old_crit:old_crit,
367
+                        old_outcome:old_outcome,
368
+                        old_cobo:old_cobo,
369
+                        old_pcobo:old_pcobo
370
+
371
+                        
372
+                    } 
373
+
374
+                    
375
+                
376
+
377
+            }
378
+
379
+            $.post(
380
+                    url,
381
+                    dict_to_send,
382
+                    function(code){
383
+                        if(code == "DUPLICATE"){
384
+                            alert("This criteria is already paired to this objective")
385
+                            $(select).val(0)
386
+                            $(select).selectpicker('refresh');
387
+                        }
388
+                        else if (code==200){
389
+                          
390
+                            
391
+                            $(select).attr('data-old-pcobo', pcobo_id)
392
+                            $(select).attr('data-old-cobo', cobo_id)
393
+                            $(select).attr('data-old-criterion', criterion_id)
394
+                            $(select).attr('data-old-outcome', outcome_id)
395
+                            $(select).attr('data-old-objective', objective_id)
396
+
397
+
398
+                        }
399
+                    }
400
+                )
401
+                
402
+            
403
+          
404
+
405
+
406
+        }
407
+
408
+    
409
+
410
+        function fetchCriteria(a){
411
+            objective_id = $(a).data('objective-id');
412
+            objective_text = $("#objective-"+objective_id).html()
413
+            outcome_id = $(a).data('outcome-id')
414
+
415
+            $.post(
416
+                "{{URL::action('Objective2Controller@fetchProgramCriteria')}}",
417
+                {
418
+                    objective_id:objective_id,
419
+                    outcome_id:outcome_id
420
+                },
421
+                function(programs){
422
+                    //modal, and its subvariants
423
+                    mc = "#match_criteria";
424
+
425
+                    $(mc).data('objective-id', objective_id)
426
+
427
+                    title_h = $('<h5>',{
428
+                        'class':'modal-title'
429
+                    }).html("Match "+ objective_text +" to Criteria")
430
+                    $(mc+"_title").html(title_h)
431
+
432
+                    $('.removable_div').remove();
433
+
434
+                    //select= $(".select_criteria").html(" ");
435
+                    program_select = $("#match_criteria_program").html(" ");
436
+                    
437
+                    $.each(programs, function(ind, program){
438
+
439
+                        prog_div = $("<div>",{
440
+                            "id":"program-"+program.id,
441
+                            "class": "program_divs removable_div",
442
+                            "style":"display: none"
443
+                        })
444
+                        program_option = $('<option>',{
445
+                            "value":program.id
446
+                        }).html(program.name)
447
+
448
+                        program_select.append(program_option);
449
+                        
450
+
451
+                        criteria = program.criteria
452
+                        options_html = '<option value="0">Nothing Selected</option>';
453
+
454
+                        more_than_one = false;
455
+                        selected_options  = [];
456
+
457
+                        $.each(criteria, function(ind, cri){
458
+
459
+                            if(cri.objective_id == objective_id && cri.outcome_id == outcome_id){
460
+                                dictionary_to_keep = {
461
+                                'value':cri.criterion_id,
462
+                                'data-program-id':program.id,
463
+                                'data-outcome-id':outcome_id,
464
+                                'data-objective-id':objective_id,
465
+                                'data-cobo-id':cri.cobo_id,
466
+                                'data-pcobo-id':cri.pcobo_id
467
+                                
468
+                            }
469
+                                option = $("<option>",{
470
+                                'value':cri.criterion_id,
471
+                                'data-program-id':program.id,
472
+                                'data-outcome-id':outcome_id,
473
+                                'data-objective-id':objective_id,
474
+                                'data-cobo-id':cri.cobo_id,
475
+                                'data-pcobo-id':cri.pcobo_id
476
+                                
477
+                            }).html(cri.name)
478
+                           // option.prop('selected', true);
479
+
480
+                            
481
+                            selected_options.push(dictionary_to_keep);
482
+                            
483
+                            
484
+                            
485
+                            
486
+
487
+                            }
488
+                            else if (cri.outcome_id == outcome_id){
489
+                            option = $("<option>",{
490
+                                'value':cri.criterion_id,
491
+                                'data-program-id':program.id,
492
+                                'data-outcome-id':outcome_id,
493
+                                'data-objective-id':objective_id,
494
+                                'data-cobo-id':cri.cobo_id,
495
+                                'data-pcobo-id':cri.pcobo_id
496
+
497
+                                
498
+                            }).html(cri.name)
499
+                        }
500
+                        
501
+                  
502
+
503
+                            options_html += option.prop('outerHTML');
504
+                            //$(select).selectpicker('refresh');
505
+
506
+                            //if(criteria)
507
+
508
+                        
509
+                        })
510
+
511
+
512
+                        //create multiple selects. 
513
+
514
+                        // el query es , Si no esta en program id, objetivo es 0. 
515
+                        //Si program id 
516
+
517
+
518
+
519
+                        
520
+                        $('#program_objectives').append(prog_div);
521
+                        select = createSelectForModal(options_html)
522
+
523
+                        select.find('div.remove-btn').hide()
524
+                        prog_div.append(select);
525
+                        $('select.criteria_select').selectpicker('refresh');
526
+                        if(selected_options){
527
+                            $.each(selected_options, function(ind, cri){
528
+
529
+                                the_picker = select.find('select.criteria_select').first();
530
+                                the_picker.val(cri['value']);
531
+                                the_picker.attr('data-old-pcobo', cri['data-pcobo-id'])
532
+                                the_picker.attr('data-old-cobo', cri['data-cobo-id'])
533
+                                the_picker.attr('data-old-criterion', cri['value'])
534
+                                the_picker.attr('data-old-outcome', cri['data-outcome-id'])
535
+                                the_picker.attr('data-old-objective', cri['data-objective-id'])
536
+
537
+                                select = createSelectForModal(options_html)
538
+                                prog_div.append(select)
539
+                            // $('.criteria_select').selectpicker('refresh');
540
+                            })
541
+                            // to remove the last one
542
+                            select.remove();
543
+                        }
544
+                        //prog_div.append(select)
545
+
546
+                       // $('#program_objectives').append(prog_div);
547
+
548
+                        $('select.criteria_select').selectpicker('refresh');
549
+
550
+                        prog_div.append(createAddCriteriaButton("program-"+program.id))
551
+                        
552
+
553
+                    
554
+                    })
555
+
556
+                    program_select.selectpicker('refresh');
557
+                    program_select.trigger('change');
558
+
559
+                    $(mc).modal('show');
560
+
561
+
562
+                    
563
+
564
+                    
565
+
566
+                    
567
+
568
+                }
569
+            )
570
+        }
571
+        
572
+        wr = "#warning"
573
+        function deleteCriterion(button){
574
+            select =  $(button).parent().parent().find('select.criteria_select');
575
+
576
+            $('.selected_criteria_to_delete').removeClass('selected_criteria_to_delete');
577
+
578
+            $(button).addClass('selected_criteria_to_delete');
579
+          
580
+            criterion_id = $(select).val()
581
+            if(criterion_id ==0){
582
+                $(button).parent().parent().remove()
583
+                return
584
+            }
585
+            option = $(select).find(':selected');
586
+            name = $(select).find(':selected').html();
587
+            program_id = $(option).data('program-id')
588
+            outcome_id = $(option).data('outcome-id')
589
+            objective_id = $(option).data('objective-id')
590
+            cobo_id = $(option).data('cobo-id')
591
+            pcobo_id = $(option).data('pcobo-id')
592
+            $(wr+'_title').html("Are you sure you want to remove this Criterion?")
593
+            $(wr+"_delete").attr('onclick', 'postDeleteCrit('+criterion_id+' ,'+program_id+' ,'+outcome_id+' ,'+objective_id+' ,'+cobo_id+' ,'+pcobo_id+'); $("'+wr+'").modal("hide") ');
594
+            $(wr+'_body').html("<p>You are about to detach <strong>"+ name+"</strong> </p>")
595
+            $(wr).modal('show');
596
+        }
597
+
598
+        function createAddCriteriaButton(program_div_id){
599
+
600
+            div= $("<div>",{
601
+                'class':'col-md-12'
602
+            });
603
+            
604
+            button = $("<button>", {
605
+                'class':'add_criteria btn btn-secondary',
606
+                'type':'button',
607
+                'onclick':'addSelect("#'+program_div_id+'")',
608
+                'style':'float: right'  
609
+            }).html(" <span class = 'glyphicon glyphicon-plus'></span> Add Criteria");
610
+            div.append(button)
611
+            div.append('<br><br>')
612
+            return div;
613
+        }
614
+
615
+        function addSelect(program_div_id){
616
+            options = $(program_div_id).children('.removable_div').first().find('select.criteria_select').html();
617
+            $(program_div_id).children(".removable_div").last().after(createSelectForModal(options));
618
+            $('select.criteria_select').selectpicker('refresh');
619
+        }
620
+
164 621
         $('.view-scales').on('click', function() {
165 622
             var number_of_scales = this.value;
166 623
 
@@ -168,6 +625,17 @@
168 625
             $('.table-responsive-0').show();
169 626
             $('.table-' + number_of_scales).show();
170 627
         })
628
+
629
+        function changeCriteriaDisplayed(select){
630
+
631
+            select = $(select)
632
+
633
+            program_id = select.val();
634
+
635
+            $('.program_divs').hide();
636
+            $("#program-"+program_id).show();
637
+        }
638
+
171 639
     </script>
172 640
 @stop
173 641
 

+ 15
- 21
script.php View File

@@ -4,7 +4,7 @@
4 4
 $servername = "127.0.0.1";
5 5
 $username = "root";
6 6
 $password = "";
7
-$database = "trabajoolas5";
7
+$database = "trabajoolasdatos";
8 8
 
9 9
 // Create connection
10 10
 $conn = mysqli_connect($servername, $username, $password, $database);
@@ -17,33 +17,27 @@ echo "Connected successfully\n";
17 17
 
18 18
 $allrubrics = mysqli_query($conn, 'select id, contents from `rubrics`');
19 19
 
20
-while ($row = mysqli_fetch_array($allrubrics)) {
21 20
 
22
-    foreach (json_decode($row['contents']) as $criterion) {
21
+$all_criterion_objectiveOutcome = mysqli_query($conn, 'select * from criterion_objective_outcome');
23 22
 
24
-        $outcome_id = $criterion->outcome_id;
25
-        $querySelect = "select * from rubric_outcome where rubric_id ={$row['id']} and outcome_id = {$outcome_id}";
26
-        $makeQuery = mysqli_query($conn, $querySelect);
27
-        if (!mysqli_num_rows($makeQuery)) {
23
+while ($row = mysqli_fetch_array($all_criterion_objectiveOutcome)) {
24
+    $id = $row['id'];
25
+
26
+    $criterion_id = $row['criterion_id'];
28 27
 
29
-            $query2 = "insert into `rubric_outcome` (`rubric_id`, `outcome_id`) values ({$row['id']}, {$outcome_id});";
30
-            $makeQuery = mysqli_query($conn, $query2);
31
-            if (!$makeQuery) {
32
-                die("Connection failed: " . mysqli_error($conn) . $query2);
33
-            }
34
-        }
35 28
 
36 29
 
30
+    $program_ids = mysqli_query($conn, "select * from program_criterion where criterion_id = {$criterion_id}");
31
+
32
+    while ($prog_id = mysqli_fetch_array($program_ids)) {
33
+
34
+        if ($prog_id['program_id'] != null) {
35
+            $query = "insert into `program_criterion_objective_outcome` (`program_id`,`cri_obj_out_id`) values ({$prog_id['program_id']},{$id})";
36
+            $makeQuery = mysqli_query($conn, $query);
37 37
 
38
-        $criteria_id = $criterion->id;
39
-        $querySelect = "select * from rubric_criterion where rubric_id ={$row['id']} and criterion_id = {$criteria_id}";
40
-        $makeQuery = mysqli_query($conn, $querySelect);
41
-        if (!mysqli_num_rows($makeQuery)) {
42
-            $query2 = "insert into `rubric_criterion` (`rubric_id`, `criterion_id`) values ({$row['id']}, {$criteria_id});";
43
-            $makeQuery = mysqli_query($conn, $query2);
44 38
             if (!$makeQuery) {
45
-                echo "Connection failed: " . mysqli_error($conn) . $query2;
39
+                die("Connection failed: " . mysqli_error($conn) . $query);
46 40
             }
47 41
         }
48 42
     }
49
-}
43
+}