暂无描述

TransformativeActionsController.php 55KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515
  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.name', 'ASC')
  147. ->orderBy('courses.code', '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. ->select('objectives.text as text', 'objectives.id as id')
  613. ->orderBy('objectives.text', 'ASC')
  614. ->get();
  615. $objective_ids = DB::table('transformative_actions')
  616. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  617. ->join('objectives', 'objectives.id', '=', 'transformative_objective.objective_id')
  618. ->where('transformative_actions.id', $ta_id)
  619. ->select('objectives.text as text', 'objectives.id as id')
  620. ->orderBy('objectives.text', 'ASC')
  621. ->lists('objectives.id');
  622. Log::info($ta_id);
  623. //$an_objective = $objectives[0]->id;
  624. $outcome_ids = DB::table('objective_outcome')
  625. ->whereIn('objective_outcome.objective_id', $objective_ids)
  626. ->select('objective_outcome.outcome_id')
  627. ->lists('outcome_id');
  628. //$outcome_id = $outcome_id[0]->outcome_id;
  629. Log::info("outcomes");
  630. Log::info($outcome_ids);
  631. $objectives_from_outcome = DB::table('objectives')
  632. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  633. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  634. ->whereIn('objective_outcome.outcome_id', $outcome_ids)
  635. ->whereIn('objective_program.program_id', $program_ids)
  636. ->orderBy('objectives.text', 'ASC')
  637. ->select('objectives.text as text', 'objectives.id as id')
  638. ->distinct()
  639. ->get();
  640. $selected_courses = DB::table('ta_course')
  641. ->join('courses', function ($join) {
  642. $join->on('courses.number', '=', 'ta_course.course_number');
  643. $join->on('courses.code', '=', 'ta_course.course_code');
  644. })
  645. ->where('ta_id', $ta_id)
  646. ->orderBy('courses.name', 'ASC')
  647. ->orderBy('courses.code', 'ASC')
  648. ->select('courses.*')
  649. ->get();
  650. $name = DB::table('transformative_actions')
  651. ->where('id', $ta_id)
  652. ->select('at_text as name')
  653. ->lists('name');
  654. $description = DB::table('transformative_actions')
  655. ->where('id', $ta_id)
  656. ->select('description')
  657. ->lists('description');
  658. $status = DB::table('transformative_actions')
  659. ->where('id', $ta_id)
  660. ->select('by_professor as status')
  661. ->lists('status');
  662. $status = $status[0];
  663. $plans_count = DB::table('annual_plan_transformative')
  664. ->where('trans_id', $ta_id)
  665. ->get();
  666. $plans_count = count($plans_count);
  667. $can_be_deleted = false;
  668. if ($plans_count == 0 /*&& $status == 1*/) {
  669. $can_be_deleted = true;
  670. }
  671. return array(
  672. 'objectives' => $objectives,
  673. 'objectives_from_outcome' => $objectives_from_outcome,
  674. 'selected_courses' => $selected_courses,
  675. 'name' => $name,
  676. 'description' => $description,
  677. 'status' => $status,
  678. 'can_be_deleted' => $can_be_deleted,
  679. 'plans_count' => $plans_count,
  680. );
  681. }
  682. // load the available objectieves from an outcome when creating a Tranformative Action
  683. public function objectivesFromOutcome()
  684. {
  685. $user_role = Auth::user()->role;
  686. switch ($user_role) {
  687. case 1:
  688. $program_ids = DB::table('programs')->lists('id');
  689. break;
  690. case 2:
  691. $user_school = Auth::user()->school_id;
  692. $program_ids = DB::table('programs')
  693. ->where('school_id', $user_school)
  694. ->lists('id');
  695. break;
  696. case 3:
  697. $user_id = Auth::user()->id;
  698. $program_ids = DB::table('program_user')
  699. ->where('user_id', $user_id)
  700. ->select('program_id')
  701. ->lists('program_id');
  702. break;
  703. }
  704. //$program_id = DB::table('program_user')
  705. // ->where('user_id', $user_id)
  706. // ->select('program_id')
  707. // ->get();
  708. //$program_id = $program_id[0]->program_id;
  709. $ta_id = Input::get("ta_id");
  710. $outcome_id = Input::get("outcome_id");
  711. $objectives = DB::table('objectives')
  712. ->join('objective_program', 'objective_program.objective_id', '=', 'objectives.id')
  713. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'objectives.id')
  714. ->where('objective_outcome.outcome_id', $outcome_id)
  715. ->whereIn('objective_program.program_id', $program_ids)
  716. ->orderBy('objectives.text', 'ASC')
  717. ->select('objectives.text as text', 'objectives.id as id')
  718. ->distinct()
  719. ->get();
  720. return array(
  721. 'objectives' => $objectives,
  722. );
  723. }
  724. // return Transformative Actions that meet the filter criterias
  725. public function filterTA()
  726. {
  727. $user_id = Auth::user()->id;
  728. $role = Auth::user()['role'];
  729. $professor_id = Input::get('professor_id');
  730. $course_id = Input::get('course_id');
  731. $outcome_id = Input::get('outcome_id');
  732. $panel_id = Input::get('panel_id');
  733. switch ($role) {
  734. case 1:
  735. $program_id = DB::table('programs')->lists('id');
  736. break;
  737. case 2:
  738. $program_id = DB::table('programs')->where('school_id', Auth::user()->school_id)
  739. ->lists('id');
  740. break;
  741. case 3:
  742. $program_id = DB::table('program_user')
  743. ->where('user_id', $user_id)
  744. ->select('program_id')
  745. ->get();
  746. $program_id = $program_id[0]->program_id;
  747. break;
  748. }
  749. // if the user is a coordinator filtering the approvePanel
  750. /*if ($role == '3' && $panel_id == 'approvePanel') {
  751. // if professor isnt a desired filter, search all professors
  752. if ($professor_id == 0) {
  753. $all_ta_users = DB::table('transformative_actions')
  754. ->where('transformative_actions.is_custom', 1)
  755. ->where('transformative_actions.program_id', $program_id)
  756. ->where('transformative_actions.by_professor', 1)
  757. ->select('transformative_actions.user_id')
  758. ->get();
  759. $professor_id = array();
  760. foreach ($all_ta_users as $key => $user) {
  761. array_push($professor_id, $user->user_id);
  762. }
  763. } else {
  764. $professor_id = array($professor_id);
  765. }
  766. // if course isnt a desired filter, search all courses
  767. if ($course_id == 0) {
  768. $courses = DB::table('ta_course')
  769. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  770. ->join('courses', function ($join) {
  771. $join->on('courses.number', '=', 'ta_course.course_number');
  772. $join->on('courses.code', '=', 'ta_course.course_code');
  773. })
  774. ->where('transformative_actions.is_custom', 1)
  775. ->where('transformative_actions.program_id', $program_id)
  776. ->where('transformative_actions.by_professor', 1)
  777. ->select('ta_course.course_number', 'ta_course.course_code')
  778. ->distinct()
  779. ->get();
  780. $course_id = array();
  781. foreach ($courses as $key => $course) {
  782. array_push($course_id["number"], $course->course_number);
  783. array_push($course_id["code"], $course->code);
  784. }
  785. } else {
  786. $parentesis = array('(', ')');
  787. $course_code_number = str_replace($parentesis, '', $course_id);
  788. $course_code_number = explode(',', $course_code_number);
  789. $course_id = array();
  790. $course_id['number'] = $course_code_number[1];
  791. $course_id['code'] = $course_code_number[0];
  792. }
  793. // if outcome isnt a desired filter, search all outcomes
  794. if ($outcome_id == 0) {
  795. $outcomes = DB::table('transformative_actions')
  796. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  797. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  798. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  799. ->where('transformative_actions.is_custom', 1)
  800. ->where('transformative_actions.program_id', $program_id)
  801. ->where('transformative_actions.by_professor', 1)
  802. ->select('outcomes.id')
  803. ->groupBy('outcomes.id')
  804. ->get();
  805. $outcome_id = array();
  806. foreach ($outcomes as $key => $outcome) {
  807. array_push($outcome_id, $outcome->id);
  808. }
  809. } else {
  810. $outcome_id = array($outcome_id);
  811. }
  812. // search TA with filters
  813. $filtered_at = DB::table('transformative_actions')
  814. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  815. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  816. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  817. ->where('transformative_actions.is_custom', 1)
  818. ->where('transformative_actions.program_id', $program_id)
  819. ->where('transformative_actions.by_professor', 1)
  820. ->whereIn('transformative_actions.user_id', $professor_id)
  821. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  822. ->whereIn('ta_course.course_code', $course_id['code'])
  823. ->whereIn('ta_course.course_number', $course_id['number'])
  824. ->select('transformative_actions.*')
  825. ->groupBy('transformative_actions.id')
  826. ->orderBy('transformative_actions.at_text', 'ASC')
  827. ->get();
  828. return $filtered_at;
  829. }*/
  830. // if the user is a coordinator filtering the editPanel
  831. if ($panel_id == 'editPanel') {
  832. // if professor isnt a desired filter, search all professors
  833. if ($professor_id == 0) {
  834. $all_ta_users = DB::table('transformative_actions')
  835. ->where('transformative_actions.is_custom', 1)
  836. ->where('transformative_actions.program_id', $program_id)
  837. ->where('transformative_actions.by_professor', 0)
  838. ->select('transformative_actions.user_id')
  839. ->get();
  840. $professor_id = array();
  841. foreach ($all_ta_users as $key => $user) {
  842. array_push($professor_id, $user->user_id);
  843. }
  844. } else {
  845. $professor_id = array($professor_id);
  846. }
  847. // if course isnt a desired filter, search all courses
  848. if ($course_id == 0) {
  849. $courses = DB::table('ta_course')
  850. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  851. ->join('courses', function ($join) {
  852. $join->on('courses.number', '=', 'ta_course.course_number');
  853. $join->on('courses.code', '=', 'ta_course.course_code');
  854. })
  855. ->where('transformative_actions.is_custom', 1)
  856. ->where('transformative_actions.program_id', $program_id)
  857. ->where('transformative_actions.by_professor', 0)
  858. ->select('ta_course.course_number', 'ta_course.course_code')
  859. ->distinct()
  860. ->get();
  861. $course_id = array();
  862. foreach ($courses as $key => $course) {
  863. array_push($course_id["number"], $course->course_number);
  864. array_push($course_id["code"], $course->code);
  865. }
  866. } else {
  867. $parentesis = array('(', ')');
  868. $course_code_number = str_replace($parentesis, '', $course_id);
  869. $course_code_number = explode(',', $course_code_number);
  870. $course_id = array();
  871. $course_id['number'] = $course_code_number[1];
  872. $course_id['code'] = $course_code_number[0];
  873. }
  874. // if outcome isnt a desired filter, search all outcomes
  875. if ($outcome_id == 0) {
  876. $outcomes = DB::table('transformative_actions')
  877. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  878. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  879. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  880. ->where('transformative_actions.is_custom', 1)
  881. ->where('transformative_actions.program_id', $program_id)
  882. ->where('transformative_actions.by_professor', 0)
  883. ->select('outcomes.id')
  884. ->groupBy('outcomes.id')
  885. ->get();
  886. $outcome_id = array();
  887. foreach ($outcomes as $key => $outcome) {
  888. array_push($outcome_id, $outcome->id);
  889. }
  890. } else {
  891. $outcome_id = array($outcome_id);
  892. }
  893. // search TA with filters
  894. $filtered_at = DB::table('transformative_actions')
  895. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  896. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  897. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  898. ->where('transformative_actions.is_custom', 1)
  899. ->where('transformative_actions.program_id', $program_id)
  900. ->where('transformative_actions.by_professor', 0)
  901. ->whereIn('transformative_actions.user_id', $professor_id)
  902. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  903. ->whereIn('ta_course.course_code', $course_id['code'])
  904. ->whereIn('ta_course.course_number', $course_id['number'])
  905. ->select('transformative_actions.*')
  906. ->groupBy('transformative_actions.id')
  907. ->orderBy('transformative_actions.at_text', 'ASC')
  908. ->get();
  909. return $filtered_at;
  910. }
  911. // if the user is a professor filtering the editPanel
  912. /*elseif ($role == '4' && $panel_id == 'editPanel') {
  913. // if course isnt a desired filter, search all courses
  914. if ($course_id == 0) {
  915. $courses = DB::table('ta_course')
  916. ->join('transformative_actions', 'transformative_actions.id', '=', 'ta_course.ta_id')
  917. ->join('courses', 'courses.id', '=', 'ta_course.course_id')
  918. ->where('transformative_actions.user_id', Auth::user()->id)
  919. ->where('transformative_actions.is_custom', 1)
  920. ->where('transformative_actions.program_id', $program_id)
  921. ->where('transformative_actions.by_professor', 1)
  922. ->select('ta_course.course_number', 'ta_course.course_code')
  923. ->distinct()
  924. ->get();
  925. $course_id = array();
  926. foreach ($courses as $key => $course) {
  927. array_push($course_id["number"], $course->course_number);
  928. array_push($course_id["code"], $course->code);
  929. }
  930. } else {
  931. $parentesis = array('(', ')');
  932. $course_code_number = str_replace($parentesis, '', $course_id);
  933. $course_code_number = explode(',', $course_code_number);
  934. $course_id = array();
  935. $course_id['number'] = $course_code_number[1];
  936. $course_id['code'] = $course_code_number[0];
  937. }
  938. // if outcome isnt a desired filter, search all outcomes
  939. if ($outcome_id == 0) {
  940. $outcomes = DB::table('transformative_actions')
  941. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  942. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  943. ->join('outcomes', 'outcomes.id', '=', 'objective_outcome.outcome_id')
  944. ->where('transformative_actions.user_id', Auth::user()->id)
  945. ->where('transformative_actions.is_custom', 1)
  946. ->where('transformative_actions.program_id', $program_id)
  947. ->where('transformative_actions.by_professor', 1)
  948. ->select('outcomes.id')
  949. ->groupBy('outcomes.id')
  950. ->get();
  951. $outcome_id = array();
  952. foreach ($outcomes as $key => $outcome) {
  953. array_push($outcome_id, $outcome->id);
  954. }
  955. } else {
  956. $outcome_id = array($outcome_id);
  957. }
  958. // search TA with filters
  959. $filtered_at = DB::table('transformative_actions')
  960. ->join('ta_course', 'ta_course.ta_id', '=', 'transformative_actions.id')
  961. ->join('transformative_objective', 'transformative_objective.ta_id', '=', 'transformative_actions.id')
  962. ->join('objective_outcome', 'objective_outcome.objective_id', '=', 'transformative_objective.objective_id')
  963. ->where('transformative_actions.user_id', Auth::user()->id)
  964. ->where('transformative_actions.is_custom', 1)
  965. ->where('transformative_actions.program_id', $program_id)
  966. ->where('transformative_actions.by_professor', 1)
  967. ->whereIn('objective_outcome.outcome_id', $outcome_id)
  968. ->whereIn('ta_course.course_code', $course_id['code'])
  969. ->whereIn('ta_course.course_number', $course_id['number'])
  970. ->select('transformative_actions.*')
  971. ->groupBy('transformative_actions.id')
  972. ->orderBy('transformative_actions.at_text', 'ASC')
  973. ->get();
  974. return $filtered_at;
  975. }*/
  976. return 'ilegal';
  977. }
  978. function postActivityCriterion($activity_id)
  979. {
  980. DB::beginTransaction();
  981. $existing_transformative_action = DB::table('transformative_actions')
  982. ->join('transformative_activity_criterion', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  983. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  984. ->where('activity_id', $activity_id)
  985. ->delete();
  986. $activity_criterion = Input::get('trans_act');
  987. $trans = new TransformativeAction;
  988. $trans->user_id = Auth::user()['id'];
  989. $program_id = DB::table('activities')
  990. ->join('courses', 'activities.course_id', '=', 'courses.id')
  991. ->where('activities.id', $activity_id)
  992. ->lists('program_id');
  993. $trans->program_id = $program_id[0];
  994. $trans->is_custom = 1;
  995. $trans->by_professor = 1;
  996. $trans->at_text = Input::get('name_trans');
  997. $trans->description = Input::get('transforming_actions');
  998. $activity = DB::table('activities')
  999. ->where('id', $activity_id)
  1000. ->first();
  1001. $course_credentials = DB::table('courses')
  1002. ->where('id', $activity->course_id)
  1003. ->first();
  1004. if ($trans->save()) {
  1005. foreach ($activity_criterion as $single_ac) {
  1006. $result = DB::insert("insert into `transformative_activity_criterion` (`trans_action_id`, `activity_criterion_id`) values ($trans->id, $single_ac)");
  1007. if (!$result) {
  1008. DB::rollback();
  1009. Session::flash('status', 'danger');
  1010. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1011. return Redirect::to("professor/activities/{$activity_id}");
  1012. }
  1013. }
  1014. $criteria = DB::table('activity_criterion')
  1015. ->whereIn('id', $activity_criterion)
  1016. ->lists('criterion_id');
  1017. $allObjectives = DB::table('criterion_objective_outcome')
  1018. ->whereIn('criterion_id', $criteria)
  1019. ->select('objective_id')
  1020. ->distinct()
  1021. ->lists('objective_id');
  1022. foreach ($allObjectives as $objective) {
  1023. $result2 = DB::insert("insert into `transformative_objective` (`ta_id`, `objective_id`) values ({$trans->id},{$objective})");
  1024. if (!$result2) {
  1025. DB::rollback();
  1026. Session::flash('status', 'danger');
  1027. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1028. return Redirect::to("professor/activities/{$activity_id}");
  1029. }
  1030. }
  1031. $result3 = DB::insert("insert into `ta_course` (`ta_id`, `course_number`, `course_code`) values ({$trans->id}, '{$course_credentials->number}', '{$course_credentials->code}')");
  1032. if (!($result3)) {
  1033. DB::rollback();
  1034. Session::flash('status', 'danger');
  1035. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1036. return Redirect::to("professor/activities/{$activity_id}");
  1037. }
  1038. DB::commit();
  1039. Session::flash('status', 'success');
  1040. Session::flash('message', 'Formative Actions Saved.');
  1041. return Redirect::to("professor/activities/{$activity_id}");
  1042. } else {
  1043. DB::rollback();
  1044. Session::flash('status', 'danger');
  1045. Session::flash('message', 'Error saving Formative Action. Try again later.');
  1046. return Redirect::to("professor/activities/{$activity_id}");
  1047. }
  1048. }
  1049. public function viewFormativeActions()
  1050. {
  1051. $title = "Formative Actions";
  1052. $semesters = Session::get('semesters_ids');
  1053. $semesters = DB::table('semesters')->whereIn('id', $semesters)->orderBy('start', 'ASC')->first();
  1054. Log::info($semesters->start);
  1055. $outcomes = Outcome::select(array('id', 'name', 'expected_outcome'))
  1056. ->whereNull('deleted_at')
  1057. ->whereRaw("(deactivation_date IS NULL or deactivation_date >= '{$semesters->start}')")
  1058. ->orderBy('name', 'ASC')->get();
  1059. $semesters = DB::table('semesters')->where('is_visible', 1)->orderBy('end', 'DESC')->get();
  1060. $role = Auth::user()->role;
  1061. switch ($role) {
  1062. case 1:
  1063. $schools = DB::table('schools')->get();
  1064. $programs = DB::table('programs')->get();
  1065. break;
  1066. case 2:
  1067. $schools = DB::table('schools')->where('id', Auth::user()->school_id)->get();
  1068. $programs = DB::table('programs')->where('school_id', $schools[0]->id)->get();
  1069. break;
  1070. case 3:
  1071. $programs = DB::table('programs')
  1072. ->join('program_user', 'programs.id', '=', 'program_user.program_id')
  1073. ->where('user_id', Auth::user()->id)
  1074. ->select('programs.*')
  1075. ->get();
  1076. $schools = DB::table('schools')->where('id', $programs[0]->school_id)->get();
  1077. break;
  1078. }
  1079. return View::make('local.managers.shared.view_formative', compact('title', 'outcomes', 'schools', 'programs', 'semesters'));
  1080. }
  1081. public function fetchCourses()
  1082. {
  1083. $school = Input::get('schools');
  1084. $programs = Input::get('programs');
  1085. $semesters = Input::get('semesters');
  1086. $outcome_id = Input::get('id');
  1087. Log::info($programs);
  1088. Log::info($semesters);
  1089. /* if (in_array(0, $semesters)) {
  1090. $semesters = DB::table('semesters')->where('is_visible', 1)->lists('id');
  1091. }*/
  1092. /* if (in_array(0, $programs)) {
  1093. $role = Auth::user()->role;
  1094. switch ($role) {
  1095. case 1:
  1096. $programs = DB::table('programs')->lists('id');
  1097. break;
  1098. case 2:
  1099. $programs = DB::table('programs')->where('school_id', Auth::user()->school_id)->lists('id');
  1100. break;
  1101. case 3:
  1102. $programs = DB::table('program_user')->where('user_id', Auth::user()->id)->lists('program_id');
  1103. break;
  1104. }
  1105. }*/
  1106. $typ_semester_outcome = DB::table('typ_semester_outcome')
  1107. ->where('semester_id', $semesters)
  1108. ->where('outcome_id', $outcome_id)
  1109. ->lists('id');
  1110. //each row has objectives, repeated ta, but distinct activity_criterion_id
  1111. /* $objective_ta = DB::table('typ_semester_objectives')
  1112. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1113. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1114. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1115. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1116. ->select('transformative_actions.*')
  1117. ->addSelect('objectives.*')
  1118. ->distinct()
  1119. ->get();
  1120. $objective_ta = DB::table('typ_semester_objectives')
  1121. ->join('transformative_objective as trob', 'trob.objective_id', '=', 'typ_semester_objectives.objective_id')
  1122. ->join('objectives', 'trob.objective_id', '=', 'objective_id')
  1123. ->join('transformative_actions', 'transformative_actions.id', 'trob.ta_id')
  1124. ->whereIn('typ_semester_objectives.typ_semester_outcome_id', $typ_semester_outcome)
  1125. ->select('transformative_actions.*')
  1126. ->addSelect('objectives.*')
  1127. ->distinct()
  1128. ->lists();*/
  1129. $grouped_courses = DB::table('courses')
  1130. ->where('program_id', $programs)
  1131. ->where('semester_id', $semesters)
  1132. ->join('activities', 'activities.course_id', '=', 'courses.id')
  1133. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1134. ->join('transformative_activity_criterion as tac', 'tac.activity_criterion_id', '=', 'activity_criterion.id')
  1135. ->select('courses.*')
  1136. ->groupBy(array('courses.code', 'courses.name', 'courses.semester_id'))
  1137. ->get();
  1138. foreach ($grouped_courses as $course_name) {
  1139. $course_name->sections = DB::table('courses')
  1140. ->where('code', $course_name->code)
  1141. ->where('name', $course_name->name)
  1142. ->where('semester_id', $course_name->semester_id)
  1143. ->where('program_id', $course_name->program_id)
  1144. ->get();
  1145. foreach ($course_name->sections as $section) {
  1146. $section->activities = DB::table('activities')
  1147. ->join('activity_criterion', 'activities.id', '=', 'activity_criterion.activity_id')
  1148. ->join('transformative_activity_criterion', 'transformative_activity_criterion.activity_criterion_id', '=', 'activity_criterion.id')
  1149. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'activity_criterion.criterion_id')
  1150. ->join('transformative_actions', 'transformative_activity_criterion.trans_action_id', '=', 'transformative_actions.id')
  1151. ->where('activities.course_id', $section->id)
  1152. ->where('activities.draft', 0)
  1153. ->where('activities.diagnostic', 0)
  1154. ->where('criterion_objective_outcome.outcome_id', $outcome_id)
  1155. ->select('activities.id as activity_id', 'activities.name')
  1156. ->addSelect('transformative_actions.*', 'transformative_activity_criterion.trans_action_id as trans_action_id')
  1157. ->groupBy('transformative_actions.id')
  1158. ->get();
  1159. //If section has activity that assessess outcome
  1160. if (count($section->activities)) {
  1161. $course_name->outcome_assessed = true;
  1162. }
  1163. foreach ($section->activities as $activity) {
  1164. /*$activity->criterion = DB::table('transformative_activity_criterion')
  1165. ->join('activity_criterion','activity_criterion.id','=','transformative_activity_criterion.activity_criterion_id')
  1166. ->join('activities','activities.id','=','activity_criterion.activity_id')
  1167. ->join('criteria','activity_criterion.criterion_id','=','criteria.id')
  1168. ->where('activity_id', $activity->id)
  1169. ->select('criteria')*/
  1170. //Log::info($activity->trans_action_id);
  1171. $activity->criterion_with_objective = DB::table('transformative_activity_criterion')
  1172. ->join('activity_criterion', 'activity_criterion.id', '=', 'transformative_activity_criterion.activity_criterion_id')
  1173. ->join('criteria', 'activity_criterion.criterion_id', '=', 'criteria.id')
  1174. ->join('criterion_objective_outcome', 'criterion_objective_outcome.criterion_id', '=', 'criteria.id')
  1175. ->join('objectives', 'objectives.id', '=', 'criterion_objective_outcome.objective_id')
  1176. ->where('activity_id', $activity->activity_id)
  1177. ->where('trans_action_id', $activity->trans_action_id)
  1178. ->get();
  1179. /*$activity->objectives = DB::table('transformative_objective')
  1180. ->join('objectives', 'transformative_objective.objective_id', '=', 'objectives.id')
  1181. ->where('ta_id', $activity->trans_action_id)
  1182. ->get();*/
  1183. /*foreach ($activity->objectives as $objective) {
  1184. // Log::info($activity->activity_id);
  1185. // Log::info($objective->objective_id);
  1186. /* Log::info(DB::table('criterion_objective_outcome')
  1187. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1188. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1189. ->where('activity_criterion.activity_id', $activity->activity_id)
  1190. ->where('objective_id', $objective->objective_id)
  1191. ->select('criteria.*')
  1192. ->distinct()
  1193. ->toSql());
  1194. $objective->criterion = DB::table('criterion_objective_outcome')
  1195. ->join('activity_criterion', 'activity_criterion.criterion_id', '=', 'criterion_objective_outcome.criterion_id')
  1196. ->join('criteria', 'criteria.id', '=', 'activity_criterion.criterion_id')
  1197. ->where('activity_criterion.activity_id', $activity->activity_id)
  1198. ->where('objective_id', $objective->objective_id)
  1199. ->select('criteria.*')
  1200. ->distinct()
  1201. ->get();
  1202. }*/
  1203. }
  1204. }
  1205. }
  1206. return $grouped_courses;
  1207. }
  1208. public function createTAForOutcome()
  1209. {
  1210. $is_custom = Input::get('is_custom');
  1211. $category = Input::get('category');
  1212. $is_new = Input::get('is_new');
  1213. $name = Input::get('name');
  1214. $description = Input::get('description');
  1215. $edit_ta_id = Input::get('edit');
  1216. if ($is_new || $is_custom)
  1217. $program_id = Input::get('program_id');
  1218. else $program_id = NULL;
  1219. $typ_semester_outcome_id = Input::get('typ_semester_outcome_id');
  1220. if (!$edit_ta_id) {
  1221. $ta_id = DB::table('transformative_actions')->insertGetId(array(
  1222. 'program_id' => $program_id,
  1223. 'type_of_TA' => $category,
  1224. 'at_text' => $name,
  1225. 'description' => $description,
  1226. 'user_id' => Auth::user()->id,
  1227. 'created_at' => date('Y-m-d H:i:s'),
  1228. 'updated_at' => date('Y-m-d H:i:s'),
  1229. 'by_professor' => 0,
  1230. 'is_custom' => $is_custom
  1231. ));
  1232. DB::table('transformative_typ_outcome')->insert(array(
  1233. 'trans_id' => $ta_id,
  1234. 'typ_semester_outcome_id' => $typ_semester_outcome_id,
  1235. 'proposing_coordinator_id' => Auth::user()->id,
  1236. ));
  1237. } else {
  1238. DB::table('transformative_actions')
  1239. ->where('id', $edit_ta_id)
  1240. ->update(array(
  1241. 'program_id' => $program_id,
  1242. 'type_of_TA' => $category,
  1243. 'at_text' => $name,
  1244. 'description' => $description,
  1245. 'user_id' => Auth::user()->id,
  1246. 'created_at' => date('Y-m-d H:i:s'),
  1247. 'updated_at' => date('Y-m-d H:i:s'),
  1248. 'by_professor' => 0,
  1249. 'is_custom' => $is_custom
  1250. ));
  1251. $ta_id = $edit_ta_id;
  1252. }
  1253. return $ta_id;
  1254. }
  1255. public function deleteTaFromOutcome()
  1256. {
  1257. DB::table('transformative_actions')
  1258. ->where('id', Input::get('trans_id'))
  1259. ->delete();
  1260. return;
  1261. }
  1262. public function fetchStatus()
  1263. {
  1264. $trans_id = Input::get('trans_id');
  1265. $semester_id = Input::get('semester_id');
  1266. $transformative_action = DB::table('transformative_actions')
  1267. ->where('id', $trans_id)
  1268. ->first();
  1269. $transformative_action->status = DB::table('transformative_action_status')
  1270. ->where('trans_id', $transformative_action->id)
  1271. ->where('semester_id', $semester_id)
  1272. ->first();
  1273. //TransformativeAction::find($trans_id)->status($semester_id);
  1274. return array($transformative_action);
  1275. }
  1276. public function saveTransStatus()
  1277. {
  1278. $semester_id = Input::get('semester_id');
  1279. $trans_id = Input::get('trans_id');
  1280. $results = Input::get('results');
  1281. $comments = Input::get('comments');
  1282. $accomplished = Input::get('accomplished');
  1283. $was_it_useful = Input::get('was_it_useful');
  1284. $existing_status = DB::table('transformative_action_status')
  1285. ->where('semester_id', $semester_id)
  1286. ->where('trans_id', $trans_id)
  1287. ->first();
  1288. if ($existing_status) {
  1289. DB::table('transformative_action_status')->update(array(
  1290. 'results' => $results,
  1291. 'comments' => $comments,
  1292. 'accomplished' => $accomplished,
  1293. 'it_was_useful' => $was_it_useful,
  1294. 'supervised_coordinator_id' => Auth::user()->id
  1295. ));
  1296. } else {
  1297. DB::table('transformative_action_status')->insert(array(
  1298. 'trans_id' => $trans_id,
  1299. 'results' => $results,
  1300. 'comments' => $comments,
  1301. 'accomplished' => $accomplished,
  1302. 'it_was_useful' => $was_it_useful,
  1303. 'semester_id' => $semester_id,
  1304. 'supervised_coordinator_id' => Auth::user()->id
  1305. ));
  1306. }
  1307. return "done";
  1308. }
  1309. }