rodzic
commit
c6b1826281

+ 87
- 43
app/controllers/Objective2Controller.php Wyświetl plik

200
 		$clean_input['program_id'] = Input::get('program_id');
200
 		$clean_input['program_id'] = Input::get('program_id');
201
 		//		Log::info(Input::get('program_id'));
201
 		//		Log::info(Input::get('program_id'));
202
 
202
 
203
+		$clean_input['agreement'] = Input::get("agreement");
204
+
203
 		return $clean_input;
205
 		return $clean_input;
204
 	}
206
 	}
205
 
207
 
216
 
218
 
217
 		$clean_input['program_id'] = Input::get('program_id');
219
 		$clean_input['program_id'] = Input::get('program_id');
218
 		$clean_input['pair_criteria'] =  Input::get('pair_every_criteria_with_objective');
220
 		$clean_input['pair_criteria'] =  Input::get('pair_every_criteria_with_objective');
221
+		$clean_input['agreement'] = Input::get('agreement');
219
 
222
 
220
 
223
 
221
 		return $clean_input;
224
 		return $clean_input;
598
 						return Redirect::to('objective')->withInput();
601
 						return Redirect::to('objective')->withInput();
599
 					}*/
602
 					}*/
600
 				}
603
 				}
601
-				DB::table('criterion_objective_outcome')
602
-					->join('program_criterion', 'criterion_objective_outcome.criterion_id', "=", 'program_criterion.criterion_id')
603
-					->whereIn('program_id', $clean_input['program_id'])
604
-					->whereIn('outcome_id', $clean_input['outcome_id'])
605
-					->where('objective_id', '=', 0)
606
-					->update(array('objective_id' => $objectiveId));
604
+				if ($clean_input['agreement']) {
605
+					DB::table('criterion_objective_outcome')
606
+						->join('program_criterion', 'criterion_objective_outcome.criterion_id', "=", 'program_criterion.criterion_id')
607
+						->whereIn('program_id', $clean_input['program_id'])
608
+						->whereIn('outcome_id', $clean_input['outcome_id'])
609
+						->where('objective_id', '=', 0)
610
+						->update(array('objective_id' => $objectiveId));
611
+				}
607
 				// 				update("update criterion_objective_outcome coo join program_criterion pc on coo.criterion_id=pc.criterion_id set 
612
 				// 				update("update criterion_objective_outcome coo join program_criterion pc on coo.criterion_id=pc.criterion_id set 
608
 				// 				objective_id= {$objectiveId} where program_id in (".$clean_input['program_id'].") and objective_id=0 and outcome_id in (".$clean_input['outcome_id'].")");
613
 				// 				objective_id= {$objectiveId} where program_id in (".$clean_input['program_id'].") and objective_id=0 and outcome_id in (".$clean_input['outcome_id'].")");
609
 
614
 
758
 	 * @return Response
763
 	 * @return Response
759
 	 */
764
 	 */
760
 
765
 
766
+	/*pasos que sigue
767
+		1. edita el texto del objetivo, si alguno,
768
+		2. escoge los criteri
769
+	 */
770
+
761
 	public function update()
771
 	public function update()
762
 
772
 
