parent
def293c680
commit
ea4a6dbfd6
@ -0,0 +1,571 @@ |
||||
<?php |
||||
|
||||
namespace Entity; |
||||
|
||||
use Doctrine\ORM\Mapping as ORM; |
||||
use Symfony\Component\Validator\Constraints as Assert; |
||||
use Symfony\Component\Validator\Mapping\ClassMetadata; |
||||
use Symfony\Component\HttpFoundation\File\UploadedFile; |
||||
|
||||
/** |
||||
* CTool |
||||
* @ORM\HasLifecycleCallbacks |
||||
* @ORM\Table(name="c_tool", indexes={@ORM\Index(name="session_id", columns={"session_id"})}) |
||||
* @ORM\Entity |
||||
*/ |
||||
class CTool |
||||
{ |
||||
/** |
||||
* @var integer |
||||
* |
||||
* @ORM\Column(name="c_id", type="integer", precision=0, scale=0, nullable=false, unique=false) |
||||
* @ORM\Id |
||||
* @ORM\GeneratedValue(strategy="NONE") |
||||
*/ |
||||
private $cId; |
||||
|
||||
/** |
||||
* @var integer |
||||
* |
||||
* @ORM\Column(name="id", type="integer", precision=0, scale=0, nullable=false, unique=false) |
||||
* @ORM\Id |
||||
* @ORM\GeneratedValue(strategy="NONE") |
||||
*/ |
||||
private $id; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="name", type="string", length=255, precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $name; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="link", type="string", length=255, precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $link; |
||||
|
||||
/** |
||||
* @var string |
||||
* @ORM\Column(name="image", type="string", length=255, precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $image; |
||||
|
||||
/** |
||||
* @var string |
||||
* @ORM\Column(name="custom_icon", type="string", length=255, precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $customIcon; |
||||
|
||||
/** |
||||
* @var boolean |
||||
* |
||||
* @ORM\Column(name="visibility", type="boolean", precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $visibility; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="admin", type="string", length=255, precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $admin; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="address", type="string", length=255, precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $address; |
||||
|
||||
/** |
||||
* @var boolean |
||||
* |
||||
* @ORM\Column(name="added_tool", type="boolean", precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $addedTool; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="target", type="string", precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $target; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="category", type="string", length=20, precision=0, scale=0, nullable=false, unique=false) |
||||
*/ |
||||
private $category; |
||||
|
||||
/** |
||||
* @var integer |
||||
* |
||||
* @ORM\Column(name="session_id", type="integer", precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $sessionId; |
||||
|
||||
/** |
||||
* @var string |
||||
* |
||||
* @ORM\Column(name="description", type="text", precision=0, scale=0, nullable=true, unique=false) |
||||
*/ |
||||
private $description; |
||||
|
||||
/** |
||||
* @ORM\ManyToOne(targetEntity="Course") |
||||
* @ORM\JoinColumn(name="c_id", referencedColumnName="id") |
||||
*/ |
||||
private $course; |
||||
|
||||
protected $originalImage; |
||||
|
||||
/** |
||||
*/ |
||||
public function __construct() |
||||
{ |
||||
} |
||||
|
||||
/** |
||||
* @param ClassMetadata $metadata |
||||
*/ |
||||
public static function loadValidatorMetadata(ClassMetadata $metadata) |
||||
{ |
||||
$metadata->addPropertyConstraint( |
||||
'customIcon', |
||||
new Assert\File(array('mimeTypes' => array("image/png"))) |
||||
); |
||||
$metadata->addPropertyConstraint( |
||||
'customIcon', |
||||
new Assert\Image(array('maxWidth' => 64, 'minHeight' => 64)) |
||||
); |
||||
$metadata->addPropertyConstraint('cId', new Assert\NotBlank()); |
||||
} |
||||
|
||||
/** |
||||
* @return Course |
||||
*/ |
||||
public function getCourse() |
||||
{ |
||||
return $this->course; |
||||
} |
||||
|
||||
/** |
||||
* @return null|string |
||||
*/ |
||||
public function getAbsolutePath() |
||||
{ |
||||
return null === $this->getCustomIcon() |
||||
? null |
||||
: $this->getUploadRootDir().'/'.$this->getCustomIcon(); |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
protected function getUploadRootDir() |
||||
{ |
||||
// the absolute directory path where uploaded |
||||
// documents should be saved |
||||
$dir = $this->getCourse()->getAbsoluteSysCoursePath().$this->getUploadDir(); |
||||
|
||||
if (is_dir($dir)) { |
||||
return $dir; |
||||
} else { |
||||
mkdir($dir); |
||||
return $dir; |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* @return string |
||||
*/ |
||||
protected function getUploadDir() |
||||
{ |
||||
// get rid of the __DIR__ so it doesn't screw up |
||||
// when displaying uploaded doc/image in the view. |
||||
return 'upload/course_home_icons'; |
||||
} |
||||
|
||||
/** |
||||
* Called before saving the entity |
||||
* |
||||
* @ORM\PrePersist() |
||||
* @ORM\PreUpdate() |
||||
*/ |
||||
public function preUpload() |
||||
{ |
||||
if (null !== $this->getCustomIcon()) { |
||||
|
||||
// do whatever you want to generate a unique name |
||||
//$filename = sha1(uniqid(mt_rand(), true)); |
||||
$this->originalImage = $this->getCustomIcon(); |
||||
$this->customIcon = $this->getName().'_'.$this->getSessionId().'.'.$this->getCustomIcon()->guessExtension(); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Called before entity removal |
||||
* |
||||
* @ORM\PostRemove() |
||||
*/ |
||||
public function removeUpload() |
||||
{ |
||||
if ($file = $this->getAbsolutePath()) { |
||||
unlink($file); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* Called after entity persistence |
||||
* |
||||
* @ORM\PostPersist() |
||||
* @ORM\PostUpdate() |
||||
*/ |
||||
public function upload() |
||||
{ |
||||
// the file property can be empty if the field is not required |
||||
if (null === $this->getCustomIcon()) { |
||||
return; |
||||
} |
||||
|
||||
// use the original file name here but you should |
||||
// sanitize it at least to avoid any security issues |
||||
|
||||
// move takes the target directory and then the |
||||
// target filename to move to |
||||
$this->originalImage->move( |
||||
$this->getUploadRootDir(), |
||||
$this->customIcon |
||||
); |
||||
|
||||
// clean up the file property as you won't need it anymore |
||||
$this->originalImage = null; |
||||
} |
||||
|
||||
/** |
||||
* Set cId |
||||
* |
||||
* @param integer $cId |
||||
* @return CTool |
||||
*/ |
||||
public function setCId($cId) |
||||
{ |
||||
$this->cId = $cId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get cId |
||||
* |
||||
* @return integer |
||||
*/ |
||||
public function getCId() |
||||
{ |
||||
return $this->cId; |
||||
} |
||||
|
||||
/** |
||||
* Set id |
||||
* |
||||
* @param integer $id |
||||
* @return CTool |
||||
*/ |
||||
public function setId($id) |
||||
{ |
||||
$this->id = $id; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get id |
||||
* |
||||
* @return integer |
||||
*/ |
||||
public function getId() |
||||
{ |
||||
return $this->id; |
||||
} |
||||
|
||||
/** |
||||
* Set name |
||||
* |
||||
* @param string $name |
||||
* @return CTool |
||||
*/ |
||||
public function setName($name) |
||||
{ |
||||
$this->name = $name; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get name |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getName() |
||||
{ |
||||
return $this->name; |
||||
} |
||||
|
||||
/** |
||||
* Set link |
||||
* |
||||
* @param string $link |
||||
* @return CTool |
||||
*/ |
||||
public function setLink($link) |
||||
{ |
||||
$this->link = $link; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get link |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getLink() |
||||
{ |
||||
return $this->link; |
||||
} |
||||
|
||||
/** |
||||
* Set image |
||||
* |
||||
* @param string $image |
||||
* @return CTool |
||||
*/ |
||||
public function setImage($image) |
||||
{ |
||||
$this->image = $image; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get image |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getImage() |
||||
{ |
||||
return $this->image; |
||||
} |
||||
|
||||
/** |
||||
* Set visibility |
||||
* |
||||
* @param boolean $visibility |
||||
* @return CTool |
||||
*/ |
||||
public function setVisibility($visibility) |
||||
{ |
||||
$this->visibility = $visibility; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get visibility |
||||
* |
||||
* @return boolean |
||||
*/ |
||||
public function getVisibility() |
||||
{ |
||||
return $this->visibility; |
||||
} |
||||
|
||||
/** |
||||
* Set admin |
||||
* |
||||
* @param string $admin |
||||
* @return CTool |
||||
*/ |
||||
public function setAdmin($admin) |
||||
{ |
||||
$this->admin = $admin; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get admin |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getAdmin() |
||||
{ |
||||
return $this->admin; |
||||
} |
||||
|
||||
/** |
||||
* Set address |
||||
* |
||||
* @param string $address |
||||
* @return CTool |
||||
*/ |
||||
public function setAddress($address) |
||||
{ |
||||
$this->address = $address; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get address |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getAddress() |
||||
{ |
||||
return $this->address; |
||||
} |
||||
|
||||
/** |
||||
* Set addedTool |
||||
* |
||||
* @param boolean $addedTool |
||||
* @return CTool |
||||
*/ |
||||
public function setAddedTool($addedTool) |
||||
{ |
||||
$this->addedTool = $addedTool; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get addedTool |
||||
* |
||||
* @return boolean |
||||
*/ |
||||
public function getAddedTool() |
||||
{ |
||||
return $this->addedTool; |
||||
} |
||||
|
||||
/** |
||||
* Set target |
||||
* |
||||
* @param string $target |
||||
* @return CTool |
||||
*/ |
||||
public function setTarget($target) |
||||
{ |
||||
$this->target = $target; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get target |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getTarget() |
||||
{ |
||||
return $this->target; |
||||
} |
||||
|
||||
/** |
||||
* Set category |
||||
* |
||||
* @param string $category |
||||
* @return CTool |
||||
*/ |
||||
public function setCategory($category) |
||||
{ |
||||
$this->category = $category; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get category |
||||
* |
||||
* @return string |
||||
*/ |
||||
public function getCategory() |
||||
{ |
||||
return $this->category; |
||||
} |
||||
|
||||
/** |
||||
* Set sessionId |
||||
* |
||||
* @param integer $sessionId |
||||
* @return CTool |
||||
*/ |
||||
public function setSessionId($sessionId) |
||||
{ |
||||
$this->sessionId = $sessionId; |
||||
|
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* Get sessionId |
||||
* |
||||
* @return integer |
||||
*/ |
||||
public function getSessionId() |
||||
{ |
||||
return $this->sessionId; |
||||
} |
||||
|
||||
public function getCustomIcon() |
||||
{ |
||||
return $this->customIcon; |
||||
} |
||||
|
||||
public function setCustomIcon($customIcon) |
||||
{ |
||||
$this->customIcon = $customIcon; |
||||
return $this; |
||||
} |
||||
|
||||
public function getDescription() |
||||
{ |
||||
return $this->description; |
||||
} |
||||
|
||||
public function setDescription($description) |
||||
{ |
||||
$this->description = $description; |
||||
return $this; |
||||
} |
||||
|
||||
/** |
||||
* @param \Imagine\Image\ImagineInterface $imagine |
||||
* @return bool |
||||
*/ |
||||
public function createGrayIcon($imagine) |
||||
{ |
||||
if (empty($this->getCustomIcon())) { |
||||
return false; |
||||
} |
||||
if (file_exists($this->getAbsolutePath())) { |
||||
$image = $imagine->open($this->getAbsolutePath()); |
||||
$fileInfo = pathinfo($this->getAbsolutePath()); |
||||
$originalFilename = $fileInfo['basename']; |
||||
$filename = $fileInfo['filename'].'_na.'.$fileInfo['extension']; |
||||
$newPath = str_replace($originalFilename, $filename, $this->getAbsolutePath()); |
||||
$transformation = new \Imagine\Filter\Advanced\Grayscale(); |
||||
$transformation->apply($image)->save($newPath); |
||||
} |
||||
} |
||||
|
||||
public function imageGifToPng() |
||||
{ |
||||
return str_replace('.gif', '.png', $this->getImage()); |
||||
} |
||||
} |
||||
@ -0,0 +1,97 @@ |
||||
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} |
||||
{% block content %} |
||||
|
||||
<script> |
||||
$(document).ready(function() { |
||||
$(".make_visible_and_invisible").attr("href", "javascript:void(0);"); |
||||
$(".make_visible_and_invisible > img").click(function () { |
||||
|
||||
var make_visible = "visible.gif"; |
||||
var make_invisible = "invisible.gif"; |
||||
var path_name = $(this).attr("src"); |
||||
var list_path_name = path_name.split("/"); |
||||
var image_link = list_path_name[list_path_name.length - 1]; |
||||
var tool_id = $(this).attr("id"); |
||||
var tool_info = tool_id.split("_"); |
||||
var my_tool_id = tool_info[1]; |
||||
|
||||
$.ajax({ |
||||
contentType: "application/x-www-form-urlencoded", |
||||
beforeSend: function(data) { |
||||
$(".normal-message").show(); |
||||
$("#id_confirmation_message").hide(); |
||||
}, |
||||
type: "GET", |
||||
url: "{{ _p.web_ajax }}course_home.ajax.php?cidReq={{ course.code }}&a=set_visibility", |
||||
data: "id=" + my_tool_id + "&sent_http_request=1", |
||||
success: function(data) { |
||||
eval("var info=" + data); |
||||
var new_current_tool_image = info.image; |
||||
var new_current_view = "{{ _p.web_img}}" + info.view; |
||||
// Eyes |
||||
$("#" + tool_id).attr("src", new_current_view); |
||||
|
||||
// Tool |
||||
$("#toolimage_" + my_tool_id).attr("src", new_current_tool_image); |
||||
|
||||
// Class |
||||
$("#tooldesc_" + my_tool_id).attr("class", info.tclass); |
||||
$("#istooldesc_" + my_tool_id).attr("class", info.tclass); |
||||
|
||||
if (image_link == "visible.gif") { |
||||
$("#" + tool_id).attr("alt", "{{ 'Activate' | trans }}"); |
||||
$("#" + tool_id).attr("title", "{{ 'Activate' | trans }}"); |
||||
} else { |
||||
$("#" + tool_id).attr("alt", "{{ 'Deactivate' | trans }}"); |
||||
$("#" + tool_id).attr("title", "{{ 'Deactivate' | trans }}"); |
||||
} |
||||
if (info.message == "is_active") { |
||||
message = "{{ 'ToolIsNowVisible' | trans }}"; |
||||
} else { |
||||
message = "{{ 'ToolIsNowHidden' | trans }}"; |
||||
} |
||||
$(".normal-message").hide(); |
||||
$("#id_confirmation_message").html(message); |
||||
$("#id_confirmation_message").show(); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
/* toogle for post-it in course home */ |
||||
$(function() { |
||||
$(".thematic-postit-head").click(function() { |
||||
$(".thematic-postit-center").slideToggle("fast"); |
||||
}); |
||||
}); |
||||
|
||||
</script> |
||||
|
||||
<div class="courseadminview" style="border:0px; margin-top: 0px;padding:0px;"> |
||||
<div class="normal-message" id="id_normal_message" style="display:none"> |
||||
<img src="{{ _p.web_img }}loading1.gif" /> |
||||
{{ 'PleaseStandBy' | trans }} |
||||
</div> |
||||
<div class="confirmation-message" id="id_confirmation_message" style="display:none"> |
||||
</div> |
||||
</div> |
||||
|
||||
{% if session_info %} |
||||
<div class="courseadminview"> |
||||
<span class="viewcaption">{{ 'SessionData' | trans }}</span> |
||||
<table class="course_activity_home"> |
||||
{{ session_info }} |
||||
</table> |
||||
</div> |
||||
{% endif %} |
||||
|
||||
{{ lp_warning }} |
||||
{{ exercise_warning }} |
||||
{{ introduction_text }} |
||||
{{ edit_icons }} |
||||
|
||||
<div id="course_tools"> |
||||
{{ icons }} |
||||
</div> |
||||
|
||||
{% endblock %} |
||||
@ -0,0 +1,7 @@ |
||||
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} |
||||
{% block content %} |
||||
{% import app.template_style ~ "/crud_macros/course_crud.tpl" as actions %} |
||||
<form action="{{ url('course_home.controller:editIconAction', {'course': course.code, 'id_session' : session.id, itemId : item.id }) }}" method = "post" {{ form_enctype(form) }}> |
||||
{{ form_widget(form) }} |
||||
</form> |
||||
{% endblock %} |
||||
@ -0,0 +1,34 @@ |
||||
{% extends app.template_style ~ "/layout/layout_1_col.tpl" %} |
||||
|
||||
{% block content %} |
||||
<table class="table"> |
||||
{% for item in items %} |
||||
<tr> |
||||
<td> |
||||
<a href="{{ url(links.read_link, {'course' : course.code, 'id_session': course_session.id, id: item.id }) }}"> |
||||
{% if item.customIcon %} |
||||
<img src="{{ url('getCourseUploadFileAction', { courseCode:course.code, file: 'course_home_icons/'~item.customIcon}) }}"/> |
||||
{% else %} |
||||
<img src="{{ _p.web_img ~ 'icons/64/' ~ item.imageGifToPng }}"/> |
||||
{% endif %} |
||||
</a> |
||||
</td> |
||||
<td> |
||||
<a href="{{ url(links.read_link, {'course' : course.code, 'id_session': course_session.id, id: item.id }) }}"> |
||||
{{ item.name }} |
||||
</a> |
||||
</td> |
||||
<td> |
||||
<a class="btn" href="{{ url(links.update_link, {'course' : course.code, 'id_session': course_session.id, id: item.id }) }}"> |
||||
{{ 'Edit' | trans }} |
||||
</a> |
||||
{% if item.customIcon %} |
||||
<a class="btn" href="{{ url('course_home.controller:deleteIconAction', {'course' : course.code, 'id_session': course_session.id, itemId: item.id }) }}"> |
||||
{{ 'Delete' |trans }} |
||||
</a> |
||||
{% endif %} |
||||
</td> |
||||
</tr> |
||||
{% endfor %} |
||||
</table> |
||||
{% endblock %} |
||||
@ -1,125 +0,0 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
namespace ChamiloLMS\Controller; |
||||
|
||||
use Silex\Application; |
||||
use Symfony\Component\HttpFoundation\Response; |
||||
|
||||
/** |
||||
* Class CourseHomeController |
||||
* @package ChamiloLMS\Controller |
||||
* @author Julio Montoya <gugli100@gmail.com> |
||||
*/ |
||||
class CourseHomeController |
||||
{ |
||||
public $language_files = array('course_home','courses'); |
||||
|
||||
public function indexAction(Application $app, $cidReq, $idSession = null) |
||||
{ |
||||
$extraJS = array(); |
||||
//@todo improve this JS includes should be added using twig |
||||
$extraJS[] ='<script> |
||||
$(document).ready(function() { |
||||
$(".make_visible_and_invisible").attr("href", "javascript:void(0);"); |
||||
$(".make_visible_and_invisible > img").click(function () { |
||||
|
||||
make_visible = "visible.gif"; |
||||
make_invisible = "invisible.gif"; |
||||
path_name = $(this).attr("src"); |
||||
list_path_name = path_name.split("/"); |
||||
image_link = list_path_name[list_path_name.length - 1]; |
||||
tool_id = $(this).attr("id"); |
||||
tool_info = tool_id.split("_"); |
||||
my_tool_id = tool_info[1]; |
||||
|
||||
$.ajax({ |
||||
contentType: "application/x-www-form-urlencoded", |
||||
beforeSend: function(objeto) { |
||||
$(".normal-message").show(); |
||||
$("#id_confirmation_message").hide(); |
||||
}, |
||||
type: "GET", |
||||
url: "'.api_get_path(WEB_AJAX_PATH).'course_home.ajax.php?'.api_get_cidreq().'&a=set_visibility", |
||||
data: "id=" + my_tool_id + "&sent_http_request=1", |
||||
success: function(data) { |
||||
eval("var info=" + data); |
||||
new_current_tool_image = info.image; |
||||
new_current_view = "'.api_get_path(WEB_IMG_PATH).'" + info.view; |
||||
//eyes |
||||
$("#" + tool_id).attr("src", new_current_view); |
||||
//tool |
||||
$("#toolimage_" + my_tool_id).attr("src", new_current_tool_image); |
||||
//clase |
||||
$("#tooldesc_" + my_tool_id).attr("class", info.tclass); |
||||
$("#istooldesc_" + my_tool_id).attr("class", info.tclass); |
||||
|
||||
if (image_link == "visible.gif") { |
||||
$("#" + tool_id).attr("alt", "'.get_lang('Activate', '').'"); |
||||
$("#" + tool_id).attr("title", "'.get_lang('Activate', '').'"); |
||||
} else { |
||||
$("#" + tool_id).attr("alt", "'.get_lang('Deactivate', '').'"); |
||||
$("#" + tool_id).attr("title", "'.get_lang('Deactivate', '').'"); |
||||
} |
||||
if (info.message == "is_active") { |
||||
message = "'.get_lang('ToolIsNowVisible', '').'"; |
||||
} else { |
||||
message = "'.get_lang('ToolIsNowHidden', '').'"; |
||||
} |
||||
$(".normal-message").hide(); |
||||
$("#id_confirmation_message").html(message); |
||||
$("#id_confirmation_message").show(); |
||||
} |
||||
}); |
||||
}); |
||||
}); |
||||
|
||||
/* toogle for post-it in course home */ |
||||
$(function() { |
||||
$(".thematic-postit-head").click(function() { |
||||
$(".thematic-postit-center").slideToggle("fast"); |
||||
}); |
||||
}); |
||||
|
||||
</script>'; |
||||
|
||||
$app['extraJS'] = $extraJS; |
||||
|
||||
//Needed because of this script: |
||||
$course_code = $cidReq; |
||||
$result = require_once api_get_path(SYS_CODE_PATH).'course_home/course_home.php'; |
||||
$app['template']->assign('content', $result['content']); |
||||
$app['template']->assign('message', $result['message']); |
||||
|
||||
$response = $app['template']->renderLayout('layout_1_col.tpl'); |
||||
return new Response($response, 200, array()); |
||||
} |
||||
|
||||
/** |
||||
* @param Application $app |
||||
* @param $courseCode |
||||
* @param $fileName |
||||
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||||
*/ |
||||
public function getFileAction(Application $app, $courseCode, $fileName) |
||||
{ |
||||
$courseInfo = api_get_course_info($courseCode); |
||||
$sessionId = $app['request']->get('id_session'); |
||||
|
||||
$docId = \DocumentManager::get_document_id($courseInfo, "/".$fileName); |
||||
|
||||
$filePath = null; |
||||
|
||||
if ($docId) { |
||||
$isVisible = \DocumentManager::is_visible_by_id($docId, $courseInfo, $sessionId, api_get_user_id()); |
||||
$documentData = \DocumentManager::get_document_data_by_id($docId, $courseCode); |
||||
$filePath = $documentData['absolute_path']; |
||||
event_download($filePath); |
||||
} |
||||
|
||||
if (!api_is_allowed_to_edit() && !$isVisible) { |
||||
$app->abort(500); |
||||
} |
||||
//DocumentManager::file_send_for_download($full_file_name); |
||||
return $app->sendFile($filePath); |
||||
} |
||||
} |
||||
@ -0,0 +1,469 @@ |
||||
<?php |
||||
/* For licensing terms, see /license.txt */ |
||||
|
||||
namespace ChamiloLMS\Controller\Tool\CourseHome; |
||||
|
||||
use Silex\Application; |
||||
use Symfony\Component\HttpFoundation\Response; |
||||
use ChamiloLMS\Controller\CommonController; |
||||
use Symfony\Component\Routing\Annotation\Route; |
||||
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method; |
||||
use Entity\CTool; |
||||
use ChamiloLMS\Form\CourseHomeToolType; |
||||
use \Display; |
||||
|
||||
/** |
||||
* Class CourseHomeController |
||||
* @package ChamiloLMS\Controller |
||||
* @author Julio Montoya <gugli100@gmail.com> |
||||
*/ |
||||
class CourseHomeController extends CommonController |
||||
{ |
||||
/** |
||||
* @Route("/courses/{cidReq}/{sessionId}") |
||||
* @Method({"GET"}) |
||||
* |
||||
* @param string $cidReq |
||||
* @param int $id_session |
||||
* @return Response |
||||
*/ |
||||
public function indexAction($cidReq, $id_session = null) |
||||
{ |
||||
api_protect_course_script(true); |
||||
|
||||
$courseCode = api_get_course_id(); |
||||
$sessionId = api_get_session_id(); |
||||
$userId = $this->getUser()->getUserId(); |
||||
|
||||
$coursesAlreadyVisited = $this->getRequest()->getSession()->get('coursesAlreadyVisited'); |
||||
|
||||
$result = $this->autolaunch(); |
||||
|
||||
$show_autolaunch_lp_warning = $result['show_autolaunch_lp_warning']; |
||||
$show_autolaunch_exercise_warning = $result['show_autolaunch_exercise_warning']; |
||||
|
||||
if ($show_autolaunch_lp_warning) { |
||||
$this->getTemplate()->assign( |
||||
'lp_warning', |
||||
Display::return_message(get_lang('TheLPAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificLP'), 'warning') |
||||
); |
||||
} |
||||
if ($show_autolaunch_exercise_warning) { |
||||
$this->getTemplate()->assign( |
||||
'exercise_warning', |
||||
Display::return_message(get_lang('TheExerciseAutoLaunchSettingIsONStudentsWillBeRedirectToAnSpecificExercise'), 'warning') |
||||
); |
||||
} |
||||
|
||||
$editIcons = Display::url( |
||||
Display::return_icon('edit.png'), |
||||
$this->generateUrl('course_home.controller:iconListAction', array('course' => api_get_course_id())) |
||||
); |
||||
$this->getTemplate()->assign('edit_icons', $editIcons); |
||||
|
||||
|
||||
if (!isset($coursesAlreadyVisited[$courseCode])) { |
||||
event_access_course(); |
||||
$coursesAlreadyVisited[$courseCode] = 1; |
||||
$this->getRequest()->getSession()->set('coursesAlreadyVisited', $coursesAlreadyVisited); |
||||
} |
||||
|
||||
$introduction = Display::return_introduction_section( |
||||
$this->get('url_generator'), |
||||
TOOL_COURSE_HOMEPAGE, |
||||
array( |
||||
'CreateDocumentWebDir' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/document/', |
||||
'CreateDocumentDir' => 'document/', |
||||
'BaseHref' => api_get_path(WEB_COURSE_PATH).api_get_course_path().'/' |
||||
) |
||||
); |
||||
|
||||
$this->getTemplate()->assign('introduction_text', $introduction); |
||||
$this->getRequest()->getSession()->remove('toolgroup'); |
||||
$this->getRequest()->getSession()->remove('_gid'); |
||||
|
||||
$isSpecialCourse = \CourseManager::is_special_course($courseCode); |
||||
|
||||
if ($isSpecialCourse) { |
||||
$autoreg = $this->getRequest()->get('autoreg'); |
||||
if ($autoreg == 1) { |
||||
\CourseManager::subscribe_user($userId, $courseCode, STUDENT); |
||||
} |
||||
} |
||||
|
||||
$script = 'activity.php'; |
||||
if (api_get_setting('homepage_view') == 'activity' || api_get_setting('homepage_view') == 'activity_big') { |
||||
$script = 'activity.php'; |
||||
} elseif (api_get_setting('homepage_view') == '2column') { |
||||
$script = '2column.php'; |
||||
} elseif (api_get_setting('homepage_view') == '3column') { |
||||
$script = '3column.php'; |
||||
} elseif (api_get_setting('homepage_view') == 'vertical_activity') { |
||||
$script = 'vertical_activity.php'; |
||||
} |
||||
|
||||
$result = require_once api_get_path(SYS_CODE_PATH).'course_home/'.$script; |
||||
$this->getTemplate()->assign('icons', $result); |
||||
|
||||
if (api_get_setting('show_session_data') == 'true' && $sessionId) { |
||||
$sessionInfo = \CourseHome::show_session_data($sessionId); |
||||
$this->getTemplate()->assign('session_info', $sessionInfo); |
||||
} |
||||
|
||||
$response = $this->get('template')->render_template($this->getTemplatePath().'index.tpl'); |
||||
|
||||
return new Response($response, 200, array()); |
||||
} |
||||
|
||||
private function autolaunch() |
||||
{ |
||||
$show_autolaunch_exercise_warning = false; |
||||
|
||||
// Exercise auto-launch |
||||
$auto_launch = api_get_course_setting('enable_exercise_auto_launch'); |
||||
|
||||
if (!empty($auto_launch)) { |
||||
$session_id = api_get_session_id(); |
||||
//Exercise list |
||||
if ($auto_launch == 2) { |
||||
if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
||||
$show_autolaunch_exercise_warning = true; |
||||
} else { |
||||
$session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||||
if (!isset($_SESSION[$session_key])) { |
||||
//redirecting to the Exercise |
||||
$url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&id_session='.$session_id; |
||||
$_SESSION[$session_key] = true; |
||||
header("Location: $url"); |
||||
exit; |
||||
} |
||||
} |
||||
} else { |
||||
$table = Database::get_course_table(TABLE_QUIZ_TEST); |
||||
$course_id = api_get_course_int_id(); |
||||
$condition = ''; |
||||
if (!empty($session_id)) { |
||||
$condition = api_get_session_condition($session_id); |
||||
$sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1"; |
||||
$result = Database::query($sql); |
||||
//If we found nothing in the session we just called the session_id = 0 autolaunch |
||||
if (Database::num_rows($result) == 0) { |
||||
$condition = ''; |
||||
} else { |
||||
//great, there is an specific auto lunch for this session we leave the $condition |
||||
} |
||||
} |
||||
|
||||
$sql = "SELECT iid FROM $table WHERE c_id = $course_id AND autolaunch = 1 $condition LIMIT 1"; |
||||
$result = Database::query($sql); |
||||
if (Database::num_rows($result) > 0) { |
||||
$data = Database::fetch_array($result,'ASSOC'); |
||||
if (!empty($data['iid'])) { |
||||
if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
||||
$show_autolaunch_exercise_warning = true; |
||||
} else { |
||||
$session_key = 'exercise_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||||
if (!isset($_SESSION[$session_key])) { |
||||
//redirecting to the LP |
||||
$url = api_get_path(WEB_CODE_PATH).'exercice/overview.php?'.api_get_cidreq().'&exerciseId='.$data['iid']; |
||||
|
||||
$_SESSION[$session_key] = true; |
||||
header("Location: $url"); |
||||
exit; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
/* Auto launch code */ |
||||
$show_autolaunch_lp_warning = false; |
||||
$auto_launch = api_get_course_setting('enable_lp_auto_launch'); |
||||
if (!empty($auto_launch)) { |
||||
$session_id = api_get_session_id(); |
||||
//LP list |
||||
if ($auto_launch == 2) { |
||||
if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
||||
$show_autolaunch_lp_warning = true; |
||||
} else { |
||||
$session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||||
if (!isset($_SESSION[$session_key])) { |
||||
//redirecting to the LP |
||||
$url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&id_session='.$session_id; |
||||
$_SESSION[$session_key] = true; |
||||
header("Location: $url"); |
||||
exit; |
||||
} |
||||
} |
||||
} else { |
||||
$lp_table = Database::get_course_table(TABLE_LP_MAIN); |
||||
$course_id = api_get_course_int_id(); |
||||
$condition = ''; |
||||
if (!empty($session_id)) { |
||||
$condition = api_get_session_condition($session_id); |
||||
$sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1"; |
||||
$result = Database::query($sql); |
||||
//If we found nothing in the session we just called the session_id = 0 autolunch |
||||
if (Database::num_rows($result) == 0) { |
||||
$condition = ''; |
||||
} else { |
||||
//great, there is an specific auto lunch for this session we leave the $condition |
||||
} |
||||
} |
||||
|
||||
$sql = "SELECT id FROM $lp_table WHERE c_id = $course_id AND autolunch = 1 $condition LIMIT 1"; |
||||
$result = Database::query($sql); |
||||
if (Database::num_rows($result) > 0) { |
||||
$lp_data = Database::fetch_array($result,'ASSOC'); |
||||
if (!empty($lp_data['id'])) { |
||||
if (api_is_platform_admin() || api_is_allowed_to_edit()) { |
||||
$show_autolaunch_lp_warning = true; |
||||
} else { |
||||
$session_key = 'lp_autolunch_'.$session_id.'_'.api_get_course_int_id().'_'.api_get_user_id(); |
||||
if (!isset($_SESSION[$session_key])) { |
||||
//redirecting to the LP |
||||
$url = api_get_path(WEB_CODE_PATH).'newscorm/lp_controller.php?'.api_get_cidreq().'&action=view&lp_id='.$lp_data['id']; |
||||
|
||||
$_SESSION[$session_key] = true; |
||||
header("Location: $url"); |
||||
exit; |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
} |
||||
|
||||
return array( |
||||
'show_autolaunch_exercise_warning' => $show_autolaunch_exercise_warning, |
||||
'show_autolaunch_lp_warning' => $show_autolaunch_lp_warning |
||||
); |
||||
} |
||||
|
||||
/** |
||||
* @param string $courseCode |
||||
* @param string $fileName |
||||
* @return \Symfony\Component\HttpFoundation\BinaryFileResponse |
||||
*/ |
||||
public function getFileAction($courseCode, $fileName) |
||||
{ |
||||
$courseInfo = api_get_course_info($courseCode); |
||||
$sessionId = $this->getRequest()->get('id_session'); |
||||
|
||||
$docId = \DocumentManager::get_document_id($courseInfo, "/".$fileName); |
||||
|
||||
$filePath = null; |
||||
|
||||
if ($docId) { |
||||
$isVisible = \DocumentManager::is_visible_by_id($docId, $courseInfo, $sessionId, api_get_user_id()); |
||||
$documentData = \DocumentManager::get_document_data_by_id($docId, $courseCode); |
||||
$filePath = $documentData['absolute_path']; |
||||
event_download($filePath); |
||||
} |
||||
|
||||
if (!api_is_allowed_to_edit() && !$isVisible) { |
||||
$this->abort(500); |
||||
} |
||||
return $this->sendFile($filePath); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/show/{iconId}") |
||||
* @Method({"GET"}) |
||||
* @param $iconId |
||||
* @return null|string |
||||
*/ |
||||
public function showIconAction($iconId) |
||||
{ |
||||
if (!api_is_allowed_to_edit(null, true)) { |
||||
return null; |
||||
} |
||||
$entityManager = $this->getManager(); |
||||
$criteria = array('cId' => api_get_course_int_id(), 'id' => $iconId); |
||||
$tool = $this->getRepository('Entity\CTool')->findOneBy($criteria); |
||||
if ($tool) { |
||||
$tool->setVisibility(1); |
||||
} |
||||
$entityManager->persist($tool); |
||||
//$entityManager->flush(); |
||||
return Display::return_message(get_lang('Visible'), 'confirmation'); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/hide/{iconId}") |
||||
* @Method({"GET"}) |
||||
* @param $iconId |
||||
* @return null|string |
||||
*/ |
||||
public function hideIconAction($iconId) |
||||
{ |
||||
if (!api_is_allowed_to_edit(null, true)) { |
||||
return null; |
||||
} |
||||
|
||||
$entityManager = $this->getManager(); |
||||
$criteria = array('cId' => api_get_course_int_id(), 'id' => $iconId); |
||||
$tool = $this->getRepository('Entity\CTool')->findOneBy($criteria); |
||||
if ($tool) { |
||||
$tool->setVisibility(0); |
||||
} |
||||
$entityManager->persist($tool); |
||||
//$entityManager->flush(); |
||||
return Display::return_message(get_lang('ToolIsNowHidden'), 'confirmation'); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/delete/{iconId}") |
||||
* @Method({"GET"}) |
||||
* @param $iconId |
||||
* @return null|string |
||||
*/ |
||||
public function deleteIcon($iconId) |
||||
{ |
||||
if (!api_is_allowed_to_edit(null, true)) { |
||||
return null; |
||||
} |
||||
|
||||
$entityManager = $this->getManager(); |
||||
$criteria = array('cId' => api_get_course_int_id(), 'id' => $iconId, 'added_tool' => 1); |
||||
$tool = $this->getRepository('Entity\CTool')->findOneBy($criteria); |
||||
$entityManager->remove($tool); |
||||
//$entityManager->flush(); |
||||
return Display::return_message(get_lang('Deleted'), 'confirmation'); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/icon_list") |
||||
* @Method({"GET"}) |
||||
*/ |
||||
public function iconListAction() |
||||
{ |
||||
$criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => 0); |
||||
$items = $this->getRepository()->findBy($criteria); |
||||
|
||||
$this->getTemplate()->assign('items', $items); |
||||
$this->getTemplate()->assign('links', $this->generateLinks()); |
||||
return $this->get('template')->render_template($this->getTemplatePath().'tool/list.tpl'); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/{itemId}/edit") |
||||
* @Method({"GET"}) |
||||
*/ |
||||
public function editIconAction($itemId) |
||||
{ |
||||
$sessionId = $this->getRequest()->get('id_session'); |
||||
|
||||
$criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => 0, 'id' => $itemId); |
||||
/** @var CTool $item */ |
||||
$item = $this->getRepository()->findOneBy($criteria); |
||||
$item->setSessionId($sessionId); |
||||
|
||||
$form = $this->createForm($this->getFormType(), $item); |
||||
$form->handleRequest($this->getRequest()); |
||||
|
||||
if ($form->isValid()) { |
||||
$sessionId = $item->getSessionId(); |
||||
$entityManager = $this->getManager(); |
||||
|
||||
if (!empty($sessionId)) { |
||||
$criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => $sessionId, 'id' => $itemId); |
||||
/** @var CTool $item */ |
||||
$itemFromDb = $this->getRepository()->findOneBy($criteria); |
||||
if (empty($itemFromDb)) { |
||||
$newTool = clone $item; |
||||
|
||||
$query = $this->getManager()->createQueryBuilder('a'); |
||||
$query->select('MAX(s.id) as id'); |
||||
$query->from('Entity\CTool', 's'); |
||||
$query->where('s.cId = :courseId')->setParameter('courseId', $this->getCourse()->getId()); |
||||
$result = $query->getQuery()->getArrayResult(); |
||||
$maxId = $result[0]['id'] + 1; |
||||
$newTool->setId($maxId); |
||||
} else { |
||||
$newTool = $item; |
||||
} |
||||
$entityManager->persist($newTool); |
||||
} else { |
||||
$entityManager->persist($item); |
||||
} |
||||
|
||||
$entityManager->flush(); |
||||
|
||||
if (!empty($item->getCustomIcon())) { |
||||
$item->createGrayIcon($this->get('imagine')); |
||||
} |
||||
|
||||
$this->get('session')->getFlashBag()->add('success', "Updated"); |
||||
$url = $this->generateUrl('course_home.controller:iconListAction'); |
||||
return $this->redirect($url); |
||||
} |
||||
|
||||
$this->getTemplate()->assign('item', $item); |
||||
$this->getTemplate()->assign('form', $form->createView()); |
||||
$this->getTemplate()->assign('links', $this->generateLinks()); |
||||
return $this->get('template')->render_template($this->getTemplatePath().'tool/edit.tpl'); |
||||
} |
||||
|
||||
/** |
||||
* @Route("/{itemId}/delete") |
||||
* @Method({"GET"}) |
||||
*/ |
||||
public function deleteIconAction($itemId) |
||||
{ |
||||
$criteria = array('cId' => $this->getCourse()->getId(), 'sessionId' => 0, 'id' => $itemId); |
||||
/** @var CTool $item */ |
||||
$item = $this->getRepository()->findOneBy($criteria); |
||||
|
||||
$item->setCustomIcon(null); |
||||
|
||||
$entityManager = $this->getManager(); |
||||
$entityManager->persist($item); |
||||
$entityManager->flush(); |
||||
|
||||
$this->get('session')->getFlashBag()->add('success', "Deleted"); |
||||
|
||||
$this->getTemplate()->assign('links', $this->generateLinks()); |
||||
$url = $this->generateUrl('course_home.controller:iconListAction'); |
||||
return $this->redirect($url); |
||||
} |
||||
|
||||
protected function getControllerAlias() |
||||
{ |
||||
return 'course_home.controller'; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
protected function getTemplatePath() |
||||
{ |
||||
return 'tool/course_home/'; |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
protected function getRepository() |
||||
{ |
||||
return $this->get('orm.em')->getRepository('Entity\CTool'); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
protected function getNewEntity() |
||||
{ |
||||
return new CTool(); |
||||
} |
||||
|
||||
/** |
||||
* {@inheritdoc} |
||||
*/ |
||||
protected function getFormType() |
||||
{ |
||||
return new CourseHomeToolType(); |
||||
} |
||||
|
||||
} |
||||
@ -0,0 +1,48 @@ |
||||
<?php |
||||
|
||||
namespace ChamiloLMS\Form; |
||||
|
||||
use Symfony\Component\Form\AbstractType; |
||||
use Symfony\Component\Form\FormBuilderInterface; |
||||
use Symfony\Component\OptionsResolver\OptionsResolverInterface; |
||||
use Entity; |
||||
use Symfony\Component\Validator\Constraints as Assert; |
||||
|
||||
class CourseHomeToolType extends AbstractType |
||||
{ |
||||
/** |
||||
* @param FormBuilderInterface $builder |
||||
* @param array $options |
||||
*/ |
||||
public function buildForm(FormBuilderInterface $builder, array $options) |
||||
{ |
||||
$builder->add('name', 'text'); |
||||
$builder->add('link', 'text'); |
||||
$builder->add( |
||||
'custom_icon', |
||||
'file', |
||||
array('required' => false, 'data_class' => null) |
||||
); |
||||
$builder->add('target', 'choice', array('choices' => array('_self', '_blank'))); |
||||
$builder->add('visibility', 'choice', array('choices' => array('1', '0'))); |
||||
$builder->add('c_id', 'hidden'); |
||||
$builder->add('session_id', 'hidden'); |
||||
|
||||
$builder->add('description', 'textarea'); |
||||
$builder->add('submit', 'submit'); |
||||
} |
||||
|
||||
public function setDefaultOptions(OptionsResolverInterface $resolver) |
||||
{ |
||||
$resolver->setDefaults( |
||||
array( |
||||
'data_class' => 'Entity\CTool' |
||||
) |
||||
); |
||||
} |
||||
|
||||
public function getName() |
||||
{ |
||||
return 'courseHomeTool'; |
||||
} |
||||
} |
||||
Loading…
Reference in new issue