Add requirements/dependencies in the session catalog and resume session

See BT#9893
1.10.x
Julio Montoya 10 years ago
parent 944e60da23
commit 643d3e6c84
  1. 2
      main/admin/index.php
  2. 58
      main/auth/courses_controller.php
  3. 34
      main/session/resume_session.php
  4. 48
      main/template/default/auth/session_catalog.tpl
  5. 35
      src/Chamilo/CoreBundle/Entity/Repository/SequenceRepository.php

@ -352,7 +352,7 @@ if (api_is_platform_admin()) {
} }
$items[] = array('url' => 'archive_cleanup.php', 'label' => get_lang('ArchiveDirCleanup')); $items[] = array('url' => 'archive_cleanup.php', 'label' => get_lang('ArchiveDirCleanup'));
$items[] = array('url' => 'resource_sequence.php', 'label' => get_lang('ResourceSequencing')); $items[] = array('url' => 'resource_sequence.php', 'label' => get_lang('ResourcesSequencing'));
if (isset($_configuration['db_manager_enabled']) && if (isset($_configuration['db_manager_enabled']) &&
$_configuration['db_manager_enabled'] == true && $_configuration['db_manager_enabled'] == true &&

@ -1,10 +1,13 @@
<?php <?php
/* For licensing terms, see /license.txt */ /* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\SequenceResource;
/** /**
* Class CoursesController * Class CoursesController
* *
* This file contains class used like controller, it should be included inside a dispatcher file (e.g: index.php) * This file contains class used like controller,
* it should be included inside a dispatcher file (e.g: index.php)
* @author Christian Fasanando <christian1827@gmail.com> - BeezNest * @author Christian Fasanando <christian1827@gmail.com> - BeezNest
* @package chamilo.auth * @package chamilo.auth
*/ */
@ -39,7 +42,8 @@ class CoursesController
$data['user_courses'] = $this->model->get_courses_of_user($user_id); $data['user_courses'] = $this->model->get_courses_of_user($user_id);
$data['user_course_categories'] = $this->model->get_user_course_categories(); $data['user_course_categories'] = $this->model->get_user_course_categories();
$data['courses_in_category'] = $this->model->get_courses_in_category(); $data['courses_in_category'] = $this->model->get_courses_in_category();
$data['all_user_categories'] = $this->model->get_user_course_categories(); $data['all_user_categories'] = $this->model->get_user_course_categories(
);
$data['action'] = $action; $data['action'] = $action;
$data['message'] = $message; $data['message'] = $message;
@ -197,7 +201,10 @@ class CoursesController
{ {
$courseInfo = api_get_course_info($course_code); $courseInfo = api_get_course_info($course_code);
// The course must be open in order to access the auto subscription // The course must be open in order to access the auto subscription
if (in_array($courseInfo['visibility'], array(COURSE_VISIBILITY_CLOSED, COURSE_VISIBILITY_REGISTERED, COURSE_VISIBILITY_HIDDEN))) { if (in_array(
$courseInfo['visibility'],
array(COURSE_VISIBILITY_CLOSED, COURSE_VISIBILITY_REGISTERED, COURSE_VISIBILITY_HIDDEN))
) {
$error = get_lang('SubscribingNotAllowed'); $error = get_lang('SubscribingNotAllowed');
//$message = get_lang('SubscribingNotAllowed'); //$message = get_lang('SubscribingNotAllowed');
} else { } else {
@ -216,6 +223,7 @@ class CoursesController
} else { } else {
$this->courses_categories('subscribe', $category_code, $message, $error, $content); $this->courses_categories('subscribe', $category_code, $message, $error, $content);
} }
return $result; return $result;
} }
@ -459,25 +467,18 @@ class CoursesController
$html .= "$subCategory3Name ($subCategory3Courses)"; $html .= "$subCategory3Name ($subCategory3Courses)";
$html .= '</a>'; $html .= '</a>';
} }
$html .= '</li>'; $html .= '</li>';
} }
$html .= '</ul>'; $html .= '</ul>';
} }
$html .= '</li>'; $html .= '</li>';
} }
$html .= '</ul>'; $html .= '</ul>';
} }
$html .= '</li>'; $html .= '</li>';
} }
$html .= '</ul>'; $html .= '</ul>';
} }
$html .= '</li>'; $html .= '</li>';
} }
} }
@ -547,8 +548,6 @@ class CoursesController
*/ */
public function sessionsList($action, $nameTools, $limit = array()) public function sessionsList($action, $nameTools, $limit = array())
{ {
global $_configuration;
$date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d'); $date = isset($_POST['date']) ? $_POST['date'] : date('Y-m-d');
$hiddenLinks = isset($_GET['hidden_links']) ? intval($_GET['hidden_links']) == 1 : false; $hiddenLinks = isset($_GET['hidden_links']) ? intval($_GET['hidden_links']) == 1 : false;
@ -590,34 +589,43 @@ class CoursesController
$session[$key], $session[$key],
$catalogSessionAutoSubscriptionAllowed $catalogSessionAutoSubscriptionAllowed
), ),
'showDescription' => $session['show_description'] 'show_description' => $session['show_description'],
);
/** @var SequenceRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
$requirementAndDependencies = $repo->getRequirementAndDependencies(
$session['id'],
SequenceResource::SESSION_TYPE
); );
$sessionsBlock = array_merge($sessionsBlock, $requirementAndDependencies);
$sessionsBlocks[] = $sessionsBlock; $sessionsBlocks[] = $sessionsBlock;
} }
$tpl = new Template(); $tpl = new Template();
$tpl->assign('action', $action); $tpl->assign('action', $action);
$tpl->assign('showCourses', CoursesAndSessionsCatalog::showCourses()); $tpl->assign('show_courses', CoursesAndSessionsCatalog::showCourses());
$tpl->assign('showSessions', CoursesAndSessionsCatalog::showSessions()); $tpl->assign('show_sessions', CoursesAndSessionsCatalog::showSessions());
$tpl->assign('showTutor', (api_get_setting('show_session_coach')==='true' ? true : false)); $tpl->assign('show_tutor', (api_get_setting('show_session_coach')==='true' ? true : false));
$tpl->assign('api_get_self', api_get_self()); $tpl->assign('api_get_self', api_get_self());
$tpl->assign('sessionUrl', $sessionUrl); //$tpl->assign('session_url', $sessionUrl);
$tpl->assign('courseUrl', $courseUrl); $tpl->assign('course_url', $courseUrl);
$tpl->assign('nameTools', $nameTools); $tpl->assign('nameTools', $nameTools);
$tpl->assign('coursesCategoriesList', $this->getCoursesCategoriesBlock(null, false, $limit)); $tpl->assign('course_category_list', $this->getCoursesCategoriesBlock(null, false, $limit));
$tpl->assign('cataloguePagination', $cataloguePagination); $tpl->assign('catalog_pagination', $cataloguePagination);
$tpl->assign('hiddenLinks', $hiddenLinks); $tpl->assign('hidden_links', $hiddenLinks);
$tpl->assign('searchToken', Security::get_token()); $tpl->assign('search_token', Security::get_token());
$tpl->assign('searchDate', $date); $tpl->assign('search_date', $date);
$tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH) . 'course.ajax.php'); $tpl->assign('web_session_courses_ajax_url', api_get_path(WEB_AJAX_PATH) . 'course.ajax.php');
$tpl->assign('sessions_blocks', $sessionsBlocks); $tpl->assign('sessions', $sessionsBlocks);
$tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel()); $tpl->assign('already_subscribed_label', $this->getAlreadyRegisteredInSessionLabel());
$contentTemplate = $tpl->get_template('auth/sessions_catalog.tpl'); $contentTemplate = $tpl->get_template('auth/session_catalog.tpl');
$tpl->display($contentTemplate); $tpl->display($contentTemplate);
} }

@ -494,40 +494,18 @@ if (!empty($userList)) {
$table->display(); $table->display();
} }
// @todo put this in a function
/** @var SequenceRepository $repo */ /** @var SequenceRepository $repo */
$repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource'); $repo = Database::getManager()->getRepository('ChamiloCoreBundle:SequenceResource');
$sequence = $repo->findRequirementForResource($sessionId, SequenceResource::SESSION_TYPE); $requirementAndDependencies = $repo->getRequirementAndDependencies($sessionId, SequenceResource::SESSION_TYPE);
if ($sequence->hasGraph()) {
$graph = $sequence->getUnserializeGraph();
$vertex = $graph->getVertex($sessionId);
$from = $vertex->getVerticesEdgeFrom();
$sessionNameList = [];
foreach ($from as $subVertex) {
$vertexId = $subVertex->getId();
$sessionInfo = api_get_session_info($vertexId);
$sessionNameList[] = $sessionInfo['name'];
}
if (!empty($sessionNameList)) { if (!empty($requirementAndDependencies['requirements'])) {
echo Display::page_subheader(get_lang('Requirements')); echo Display::page_subheader(get_lang('Requirements'));
echo implode(',', $sessionNameList); echo implode(',', array_column($requirementAndDependencies['requirements'], 'name'));
} }
$to = $vertex->getVerticesEdgeTo();
$sessionNameList = [];
foreach ($to as $subVertex) {
$vertexId = $subVertex->getId();
$sessionInfo = api_get_session_info($vertexId);
$sessionNameList[] = $sessionInfo['name'];
}
if (!empty($sessionNameList)) { if (!empty($requirementAndDependencies['dependencies'])) {
echo Display::page_subheader(get_lang('Dependencies')); echo Display::page_subheader(get_lang('Dependencies'));
echo implode(',', $sessionNameList); echo implode(',', array_column($requirementAndDependencies['dependencies'], 'name'));
}
} }
Display :: display_footer(); Display :: display_footer();

