Browse Source

Anted de fetch

parent
commit
c042db9dca

+ 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'];

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

@@ -49,6 +49,7 @@ 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;
@@ -168,6 +169,45 @@ class Objective2Controller extends \BaseController
168 169
 		return Objective::find(Input::get('id'));
169 170
 	}
170 171
 
172
+	public function fetchProgramCriteria()
173
+	{
174
+		$outcome_id = Input::get("outcome_id");
175
+		$objective = Objective::findOrFail(Input::get('objective_id'));
176
+
177
+
178
+
179
+
180
+		$user_objective_programs_query = DB::table('objective_program');
181
+
182
+		//Si es admin o school, puede ver todos los criterios de los programas pareados
183
+		//Si es program_coordinator depende.
184
+		if (Auth::user()->role == 3) {
185
+			$user_objective_programs_query = $user_objective_programs_query
186
+				->join("program_user", 'program_user.program_id', '=', 'objective_program.program_id')
187
+				->where('user_id', Auth::user()->id);
188
+		} elseif (Auth::user()->role == 2) {
189
+			$user_objective_programs_query = $user_objective_programs_query
190
+				->join('programs', 'programs.id', '=', 'objective_program.program_id')
191
+				->where("programs.school_id", Auth::user()->school->id);
192
+		}
193
+		$program_ids = $user_objective_programs_query->where('objective_id', $objective->id)
194
+			->select('objective_program.program_id')
195
+			->lists('objective_program.program_id');
196
+
197
+		Log::info("PRogram");
198
+		//Log::info();
199
+
200
+		//$array_to_send = [];
201
+		//$array_to_send["programs"] = Program::whereIn('id', $program_ids)->with('criteria')->get();
202
+		//$array_to_send['selected_criteria'] = $objective->pairedCriteria();
203
+
204
+		//Program
205
+		return Program::whereIn('id', $program_ids)
206
+			->select(DB::raw("programs.*, {$outcome_id} as outcome_id"))
207
+
208
+			->get();
209
+	}
210
+
171 211
 	public function fetchObjectiveWithTrashed()
172 212
 	{
173 213
 		$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
     {

+ 38
- 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,21 @@ 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
+				->where('program_id', $this->id)
47
+				->where('outcome_id', $this->outcome_id)
48
+				->get();
49
+		}
50
+		return Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
51
+			->join('program_criterion_objective_outcome', 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'cobo.id')
52
+			->where('program_id', $this->id)
53
+			->get();
54
+	}
30 55
 	public function templates()
