Chamilo is a learning management system focused on ease of use and accessibility
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.
chamilo-lms/public/main/inc/lib/course_description.lib.php

545 lines
16 KiB

<?php
/* For licensing terms, see /license.txt */
/**
* This file contains a class used like library provides functions for
* course description tool. It's also used like model to
* course_description_controller (MVC pattern).
*
* @author Christian Fasanando <christian1827@gmail.com>
*/
use Chamilo\CoreBundle\Framework\Container;
use Chamilo\CourseBundle\Entity\CCourseDescription;
/**
* Class CourseDescription course descriptions.
*/
class CourseDescription
{
private $id;
private $course_id;
private $title;
private $content;
private $session_id;
private $description_type;
private $progress;
/**
* Constructor.
*/
public function __construct()
{
}
/**
* Returns an array of objects of type CourseDescription corresponding to
* a specific course, without session ids (session id = 0).
*
* @param int $course_id
*
* @return array Array of CourseDescriptions
*/
public static function get_descriptions($course_id)
11 years ago
{
$course_id = (int) $course_id;
// Get course code
$course_info = api_get_course_info_by_id($course_id);
if (!empty($course_info)) {
$course_id = $course_info['real_id'];
} else {
return [];
}
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$sql = "SELECT * FROM $table";
$sql_result = Database::query($sql);
$results = [];
while ($row = Database::fetch_array($sql_result)) {
$desc_tmp = new CourseDescription();
$desc_tmp->set_id($row['iid']);
$desc_tmp->set_title($row['title']);
$desc_tmp->set_content($row['content']);
$desc_tmp->set_session_id($row['session_id']);
$desc_tmp->set_description_type($row['description_type']);
$desc_tmp->set_progress($row['progress']);
$results[] = $desc_tmp;
}
return $results;
}
/**
* Get all data of course description by session id,
* first you must set session_id property with the object CourseDescription.
*
* @return CCourseDescription[]
*/
public function get_description_data()
{
$repo = Container::getCourseDescriptionRepository();
$course_id = $this->course_id ?: api_get_course_int_id();
$course = api_get_course_entity($course_id);
$session = api_get_session_entity($this->session_id);
$qb = $repo->getResourcesByCourse($course, $session);
return $qb->getQuery()->getResult();
/*$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$condition_session = api_get_session_condition(
$this->session_id,
true,
true
);
if (empty($course_id)) {
return [];
}
$sql = "SELECT * FROM $table
5 years ago
ORDER BY iid ";
$rs = Database::query($sql);
$data = [];
while ($description = Database::fetch_array($rs)) {
$data['descriptions'][$description['iid']] = $description;
}
return $data;*/
}
/**
* Get all data by description and session id,
* first you must set session_id property with the object CourseDescription.
*
* @param int $description_type Description type
* @param string $courseId Course code (optional)
* @param int $session_id Session id (optional)
*
* @return array List of fields from the descriptions found of the given type
*/
public function get_data_by_description_type(
$description_type,
$courseId = null,
$session_id = null
) {
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$courseId = (int) $courseId;
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
if (!isset($session_id)) {
$session_id = $this->session_id;
}
$condition_session = api_get_session_condition($session_id);
$description_type = (int) $description_type;
$sql = "SELECT * FROM $table
WHERE
description_type = '$description_type'
";
$rs = Database::query($sql);
$data = [];
if ($description = Database::fetch_array($rs)) {
$data['description_title'] = $description['title'];
$data['description_content'] = $description['content'];
$data['progress'] = $description['progress'];
$data['iid'] = $description['iid'];
}
return $data;
}
11 years ago
/**
* @param int $id
11 years ago
* @param string $course_code
* @param int $session_id
*
11 years ago
* @return array
*/
public function get_data_by_id($id, $course_code = '', $session_id = null)
{
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$id = (int) $id;
if (!isset($session_id)) {
$session_id = $this->session_id;
}
$condition_session = api_get_session_condition($session_id);
if (!empty($course_code)) {
$course_info = api_get_course_info($course_code);
$course_id = $course_info['real_id'];
}
$sql = "SELECT * FROM $table
WHERE iid='$id' ";
$rs = Database::query($sql);
$data = [];
if ($description = Database::fetch_array($rs)) {
$data['description_type'] = $description['description_type'];
$data['description_title'] = $description['title'];
$data['description_content'] = $description['content'];
$data['progress'] = $description['progress'];
}
11 years ago
return $data;
}
/**
11 years ago
* Get maximum description type by session id,
* first you must set session_id properties with the object CourseDescription.
*
* @return int maximum description time adding one
*/
public function get_max_description_type()
11 years ago
{
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "SELECT MAX(description_type) as MAX
FROM $table
";
$rs = Database::query($sql);
$max = Database::fetch_array($rs);
if ($max['MAX'] >= 8) {
$description_type = 8;
} else {
$description_type = $max['MAX'] + 1;
}
if ($description_type < ADD_BLOCK) {
$description_type = ADD_BLOCK;
}
return $description_type;
}
/**
* Insert a description to the course_description table,
11 years ago
* first you must set description_type, title, content, progress and
* session_id properties with the object CourseDescription.
*
* @return int affected rows
*/
public function insert()
{
if (empty($this->course_id)) {
$course_id = api_get_course_int_id();
} else {
$course_id = $this->course_id;
}
$courseDescription = new CCourseDescription();
$courseDescription
->setTitle($this->title)
->setContent($this->content)
->setProgress((int) $this->progress)
->setDescriptionType($this->description_type)
;
$course = api_get_course_entity($course_id);
$session = api_get_session_entity($this->session_id);
$courseDescription->setParent($course);
$courseDescription->addCourseLink($course, $session);
$repo = Container::getCourseDescriptionRepository();
$repo->create($courseDescription);
return true;
}
/**
* Update a description, first you must set description_type, title, content, progress
* and session_id properties with the object CourseDescription.
*
* @return int affected rows
*/
public function update()
{
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$params = [
'title' => $this->title,
'content' => $this->content,
10 years ago
'progress' => intval($this->progress),
];
Database::update(
$table,
$params,
[
'id = ? AND session_id = ? AND c_id = ?' => [
$this->id,
$this->session_id,
$this->course_id ? $this->course_id : api_get_course_int_id(),
],
]
);
if ($this->id > 0) {
// Insert into item_property
11 years ago
api_item_property_update(
api_get_course_info(),
TOOL_COURSE_DESCRIPTION,
$this->id,
'CourseDescriptionUpdated',
api_get_user_id()
);
}
return 1;
}
/**
11 years ago
* Delete a description, first you must set description_type and session_id
* properties with the object CourseDescription.
*
* @return int affected rows
*/
public function delete($id)
{
$repo = Container::getCourseDescriptionRepository();
/** @var CCourseDescription $courseDescription */
$courseDescription = $repo->find($id);
if ($courseDescription) {
$repo->delete($courseDescription);
return true;
}
11 years ago
return false;
}
/**
* Get description titles by default.
*
* @return array
*/
public function get_default_description_title()
{
$default_description_titles = [];
$default_description_titles[1] = get_lang('Description');
$default_description_titles[2] = get_lang('Objectives');
$default_description_titles[3] = get_lang('Topics');
$default_description_titles[4] = get_lang('Methodology');
$default_description_titles[5] = get_lang('Course material');
$default_description_titles[6] = get_lang('Resources');
$default_description_titles[7] = get_lang('Assessment');
$default_description_titles[8] = get_lang('Other');
return $default_description_titles;
}
/**
* Get description titles editable by default.
*
* @return array
*/
public function get_default_description_title_editable()
11 years ago
{
$default_description_title_editable = [];
$default_description_title_editable[1] = true;
$default_description_title_editable[2] = true;
$default_description_title_editable[3] = true;
$default_description_title_editable[4] = true;
$default_description_title_editable[5] = true;
$default_description_title_editable[6] = true;
$default_description_title_editable[7] = true;
//$default_description_title_editable[8] = true;
return $default_description_title_editable;
}
/**
* Get description icons by default.
*
* @return array
*/
public function get_default_description_icon()
11 years ago
{
$default_description_icon = [];
$default_description_icon[1] = 'info.png';
$default_description_icon[2] = 'objective.png';
$default_description_icon[3] = 'topics.png';
$default_description_icon[4] = 'strategy.png';
$default_description_icon[5] = 'laptop.png';
$default_description_icon[6] = 'teacher.png';
$default_description_icon[7] = 'assessment.png';
$default_description_icon[8] = 'wizard.png';
return $default_description_icon;
}
/**
* Get questions by default for help.
*
* @return array
*/
public function get_default_question()
11 years ago
{
$question = [];
$question[1] = get_lang('DescriptionQuestions');
$question[2] = get_lang('What should the end results be when the learner has completed the course? What are the activities performed during the course?');
$question[3] = get_lang('How does the course progress? Where should the learner pay special care? Are there identifiable problems in understanding different areas? How much time should one dedicate to the different areas of the course?');
$question[4] = get_lang('What methods and activities help achieve the objectives of the course? What would the schedule be?');
$question[5] = get_lang('Course materialQuestions');
$question[6] = get_lang('ResourcesQuestions');
$question[7] = get_lang('How will learners be assessed? Are there strategies to develop in order to master the topic?');
//$question[8]= get_lang('What is the current progress you have reached with your learners inside your course? How much do you think is remaining in comparison to the complete program?');
return $question;
}
/**
* Get informations by default for help.
*
* @return array
*/
public function get_default_information()
11 years ago
{
$information = [];
$information[1] = get_lang('DescriptionInformation');
$information[2] = get_lang('What are the objectives of the course (competences, skills, outcomes)?');
$information[3] = get_lang('List of topics included in the training. Importance of each topic. Level of difficulty. Structure and inter-dependence of the different parts.');
$information[4] = get_lang('Presentation of the activities (conference, papers, group research, labs...).');
$information[5] = get_lang('Course materialInformation');
$information[6] = get_lang('ResourcesInformation');
$information[7] = get_lang('Criteria for skills acquisition.');
//$information[8]= get_lang('The thematic advance tool allows you to organize your course through time.');
return $information;
}
/**
* Set description id.
*/
public function set_id($id)
11 years ago
{
$this->id = $id;
}
/**
* Set description's course id.
*
* @param int $id Course ID
*/
11 years ago
public function set_course_id($id)
{
$this->course_id = intval($id);
}
/**
* Set description title.
*
* @param string $title
*/
public function set_title($title)
11 years ago
{
$this->title = $title;
}
/**
* Set description content.
*
* @param string $content
*/
public function set_content($content)
11 years ago
{
$this->content = $content;
}
/**
* Set description session id.
*
* @param int $session_id
*/
public function set_session_id($session_id)
11 years ago
{
$this->session_id = $session_id;
}
/**
* Set description type.
*/
public function set_description_type($description_type)
11 years ago
{
$this->description_type = $description_type;
}
/**
* Set progress of a description.
*
* @param string $progress
*/
public function set_progress($progress)
11 years ago
{
$this->progress = $progress;
}
/**
* get description id.
*
* @return int
*/
public function get_id()
11 years ago
{
return $this->id;
}
/**
* get description title.
*
* @return string
*/
public function get_title()
11 years ago
{
return $this->title;
}
/**
* get description content.
*
* @return string
*/
public function get_content()
11 years ago
{
return $this->content;
}
/**
* get session id.
*
* @return int
*/
public function get_session_id()
11 years ago
{
return $this->session_id;
}
/**
* get description type.
*
* @return int
*/
public function get_description_type()
11 years ago
{
return $this->description_type;
}
/**
* get progress of a description.
*
* @return int
*/
public function get_progress()
11 years ago
{
return $this->progress;
}
}