Adding Timeline tool demo controller (using doctrine2) see #4570 + adding htaccess for test only
parent
5199de5e14
commit
b2b2cff7bf
@ -0,0 +1,8 @@ |
||||
<IfModule mod_rewrite.c> |
||||
Options -MultiViews |
||||
|
||||
RewriteEngine On |
||||
#RewriteBase /path/to/app |
||||
RewriteCond %{REQUEST_FILENAME} !-f |
||||
RewriteRule ^ index.php [L] |
||||
</IfModule> |
@ -1,161 +1,89 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
/** |
||||
@author Julio Montoya <gugli100@gmail.com> BeezNest 2011 |
||||
* @package chamilo.timeline |
||||
*/ |
||||
|
||||
// name of the language file that needs to be included |
||||
$language_file = array ('registration','admin'); |
||||
require_once '../inc/global.inc.php'; |
||||
|
||||
require_once api_get_path(LIBRARY_PATH).'timeline.lib.php'; |
||||
use Silex\Application; |
||||
use Symfony\Component\HttpFoundation\Response; |
||||
use Entity\EntityCTimeline; |
||||
|
||||
$htmlHeadXtra[] = api_get_jqgrid_js(); |
||||
class TimeLineController { |
||||
|
||||
//$htmlHeadXtra[] = api_get_js('timeline/timeline-min.js'); |
||||
//$htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/timeline/timeline.css'); |
||||
|
||||
// setting breadcrumbs |
||||
//$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('PlatformAdmin')); |
||||
//$interbreadcrumb[]=array('url' => 'career_dashboard.php','name' => get_lang('CareersAndPromotions')); |
||||
|
||||
$action = isset($_GET['action']) ? $_GET['action'] : null; |
||||
|
||||
$check = Security::check_token('request'); |
||||
$token = Security::get_token(); |
||||
|
||||
switch ($action) { |
||||
case 'add': |
||||
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Timeline')); |
||||
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Add')); |
||||
break; |
||||
case 'edit': |
||||
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Timeline')); |
||||
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Edit')); |
||||
break; |
||||
case 'add_item': |
||||
$interbreadcrumb[]=array('url' => 'index.php','name' => get_lang('Timeline')); |
||||
$interbreadcrumb[]=array('url' => '#','name' => get_lang('TimelineItem')); |
||||
break; |
||||
default: |
||||
$interbreadcrumb[]=array('url' => '#','name' => get_lang('Timeline')); |
||||
} |
||||
|
||||
//jqgrid will use this URL to do the selects |
||||
$url = api_get_path(WEB_AJAX_PATH).'model.ajax.php?a=get_timelines'; |
||||
|
||||
//The order is important you need to check the the $column variable in the model.ajax.php file |
||||
$columns = array(get_lang('Name'), get_lang('Actions')); |
||||
|
||||
//Column config |
||||
$column_model = array( |
||||
array('name'=>'name', 'index'=>'name', 'width'=>'120', 'align'=>'left'), |
||||
array('name'=>'actions', 'index'=>'actions', 'width'=>'100', 'align'=>'left', 'sortable'=>'false') |
||||
); |
||||
//Autowidth |
||||
$extra_params['autowidth'] = 'true'; |
||||
//height auto |
||||
$extra_params['height'] = 'auto'; |
||||
|
||||
//With this function we can add actions to the jgrid (edit, delete, etc) |
||||
$htmlHeadXtra[] =' |
||||
<script> |
||||
$(function() { |
||||
// grid definition see the $timeline->display() function |
||||
'.Display::grid_js('timelines', $url,$columns,$column_model,$extra_params, array(), null,true).' |
||||
}); |
||||
</script>'; |
||||
|
||||
$timeline = new Timeline(); |
||||
function indexAction(Application $app) { |
||||
$timeline_query = $app['orm.em']->getRepository('Entity\EntityCTimeline')->findAll(); |
||||
|
||||
$timeline_query = $app['orm.em']->createQuery('SELECT a FROM Entity\EntityCTimeline a'); |
||||
|
||||
// Action handling: Add |
||||
switch ($action) { |
||||
case 'add': |
||||
if (api_get_session_id() != 0 && !api_is_allowed_to_session_edit(false, true)) { |
||||
api_not_allowed(); |
||||
} |
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']); |
||||
$form = $timeline->return_form($url, 'add'); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
if ($check) { |
||||
$values = $form->exportValues(); |
||||
$res = $timeline->save($values); |
||||
if ($res) { |
||||
$message = Display::return_message(get_lang('ItemAdded'),'success'); |
||||
} |
||||
} |
||||
$content = $timeline->listing(); |
||||
} else { |
||||
$actions .= '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(array('sec_token' => $token)); |
||||
$content = $form->return_form(); |
||||
$paginator = new Doctrine\ORM\Tools\Pagination\Paginator($timeline_query, $fetchJoinCollection = true); |
||||
$c = count($paginator); |
||||
$test = null; |
||||
foreach ($paginator as $item) { |
||||
$test .= $item->getHeadline() . "\n"; |
||||
} |
||||
break; |
||||
case 'edit': |
||||
// Action handling: Editing |
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&id='.intval($_GET['id']); |
||||
$form = $timeline->return_form($url, 'edit'); |
||||
$response = $test; |
||||
return new Response($response, 200, array()); |
||||
} |
||||
|
||||
function addAction(Application $app) { |
||||
$timeline = new Timeline(); |
||||
$url = $app['url_generator']->generate('add'); |
||||
$form = $timeline->return_item_form($url, 'edit'); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
if ($check) { |
||||
$values = $form->exportValues(); |
||||
//$timeline->update_all_promotion_status_by_career_id($values['id'],$values['status']); |
||||
$res = $timeline->update($values); |
||||
$message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation'); |
||||
} |
||||
$timeline->display(); |
||||
} else { |
||||
$actions = '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(array('sec_token' => $token)); |
||||
$content = $form->return_form(); |
||||
} |
||||
break; |
||||
case 'add_item': |
||||
// Action handling: Editing |
||||
$url = api_get_self().'?action='.Security::remove_XSS($_GET['action']).'&parent_id='.intval($_GET['parent_id']); |
||||
$form = $timeline->return_item_form($url, 'edit'); |
||||
|
||||
// The validation or display |
||||
if ($form->validate()) { |
||||
if ($check) { |
||||
$values = $form->exportValues(); |
||||
$values['type'] = ''; |
||||
//$timeline->update_all_promotion_status_by_career_id($values['id'],$values['status']); |
||||
$res = $timeline->save_item($values); |
||||
$message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation'); |
||||
} |
||||
$timeline->display(); |
||||
} else { |
||||
$actions = '<a href="'.api_get_self().'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; |
||||
$form->addElement('hidden', 'sec_token'); |
||||
$form->setConstants(array('sec_token' => $token)); |
||||
if ($form->validate()) { |
||||
$values = $form->exportValues(); |
||||
$values['type'] = 0; |
||||
$values['status'] = 0; |
||||
|
||||
$my_timeline = new EntityCTimeline(); |
||||
$my_timeline->setCId(api_get_course_int_id()); |
||||
$my_timeline->setHeadline($values['headline']); |
||||
$my_timeline->setType($values['type']); |
||||
$my_timeline->setStartDate($values['start_date']); |
||||
$my_timeline->setEndDate($values['end_date']); |
||||
$my_timeline->setText($values['text']); |
||||
$my_timeline->setMedia($values['media']); |
||||
$my_timeline->setMediaCredit($values['media_credit']); |
||||
$my_timeline->setMediaCaption($values['media_caption']); |
||||
$my_timeline->setTitleSlide($values['title_slide']); |
||||
$my_timeline->setParentId($values['parent_id']); |
||||
$my_timeline->setStatus($values['status']); |
||||
|
||||
$app['orm.em']->persist($my_timeline); |
||||
$app['orm.em']->flush(); |
||||
|
||||
$message = Display::return_message(sprintf(get_lang('ItemUpdated'), $values['name']), 'confirmation'); |
||||
//$app['session']->setFlash('error', $message); |
||||
|
||||
return $app->redirect($app['url_generator']->generate('view', array('id'=> $my_timeline->getId())), 201); |
||||
} else { |
||||
$actions = '<a href="'.$app['url_generator']->generate('index').'">'.Display::return_icon('back.png',get_lang('Back'),'',ICON_SIZE_MEDIUM).'</a>'; |
||||
$content = $form->return_form(); |
||||
} |
||||
break; |
||||
case 'delete': |
||||
// Action handling: delete |
||||
if ($check) { |
||||
$res = $timeline->delete($_GET['id']); |
||||
if ($res) { |
||||
$message = Display::return_message(get_lang('ItemDeleted'), 'success'); |
||||
} |
||||
} |
||||
$content = $timeline->listing(); |
||||
break; |
||||
default: |
||||
$content = $timeline->listing(); |
||||
break; |
||||
$app['template']->assign('content', $content); |
||||
$response = $app['template']->render_layout('layout_1_col.tpl'); |
||||
return new Response($response, 200, array()); |
||||
} |
||||
|
||||
function viewAction(Application $app, $id) { |
||||
$timeline = $app['db.orm.em']->find('EntityCTimeline', $id); |
||||
$app['template']->assign('timeline', $timeline); |
||||
$response = $app['template']->render_template('timeline/view.tpl'); |
||||
return new Response($response, 200, array()); |
||||
} |
||||
|
||||
function editAction(Application $app, $id) { |
||||
$timeline = $app['db.orm.em']->find('EntityCTimeline', $id); |
||||
$app['template']->assign('timeline', $timeline); |
||||
$content = $app['template']->fetch('default/timeline/edit.tpl'); |
||||
$app['template']->assign('content', $content); |
||||
$response = $app['template']->render_layout('layout_1_col.tpl'); |
||||
return new Response($response, 200, array()); |
||||
} |
||||
} |
||||
|
||||
$tpl = new Template($tool_name); |
||||
|
||||
$tpl->assign('actions', $actions); |
||||
$tpl->assign('message', $message); |
||||
$tpl->assign('content', $content); |
||||
$tpl->display_one_col_template(); |
||||
$app->get('/', 'TimeLineController::indexAction')->bind('index'); |
||||
$app->get('/view/{id}', 'TimeLineController::viewAction')->bind('view'); |
||||
$app->get('/edit/{id}', 'TimeLineController::editAction')->bind('edit'); |
||||
$app->match('/add', 'TimeLineController::addAction', 'GET|POST')->bind('add'); |
||||
$app->run(); |
Loading…
Reference in new issue