763
 	{
773
 	{
839
 					->select('criterion_objective_outcome.criterion_id')
849
 					->select('criterion_objective_outcome.criterion_id')
840
 					->lists('criterion_objective_outcome.criterion_id');
850
 					->lists('criterion_objective_outcome.criterion_id');
841
 				//DB::delete("delete from `objective_outcome` where objective_id ={$objectiveId}");
851
 				//DB::delete("delete from `objective_outcome` where objective_id ={$objectiveId}");
852
+
853
+
842
 				DB::delete("delete from objective_program where objective_id = {$objectiveId}");
854
 				DB::delete("delete from objective_program where objective_id = {$objectiveId}");
843
 
855
 
844
 				foreach ($clean_input['program_id'] as $program_id) {
856
 				foreach ($clean_input['program_id'] as $program_id) {
845
 					DB::insert("insert into `objective_program`(objective_id, program_id) values ({$objectiveId},{$program_id})");
857
 					DB::insert("insert into `objective_program`(objective_id, program_id) values ({$objectiveId},{$program_id})");
846
 				}
858
 				}
847
 
859
 
848
-				//borra todos los pareos de este objetivo de programas que no estan vinculados a este objetivo
860
+				//$cri_obj_out_ids = DB::table('criterion_objective_outcome as cobo')
861
+				//->where('objective_id', $objectiveId)
862
+				//->lists('cobo.id')
863
+				//Todos los criterios, que están pareados a este objetivo, pero 
864
+				// están pareados a otros dominios que no son los seleccionados, ponlos en holder. 
865
+				DB::table('criterion_objective_outcome as cobo')
866
+					//->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
849
 
867
 
850
-				$cri_obj_out_ids = DB::table('criterion_objective_outcome as cobo')
868
+					//->whereIn('program_id', $clean_input['program_id'])
851
 					->where('objective_id', $objectiveId)
869
 					->where('objective_id', $objectiveId)
852
-					->lists('cobo.id');
853
-				DB::table("program_criterion_objective_outcome")
854
-					->whereIn('cri_obj_out_id', $cri_obj_out_ids)
855
-					->whereNotIn('program_id', $clean_input['program_id'])
856
-					->delete();
870
+					->whereNotIn('outcome_id', $clean_input['outcome_id'])
871
+					->update(array(
872
+						'objective_id' => 0
873
+					));
874
+
875
+				//borra todos los pareos de este objetivo con programas que no están en los programas que el usuario escogió
876
+
877
+
878
+				//DB::table("program_criterion_objective_outcome as poco")
879
+				//	->join("criterion_objective_outcome as cobo", 'poco.cri_obj_out_id', '=', 'cobo.id')
880
+				//	->where('objective_id',$objectiveId)
881
+				//	->whereNotIn('program_id', $clean_input['program_id'])
882
+				//	->delete();
883
+
884
+
857
 
885
 
858
-				//el plan es, convertir todos los pareos de criterios-obj-out asociado a mi programa
859
-				//a holder primero
886
+				Log::info($clean_input);
860
 
887
 
861
-				$cri_obj_out = DB::table('criterion_objective_outcome')
888
+
889
+
890
+				/*$cri_obj_out = DB::table('criterion_objective_outcome')
862
 					->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
891
 					->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
863
 					->whereIn('program_id', $clean_input['program_id'])
892
 					->whereIn('program_id', $clean_input['program_id'])
864
 					->where('objective_id', $objectiveId)
893
 					->where('objective_id', $objectiveId)
865
 					->update(array(
894
 					->update(array(
866
 						'objective_id' => 0
895
 						'objective_id' => 0
867
-					));
896
+					));*/
868
 
897
 
869
 				//Luego por cada dominio que haya, chequea si existe ya el pareo
898
 				//Luego por cada dominio que haya, chequea si existe ya el pareo
870
 				//si no existe insertalo.
899
 				//si no existe insertalo.
887
 							foreach ($criteria_assoc as $criterion_id) {
916
 							foreach ($criteria_assoc as $criterion_id) {
888
 
917
 
889
 								$cob_id = DB::table('criterion_objective_outcome')
918
 								$cob_id = DB::table('criterion_objective_outcome')
890
-									->insertGetId(array(
891
-										"criterion_id" => $criterion_id,
892
-										"objective_id" => $objectiveId,
893
-										"outcome_id" => $outcome_id
894
-									));
895
-								foreach ($clean_input['program_id'] as $program_id)
896
-									DB::table('program_criterion_objective_outcome')
897
-										->insert(array(
898
-											'cri_obj_out_id' => $cob_id,
899
-											'program_id' => $program_id
919
+									->where('criterion_id', $criterion_id)
920
+									->where('objective_id', $objectiveId)
921
+									->where('outcome_id', $outcome_id)
922
+									->first();
923
+								if (!isset($cob_id)) {
924
+									$cob_id = DB::table('criterion_objective_outcome')
925
+										->insertGetId(array(
926
+											"criterion_id" => $criterion_id,
927
+											"objective_id" => $objectiveId,
928
+											"outcome_id" => $outcome_id
900
 										));
929
 										));
930
+								} else
931
+									$cob_id = $cob_id->id;
932
+								//inserta los. criterios asociados a los nuevos dominios y parealos a estos programas_id
933
+
934
+								foreach ($clean_input['program_id'] as $program_id) {
935
+									$poco_id = DB::table('program_criterion_objective_outcome')
936
+										->where("cri_obj_out_id", $cob_id)
937
+										->where('program_id', $program_id)
938
+										->first();
939
+									if (!isset($poco_id)) {
940
+										DB::table('program_criterion_objective_outcome')
941
+											->insert(array(
942
+												"program_id" => $program_id,
943
+												"cri_obj_out_id" => $cob_id
944
+											));
945
+									} else {
946
+										DB::table('program_criterion_objective_outcome')
947
+											->where('id', $poco_id->id)
948
+											->update(array(
949
+												'cri_obj_out_id' => $cob_id
950
+											));
951
+									}
952
+								}
901
 							}
953
 							}
902
 						}
954
 						}
903
 					}
955
 					}
956
+				}
904
 
957
 
