index.php 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. <?php
  2. require_once '../inc/global.inc.php';
  3. use Silex\Application;
  4. use Symfony\Component\HttpFoundation\Response;
  5. use Entity\CTimeline;
  6. class TimeLineController {
  7. function indexAction(Application $app) {
  8. $timeline_query = $app['orm.em']->getRepository('Entity\CTimeline')->findAll();
  9. $timeline_query = $app['orm.em']->createQuery('SELECT a FROM Entity\CTimeline a');
  10. $paginator = new Doctrine\ORM\Tools\Pagination\Paginator($timeline_query, $fetchJoinCollection = true);
  11. $c = count($paginator);
  12. $test = null;
  13. foreach ($paginator as $item) {
  14. $test .= $item->getHeadline() . "\n";
  15. }
  16. $response = $test;
  17. return new Response($response, 200, array());
  18. }
  19. function addAction(Application $app) {
  20. $timeline = new Timeline();
  21. $url = $app['url_generator']->generate('add');
  22. $form = $timeline->return_item_form($url, 'edit');
  23. // The validation or display
  24. if ($form->validate()) {
  25. $values = $form->exportValues();
  26. $values['type'] = 0;
  27. $values['status'] = 0;
  28. $my_timeline = new CTimeline();
  29. $my_timeline->setCId(api_get_course_int_id());
  30. $my_timeline->setHeadline($values['headline']);
  31. $my_timeline->setType($values['type']);
  32. $my_timeline->setStartDate($values['start_date']);
  33. $my_timeline->setEndDate($values['end_date']);
  34. $my_timeline->setText($values['text']);
  35. $my_timeline->setMedia($values['media']);
  36. $my_timeline->setMediaCredit($values['media_credit']);
  37. $my_timeline->setMediaCaption($values['media_caption']);
  38. $my_timeline->setTitleSlide($values['title_slide']);
  39. $my_timeline->setParentId($values['parent_id']);
  40. $my_timeline->setStatus($values['status']);
  41. $app['orm.em']->persist($my_timeline);
  42. $app['orm.em']->flush();
  43. $message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation');
  44. //$app['session']->setFlash('error', $message);
  45. return $app->redirect($app['url_generator']->generate('view', array('id'=> $my_timeline->getId())), 201);
  46. } else {
  47. $actions = '<a href="'.$app['url_generator']->generate('index').'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>';
  48. $content = $form->return_form();
  49. }
  50. $app['template']->assign('content', $content);
  51. $response = $app['template']->render_layout('layout_1_col.tpl');
  52. return new Response($response, 200, array());
  53. }
  54. function viewAction(Application $app, $id) {
  55. $timeline = $app['db.orm.em']->find('CTimeline', $id);
  56. $app['template']->assign('timeline', $timeline);
  57. $response = $app['template']->render_template('timeline/view.tpl');
  58. return new Response($response, 200, array());
  59. }
  60. function editAction(Application $app, $id) {
  61. $timeline = $app['db.orm.em']->find('CTimeline', $id);
  62. $app['template']->assign('timeline', $timeline);
  63. $content = $app['template']->fetch('default/timeline/edit.tpl');
  64. $app['template']->assign('content', $content);
  65. $response = $app['template']->render_layout('layout_1_col.tpl');
  66. return new Response($response, 200, array());
  67. }
  68. }
  69. $app->get('/', 'TimeLineController::indexAction')->bind('index');
  70. $app->get('/view/{id}', 'TimeLineController::viewAction')->bind('view');
  71. $app->get('/edit/{id}', 'TimeLineController::editAction')->bind('edit');
  72. $app->match('/add', 'TimeLineController::addAction', 'GET|POST')->bind('add');
  73. $app->run();