Browse Source

update para templates

parent
commit
1e3ca1ad39
1 changed files with 12 additions and 5 deletions
  1. 12
    5
      app/controllers/TemplatesController.php

+ 12
- 5
app/controllers/TemplatesController.php View File

261
 		if ($role == 1) {
261
 		if ($role == 1) {
262
 			$templates = Template::orderBy('name', 'ASC')->get();
262
 			$templates = Template::orderBy('name', 'ASC')->get();
263
 			$programs = Program::orderBy('name', 'ASC')->get();
263
 			$programs = Program::orderBy('name', 'ASC')->get();
264
-			$criteria = Criterion::orderBy('name', 'ASC')->get();
264
+			$criteria_ids = Criterion::orderBy('name', 'ASC')->lists('id');
265
 			$school_id_user = NULL;
265
 			$school_id_user = NULL;
266
 			$program_ids =  Program::orderBy('name', 'ASC')->lists('id');
266
 			$program_ids =  Program::orderBy('name', 'ASC')->lists('id');
267
 		} else {
267
 		} else {
280
 			foreach ($programs as $program) {
280
 			foreach ($programs as $program) {
281
 				$program_ids[] = $program->id;
281
 				$program_ids[] = $program->id;
282
 			}
282
 			}
283
-
283
+			/*
284
 			$criteria = Criterion::whereHas(
284
 			$criteria = Criterion::whereHas(
285
 				'programs',
285
 				'programs',
286
 				function ($q) use ($program_ids) {
286
 				function ($q) use ($program_ids) {
293
 						$q->where('objective_id', '!=', 0);
293
 						$q->where('objective_id', '!=', 0);
294
 					}
294
 					}
295
 				)
295
 				)
296
-				->orderBy('name', 'ASC')->get();
296
+				->orderBy('name', 'ASC')->get(); */
297
+			$criteria_ids = Criterion::join('criterion_objective_outcome as cobo', 'cobo.criterion_id', '=', 'criteria.id')
298
+				->join('program_criterion_objective_outcome as poco', 'poco.cri_obj_out_id', '=', 'cobo.id')
299
+				->whereIn('program_id', $program_ids)
300
+				->where('objective_id', '<>', 0)
301
+				->select('criteria.*')
302
+				->distinct()
303
+				->lists('criteria.id');
297
 		}
304
 		}
298
 		// 			Log::info("aqui".(count($criteria)));
305
 		// 			Log::info("aqui".(count($criteria)));
299
 		// 			Log::info(json_encode(count($criteria)));
306
 		// 			Log::info(json_encode(count($criteria)));
302
 
309
 
303
 		$templates = Template::where('school_id', '=', $school_id_user)->orWhere('school_id', '=', NULL)
310
 		$templates = Template::where('school_id', '=', $school_id_user)->orWhere('school_id', '=', NULL)
304
 			->orderBy('name', 'ASC')->get();
311
 			->orderBy('name', 'ASC')->get();
305
-		$criteria_ids = array();
312
+		/*$criteria_ids = array();
306
 
313
 
307
 		foreach ($criteria as $criterion) {
314
 		foreach ($criteria as $criterion) {
308
 			$criteria_ids[] = $criterion->id;
315
 			$criteria_ids[] = $criterion->id;
309
-		}
316
+		}*/
310
 		$templates_fuera = Template::whereHas('criteria', function ($q) use ($criteria_ids) {
317
 		$templates_fuera = Template::whereHas('criteria', function ($q) use ($criteria_ids) {
311
 			$q->whereNotIn('criterion_id', $criteria_ids);
318
 			$q->whereNotIn('criterion_id', $criteria_ids);
312
 		})
319
 		})