905
-					//aqui estoy diciendo, todos los pareos bajo estos programas que tienen objetivo 0, y este dominio,
906
-					//unelo a este objetivo. 
958
+				if ($clean_input["agreement"] == 1) {
907
 					DB::table('criterion_objective_outcome')
959
 					DB::table('criterion_objective_outcome')
908
-						->join("program_criterion_objective_outcome", 'program_criterion_objective_outcome.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
960
+						->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'criterion_objective_outcome.id')
909
 						->whereIn('program_id', $clean_input['program_id'])
961
 						->whereIn('program_id', $clean_input['program_id'])
910
 						->where('objective_id', 0)
962
 						->where('objective_id', 0)
911
-						->where('outcome_id', $outcome_id)
963
+						->whereIn('outcome_id', $clean_input['outcome_id'])
964
+
912
 						->update(array(
965
 						->update(array(
913
 							'objective_id' => $objectiveId
966
 							'objective_id' => $objectiveId
914
 						));
967
 						));
968
+				}
915
 
969
 
916
 
970
 
917
-
918
-
919
-
920
-
921
-
922
-
923
-
924
-
925
-					$criterion_array = [];
926
-				}
971
+				//Borra los objective outcomes que no estan pareado a nada
927
 
972
 
928
 				DB::table('objective_outcome')
973
 				DB::table('objective_outcome')
929
-					->whereNotIn('outcome_id', $clean_input['outcome_id'])
930
 					->where('objective_id', $objectiveId)
974
 					->where('objective_id', $objectiveId)
931
-					->delete();
975
+					->whereNotIn('outcome_id', $clean_input['outcome_id'])->delete();
932
 
976
 
933
 				//Session::flash('status', 'success');
977
 				//Session::flash('status', 'success');
934
 				//Session::flash('message', 'Updated Objective: "' . $Objective->text . '"');
978
 				//Session::flash('message', 'Updated Objective: "' . $Objective->text . '"');

+ 35
- 1
app/views/local/managers/shared/objectives.blade.php Wyświetl plik

81
                         {{ Form::text('text', '', ['class' => 'form-control']) }}
81
                         {{ Form::text('text', '', ['class' => 'form-control']) }}
82
                     </div>
82
                     </div>
83
 
83
 
84
+                    <div class = "form-group">
85
+                      
86
+                        <input type="checkbox" id="agreement" name="agreement"
87
+                                value="1">
88
+                                  {{Form::label('agreement', 'I would like to pair criteria without objectives to this one.')}}
89
+
90
+                        
91
+                 
92
+
93
+                    </div>
94
+
84
 
95
 
85
 
96
 
86
                     {{ Form::submit('Create', ['class' => 'btn btn-primary btn-block', 'id' => 'createObjectiveButton']) }}
97
                     {{ Form::submit('Create', ['class' => 'btn btn-primary btn-block', 'id' => 'createObjectiveButton']) }}
228
 
239
 
229
                     </div>
240
                     </div>
230
 
241
 
242
+                    <div class = "form-group">
243
+                      
244
+                        <input type="checkbox" id="agreement_assoc" name="agreement"
245
+                                value="1">
246
+                                  {{Form::label('agreement_assoc', 'I would like to pair criteria without objectives to this one.')}}
247
+
248
+                        
249
+                 
250
+
251
+                    </div>
252
+
231
                     {{ Form::submit('Update', ['class' => 'btn btn-primary btn-block', 'id' => 'update_button_to_modal']) }}
253
                     {{ Form::submit('Update', ['class' => 'btn btn-primary btn-block', 'id' => 'update_button_to_modal']) }}
232
                     {{ Form::close() }}
254
                     {{ Form::close() }}
233
 
255
 
699
                 if (this.checked)
721
                 if (this.checked)
700
                     program_id.push($(this).val())
722
                     program_id.push($(this).val())
701
             });
723
             });
724
+
725
+            agreement = null;
726
+            if($('#agreement_assoc').is(':checked')){
727
+                agreement = 1;
728
+            }
729
+            else{
730
+                alert("LMAOOOO");
731
+            }
732
+           
733
+
734
+
702
             $.post(
735
             $.post(
703
                 "{{ URL::action('Objective2Controller@update') }}", {
736
                 "{{ URL::action('Objective2Controller@update') }}", {
704
                     assoc_outcome: outcome_id,
737
                     assoc_outcome: outcome_id,
706
                     status: status,
739
                     status: status,
707
                     text: text,
740
                     text: text,
708
                     id: id,
741
                     id: id,
709
-                    pair_every_criteria_with_objective: pair_every_criteria_with_objective
742
+                    pair_every_criteria_with_objective: pair_every_criteria_with_objective,
743
+                    agreement:agreement
710
                 },
744
                 },
711
                 function($array) {
745
                 function($array) {
712
                     div = $('<div/>', {
746
                     div = $('<div/>', {