@ -52,12 +52,12 @@
</script> </script>
<div class="col-md-3"> <div class="col-md-3">
{% if showCourses %} {% if show_courses %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-body"> <div class="panel-body">
{% if not hiddenLinks %} {% if not hidden_links %}
<form class="form-search" method="post" action="{{ courseUrl }}"> <form class="form-search" method="post" action="{{ course_url }}">
<input type="hidden" name="sec_token" value="{{ searchToken }}"> <input type="hidden" name="sec_token" value="{{ search_token }}">
<input type="hidden" name="search_course" value="1" /> <input type="hidden" name="search_course" value="1" />
<div class="form-group"> <div class="form-group">
<input type="text" name="search_term" class="form-control"/> <input type="text" name="search_term" class="form-control"/>
@ -66,7 +66,7 @@
</form> </form>
{% endif %} {% endif %}
{% if coursesCategoriesList is not empty %} {% if course_category_list is not empty %}
<a class="btn btn-block btn-default" href="{{ api_get_self }}?action=display_random_courses">{{ 'RandomPick' | get_lang }}</a> <a class="btn btn-block btn-default" href="{{ api_get_self }}?action=display_random_courses">{{ 'RandomPick' | get_lang }}</a>
{% endif %} {% endif %}
</div> </div>
@ -88,7 +88,7 @@
{% endif %} {% endif %}
{% endif %} {% endif %}
{% if showSessions %} {% if show_sessions %}
<div class="sidebar-nav"> <div class="sidebar-nav">
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
@ -97,7 +97,7 @@
<div class="panel-body"> <div class="panel-body">
<form class="form-search" method="post" action="{{ api_get_self }}?action=display_sessions"> <form class="form-search" method="post" action="{{ api_get_self }}?action=display_sessions">
<div class="form-group"> <div class="form-group">
<input type="date" name="date" id="date" class="form-control" value="{{ searchDate }}" readonly> <input type="date" name="date" id="date" class="form-control" value="{{ search_date }}" readonly>
<button class="btn btn-block btn-default" type="submit"><i class="fa fa-search"></i> {{ 'Search' | get_lang }}</button> <button class="btn btn-block btn-default" type="submit"><i class="fa fa-search"></i> {{ 'Search' | get_lang }}</button>
</div> </div>
</form> </form>
@ -107,7 +107,7 @@
{% endif %} {% endif %}
</div> </div>
<div class="col-md-9"> <div class="col-md-9">
{% for session in sessions_blocks %} {% for session in sessions %}
<div class="panel panel-default" id="panel-{{ session.id }}"> <div class="panel panel-default" id="panel-{{ session.id }}">
<div class="panel-heading"> <div class="panel-heading">
@ -116,20 +116,40 @@
<div class="panel-body"> <div class="panel-body">
<div class="row"> <div class="row">
<div class="col-md-9"> <div class="col-md-9">
{% if showTutor %} {% if show_tutor %}
<div class="tutor"> <div class="tutor">
<img src="{{ 'teacher.png' | icon(22) }}" width="16"> {{ 'GeneralCoach' | get_lang }} {{ session.coach_name }} <img src="{{ 'teacher.png' | icon(22) }}" width="16">
{{ 'GeneralCoach' | get_lang }} {{ session.coach_name }}
</div> </div>
{% endif %} {% endif %}
{% if session.requirements %}
<h4>{{ 'Requirements' | get_lang }}</h4>
{% for requirement in session.requirements %}
{{ requirement.name }}
{% endfor %}
{% endif %}
{% if session.dependencies %}
<h4>{{ 'Dependencies' | get_lang }}</h4>
{% for dependency in session.dependencies %}
{{ dependency.name }}
{% endfor %}
{% endif %}
<a id="list-course" class="btn btn-default" data-toggle="collapse" href="#session-{{ session.id }}-courses"> <a id="list-course" class="btn btn-default" data-toggle="collapse" href="#session-{{ session.id }}-courses">
{{ 'CourseList' | get_lang }} {{ 'CourseList' | get_lang }}
</a> </a>
<div class="collapse" id="session-{{ session.id }}-courses"> <div class="collapse" id="session-{{ session.id }}-courses">
<div class="list"></div> <div class="list"></div>
</div> </div>
</div> </div>
<div class="col-md-3"> <div class="col-md-3">
{% if session.showDescription %} {% if session.show_description %}
<div class="buttom-subscribed"> <div class="buttom-subscribed">
<a class="ajax btn btn-large btn-info" href="{{ _p.web_ajax }}session.ajax.php?a=get_description&session={{ session.id }}"> <a class="ajax btn btn-large btn-info" href="{{ _p.web_ajax }}session.ajax.php?a=get_description&session={{ session.id }}">
{{ 'Description' | get_lang }} {{ 'Description' | get_lang }}
@ -144,14 +164,16 @@
{{ session.subscribe_button }} {{ session.subscribe_button }}
{% endif %} {% endif %}
</div> </div>
<div class="time"><img src="{{ 'agenda.png' | icon(22) }}"> {{ session.date }}</div> <div class="time">
<img src="{{ 'agenda.png' | icon(22) }}"> {{ session.date }}
</div>
</div> </div>
</div> </div>
</div> </div>
</div> </div>
{% endfor %} {% endfor %}
{{ cataloguePagination }} {{ catalog_pagination }}
</div> </div>
{% endblock %} {% endblock %}

@ -31,6 +31,41 @@ class SequenceRepository extends EntityRepository
return $this->findOneBy(['resourceId' => $resourceId, 'type' => $type]); return $this->findOneBy(['resourceId' => $resourceId, 'type' => $type]);
} }
/**
* @todo implement for all types only work for sessions
*
* @param int $resourceId
* @param int $type
*
* @return array
*/
public function getRequirementAndDependencies($resourceId, $type)
{
$sequence = $this->findRequirementForResource($resourceId, $type);
$result = ['requirements' => '', 'dependencies' => ''];
if ($sequence && $sequence->hasGraph()) {
$graph = $sequence->getUnserializeGraph();
$vertex = $graph->getVertex($resourceId);
$from = $vertex->getVerticesEdgeFrom();
foreach ($from as $subVertex) {
$vertexId = $subVertex->getId();
$sessionInfo = api_get_session_info($vertexId);
$result['requirements'][] = $sessionInfo;
}
$to = $vertex->getVerticesEdgeTo();
foreach ($to as $subVertex) {
$vertexId = $subVertex->getId();
$sessionInfo = api_get_session_info($vertexId);
$result['dependencies'][] = $sessionInfo;
}
}
return $result;
}
/** /**
* Deletes a node and check in all the dependencies if the node exists in * Deletes a node and check in all the dependencies if the node exists in
* order to deleted. * order to deleted.

Loading…
Cancel
Save