Ingen beskrivning

TransformativeActionsController.php 56KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521
  1. <?php
  2. use Illuminate\Support\Facades\Input;
  3. use Illuminate\Support\Facades\Session;
  4. class TransformativeActionsController extends \BaseController
  5. {
  6. // load the Tranformative actions page
  7. public function editTA()
  8. {
  9. $title = "Transformative Action";
  10. $role = Auth::user()['role'];
  11. $outcomes = Outcome::orderBy('name', 'ASC')->lists('name', 'id');
  12. $schools = School::orderBy('name', 'ASC')->get();
  13. $criteria = Criterion::withTrashed()->orderBy('name', 'ASC')->get();
  14. $programs = Program::orderBy('name', 'ASC')->get();
  15. $user_id = auth::user()->id;
  16. switch ($role) {
  17. case 3:
  18. $program_id = DB::table('program_user')
  19. ->where('user_id', $user_id)
  20. ->select('program_id')
  21. ->lists('program_id');
  22. break;
  23. case 2:
  24. $program_id = DB::table('programs')
  25. ->where('school_id', Auth::user()->school_id)
  26. ->lists('id');
  27. break;
  28. }
  29. /*$program_id = DB::table('program_user')
  30. ->where('user_id', $user_id)
  31. ->select('program_id')
  32. ->get();
  33. $program_id = $program_id[0]->program_id; */ //program id 15 debido al user 8
  34. $outcomes = Outcome::orderBy('name', 'ASC')
  35. ->where('deactivation_date', '=', '0000-00-00')
  36. ->orWhereNull('deactivation_date')
  37. ->get();
  38. $objectives = array();
  39. $types = DB::table('transformative_actions')
  40. ->select('type_of_TA')
  41. ->where('type_of_TA', '<>', '')
  42. ->groupBy('type_of_TA')
  43. ->get();
  44. // if user is program coordinator
  45. //1 edit panel: load the TA that
  46. // are custom ('transformative_actions.by_professor' == 0)
  47. // were approved in past ('transformative_actions.is_custom' == 1)
  48. $ta_edit_panel = DB::table('transformative_actions')
  49. ->where('transformative_actions.is_custom', 1)
  50. ->whereIn('transformative_actions.program_id', $program_id)
  51. ->where('transformative_actions.by_professor', 0)
  52. ->orderBy('at_text', 'ASC')
  53. ->get();
  54. //2 approve panel: load TAs that
  55. // can be approved ('transformative_actions.by_professor' == 1)
  56. $ta_approval_panel = DB::table('transformative_actions')
  57. ->where('transformative_actions.is_custom', 1)
  58. ->whereIn('transformative_actions.program_id', $program_id)
  59. ->where('transformative_actions.by_professor', 1)
  60. ->orderBy('at_text', 'ASC')
  61. ->get();
  62. //2.1 approve panel: load the filter options.
  63. // the "->where()" should be the same from $ta_approval_panel,
  64. // but with aditional joins and different select
  65. //
  66. // get the names of the professors
  67. $professor_filter_approvePanel = DB::table('transformative_actions')
  68. ->join('users', 'users.id', '=', 'transformative_actions.user_id')
  69. ->where('transformative_actions.is_custom', 1)
  70. ->whereIn('transformative_actions.program_id', $program_id)
  71. ->where('transformative_actions.by_professor', 1)
  72. ->select('users.*')
  73. ->groupBy('transformative_actions.user_id')
  74. ->orderBy('users.first_name', 'ASC')
  75. ->get();
  76. // get the courses from asociated with a TA
  77. $course_filter_approvePanel = DB::table('ta_course')
  78. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  79. ->join('courses', function ($join) {
  80. $join->on('courses.number', '=', 'ta_course.course_number');
  81. $join->on('courses.code', '=', 'ta_course.course_code');
  82. })
  83. ->where('transformative_actions.is_custom', 1)
  84. ->whereIn('transformative_actions.program_id', $program_id)
  85. ->where('transformative_actions.by_professor', 1)
  86. ->select('courses.*')
  87. ->groupBy('courses.number', 'courses.code', 'courses.name')
  88. ->orderBy('courses.name', 'ASC')
  89. ->orderBy('courses.code', 'ASC')
  90. ->get();
  91. // get the outcome asociated with a TA
  92. $outcome_filter_approvePanel = DB::table('transformative_actions')
  93. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  94. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  95. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  96. ->where('transformative_actions.is_custom', 1)
  97. ->whereIn('transformative_actions.program_id', $program_id)
  98. ->where('transformative_actions.by_professor', 1)
  99. ->select('outcomes.*')
  100. ->groupBy('outcomes.id')
  101. ->orderBy('outcomes.name', 'ASC')
  102. ->get();
  103. //3 edit panel: load the filter options.
  104. // the "->where()" should be the same from $ta_edit_panel,
  105. // but with aditional joins and different select
  106. //
  107. $professor_filter_editPanel = DB::table('transformative_actions')
  108. ->join('users', 'users.id', '=', 'transformative_actions.user_id')
  109. ->where('transformative_actions.is_custom', 1)
  110. ->whereIn('transformative_actions.program_id', $program_id)
  111. ->where('transformative_actions.by_professor', 0)
  112. ->select('users.*')
  113. ->groupBy('transformative_actions.user_id')
  114. ->orderBy('users.first_name', 'ASC')
  115. ->get();
  116. $course_filter_editPanel = DB::table('ta_course')
  117. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  118. ->join('courses', function ($join) {
  119. $join->on('courses.number', '=', 'ta_course.course_number');
  120. $join->on('courses.code', '=', 'ta_course.course_code');
  121. })
  122. ->where('transformative_actions.is_custom', 1)
  123. ->whereIn('transformative_actions.program_id', $program_id)
  124. ->where('transformative_actions.by_professor', 0)
  125. ->select('courses.*')
  126. ->groupBy('courses.number', 'courses.code', 'courses.name')
  127. ->orderBy('courses.name', 'ASC')
  128. ->orderBy('courses.code', 'ASC')
  129. ->get();
  130. $outcome_filter_editPanel = DB::table('transformative_actions')
  131. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  132. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  133. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  134. ->where('transformative_actions.is_custom', 1)
  135. ->whereIn('transformative_actions.program_id', $program_id)
  136. ->where('transformative_actions.by_professor', 0)
  137. ->select('outcomes.*')
  138. ->groupBy('outcomes.id')
  139. ->orderBy('outcomes.name', 'ASC')
  140. ->get();
  141. // 4 create panel: search all courses
  142. $courses_create = DB::table('courses')
  143. ->whereIn('courses.program_id', $program_id)
  144. ->select('courses.*')
  145. ->groupBy('courses.number', 'courses.code', 'courses.name')
  146. ->orderBy('courses.code', 'ASC')
  147. ->orderBy('courses.number', 'ASC')
  148. ->get();
  149. /*
  150. // if user is profesor
  151. elseif ($role == 4) {
  152. // 1 the user can only edit TA that need approval and has been submited by the same user
  153. $ta_edit_panel = DB::table('transformative_actions')
  154. ->where('transformative_actions.is_custom', 1)
  155. ->where('transformative_actions.program_id', $program_id)
  156. ->where('transformative_actions.user_id', Auth::user()->id)
  157. ->where('transformative_actions.by_professor', 1)
  158. ->select('transformative_actions.*')
  159. ->orderBy('at_text', 'ASC')
  160. ->get();
  161. // 2 approve panel: dont load TA since professors cant approve them
  162. $ta_approval_panel = array();
  163. // 3 edit panel: load professor filter for his courses
  164. $professor_filter_editPanel = array();
  165. $course_filter_editPanel = DB::table('ta_course')
  166. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  167. ->join('courses', 'courses.id', '=', 'ta_course.course_id')
  168. ->where('transformative_actions.is_custom', 1)
  169. ->where('transformative_actions.user_id', Auth::user()->id)
  170. ->where('transformative_actions.program_id', $program_id)
  171. ->where('transformative_actions.by_professor', 1)
  172. ->select('courses.*')
  173. ->groupBy('courses.name', 'courses.code')
  174. ->orderBy('courses.name', 'ASC')
  175. ->orderBy('courses.code', 'ASC')
  176. ->get();
  177. $outcome_filter_editPanel = DB::table('transformative_actions')
  178. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  179. ->join('criterion_objective_outcome', 'criterion_objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  180. ->join('outcomes', 'outcomes.id', '=', 'criterion_objective_outcome.outcome_id')
  181. ->where('transformative_actions.is_custom', 1)
  182. ->where('transformative_actions.user_id', Auth::user()->id)
  183. ->where('transformative_actions.program_id', $program_id)
  184. ->where('transformative_actions.by_professor', 1)
  185. ->select('outcomes.*')
  186. ->groupBy('outcomes.id')
  187. ->orderBy('outcomes.name', 'ASC')
  188. ->get();
  189. // these arent used by professors
  190. $professor_filter_approvePanel = array();
  191. $course_filter_approvePanel = array();
  192. $outcome_filter_approvePanel = array();
  193. // 4 create panel: search courses given by the professor
  194. $courses_create = DB::table('courses')
  195. ->where('courses.program_id', $program_id)
  196. ->where('courses.user_id', Auth::user()->id)
  197. ->select('courses.*')
  198. ->groupBy('courses.name', 'courses.code')
  199. ->orderBy('courses.name', 'ASC')
  200. ->orderBy('courses.code', 'ASC')
  201. ->get();
  202. }
  203. */
  204. return View::make('local.managers.admins.transformativeAction', compact(
  205. 'title',
  206. 'role',
  207. 'types',
  208. 'outcomes',
  209. 'schools',
  210. 'criteria',
  211. 'programs',
  212. 'outcomes',
  213. 'objectives',
  214. 'ta_edit_panel',
  215. 'ta_approval_panel',
  216. 'courses_create',
  217. 'professor_filter_approvePanel',
  218. 'course_filter_approvePanel',
  219. 'outcome_filter_approvePanel',
  220. 'professor_filter_editPanel',
  221. 'outcome_filter_editPanel',
  222. 'course_filter_editPanel'
  223. ));
  224. }
  225. private function cleanInput()
  226. {
  227. $clean_input = array();
  228. $trimmed = trim(preg_replace('/\t+/', '', Input::get('text')));
  229. Log::info('trimmed 1 -->' . $trimmed . '<--');
  230. // if ($trimmed == '') {
  231. // $trimmed = NULL;
  232. // } else {
  233. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  234. // }
  235. Log::info('trimmed 2 -->' . $trimmed . '<--');
  236. $clean_input['text'] = $trimmed;
  237. //////
  238. $trimmed = trim(preg_replace('/\t+/', '', Input::get('description')));
  239. Log::info('trimmed 3 -->' . $trimmed . '<--');
  240. // if ($trimmed == '') {
  241. // $trimmed = NULL;
  242. // } else {
  243. // $trimmed = json_encode(preg_split('/\r\n/', $trimmed));
  244. // }
  245. Log::info('trimmed 4 -->' . $trimmed . '<--');
  246. $clean_input['description'] = $trimmed;
  247. $clean_input['objectiveid'] = Input::get('objectiveid');
  248. $clean_input['courseid'] = Input::get('courseid');
  249. $clean_input['approval'] = Input::get('approval');
  250. $clean_input['type'] = Input::get('type_of_ta');
  251. $clean_input['ta_id'] = Input::get('ta_id');
  252. $clean_input['new_type'] = Input::get('new_type');
  253. return $clean_input;
  254. }
  255. private function makeValidator($clean_input)
  256. {
  257. /** Validation rules */
  258. return Validator::make(
  259. array(
  260. 'text' => $clean_input['text'],
  261. 'description' => $clean_input['description'],
  262. 'objectiveid' => $clean_input['objectiveid'],
  263. 'courseid' => $clean_input['courseid'],
  264. 'approval' => $clean_input['approval'],
  265. 'ta_id' => $clean_input['ta_id'],
  266. 'type_of_ta' => $clean_input['type'],
  267. ),
  268. array(
  269. 'text' => 'required|string',
  270. 'description' => 'required|string',
  271. 'objectiveid' => 'required|array',
  272. 'courseid' => 'required|string',
  273. 'approval' => 'integer',
  274. 'ta_id' => 'integer',
  275. 'type_of_ta' => 'required|string'
  276. )
  277. );
  278. }
  279. // Create a Transformative Action
  280. public function createTA()
  281. {
  282. $clean_input = $this->cleanInput();
  283. /** Validation rules */
  284. $validator = $this->makeValidator($clean_input);
  285. /** If validation fails */
  286. if ($validator->fails()) {
  287. /** Prepare error message */
  288. $message = '<p>Error(s) creating a new Transformative Action:</p><ul>';
  289. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  290. $message .= $validationError;
  291. }
  292. $message .= '</ul>';
  293. /** Send error message and old data */
  294. Session::flash('status', 'danger');
  295. Session::flash('message', $message);
  296. $role = Auth::user()['role'];
  297. return Redirect::to('transformativeAction')->withInput();
  298. } else {
  299. $user_id = Auth::user()->id;
  300. /*$program_id = DB::table('program_user')
  301. ->where('user_id', $user_id)
  302. ->select('program_id')
  303. ->get();
  304. $program_id = $program_id[0]->program_id;*/
  305. $role = Auth::user()['role'];
  306. $by_professor = 1;
  307. if ($role != 4) {
  308. $by_professor = 0;
  309. }
  310. Log::info($clean_input['courseid']);
  311. // $by_professor = $clean_input['approval'];
  312. $parentesis = array('(', ')');
  313. $course_code_number = str_replace($parentesis, '', $clean_input['courseid']);
  314. $course_code_number = explode(',', $course_code_number);
  315. $program_id = DB::table('courses')
  316. ->where('code', $course_code_number[0])
  317. ->where('number', $course_code_number[1])
  318. ->select('program_id')
  319. ->first()->program_id;
  320. $current_timestamp = date('Y/m/d H:i:s', time());
  321. if ($clean_input['new_type']) $type = $clean_input['new_type'];
  322. else $type = $clean_input['type'];
  323. // insert the TA
  324. $ta_id = DB::table('transformative_actions')->insertGetId(
  325. array(
  326. 'at_text' => $clean_input['text'],
  327. 'description' => $clean_input['description'],
  328. 'is_custom' => 1,
  329. 'user_id' => $user_id,
  330. 'program_id' => $program_id,
  331. 'created_at' => $current_timestamp,
  332. 'by_professor' => $by_professor,
  333. 'type_of_TA' => $type
  334. )
  335. );
  336. //
  337. // // insert the multiple TA_objective_program
  338. foreach ($clean_input['objectiveid'] as $objective_id) {
  339. DB::table('transformative_objective')->insert(
  340. array(
  341. 'ta_id' => $ta_id,
  342. 'objective_id' => $objective_id,
  343. )
  344. );
  345. }
  346. //
  347. // // insert the multiple TA_course
  348. DB::table('ta_course')->insert(
  349. array(
  350. 'ta_id' => $ta_id,
  351. 'course_number' => $course_code_number[1],
  352. 'course_code' => $course_code_number[0],
  353. )
  354. );
  355. Session::flash('status', 'success');
  356. Session::flash('message', 'Transformative Action created: "' . $clean_input['text'] . '".');
  357. $role = Auth::user()['role'];
  358. return Redirect::to('transformativeAction')->withInput();
  359. }
  360. }
  361. // apporve a Transformative Action
  362. public function approveTA()
  363. {
  364. $role = Auth::user()['role'];
  365. if ($role != 3) {
  366. $message = 'Only Program Coordinators can approve a TA';
  367. Session::flash('status', 'danger');
  368. Session::flash('message', $message);
  369. return Redirect::to('transformativeAction')->withInput();
  370. }
  371. $ta_id = Input::get('ta_id');
  372. $text = Input::get('at_text');
  373. if ($ta_id == 0) {
  374. $message = 'Please select a Transformative Action</p>';
  375. Session::flash('status', 'danger');
  376. Session::flash('message', $message);
  377. $role = Auth::user()['role'];
  378. return Redirect::to('transformativeAction')->withInput();
  379. }
  380. $current_timestamp = date('Y/m/d H:i:s', time());
  381. if (Input::get('new_type')) {
  382. $type = Input::get('new_type');
  383. } else {
  384. $type = Input::get('type_of_ta');
  385. }
  386. // edit the TA
  387. DB::table('transformative_actions')
  388. ->where('id', $ta_id)
  389. ->update([
  390. 'by_professor' => 0,
  391. 'updated_at' => $current_timestamp,
  392. 'type_of_TA' => $type
  393. ]);
  394. Session::flash('status', 'success');
  395. Session::flash('message', 'Approved the Transformative Action: "' . $text . '".');
  396. $role = Auth::user()['role'];
  397. return Redirect::to('transformativeAction')->withInput();
  398. }
  399. // update a Tranformative Action
  400. public function updateTA()
  401. {
  402. $clean_input = $this->cleanInput();
  403. /** Validation rules */
  404. $validator = $this->makeValidator($clean_input);
  405. /** If validation fails */
  406. if ($validator->fails()) {
  407. /** Prepare error message */
  408. $message = 'Error(s) updating the Transformative Action: <ul>';
  409. foreach ($validator->messages()->all('<li>:message</li>') as $validationError) {
  410. $message .= $validationError;
  411. }
  412. $message .= '</ul>';
  413. /** Send error message and old data */
  414. Session::flash('status', 'danger');
  415. Session::flash('message', $message);
  416. $role = Auth::user()['role'];
  417. return Redirect::to('transformativeAction')->withInput();
  418. } else {
  419. $parentesis = array('(', ')');
  420. $course_code_number = str_replace($parentesis, '', $clean_input['courseid']);
  421. $course_code_number = explode(',', $course_code_number);
  422. $program_id = DB::table('courses')
  423. ->where('code', $course_code_number[0])
  424. ->where('number', $course_code_number[1])
  425. ->select('program_id')
  426. ->first()->program_id;
  427. $user_id = auth::user()->id;
  428. /* $program_id = DB::table('program_user')
  429. ->where('user_id', $user_id)
  430. ->select('program_id')
  431. ->get();
  432. $program_id = $program_id[0]->program_id;*/
  433. $role = Auth::user()['role'];
  434. $by_professor = $clean_input['approval'];
  435. if ($role == 4) {
  436. $by_professor = 1;
  437. }
  438. // $by_professor = $clean_input['approval'];
  439. if ($clean_input['new_type']) $type = $clean_input['new_type'];
  440. else $type = $clean_input['type'];
  441. $current_timestamp = date('Y/m/d H:i:s', time());
  442. // edit the TA
  443. DB::table('transformative_actions')
  444. ->where('id', $clean_input['ta_id'])
  445. ->update([
  446. 'by_professor' => $by_professor,
  447. 'at_text' => $clean_input['text'],
  448. 'description' => $clean_input['description'],
  449. 'updated_at' => $current_timestamp,
  450. 'type_of_TA' => $type
  451. ]);
  452. $ta_id = $clean_input['ta_id'];
  453. $new_objective_id = $clean_input['objectiveid'];
  454. $old_objective_id = DB::table('transformative_objective')
  455. ->where('ta_id', $ta_id)
  456. ->select('objective_id')
  457. ->lists('objective_id');
  458. //delete existing objective_id if it isnt in new_ids array
  459. foreach ($old_objective_id as $old_id) {
  460. if (in_array($old_id, $new_objective_id)) {
  461. //do nothing if a new id is already in atble
  462. } else {
  463. //if old id not in new id, delete
  464. DB::table('transformative_objective')
  465. ->where('ta_id', $ta_id)
  466. ->where('objective_id', $old_id)
  467. ->delete();
  468. }
  469. }
  470. //
  471. foreach ($new_objective_id as $new_id) {
  472. $result = DB::table('transformative_objective')
  473. ->where('objective_id', $new_id)
  474. ->select('objective_id')
  475. ->lists('objective_id');
  476. if (count($result) == 0) {
  477. //if the new_id does not exists, do nothing
  478. DB::table('transformative_objective')->insert(
  479. array(
  480. 'ta_id' => $ta_id,
  481. 'objective_id' => $new_id,
  482. // 'created_at' => $current_timestamp,
  483. )
  484. );
  485. } else {
  486. //if the new_id already exists, do nothing
  487. }
  488. }
  489. DB::update(
  490. "UPDATE `ta_course` set `course_number` = '{$course_code_number[1]}', `course_code` = '{$course_code_number[0]}' where ta_id = {$ta_id}"
  491. );
  492. /*$new_course_id = $clean_input['courseid'];
  493. $old_course_id = DB::table('ta_course')
  494. ->where('ta_id', $ta_id)
  495. ->select('course_id')
  496. ->lists('course_id');
  497. //delete existing course_id if it isnt in new_ids array
  498. foreach ($old_course_id as $old_id) {
  499. if (in_array($old_id, $new_course_id)) {
  500. //do nothing if a new id is already in atble
  501. } else {
  502. //if old id not in new id, delete
  503. DB::table('ta_course')
  504. ->where('ta_id', $ta_id)
  505. ->where('course_id', $old_id)
  506. ->delete();
  507. }
  508. }
  509. //add course_id if it isnt already inserted
  510. foreach ($new_course_id as $new_id) {
  511. $result = DB::table('ta_course')
  512. ->where('ta_id', $ta_id)
  513. ->where('course_id', $new_id)
  514. ->select('course_id')
  515. ->lists('course_id');
  516. if (count($result) == 0) {
  517. //if the new_id does not exists, do nothing
  518. DB::table('ta_course')->insert(
  519. array(
  520. 'ta_id' => $ta_id,
  521. 'course_id' => $new_id,
  522. )
  523. );
  524. } else {
  525. //if the new_id already exists, do nothing
  526. }
  527. } */
  528. Session::flash('status', 'success');
  529. Session::flash('message', 'Updated Transformative Action: "' . $clean_input['text'] . '".');
  530. $role = Auth::user()['role'];
  531. return Redirect::to('transformativeAction')->withInput();
  532. }
  533. }
  534. // delete a Transformative Action
  535. public function deleteTA()
  536. {
  537. $ta_id = array(Input::get('ta_id'));
  538. // si envia id 0, el backend se queja en la linea: $ta = $ta[0];
  539. // nunca deberia ocurrir, pero es un safity measure.
  540. if ($ta_id == 0) {
  541. $message = 'Please select a Transformative Action</p>';
  542. Session::flash('status', 'danger');
  543. Session::flash('message', $message);
  544. $role = Auth::user()['role'];
  545. return Redirect::to('transformativeAction')->withInput();
  546. }
  547. $ta = DB::table('transformative_actions')
  548. ->where('transformative_actions.is_custom', 1)
  549. ->where('id', $ta_id)
  550. ->get();
  551. $ta = $ta[0];
  552. $used = DB::table('annual_plan_transformative')
  553. ->where('id', $ta_id)
  554. ->get();
  555. $recommended = $ta->by_professor;
  556. // the TA can only be deleted if error if the TA is not currently as "Recommended"
  557. // and isnt used in an anual plan
  558. if ($recommended == 1 && count($used) == 0) {
  559. // delete the TA if it qualifies
  560. DB::delete("delete from transformative_actions where id = ?", $ta_id);
  561. $name = $ta->at_text;
  562. $message = 'The Transformative Action has been deleted:</p><ul>';
  563. $message .= '<li> ' . $name . ' </li>';
  564. $message .= '</ul>';
  565. Session::flash('status', 'success');
  566. Session::flash('message', $message);
  567. $role = Auth::user()['role'];
  568. return Redirect::to('transformativeAction')->withInput();
  569. }
  570. $message = 'Transformative Actions can only be deleted if:</p><ul>';
  571. $message .= '<li> It has a status of "Recommended"</li>';
  572. $message .= '<li> It is not currently used in a plan</li>';
  573. $message .= '</ul>';
  574. Session::flash('status', 'danger');
  575. Session::flash('message', $message);
  576. $role = Auth::user()['role'];
  577. return Redirect::to('transformativeAction')->withInput();
  578. }
  579. // load the information of a Tranformative Action when its
  580. // selected on the approve or edit panel
  581. public function selectTA()
  582. {
  583. $ta_id = Input::get("ta_id");
  584. $user_role = Auth::user()->role;
  585. switch ($user_role) {
  586. case 1:
  587. $program_ids = DB::table('programs')->lists('id');
  588. break;
  589. case 2:
  590. $user_school = Auth::user()->school_id;
  591. $program_ids = DB::table('programs')
  592. ->where('school_id', $user_school)
  593. ->lists('id');
  594. break;
  595. case 3:
  596. $user_id = Auth::user()->id;
  597. $program_ids = DB::table('program_user')
  598. ->where('user_id', $user_id)
  599. ->select('program_id')
  600. ->lists('program_id');
  601. break;
  602. }
  603. //$program_id = DB::table('program_user')
  604. // ->where('user_id', $user_id)
  605. // ->select('program_id')
  606. // ->get();
  607. //$program_id = $program_id[0]->program_id;
  608. $objectives = DB::table('transformative_actions')
  609. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  610. ->join('objectives', 'objectives.id', '=', 'transformative_objective.objective_id')
  611. ->where('transformative_actions.id', $ta_id)
  612. ->where('objectives.id', '<>',0)
  613. ->select('objectives.text as text', 'objectives.id as id')
  614. ->orderBy('objectives.text', 'ASC')
  615. ->get();
  616. $objective_ids = DB::table('transformative_actions')
  617. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  618. ->join('objectives', 'objectives.id', '=', 'transformative_objective.objective_id')
  619. ->where('transformative_actions.id', $ta_id)
  620. ->where('objectives.id', '<>',0)
  621. ->select('objectives.text as text', 'objectives.id as id')
  622. ->orderBy('objectives.text', 'ASC')
  623. ->lists('objectives.id');
  624. Log::info($ta_id);
  625. //$an_objective = $objectives[0]->id;
  626. $outcome_ids = DB::table('objective_outcome')
  627. ->whereIn('objective_outcome.objective_id', $objective_ids)
  628. ->select('objective_outcome.outcome_id')
  629. ->lists('outcome_id');
  630. //$outcome_id = $outcome_id[0]->outcome_id;
  631. Log::info("outcomes");
  632. Log::info($outcome_ids);
  633. $objectives_from_outcome = DB::table('objectives')
  634. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  635. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  636. ->whereIn('objective_outcome.outcome_id', $outcome_ids)
  637. ->whereIn('objective_program.program_id', $program_ids)
  638. ->where('objective_outcome.objective_id', '<>',0)
  639. ->orderBy('objectives.text', 'ASC')
  640. ->select('objectives.text as text', 'objectives.id as id')
  641. ->distinct()
  642. ->get();
  643. $selected_courses = DB::table('ta_course')
  644. ->join('courses', function ($join) {
  645. $join->on('courses.number', '=', 'ta_course.course_number');
  646. $join->on('courses.code', '=', 'ta_course.course_code');
  647. })
  648. ->where('ta_id', $ta_id)
  649. ->orderBy('courses.name', 'ASC')
  650. ->orderBy('courses.code', 'ASC')
  651. ->select('courses.*')
  652. ->get();
  653. $name = DB::table('transformative_actions')
  654. ->where('id', $ta_id)
  655. ->select('at_text as name')
  656. ->lists('name');
  657. $description = DB::table('transformative_actions')
  658. ->where('id', $ta_id)
  659. ->select('description')
  660. ->lists('description');
  661. $status = DB::table('transformative_actions')
  662. ->where('id', $ta_id)
  663. ->select('by_professor as status')
  664. ->lists('status');
  665. $status = $status[0];
  666. $plans_count = DB::table('annual_plan_transformative')
  667. ->where('trans_id', $ta_id)
  668. ->get();
  669. $plans_count = count($plans_count);
  670. $can_be_deleted = false;
  671. if ($plans_count == 0 /*&& $status == 1*/) {
  672. $can_be_deleted = true;
  673. }
  674. return array(
  675. 'objectives' => $objectives,
  676. 'objectives_from_outcome' => $objectives_from_outcome,
  677. 'selected_courses' => $selected_courses,
  678. 'name' => $name,
  679. 'description' => $description,
  680. 'status' => $status,
  681. 'can_be_deleted' => $can_be_deleted,
  682. 'plans_count' => $plans_count,
  683. );
  684. }
  685. // load the available objectieves from an outcome when creating a Tranformative Action
  686. public function objectivesFromOutcome()
  687. {
  688. $user_role = Auth::user()->role;
  689. switch ($user_role) {
  690. case 1:
  691. $program_ids = DB::table('programs')->lists('id');
  692. break;
  693. case 2:
  694. $user_school = Auth::user()->school_id;
  695. $program_ids = DB::table('programs')
  696. ->where('school_id', $user_school)
  697. ->lists('id');
  698. break;
  699. case 3:
  700. $user_id = Auth::user()->id;
  701. $program_ids = DB::table('program_user')
  702. ->where('user_id', $user_id)
  703. ->select('program_id')
  704. ->lists('program_id');
  705. break;
  706. }
  707. //$program_id = DB::table('program_user')
  708. // ->where('user_id', $user_id)
  709. // ->select('program_id')
  710. // ->get();
  711. //$program_id = $program_id[0]->program_id;
  712. $ta_id = Input::get("ta_id");
  713. $outcome_id = Input::get("outcome_id");
  714. $objectives = DB::table('objectives')
  715. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  716. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  717. ->where('objective_outcome.outcome_id', $outcome_id)
  718. ->where('objective_outcome.objective_id','<>',0 )
  719. ->whereIn('objective_program.program_id', $program_ids)
  720. ->orderBy('objectives.text', 'ASC')
  721. ->select('objectives.text as text', 'objectives.id as id')
  722. ->distinct()
  723. ->get();
  724. return array(
  725. 'objectives' => $objectives,
  726. );
  727. }
  728. // return Transformative Actions that meet the filter criterias
  729. public function filterTA()
  730. {
  731. $user_id = Auth::user()->id;
  732. $role = Auth::user()['role'];
  733. $professor_id = Input::get('professor_id');
  734. $course_id = Input::get('course_id');
  735. $outcome_id = Input::get('outcome_id');
  736. $panel_id = Input::get('panel_id');
  737. switch ($role) {
  738. case 1:
  739. $program_id = DB::table('programs')->lists('id');
  740. break;
  741. case 2:
  742. $program_id = DB::table('programs')->where('school_id', Auth::user()->school_id)
  743. ->lists('id');
  744. break;
  745. case 3:
  746. $program_id = DB::table('program_user')
  747. ->where('user_id', $user_id)
  748. ->select('program_id')
  749. ->get();
  750. $program_id = $program_id[0]->program_id;
  751. break;
  752. }
  753. // if the user is a coordinator filtering the approvePanel
  754. /*if ($role == '3' && $panel_id == 'approvePanel') {
  755. // if professor isnt a desired filter, search all professors
  756. if ($professor_id == 0) {
  757. $all_ta_users = DB::table('transformative_actions')
  758. ->where('transformative_actions.is_custom', 1)
  759. ->where('transformative_actions.program_id', $program_id)
  760. ->where('transformative_actions.by_professor', 1)
  761. ->select('transformative_actions.user_id')
  762. ->get();
  763. $professor_id = array();
  764. foreach ($all_ta_users as $key => $user) {
  765. array_push($professor_id, $user->user_id);
  766. }
  767. } else {
  768. $professor_id = array($professor_id);
  769. }
  770. // if course isnt a desired filter, search all courses
  771. if ($course_id == 0) {
  772. $courses = DB::table('ta_course')
  773. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  774. ->join('courses', function ($join) {
  775. $join->on('courses.number', '=', 'ta_course.course_number');
  776. $join->on('courses.code', '=', 'ta_course.course_code');
  777. })
  778. ->where('transformative_actions.is_custom', 1)
  779. ->where('transformative_actions.program_id', $program_id)
  780. ->where('transformative_actions.by_professor', 1)
  781. ->select('ta_course.course_number', 'ta_course.course_code')
  782. ->distinct()
  783. ->get();
  784. $course_id = array();
  785. foreach ($courses as $key => $course) {
  786. array_push($course_id["number"], $course->course_number);
  787. array_push($course_id["code"], $course->code);
  788. }
  789. } else {
  790. $parentesis = array('(', ')');
  791. $course_code_number = str_replace($parentesis, '', $course_id);
  792. $course_code_number = explode(',', $course_code_number);
  793. $course_id = array();
  794. $course_id['number'] = $course_code_number[1];
  795. $course_id['code'] = $course_code_number[0];
  796. }
  797. // if outcome isnt a desired filter, search all outcomes
  798. if ($outcome_id == 0) {
  799. $outcomes = DB::table('transformative_actions')
  800. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  801. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  802. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  803. ->where('transformative_actions.is_custom', 1)
  804. ->where('transformative_actions.program_id', $program_id)
  805. ->where('transformative_actions.by_professor', 1)
  806. ->select('outcomes.id')
  807. ->groupBy('outcomes.id')
  808. ->get();
  809. $outcome_id = array();
  810. foreach ($outcomes as $key => $outcome) {
  811. array_push($outcome_id, $outcome->id);
  812. }
  813. } else {
  814. $outcome_id = array($outcome_id);
  815. }
  816. // search TA with filters
  817. $filtered_at = DB::table('transformative_actions')
  818. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  819. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  820. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  821. ->where('transformative_actions.is_custom', 1)
  822. ->where('transformative_actions.program_id', $program_id)
  823. ->where('transformative_actions.by_professor', 1)
  824. ->whereIn('transformative_actions.user_id', $professor_id)
  825. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  826. ->whereIn('ta_course.course_code', $course_id['code'])
  827. ->whereIn('ta_course.course_number', $course_id['number'])
  828. ->select('transformative_actions.*')
  829. ->groupBy('transformative_actions.id')
  830. ->orderBy('transformative_actions.at_text', 'ASC')
  831. ->get();
  832. return $filtered_at;
  833. }*/
  834. // if the user is a coordinator filtering the editPanel
  835. if ($panel_id == 'editPanel') {
  836. // if professor isnt a desired filter, search all professors
  837. if ($professor_id == 0) {
  838. $all_ta_users = DB::table('transformative_actions')
  839. ->where('transformative_actions.is_custom', 1)
  840. ->where('transformative_actions.program_id', $program_id)
  841. ->where('transformative_actions.by_professor', 0)
  842. ->select('transformative_actions.user_id')
  843. ->get();
  844. $professor_id = array();
  845. foreach ($all_ta_users as $key => $user) {
  846. array_push($professor_id, $user->user_id);
  847. }
  848. } else {
  849. $professor_id = array($professor_id);
  850. }
  851. // if course isnt a desired filter, search all courses
  852. if ($course_id == 0) {
  853. $courses = DB::table('ta_course')
  854. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  855. ->join('courses', function ($join) {
  856. $join->on('courses.number', '=', 'ta_course.course_number');
  857. $join->on('courses.code', '=', 'ta_course.course_code');
  858. })
  859. ->where('transformative_actions.is_custom', 1)
  860. ->where('transformative_actions.program_id', $program_id)
  861. ->where('transformative_actions.by_professor', 0)
  862. ->select('ta_course.course_number', 'ta_course.course_code')
  863. ->distinct()
  864. ->get();
  865. $course_id = array();
  866. foreach ($courses as $key => $course) {
  867. array_push($course_id["number"], $course->course_number);
  868. array_push($course_id["code"], $course->code);
  869. }
  870. } else {
  871. $parentesis = array('(', ')');
  872. $course_code_number = str_replace($parentesis, '', $course_id);
  873. $course_code_number = explode(',', $course_code_number);
  874. $course_id = array();
  875. $course_id['number'] = $course_code_number[1];
  876. $course_id['code'] = $course_code_number[0];
  877. }
  878. // if outcome isnt a desired filter, search all outcomes
  879. if ($outcome_id == 0) {
  880. $outcomes = DB::table('transformative_actions')
  881. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  882. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  883. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  884. ->where('transformative_actions.is_custom', 1)
  885. ->where('transformative_actions.program_id', $program_id)
  886. ->where('transformative_actions.by_professor', 0)
  887. ->select('outcomes.id')
  888. ->groupBy('outcomes.id')
  889. ->get();
  890. $outcome_id = array();
  891. foreach ($outcomes as $key => $outcome) {
  892. array_push($outcome_id, $outcome->id);
  893. }
  894. } else {
  895. $outcome_id = array($outcome_id);
  896. }
  897. // search TA with filters
  898. $filtered_at = DB::table('transformative_actions')
  899. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  900. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  901. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  902. ->where('transformative_actions.is_custom', 1)
  903. ->where('transformative_actions.program_id', $program_id)
  904. ->where('transformative_actions.by_professor', 0)
  905. ->whereIn('transformative_actions.user_id', $professor_id)
  906. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  907. ->whereIn('ta_course.course_code', $course_id['code'])
  908. ->whereIn('ta_course.course_number', $course_id['number'])
  909. ->select('transformative_actions.*')
  910. ->groupBy('transformative_actions.id')
  911. ->orderBy('transformative_actions.at_text', 'ASC')
  912. ->get();
  913. return $filtered_at;
  914. }
  915. // if the user is a professor filtering the editPanel
  916. /*elseif ($role == '4' && $panel_id == 'editPanel') {
  917. // if course isnt a desired filter, search all courses
  918. if ($course_id == 0) {
  919. $courses = DB::table('ta_course')
  920. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  921. ->join('courses', 'courses.id', '=', 'ta_course.course_id')
  922. ->where('transformative_actions.user_id', Auth::user()->id)
  923. ->where('transformative_actions.is_custom', 1)
  924. ->where('transformative_actions.program_id', $program_id)
  925. ->where('transformative_actions.by_professor', 1)
  926. ->select('ta_course.course_number', 'ta_course.course_code')
  927. ->distinct()
  928. ->get();
  929. $course_id = array();
  930. foreach ($courses as $key => $course) {
  931. array_push($course_id["number"], $course->course_number);
  932. array_push($course_id["code"], $course->code);
  933. }
  934. } else {
  935. $parentesis = array('(', ')');
  936. $course_code_number = str_replace($parentesis, '', $course_id);
  937. $course_code_number = explode(',', $course_code_number);
  938. $course_id = array();
  939. $course_id['number'] = $course_code_number[1];
  940. $course_id['code'] = $course_code_number[0];
  941. }
  942. // if outcome isnt a desired filter, search all outcomes
  943. if ($outcome_id == 0) {
  944. $outcomes = DB::table('transformative_actions')
  945. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  946. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  947. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  948. ->where('transformative_actions.user_id', Auth::user()->id)
  949. ->where('transformative_actions.is_custom', 1)
  950. ->where('transformative_actions.program_id', $program_id)
  951. ->where('transformative_actions.by_professor', 1)
  952. ->select('outcomes.id')
  953. ->groupBy('outcomes.id')
  954. ->get();
  955. $outcome_id = array();
  956. foreach ($outcomes as $key => $outcome) {
  957. array_push($outcome_id, $outcome->id);
  958. }
  959. } else {
  960. $outcome_id = array($outcome_id);
  961. }
  962. // search TA with filters
  963. $filtered_at = DB::table('transformative_actions')
  964. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  965. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  966. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  967. ->where('transformative_actions.user_id', Auth::user()->id)
  968. ->where('transformative_actions.is_custom', 1)
  969. ->where('transformative_actions.program_id', $program_id)
  970. ->where('transformative_actions.by_professor', 1)
  971. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  972. ->whereIn('ta_course.course_code', $course_id['code'])
  973. ->whereIn('ta_course.course_number', $course_id['number'])
  974. ->select('transformative_actions.*')
  975. ->groupBy('transformative_actions.id')
  976. ->orderBy('transformative_actions.at_text', 'ASC')
  977. ->get();
  978. return $filtered_at;
  979. }*/
  980. return 'ilegal';
  981. }
  982. function postActivityCriterion($activity_id)
  983. {
  984. DB::beginTransaction();
  985. $existing_transformative_action = DB::table('transformative_actions')
  986. ->join('transformative_activity_criterion', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  987. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  988. ->where('activity_id', $activity_id)
  989. ->delete();
  990. $activity_criterion = Input::get('trans_act');
  991. $trans = new TransformativeAction;
  992. $trans->user_id = Auth::user()['id'];
  993. $program_id = DB::table('activities')
  994. ->join('courses', 'activities.course_id', '=', 'courses.id')
  995. ->where('activities.id', $activity_id)
  996. ->lists('program_id');
  997. $trans->program_id = $program_id[0];
  998. $trans->is_custom = 1;
  999. $trans->by_professor = 1;
  1000. $trans->at_text = Input::get('name_trans');
  1001. $trans->description = Input::get('transforming_actions');
  1002. $activity = DB::table('activities')
  1003. ->where('id', $activity_id)
  1004. ->first();
  1005. $course_credentials = DB::table('courses')
  1006. ->where('id', $activity->course_id)
  1007. ->first();
  1008. if ($trans->save()) {
  1009. foreach ($activity_criterion as $single_ac) {
  1010. $result = DB::insert("insert into `transformative_activity_criterion` (`trans_action_id`, `activity_criterion_id`) values ($trans->id, $single_ac)");
  1011. if (!$result) {
  1012. DB::rollback();
  1013. Session::flash('status', 'danger');
  1014. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1015. return Redirect::to("professor/activities/{$activity_id}");
  1016. }
  1017. }
  1018. $criteria = DB::table('activity_criterion')
  1019. ->whereIn('id', $activity_criterion)
  1020. ->lists('criterion_id');
  1021. $allObjectives = DB::table('criterion_objective_outcome')
  1022. ->whereIn('criterion_id', $criteria)
  1023. ->select('objective_id')
  1024. ->distinct()
  1025. ->lists('objective_id');
  1026. foreach ($allObjectives as $objective) {
  1027. $result2 = DB::insert("insert into `transformative_objective` (`ta_id`, `objective_id`) values ({$trans->id},{$objective})");
  1028. if (!$result2) {
  1029. DB::rollback();
  1030. Session::flash('status', 'danger');
  1031. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1032. return Redirect::to("professor/activities/{$activity_id}");
  1033. }
  1034. }
  1035. $result3 = DB::insert("insert into `ta_course` (`ta_id`, `course_number`, `course_code`) values ({$trans->id}, '{$course_credentials->number}', '{$course_credentials->code}')");
  1036. if (!($result3)) {
  1037. DB::rollback();
  1038. Session::flash('status', 'danger');
  1039. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1040. return Redirect::to("professor/activities/{$activity_id}");
  1041. }
  1042. DB::commit();
  1043. Session::flash('status', 'success');
  1044. Session::flash('message', 'Formative Actions Saved.');
  1045. return Redirect::to("professor/activities/{$activity_id}");
  1046. } else {
  1047. DB::rollback();
  1048. Session::flash('status', 'danger');
  1049. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1050. return Redirect::to("professor/activities/{$activity_id}");
  1051. }
  1052. }
  1053. public function viewFormativeActions()
  1054. {
  1055. $title = "Formative Actions";
  1056. $semesters = Session::get('semesters_ids');
  1057. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  1058. Log::info($semesters->start);
  1059. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  1060. ->whereNull('deleted_at')
  1061. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  1062. ->orderBy('name', 'ASC')->get();
  1063. $semesters = DB::table('semesters')->where('is_visible', 1)->orderBy('end', 'DESC')->get();
  1064. $role = Auth::user()->role;
  1065. switch ($role) {
  1066. case 1:
  1067. $schools = DB::table('schools')->get();
  1068. $programs = DB::table('programs')->get();
  1069. break;
  1070. case 2:
  1071. $schools = DB::table('schools')->where('id', Auth::user()->school_id)->get();
  1072. $programs = DB::table('programs')->where('school_id', $schools[0]->id)->get();
  1073. break;
  1074. case 3:
  1075. $programs = DB::table('programs')
  1076. ->join('program_user', 'programs.id', '=', 'program_user.program_id')
  1077. ->where('user_id', Auth::user()->id)
  1078. ->select('programs.*')
  1079. ->get();
  1080. $schools = DB::table('schools')->where('id', $programs[0]->school_id)->get();
  1081. break;
  1082. }
  1083. return View::make('local.managers.shared.view_formative', compact('title', 'outcomes', 'schools', 'programs', 'semesters'));
  1084. }
  1085. public function fetchCourses()
  1086. {
  1087. $school = Input::get('schools');
  1088. $programs = Input::get('programs');
  1089. $semesters = Input::get('semesters');
  1090. $outcome_id = Input::get('id');
  1091. Log::info($programs);
  1092. Log::info($semesters);
  1093. /* if (in_array(0, $semesters)) {
  1094. $semesters = DB::table('semesters')->where('is_visible', 1)->lists('id');
  1095. }*/
  1096. /* if (in_array(0, $programs)) {
  1097. $role = Auth::user()->role;
  1098. switch ($role) {
  1099. case 1:
  1100. $programs = DB::table('programs')->lists('id');
  1101. break;
  1102. case 2:
  1103. $programs = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  1104. break;
  1105. case 3:
  1106. $programs = DB::table('program_user')->where('user_id', Auth::user()->id)->lists('program_id');
  1107. break;
  1108. }
  1109. }*/
  1110. $typ_semester_outcome = DB::table('typ_semester_outcome')
  1111. ->where('semester_id', $semesters)
  1112. ->where('outcome_id', $outcome_id)
  1113. ->lists('id');
  1114. //each row has objectives, repeated ta, but distinct activity_criterion_id
  1115. /* $objective_ta = DB::table('typ_semester_objectives')
  1116. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1117. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1118. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1119. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1120. ->select('transformative_actions.*')
  1121. ->addSelect('objectives.*')
  1122. ->distinct()
  1123. ->get();
  1124. $objective_ta = DB::table('typ_semester_objectives')
  1125. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1126. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1127. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1128. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1129. ->select('transformative_actions.*')
  1130. ->addSelect('objectives.*')
  1131. ->distinct()
  1132. ->lists();*/
  1133. $grouped_courses = DB::table('courses')
  1134. ->where('program_id', $programs)
  1135. ->where('semester_id', $semesters)
  1136. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1137. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1138. ->join('transformative_activity_criterion as tac', 'tac.activity_criterion_id', '=', 'activity_criterion.id')
  1139. ->select('courses.*')
  1140. ->groupBy(array('courses.code', 'courses.name', 'courses.semester_id'))
  1141. ->orderBy('courses.code')
  1142. ->orderBy('courses.number')
  1143. ->get();
  1144. foreach ($grouped_courses as $course_name) {
  1145. $course_name->sections = DB::table('courses')
  1146. ->where('code', $course_name->code)
  1147. ->where('name', $course_name->name)
  1148. ->where('semester_id', $course_name->semester_id)
  1149. ->where('program_id', $course_name->program_id)
  1150. ->get();
  1151. foreach ($course_name->sections as $section) {
  1152. $section->activities = DB::table('activities')
  1153. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1154. ->join('transformative_activity_criterion', 'transformative_activity_criterion.activity_criterion_id', '=', 'activity_criterion.id')
  1155. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  1156. ->join('transformative_actions', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  1157. ->where('activities.course_id', $section->id)
  1158. ->where('activities.draft', 0)
  1159. ->where('activities.diagnostic', 0)
  1160. ->where('criterion_objective_outcome.outcome_id', $outcome_id)
  1161. ->select('activities.id as activity_id', 'activities.name')
  1162. ->addSelect('transformative_actions.*', 'transformative_activity_criterion.trans_action_id as trans_action_id')
  1163. ->groupBy('transformative_actions.id')
  1164. ->get();
  1165. //If section has activity that assessess outcome
  1166. if (count($section->activities)) {
  1167. $course_name->outcome_assessed = true;
  1168. }
  1169. foreach ($section->activities as $activity) {
  1170. /*$activity->criterion = DB::table('transformative_activity_criterion')
  1171. ->join('activity_criterion','activity_criterion.id','=','transformative_activity_criterion.activity_criterion_id')
  1172. ->join('activities','activities.id','=','activity_criterion.activity_id')
  1173. ->join('criteria','activity_criterion.criterion_id','=','criteria.id')
  1174. ->where('activity_id', $activity->id)
  1175. ->select('criteria')*/
  1176. //Log::info($activity->trans_action_id);
  1177. $activity->criterion_with_objective = DB::table('transformative_activity_criterion')
  1178. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  1179. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  1180. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  1181. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  1182. ->where('activity_id', $activity->activity_id)
  1183. ->where('trans_action_id', $activity->trans_action_id)
  1184. ->get();
  1185. /*$activity->objectives = DB::table('transformative_objective')
  1186. ->join('objectives', 'transformative_objective.objective_id', '=', 'objectives.id')
  1187. ->where('ta_id', $activity->trans_action_id)
  1188. ->get();*/
  1189. /*foreach ($activity->objectives as $objective) {
  1190. // Log::info($activity->activity_id);
  1191. // Log::info($objective->objective_id);
  1192. /* Log::info(DB::table('criterion_objective_outcome')
  1193. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1194. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1195. ->where('activity_criterion.activity_id', $activity->activity_id)
  1196. ->where('objective_id', $objective->objective_id)
  1197. ->select('criteria.*')
  1198. ->distinct()
  1199. ->toSql());
  1200. $objective->criterion = DB::table('criterion_objective_outcome')
  1201. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1202. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1203. ->where('activity_criterion.activity_id', $activity->activity_id)
  1204. ->where('objective_id', $objective->objective_id)
  1205. ->select('criteria.*')
  1206. ->distinct()
  1207. ->get();
  1208. }*/
  1209. }
  1210. }
  1211. }
  1212. return $grouped_courses;
  1213. }
  1214. public function createTAForOutcome()
  1215. {
  1216. $is_custom = Input::get('is_custom');
  1217. $category = Input::get('category');
  1218. $is_new = Input::get('is_new');
  1219. $name = Input::get('name');
  1220. $description = Input::get('description');
  1221. $edit_ta_id = Input::get('edit');
  1222. if ($is_new || $is_custom)
  1223. $program_id = Input::get('program_id');
  1224. else $program_id = NULL;
  1225. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  1226. if (!$edit_ta_id) {
  1227. $ta_id = DB::table('transformative_actions')->insertGetId(array(
  1228. 'program_id' => $program_id,
  1229. 'type_of_TA' => $category,
  1230. 'at_text' => $name,
  1231. 'description' => $description,
  1232. 'user_id' => Auth::user()->id,
  1233. 'created_at' => date('Y-m-d H:i:s'),
  1234. 'updated_at' => date('Y-m-d H:i:s'),
  1235. 'by_professor' => 0,
  1236. 'is_custom' => $is_custom
  1237. ));
  1238. DB::table('transformative_typ_outcome')->insert(array(
  1239. 'trans_id' => $ta_id,
  1240. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  1241. 'proposing_coordinator_id' => Auth::user()->id,
  1242. ));
  1243. } else {
  1244. DB::table('transformative_actions')
  1245. ->where('id', $edit_ta_id)
  1246. ->update(array(
  1247. 'program_id' => $program_id,
  1248. 'type_of_TA' => $category,
  1249. 'at_text' => $name,
  1250. 'description' => $description,
  1251. 'user_id' => Auth::user()->id,
  1252. 'created_at' => date('Y-m-d H:i:s'),
  1253. 'updated_at' => date('Y-m-d H:i:s'),
  1254. 'by_professor' => 0,
  1255. 'is_custom' => $is_custom
  1256. ));
  1257. $ta_id = $edit_ta_id;
  1258. }
  1259. return $ta_id;
  1260. }
  1261. public function deleteTaFromOutcome()
  1262. {
  1263. DB::table('transformative_actions')
  1264. ->where('id', Input::get('trans_id'))
  1265. ->delete();
  1266. return;
  1267. }
  1268. public function fetchStatus()
  1269. {
  1270. $trans_id = Input::get('trans_id');
  1271. $semester_id = Input::get('semester_id');
  1272. $transformative_action = DB::table('transformative_actions')
  1273. ->where('id', $trans_id)
  1274. ->first();
  1275. $transformative_action->status = DB::table('transformative_action_status')
  1276. ->where('trans_id', $transformative_action->id)
  1277. ->where('semester_id', $semester_id)
  1278. ->first();
  1279. //TransformativeAction::find($trans_id)->status($semester_id);
  1280. return array($transformative_action);
  1281. }
  1282. public function saveTransStatus()
  1283. {
  1284. $semester_id = Input::get('semester_id');
  1285. $trans_id = Input::get('trans_id');
  1286. $results = Input::get('results');
  1287. $comments = Input::get('comments');
  1288. $accomplished = Input::get('accomplished');
  1289. $was_it_useful = Input::get('was_it_useful');
  1290. $existing_status = DB::table('transformative_action_status')
  1291. ->where('semester_id', $semester_id)
  1292. ->where('trans_id', $trans_id)
  1293. ->first();
  1294. if ($existing_status) {
  1295. DB::table('transformative_action_status')->update(array(
  1296. 'results' => $results,
  1297. 'comments' => $comments,
  1298. 'accomplished' => $accomplished,
  1299. 'it_was_useful' => $was_it_useful,
  1300. 'supervised_coordinator_id' => Auth::user()->id
  1301. ));
  1302. } else {
  1303. DB::table('transformative_action_status')->insert(array(
  1304. 'trans_id' => $trans_id,
  1305. 'results' => $results,
  1306. 'comments' => $comments,
  1307. 'accomplished' => $accomplished,
  1308. 'it_was_useful' => $was_it_useful,
  1309. 'semester_id' => $semester_id,
  1310. 'supervised_coordinator_id' => Auth::user()->id
  1311. ));
  1312. }
  1313. return "done";
  1314. }
  1315. }