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,7 +261,7 @@ class TemplatesController extends \BaseController
261 261
 		if ($role == 1) {
262 262
 			$templates = Template::orderBy('name', 'ASC')->get();
263 263
 			$programs = Program::orderBy('name', 'ASC')->get();
264
-			$criteria = Criterion::orderBy('name', 'ASC')->get();
264
+			$criteria_ids = Criterion::orderBy('name', 'ASC')->lists('id');
265 265
 			$school_id_user = NULL;
266 266
 			$program_ids =  Program::orderBy('name', 'ASC')->lists('id');
267 267
 		} else {
@@ -280,7 +280,7 @@ class TemplatesController extends \BaseController
280 280
 			foreach ($programs as $program) {
281 281
 				$program_ids[] = $program->id;
282 282
 			}
283
-
283
+			/*
284 284
 			$criteria = Criterion::whereHas(
285 285
 				'programs',
286 286
 				function ($q) use ($program_ids) {
@@ -293,7 +293,14 @@ class TemplatesController extends \BaseController
293 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 305
 		// 			Log::info("aqui".(count($criteria)));
299 306
 		// 			Log::info(json_encode(count($criteria)));
@@ -302,11 +309,11 @@ class TemplatesController extends \BaseController
302 309
 
303 310
 		$templates = Template::where('school_id', '=', $school_id_user)->orWhere('school_id', '=', NULL)
304 311
 			->orderBy('name', 'ASC')->get();
305
-		$criteria_ids = array();
312
+		/*$criteria_ids = array();
306 313
 
307 314
 		foreach ($criteria as $criterion) {
308 315
 			$criteria_ids[] = $criterion->id;
309
-		}
316
+		}*/
310 317
 		$templates_fuera = Template::whereHas('criteria', function ($q) use ($criteria_ids) {
311 318
 			$q->whereNotIn('criterion_id', $criteria_ids);
312 319
 		})