31 56
 	{
32 57
 		return $this->hasMany('Template');
@@ -110,7 +135,19 @@ class Program extends Eloquent
110 135
 	 */
111 136
 	public function criteria()
112 137
 	{
113
-		return $this->hasMany('Criterion');
138
+
139
+		Log::info("AQUI");
140
+		$lmao = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
141
+			->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
142
+			->where('program_id', $this->id);
143
+		//->get();
144
+
145
+
146
+		return $lmao;
147
+		$l = Criterion::join('criterion_objective_outcome', 'criteria.id', '=', 'criterion_objective_outcome.criterion_id')
148
+			->join('program_criterion_objective_outcome', 'cri_obj_out_id', '=', 'criterion_objective_outcome.id')
149
+			->where('program_id', $this->id)->get();
150
+		//get();
114 151
 	}
115 152
 
116 153
 	// 	public function attempted_outcome($outcome_id, $semester)

+ 5
- 1
app/routes.php View File

@@ -363,6 +363,9 @@ Route::group(array('before' => 'auth|has_access'), function () {
363 363
     // Show professor overview to users with courses
364 364
     Route::get('professor', 'ProfessorsController@overview');
365 365
 
366
+    // view objectives and criteria, edit criteria
367
+    Route::post('fetchCriteriaFromProgram', 'Objective2Controller@fetchProgramCriteria');
368
+
366 369
     // Assessment reports for users' courses
367 370
 
368 371
     Route::get('my-assessment-reports', 'OutcomesController@professorAssessmentReport');
@@ -376,6 +379,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
376 379
     Route::post('transformativeAction/filterTA', array('before' => 'csrf', 'uses' => 'TransformativeActionsController@filterTA'));
377 380
     Route::post('transformativeAction/objectivesFromOutcome', array('before' => 'csrf', 'uses' => 'TransformativeActionsController@objectivesFromOutcome'));
378 381
 
382
+
379 383
     /**
380 384
      * Administrator Routes
381 385
      */
@@ -652,7 +656,7 @@ Route::group(array('before' => 'auth|has_access'), function () {
652 656
         Route::get('learning-outcomes-criteria', 'CriteriaController@index');
653 657
         Route::get('learning-objectives-criteria', 'Objective2Controller@viewObjectives');
654 658
         Route::get('export_grades/{id}', 'CoursesController@exportGrades');
655
-        Route::get('learning-objectives-criteria', 'Objective2Controller@viewObjectives');
659
+        Route::get('template/{template}', 'TemplatesController@show');
656 660
         Route::get('compare_activities/{activity_1}/{activity_2}', 'ActivitiesController@compareActivities');
657 661
         // Assessment reports
658 662
         //Route::get('professor-assessment-report/{outcome_id}', 'OutcomesController@professorAssessmentReport');

+ 257
- 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,41 @@
83 84
         </div>
84 85
 
85 86
     </div>
87
+
88
+    <div id="match_criteria" class="modal fade" tabindex="-1" data-objective-id="0">
89
+        <div class="modal-dialog">
90
+            <div class="modal-content">
91
+                <div class="modal-header">
92
+                    <h5 class="modal-title" id = 'match_criteria_title'></h5>
93
+                    <button type="button" class="close" data-dismiss="modal">&times;</button>
94
+                </div>
95
+                <div class="modal-body" id = "match_criteria_body">
96
+                    <p>The following criteria appear based on objective's programs and your available programs</p>
97
+
98
+                    <div class ='form-group col-md-12'>
99
+                        <select id="match_criteria_program" class ='form-control selectpicker select_program' onchange="changeCriteriaDisplayed('#match_criteria_program')">
100
+                            
101
+                        </select>
102
+                    </div>
103
+                    <hr>
104
+
105
+                    <div id="program_objectives">
106
+
107
+                    </div>
108
+
109
+                
110
+
111
+
112
+
113
+
114
+                </div>
115
+                <div class="modal-footer">
116
+                    <button type="button" class="btn btn-secondary" data-dismiss="modal" onclick="$('#match_criteria').data('objective-id', '0');">Cancel</button>
117
+                    <button type="button" class="btn btn-primary" onclick = 'matchCriteriaToObjective("#match_criteria")'>Save</button>
118
+                </div>
119
+            </div>
120
+        </div>
121
+    </div>
86 122
     <script>
87 123
         $(document).ready(function() {
88 124
             // --------------------------------------------------------------------------
@@ -100,6 +136,8 @@
100 136
             /*
101 137
 
102 138
               */
139
+
140
+            
103 141
             function fetchObjectives(li) {
104 142
                 {
105 143
 
@@ -130,8 +168,12 @@
130 168
 
131 169
                             $.each(json, function(ind2, objective) {
132 170
                                 tr = $("<tr>");
133
-                                td_text = $("<td>").html(objective.text);
134 171
 
172
+                                //objectives
173
+                                td_text = $("<td>",{
174
+                                    'id':"objective-"+objective.id
175
+                                }).html(objective.text);
176
+                                 //programs
135 177
                                 td_programs = $("<td>");
136 178
                                 ol = $("<ol>");
137 179
 
@@ -140,10 +182,29 @@
140 182
                                     li.appendTo(ol);
141 183
                                 })
142 184
                                 ol.appendTo(td_programs);
185
+
186
+                                //link to criteria matching
187
+                                link_td = $("<td>");
188
+                                
189
+                                a = $('<a>',{
190
+                                    'onclick':'fetchCriteria(this)',
191
+                                    'data-objective-id': objective.id,
192
+                                    'data-outcome-id':id
193
+
194
+                                    
195
+                                }).html("Change Associated Criteria");
196
+
197
+                                link_td.append(a)
198
+
199
+                                
143 200
                                 tr.append(td_text);
144 201
                                 tr.append(td_programs);
202
+                                tr.append(link_td)
145 203
                                 tr.appendTo($('#table_objectives'))
146 204
 
205
+
206
+                                
207
+
147 208
                             })
148 209
                         },
149 210
                         'json'
@@ -161,6 +222,190 @@
161 222
             })
162 223
         });
163 224
 
225
+
226
+        function createSelectForModal(options){
227
+            
228
+            div_master = $('<div>',{
229
+                'class':'removable_div'
230
+            })
231
+            div_select = $("<div>",{
232
+                'class':'form-group col-md-11',
233
+
234
+            })
235
+            select = $('<select>',{
236
+                'class':'selectpicker form-control criteria_select',
237
+                'name':'criteria[]'
238
+
239
+            }).html(options);
240
+            div_rem_button = $('<div>',
241
+                {
242
+                    'class':'col-md-1 remove-btn'
243
+                    
244
+                })
245
+            rem_button = $('<button>',{
246
+                'type':'button',
247
+                'class':'btn btn-primary',
248
+                'onclick':'$(this).parent().parent().remove()'
249
+            }).html("<span class='glyphicon glyphicon-remove'></span>")
250
+
251
+            div_select.append(select);
252
+            div_rem_button.append(rem_button);
253
+            div_master.append(div_select);
254
+            div_master.append(div_rem_button);
255
+
256
+            return div_master;
257
+
258
+        }
259
+
260
+        function fetchCriteria(a){
261
+            objective_id = $(a).data('objective-id');
262
+            objective_text = $("#objective-"+objective_id).html()
263
+            outcome_id = $(a).data('outcome-id')
264
+
265
+            $.post(
266
+                "{{URL::action('Objective2Controller@fetchProgramCriteria')}}",
267
+                {
268
+                    objective_id:objective_id,
269
+                    outcome_id:outcome_id
270
+                },
271
+                function(programs){
272
+                    //modal, and its subvariants
273
+                    mc = "#match_criteria";
274
+
275
+                    $(mc).data('objective-id', objective_id)
276
+
277
+                    title_h = $('<h5>',{
278
+                        'class':'modal-title'
279
+                    }).html("Match "+ objective_text +" to Criteria")
280
+                    $(mc+"_title").html(title_h)
281
+
282
+                    $('.removable_div').remove();
283
+
284
+                    //select= $(".select_criteria").html(" ");
285
+                    program_select = $("#match_criteria_program").html(" ");
286
+                    
287
+                    $.each(programs, function(ind, program){
288
+
289
+                        prog_div = $("<div>",{
290
+                            "id":"program-"+program.id,
291
+                            "class": "program_divs removable_div",
292
+                            "style":"display: none"
293
+                        })
294
+                        program_option = $('<option>',{
295
+                            "value":program.id
296
+                        }).html(program.name)
297
+
298
+                        program_select.append(program_option);
299
+                        
300
+
301
+                        criteria = program.criteria
302
+                        options_html = '<option value="0">Nothing Selected</option>';
303
+
304
+                        more_than_one = false;
305
+                        selected_options  = [];
306
+
307
+                        $.each(criteria, function(ind, cri){
308
+
309
+                            if(cri.objective_id == objective_id && cri.outcome_id == outcome_id){
310
+                                option = $("<option>",{
311
+                                'value':cri.criterion_id,
312
+                                'data-program-id':program.id,
313
+                                'data-outcome-id':outcome_id,
314
+                                
315
+                            }).html(cri.name)
316
+                           // option.prop('selected', true);
317
+
318
+                            
319
+                            selected_options.push(cri.criterion_id);
320
+                            
321
+                            
322
+                            
323
+                            
324
+
325
+                            }
326
+                            else if (cri.outcome_id == outcome_id){
327
+                            option = $("<option>",{
328
+                                'value':cri.criterion_id,
329
+                                'data-program-id':program.id,
330
+                                'data-outcome-id':outcome_id,
331
+                                
332
+                            }).html(cri.name)
333
+                        }
334
+                  
335
+
336
+                            options_html += option.prop('outerHTML');
337
+                            //$(select).selectpicker('refresh');
338
+
339
+                            //if(criteria)
340
+
341
+                        
342
+                        })
343
+
344
+
345
+                        //create multiple selects. 
346
+
347
+                        // el query es , Si no esta en program id, objetivo es 0. 
348
+                        //Si program id 
349
+
350
+
351
+
352
+                        
353
+                        $('#program_objectives').append(prog_div);
354
+                        select = createSelectForModal(options_html)
355
+
356
+                        select.find('.remove_btn').hide()
357
+                        prog_div.append(select);
358
+                        $('select.criteria_select').selectpicker('refresh');
359
+
360
+                        $.each(selected_options, function(ind, cri_id){
361
+
362
+                            the_picker = select.find('select.criteria_select').first();
363
+                            the_picker.val(cri_id);
364
+
365
+                            select = createSelectForModal(options_html)
366
+                            prog_div.append(select)
367
+                           // $('.criteria_select').selectpicker('refresh');
368
+                        })
369
+
370
+                        //prog_div.append(select)
371
+
372
+                       // $('#program_objectives').append(prog_div);
373
+
374
+                        $('select.criteria_select').selectpicker('refresh');
375
+
376
+                        prog_div.append(createAddCriteriaButton("program-"+program.id))
377
+
378
+                    
379
+                    })
380
+
381
+                    program_select.selectpicker('refresh');
382
+                    program_select.trigger('change');
383
+
384
+                    $(mc).modal('show');
385
+
386
+
387
+                    
388
+
389
+                    
390
+
391
+                    
392
+
393
+                }
394
+            )
395
+        }
396
+
397
+        function createAddCriteriaButton(program_div_id){
398
+
399
+
400
+            button = $("<button>", {
401
+                'class':'add_criteria btn btn-secondary',
402
+                'type':'button',
403
+                'onclick':'addSelect('+program_div_id+')'
404
+                
405
+            }).html("+ Add Criteria");
406
+
407
+        }
408
+
164 409
         $('.view-scales').on('click', function() {
165 410
             var number_of_scales = this.value;
166 411
 
@@ -168,6 +413,17 @@
168 413
             $('.table-responsive-0').show();
169 414
             $('.table-' + number_of_scales).show();
170 415
         })
416
+
417
+        function changeCriteriaDisplayed(select){
418
+
419
+            select = $(select)
420
+
421
+            program_id = select.val();
422
+
423
+            $('.program_divs').hide();
424
+            $("#program-"+program_id).show();
425
+        }
426
+
171 427
     </script>
172 428
 @stop
173 429
 

+ 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
+}