You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
139 lines
4.4 KiB
139 lines
4.4 KiB
|
13 years ago
|
<?php
|
||
|
|
/* For licensing terms, see /license.txt */
|
||
|
13 years ago
|
|
||
|
12 years ago
|
namespace Chamilo\CourseBundle\Controller\Introduction;
|
||
|
13 years ago
|
|
||
|
12 years ago
|
use Chamilo\CourseBundle\Controller\ToolBaseController;
|
||
|
|
use Chamilo\CoreBundle\Entity\CToolIntro;
|
||
|
13 years ago
|
use Symfony\Component\HttpFoundation\Response;
|
||
|
12 years ago
|
use Chamilo\CoreBundle\Controller\CrudController;
|
||
|
13 years ago
|
use Symfony\Component\Routing\Annotation\Route;
|
||
|
|
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
|
||
|
13 years ago
|
|
||
|
|
/**
|
||
|
|
* Class IntroductionToolController
|
||
|
12 years ago
|
* @package Chamilo\CourseBundle\Controller\Introduction
|
||
|
13 years ago
|
* @author Julio Montoya <gugli100@gmail.com>
|
||
|
12 years ago
|
* @Route("/introduction")
|
||
|
13 years ago
|
*/
|
||
|
12 years ago
|
class IntroductionController extends ToolBaseController
|
||
|
13 years ago
|
{
|
||
|
12 years ago
|
|
||
|
13 years ago
|
/**
|
||
|
13 years ago
|
* @Route("/edit/{tool}")
|
||
|
12 years ago
|
* @Method({"GET|POST"})
|
||
|
13 years ago
|
*
|
||
|
13 years ago
|
* @param string $tool
|
||
|
|
* @return Response
|
||
|
|
*/
|
||
|
13 years ago
|
public function editAction($tool)
|
||
|
13 years ago
|
{
|
||
|
|
$message = null;
|
||
|
13 years ago
|
// @todo use proper functions not api functions.
|
||
|
|
$courseId = api_get_course_int_id();
|
||
|
|
$sessionId = api_get_session_id();
|
||
|
13 years ago
|
$tool = \Database::escape_string($tool);
|
||
|
|
|
||
|
|
$TBL_INTRODUCTION = \Database::get_course_table(TABLE_TOOL_INTRO);
|
||
|
|
|
||
|
13 years ago
|
$url = $this->generateUrl(
|
||
|
12 years ago
|
'chamilo_course_introduction_introduction_edit',
|
||
|
12 years ago
|
array('tool' => $tool, 'course' => api_get_course_id())
|
||
|
13 years ago
|
);
|
||
|
|
|
||
|
13 years ago
|
$form = $this->getForm($url, $tool);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
if ($form->validate()) {
|
||
|
|
$values = $form->exportValues();
|
||
|
12 years ago
|
$content = $values['content'];
|
||
|
13 years ago
|
|
||
|
13 years ago
|
$sql = "REPLACE $TBL_INTRODUCTION
|
||
|
13 years ago
|
SET c_id = $courseId,
|
||
|
|
id = '$tool',
|
||
|
|
intro_text='".\Database::escape_string($content)."',
|
||
|
|
session_id='".intval($sessionId)."'";
|
||
|
13 years ago
|
\Database::query($sql);
|
||
|
|
$message = \Display::return_message(get_lang('IntroductionTextUpdated'), 'confirmation', false);
|
||
|
|
} else {
|
||
|
|
|
||
|
|
$sql = "SELECT intro_text FROM $TBL_INTRODUCTION
|
||
|
|
WHERE c_id = $courseId AND id='".$tool."' AND session_id = '".intval($sessionId)."'";
|
||
|
|
$result = \Database::query($sql);
|
||
|
|
$content = null;
|
||
|
|
if (\Database::num_rows($result) > 0) {
|
||
|
|
$row = \Database::fetch_array($result);
|
||
|
|
$content = $row['intro_text'];
|
||
|
|
}
|
||
|
|
$form->setDefaults(array('content' => $content));
|
||
|
|
}
|
||
|
|
|
||
|
12 years ago
|
/*$this->getTemplate()->assign('content', $form->return_form());
|
||
|
13 years ago
|
$this->getTemplate()->assign('message', $message);
|
||
|
12 years ago
|
$response = $this->getTemplate()->renderLayout('layout_1_col.tpl');*/
|
||
|
|
$response = null;
|
||
|
|
return $this->render(
|
||
|
12 years ago
|
'ChamiloCoreBundle:Legacy:index.html.twig',
|
||
|
12 years ago
|
array(
|
||
|
|
'content' => $form->return_form(),
|
||
|
|
'message' => $message
|
||
|
|
)
|
||
|
|
);
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
13 years ago
|
* @Route("/delete/{tool}")
|
||
|
|
* @Method({"GET"})
|
||
|
|
*
|
||
|
13 years ago
|
* @param string $tool
|
||
|
|
* @return Response
|
||
|
|
*/
|
||
|
13 years ago
|
public function deleteAction($tool)
|
||
|
13 years ago
|
{
|
||
|
13 years ago
|
$request = $this->getRequest();
|
||
|
13 years ago
|
$courseId = $request->get('courseId');
|
||
|
|
$sessionId = $request->get('sessionId');
|
||
|
13 years ago
|
$criteria = array(
|
||
|
|
'sessionId' => $sessionId,
|
||
|
|
'id' => $tool,
|
||
|
|
'cId' => $courseId
|
||
|
|
);
|
||
|
13 years ago
|
|
||
|
13 years ago
|
$toolIntro = $this->getRepository()->findOneBy($criteria);
|
||
|
|
if ($toolIntro) {
|
||
|
|
$this->getManager()->remove($toolIntro);
|
||
|
|
$this->getManager()->flush();
|
||
|
|
$this->get('session')->getFlashBag()->add('success', "IntroductionTextDeleted");
|
||
|
|
}
|
||
|
13 years ago
|
|
||
|
12 years ago
|
return $this->redirect('course_home');
|
||
|
13 years ago
|
}
|
||
|
|
|
||
|
|
/**
|
||
|
|
*
|
||
|
|
* @param $url
|
||
|
13 years ago
|
* @param string
|
||
|
13 years ago
|
* @return \FormValidator
|
||
|
|
*/
|
||
|
13 years ago
|
private function getForm($url, $tool)
|
||
|
13 years ago
|
{
|
||
|
|
$toolbar_set = 'IntroductionTool';
|
||
|
|
$width = '100%';
|
||
|
|
$height = '300';
|
||
|
|
|
||
|
|
$editor_config = array('ToolbarSet' => $toolbar_set, 'Width' => $width, 'Height' => $height);
|
||
|
|
|
||
|
|
$form = new \FormValidator('form', 'post', $url);
|
||
|
|
$form->add_html_editor('content', null, null, false, $editor_config);
|
||
|
13 years ago
|
if ($tool == 'course_homepage') {
|
||
|
13 years ago
|
$form->addElement(
|
||
|
|
'label',
|
||
|
|
get_lang('YouCanUseAllTheseTags'),
|
||
|
|
'(('.implode(')) <br /> ((', \CourseHome::availableTools()).'))'
|
||
|
|
);
|
||
|
13 years ago
|
}
|
||
|
13 years ago
|
$form->addElement('button', 'submit', get_lang('SaveIntroText'));
|
||
|
|
return $form;
|
||
|
|
}
|
||
|
13 years ago
|
|
||
|
13 years ago
|
}
|