Add portfolio tool - refs BT#14056 (#2455)

pull/2459/head
jmontoyaa 8 years ago
parent 1f1f7d774d
commit f2c684e43a
  1. 1
      .codeclimate.yml
  2. 1
      .gitignore
  3. 1
      .scrutinizer.yml
  4. 19
      app/config/portfolio.conf.dist.php
  5. 4
      main/document/document.php
  6. 1
      main/inc/global.inc.php
  7. 23
      main/inc/lib/add_course.lib.inc.php
  8. 1
      main/inc/lib/api.lib.php
  9. 653
      main/inc/lib/portfolio.class.php
  10. 30
      main/inc/lib/social.lib.php
  11. 12
      main/install/configuration.dist.php
  12. 1
      main/install/install.lib.php
  13. 4
      main/install/install_files.inc.php
  14. 223
      main/portfolio/index.php
  15. 14
      main/portfolio/share.php
  16. 8
      main/work/work.lib.php
  17. 1
      src/Chamilo/CoreBundle/Composer/ScriptHandler.php

@ -89,7 +89,6 @@ exclude_patterns:
- main/inc/lib/pear/ - main/inc/lib/pear/
- main/inc/lib/phpmailer/ - main/inc/lib/phpmailer/
- main/inc/lib/phpseclib/ - main/inc/lib/phpseclib/
- main/inc/lib/portfolio.class.php
- main/inc/lib/svg-edit/ - main/inc/lib/svg-edit/
- main/inc/lib/swfobject/ - main/inc/lib/swfobject/
- main/inc/lib/wami-recorder/ - main/inc/lib/wami-recorder/

1
.gitignore vendored

@ -13,7 +13,6 @@ app/logs/*
/app/config/course_info.conf.php /app/config/course_info.conf.php
/app/config/events.conf.php /app/config/events.conf.php
/app/config/mail.conf.php /app/config/mail.conf.php
/app/config/portfolio.conf.php
/app/config/profile.conf.php /app/config/profile.conf.php
/app/config/configuration.php /app/config/configuration.php

@ -49,7 +49,6 @@ filter:
- 'main/inc/lib/pear/*' - 'main/inc/lib/pear/*'
- 'main/inc/lib/phpmailer/*' - 'main/inc/lib/phpmailer/*'
- 'main/inc/lib/phpseclib/*' - 'main/inc/lib/phpseclib/*'
- 'main/inc/lib/portfolio.class.php'
- 'main/inc/lib/svg-edit/*' - 'main/inc/lib/svg-edit/*'
- 'main/inc/lib/swfobject/*' - 'main/inc/lib/swfobject/*'
- 'main/inc/lib/wami-recorder/*' - 'main/inc/lib/wami-recorder/*'

@ -1,19 +0,0 @@
<?php
/*
* This file contains the portfolios configuration.
*
* Portfolios are external applicatoins used to display and share files. The
* portfolio configuration set up where files can be sent.
*
* @see \Portfolio
*/
$portfolios = array();
//$_mahara_portfolio = new Portfolio\Mahara('http(s)://...');
//$portfolios[] = $_mahara_portfolio;
//$download_portfolio = new Portfolio\Download();
//$download_portfolio->set_title(get_lang('Download'));
//$portfolios[] = $download_portfolio;

@ -2097,10 +2097,6 @@ if (count($documentAndFolders) > 1) {
$form_action['set_invisible'] = get_lang('SetInvisible'); $form_action['set_invisible'] = get_lang('SetInvisible');
$form_action['set_visible'] = get_lang('SetVisible'); $form_action['set_visible'] = get_lang('SetVisible');
$form_action['delete'] = get_lang('Delete'); $form_action['delete'] = get_lang('Delete');
/*$portfolio_actions = Portfolio::actions();
foreach ($portfolio_actions as $action) {
$form_action[$action->get_name()] = $action->get_title();
}*/
$table->set_form_actions($form_action, 'ids'); $table->set_form_actions($form_action, 'ids');
} }
} }

@ -321,7 +321,6 @@ $configurationFiles = [
'add_course.conf.php', 'add_course.conf.php',
'events.conf.php', 'events.conf.php',
'auth.conf.php', 'auth.conf.php',
'portfolio.conf.php',
]; ];
foreach ($configurationFiles as $file) { foreach ($configurationFiles as $file) {

@ -553,6 +553,29 @@ class AddCourse
api_get_setting('course_create_active_tools', 'notebook') api_get_setting('course_create_active_tools', 'notebook')
)."','0','squaregrey.gif',0,'_self','interaction','0')" )."','0','squaregrey.gif',0,'_self','interaction','0')"
); );
if (api_get_configuration_value('allow_portfolio_tool')) {
$tId = Database::insert(
$tbl_course_homepage,
[
'c_id' => $course_id,
'name' => 'portfolio',
'link' => 'portfolio/index.php',
'image' => 'wiki_task.png',
'visibility' => api_get_setting('course_create_active_tools', 'portfolio') == 'true' ? 1 : 0,
'admin' => 0,
'address' => 'squaregrey.gif',
'added_tool' => 0,
'target' => '_self',
'category' => 'interaction',
'session_id' => 0,
]
);
Database::update(
$tbl_course_homepage,
['id' => $tId],
['iid = ?' => $tId]
);
}
$setting = intval(self::string2binary( $setting = intval(self::string2binary(
api_get_setting('course_create_active_tools', 'attendances') api_get_setting('course_create_active_tools', 'attendances')

@ -148,6 +148,7 @@ define('TOOL_GRADEBOOK', 'gradebook');
define('TOOL_NOTEBOOK', 'notebook'); define('TOOL_NOTEBOOK', 'notebook');
define('TOOL_ATTENDANCE', 'attendance'); define('TOOL_ATTENDANCE', 'attendance');
define('TOOL_COURSE_PROGRESS', 'course_progress'); define('TOOL_COURSE_PROGRESS', 'course_progress');
define('TOOL_PORTFOLIO', 'portfolio');
// CONSTANTS defining Chamilo interface sections // CONSTANTS defining Chamilo interface sections
define('SECTION_CAMPUS', 'mycampus'); define('SECTION_CAMPUS', 'mycampus');

@ -1,653 +0,0 @@
<?php
/* For licensing terms, see /license.txt */
/*
* This file contains several classes related to portfolios management to avoid
* having too much files under the lib/.
*
* Once external libraries are moved to their own directory it would be worth
* moving them to their own files under a common portfolio directory.
* @package chamilo.portfolio
* @deprecated
*/
/**
* Init.
*/
use Model\Course;
use Model\Document;
/**
* A portfolio is used to present content to other people. In most cases it is
* an external application.
*
* From the application point of view it is an end point to which the user can send
* content.
*
* Available portfolios are configured in /main/inc/config/portfolio.conf.php
*
* The Portfolio class serves as an entry point to other portfolio components:
*
* - portfolio controller
* - portfolio share button
* - portfolio action
*
* Note:
*
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
//class Portfolio extends Portfolio\Portfolio
class Portfolio
{
/**
* Returns all portfolios available.
*
* @return array
*/
public static function all()
{
$conf = api_get_path(SYS_CODE_PATH).'inc/conf/portfolio.conf.php';
if (!is_readable($conf)) {
return [];
}
include $conf;
return isset($portfolios) ? $portfolios : [];
}
/**
* Returns a portfolio from its name.
*
* @param string $name
*
* @return Portfolio\Portfolio
*/
public static function get($name)
{
$items = self::all();
foreach ($items as $item) {
if ($item->get_name() == $name) {
return $item;
}
}
return Portfolio\Portfolio::none();
}
/**
* True if portfolios are enabled. False otherwise.
*
* @return bool
*/
public static function is_enabled()
{
if (api_is_anonymous()) {
return false;
}
$user_id = api_get_user_id();
if (empty($user_id)) {
return false;
}
$portfolios = self::all();
if (count($portfolios) == 0) {
return false;
}
return true;
}
/**
* The controller for portfolio.
*
* @return \PortfolioController
*/
public static function controller()
{
return PortfolioController::instance();
}
/**
* Returns a share component/button.
*
* @param string $tool
* @param int $id
* @param array $attributes
*
* @return \PortfolioShare
*/
public static function share($tool, $id, $attributes = [])
{
return PortfolioShare::factory($tool, $id, $attributes);
}
/**
* Returns the list of actions.
*
* @return array
*/
public static function actions()
{
return PortfolioController::actions();
}
/**
* Returns a temporary url to download files and/or folders.
*
* @param string|array $ids
*
* @return string
*/
public static function download_url($ids, $tool)
{
$ids = is_array($ids) ? implode(',', $ids) : $ids;
$params = Uri::course_params();
$params['id'] = $ids;
$params[KeyAuth::PARAM_ACCESS_TOKEN] = KeyAuth::create_temp_token();
$result = Uri::url("/main/$tool/file.php", $params, false);
return $result;
}
}
/**
* The portfolio controller. Responsible to dispatch/process portfolio actions.
*
* Usage:
*
* if(Porfolio::contoller()->accept()){
* Portfolio::controller()->run();
* }
*/
class PortfolioController
{
const PARAM_ACTION = 'action';
const PARAM_ID = 'id';
const PARAM_TOOL = 'tool';
const PARAM_PORTFOLIO = 'portfolio';
const PARAM_CONTROLLER = 'controller';
const PARAM_SECURITY_TOKEN = 'sec_token';
const ACTION_SHARE = 'share';
const NAME = 'portfolio';
protected $message = '';
protected function __construct()
{
}
/**
* @return \PortfolioController
*/
public static function instance()
{
static $result = null;
if (empty($result)) {
$result = new self();
}
return $result;
}
public static function portfolios()
{
return Portfolio::all();
}
/**
* List of actions for the SortableTable.
*
* @return array
*/
public static function actions()
{
static $result = null;
if (!is_null($result)) {
return $result;
}
$items = self::portfolios();
if (empty($items)) {
$result = [];
return $result;
}
$result = [];
foreach ($items as $item) {
$action = PortfolioBulkAction::create($item);
$result[] = $action;
}
return $result;
}
/**
* Returns true if the controller accept to process the current request.
* Returns false otherwise.
*
* @return bool
*/
public function accept()
{
if (!Portfolio::is_enabled()) {
return false;
}
$actions = self::actions();
foreach ($actions as $action) {
if ($action->accept()) {
return true;
}
}
if ($this->get_controller() != self::NAME) {
return false;
}
if (!Security::check_token('get')) {
return false;
}
$id = $this->get_id();
if (empty($id)) {
return false;
}
return $this->get_action() == self::ACTION_SHARE;
}
/**
* Returns the value of the current controller request parameters. That is
* the name of the controller which shall handle the current request.
*
* @return string
*/
public function get_controller()
{
return Request::get(self::PARAM_CONTROLLER);
}
/**
* Returns the value of the action parameter. That is which action shall be
* performed. That is share to send an object to a portfolio.
*
* @return string
*/
public function get_action()
{
$result = Request::get(self::PARAM_ACTION);
return ($result == self::ACTION_SHARE) ? self::ACTION_SHARE : '';
}
/**
* Returns the value of the id parameter: id of object to send.
*
* @return int
*/
public function get_id()
{
return (int) Request::get(self::PARAM_ID);
}
/**
* The course code (id) to which the object belongs.
*
* @return string
*/
public function course_code()
{
return ChamiloSession::instance()->course()->code();
}
/**
* The name of the porfolio where to send.
*
* @return type
*/
public function get_portfolio()
{
return Request::get(self::PARAM_PORTFOLIO);
}
/**
* Name of the tool: document, work, etc. Defaults to current_course_tool.
*
* @global string $current_course_tool
*
* @return string
*/
public function get_tool()
{
global $current_course_tool;
return Request::get(self::PARAM_TOOL, $current_course_tool);
}
/**
* Returns the end user message after running the controller..
*
* @return string
*/
public function message()
{
return $this->message;
}
/**
* Execute the controller action as required. If a registered action accept
* the current request the controller calls it.
*
* If not action is accept the current request and current action is "share"
* the controller execute the "send to portfolio" action
*
* @return PortfolioController
*/
public function run()
{
if (!$this->accept()) {
return $this;
}
$actions = self::actions();
foreach ($actions as $action) {
if ($action->accept()) {
return $action->run();
}
}
$action = $this->get_action();
if ($action == self::ACTION_SHARE) {
$user = new \Portfolio\User();
$user->email = Chamilo::user()->email();
$tool = $this->get_tool();
$id = $this->get_id();
$url = Portfolio::download_url($id, $tool);
$artefact = new Portfolio\Artefact($url);
$name = $this->get_portfolio();
$result = Portfolio::get($name)->send($user, $artefact);
if ($result) {
$this->message = Display::return_message(get_lang('SentSuccessfully'), 'normal');
} else {
$this->message = Display::return_message(get_lang('SentFailed'), 'error');
}
return $this;
} else {
$this->message = '';
}
return $this;
}
}
/**
* This component is used to display a "send to portfolio" button for a specific
* object.
*
* Note that the component implement the __toString() magic method and can be
* therefore used in situation where a string is expected: for ex echo $button.
*
* Usage
*
* $button = Portfolio::share(...);
* echo $button;
*/
class PortfolioShare
{
protected $id = 0;
protected $attributes = [];
protected $tool = '';
public function __construct($tool, $id, $attributes = [])
{
$this->tool = $tool;
$this->id = (int) $id;
$this->attributes = $attributes;
}
public function __toString()
{
return $this->display();
}
/**
* Create a "send to portfolio" button.
*
* @param string $tool the name of the tool: document, work
* @param int $c_id The id of the course
* @param int $id The id of the object
* @param array $attributes Html attributes
*
* @return \PortfolioShare
*/
public static function factory($tool, $id, $attributes = [])
{
$result = new self($tool, $id, $attributes);
return $result;
}
/**
* Returns the current secuirty token. Used to avoid see surfing attacks.
*
* @return type
*/
public static function security_token()
{
static $result = null;
if (empty($result)) {
$result = Security::get_token();
}
return $result;
}
/**
* Object id to send.
*
* @return int
*/
public function get_id()
{
return $this->id;
}
/**
* Object id to send.
*
* @return int
*/
public function get_c_id()
{
return $this->c_id;
}
/**
* Html attributes.
*
* @return array
*/
public function get_attributes()
{
return $this->attributes;
}
/**
* Name of the tool. I.e. the type of the id parameter. Can be document, work.
*
* @return string
*/
public function get_tool()
{
return $this->tool;
}
/**
* Display the component.
*
* @return string
*/
public function display()
{
if (!Portfolio::is_enabled()) {
return '';
}
$id = $this->id;
$tool = $this->tool;
$attributes = $this->attributes;
$attributes['z-index'] = 100000;
$s = ' ';
foreach ($attributes as $key => $value) {
$s .= $key.'="'.$value.'" ';
}
$result = [];
$result[] = '<span '.$s.' >';
$result[] = '<span class="dropdown" >';
$result[] = '<a href="#" data-toggle="dropdown" class="dropdown-toggle">';
$result[] = Display::return_icon('document_send.png', get_lang('Send'), [], ICON_SIZE_SMALL).'<b class="caret"></b>';
$result[] = '</a>';
$result[] = '<ul class="dropdown-menu">';
$portfolios = Portfolio::all();
foreach ($portfolios as $portfolio) {
$parameters = Uri::course_params();
$parameters[PortfolioController::PARAM_ACTION] = PortfolioController::ACTION_SHARE;
$parameters[PortfolioController::PARAM_CONTROLLER] = PortfolioController::NAME;
$parameters[PortfolioController::PARAM_PORTFOLIO] = $portfolio->get_name();
$parameters[PortfolioController::PARAM_SECURITY_TOKEN] = self::security_token();
$parameters[PortfolioController::PARAM_TOOL] = $this->get_tool();
$parameters[PortfolioController::PARAM_ID] = $id;
$parameters[PortfolioController::PARAM_TOOL] = $tool;
$url = api_get_path(WEB_CODE_PATH).'portfolio/share.php?';
$result[] = '<li>';
$result[] = '<a href="'.$url.'">'.$portfolio->get_title().'</a>';
$result[] = '</li>';
}
$result[] = '</ul>';
$result[] = '</span>';
$result[] = '</span>';
return implode("\n", $result);
}
}
/**
* A "send to this portfolio" action. Actions are used by the SortableTable to
* perform actions on a set of objects. An action is composed of.
*
* - a name
* - a title (displayed to the user)
* - code to execute
*
* Usage:
*
* $form_actions = array();
* $form_action['...'] = get_lang('...');
* $portfolio_actions = Portfolio::actions();
* foreach($portfolio_actions as $action){
* $form_action[$action->get_name()] = $action->get_title();
* }
* $table->set_form_actions($form_action, 'path');
*
* @see SortableTable
*/
class PortfolioBulkAction
{
protected $name = '';
protected $title = '';
protected $portfolio = null;
/**
* @param \Portfolio\Portfolio $portfolio
*/
public function __construct($portfolio)
{
$this->name = md5(__CLASS__).'_'.$portfolio->get_name();
$this->title = $portfolio->get_title() ? $portfolio->get_title() : get_lang('SendTo').' '.$portfolio->get_name();
$this->portfolio = $portfolio;
}
/**
* @param \Portfolio\Portfolio $portfolio
*
* @return PortfolioBulkAction
*/
public static function create($portfolio)
{
return new self($portfolio);
}
public function get_name()
{
return $this->name;
}
public function get_title()
{
return $this->title;
}
/**
* @return \Portfolio\Portfolio
*/
public function get_portfolio()
{
return $this->portfolio;
}
public function accept()
{
$name = $this->get_name();
$action = Request::get(PortfolioController::PARAM_ACTION);
if ($name != $action) {
return false;
}
$pathes = Request::get('path');
if (empty($pathes)) {
return false;
}
$course = Course::current();
if (empty($course)) {
return false;
}
return true;
}
public function run()
{
if (!$this->accept()) {
return false;
}
$course = Course::current();
$pathes = Request::get('path');
$pathes = is_array($pathes) ? $pathes : [$pathes];
$ids = [];
foreach ($pathes as $path) {
$doc = Document::get_by_path($course, $path);
if ($doc) {
$ids[] = $doc->get_id();
}
}
if (empty($ids)) {
return false;
}
$user = new \Portfolio\User();
$user->email = Chamilo::user()->email();
$artefact = new Portfolio\Artefact();
$artefact->url = Portfolio::download_url($ids);
$portfolio = $this->get_portfolio();
$result = $portfolio->send($user, $artefact);
return $result;
}
}

@ -924,6 +924,7 @@ class SocialManager extends UserManager
$messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL); $messagesIcon = Display::return_icon('sn-message.png', get_lang('Messages'), null, ICON_SIZE_SMALL);
$sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile')); $sharedProfileIcon = Display::return_icon('sn-profile.png', get_lang('ViewMySharedProfile'));
$searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL); $searchIcon = Display::return_icon('sn-search.png', get_lang('Search'), null, ICON_SIZE_SMALL);
$portfolioIcon = Display::return_icon('wiki_task.png', get_lang('Portfolio'));
$html = ''; $html = '';
$active = null; $active = null;
@ -1002,6 +1003,15 @@ class SocialManager extends UserManager
$myFiles = ''; $myFiles = '';
} }
$links .= $myFiles; $links .= $myFiles;
if (api_get_configuration_value('allow_portfolio_tool')) {
$links .= '
<li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'">
<a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php">
'.$portfolioIcon.' '.get_lang('Portfolio').'
</a>
</li>
';
}
$links .= '</ul>'; $links .= '</ul>';
$html .= Display::panelCollapse( $html .= Display::panelCollapse(
@ -1081,6 +1091,16 @@ class SocialManager extends UserManager
$myFiles = ''; $myFiles = '';
} }
$links .= $myFiles; $links .= $myFiles;
if (api_get_configuration_value('allow_portfolio_tool')) {
$links .= '
<li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'">
<a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php">
'.$portfolioIcon.' '.get_lang('Portfolio').'
</a>
</li>
';
}
} }
// My friend profile. // My friend profile.
@ -1106,6 +1126,16 @@ class SocialManager extends UserManager
] ]
); );
$links .= '</li>'; $links .= '</li>';
if (api_get_configuration_value('allow_portfolio_tool')) {
$links .= '
<li class="portoflio-icon '.($show == 'portfolio' ? 'active' : '').'">
<a href="'.api_get_path(WEB_CODE_PATH).'portfolio/index.php?user='.$user_id.'">
'.$portfolioIcon.' '.get_lang('Portfolio').'
</a>
</li>
';
}
} }
// Check if I already sent an invitation message // Check if I already sent an invitation message

@ -794,3 +794,15 @@ ALTER TABLE skill_rel_course ADD CONSTRAINT FK_E7CEC7FA613FECDF FOREIGN KEY (ses
// You need add a new option called "confirmation" to the registration settings // You need add a new option called "confirmation" to the registration settings
//INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_registration', 'confirmation', 'MailConfirmation'); //INSERT INTO settings_options (variable, value, display_text) VALUES ('allow_registration', 'confirmation', 'MailConfirmation');
// ------ (End) Custom DB changes // ------ (End) Custom DB changes
// Add a portfolio tool (duplicating the Notebook tool). Requires DB changes:
/*
CREATE TABLE portfolio (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, c_id INT DEFAULT NULL, session_id INT DEFAULT NULL, category_id INT DEFAULT NULL, title VARCHAR(255) NOT NULL, content LONGTEXT NOT NULL, creation_date DATETIME NOT NULL, update_date DATETIME NOT NULL, is_visible TINYINT(1) DEFAULT '1' NOT NULL, INDEX user (user_id), INDEX course (c_id), INDEX session (session_id), INDEX category (category_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
CREATE TABLE portfolio_category (id INT AUTO_INCREMENT NOT NULL, user_id INT NOT NULL, title VARCHAR(255) NOT NULL, description LONGTEXT DEFAULT NULL, is_visible TINYINT(1) DEFAULT '1' NOT NULL, INDEX user (user_id), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB;
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED106291D79BD3 FOREIGN KEY (c_id) REFERENCES course (id);
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062613FECDF FOREIGN KEY (session_id) REFERENCES session (id);
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED106212469DE2 FOREIGN KEY (category_id) REFERENCES portfolio_category (id);
ALTER TABLE portfolio_category ADD CONSTRAINT FK_7AC64359A76ED395 FOREIGN KEY (user_id) REFERENCES user (id);
*/
//$_configuration['allow_portfolio_tool'] = false;

@ -3223,7 +3223,6 @@ function migrateSwitch($fromVersion, $manager, $processFiles = true)
'add_course.conf.php', 'add_course.conf.php',
'events.conf.php', 'events.conf.php',
'auth.conf.php', 'auth.conf.php',
'portfolio.conf.php',
]; ];
error_log('Copy conf files'); error_log('Copy conf files');

@ -48,10 +48,6 @@ if (defined('SYSTEM_INSTALLATION')) {
api_get_path(CONFIGURATION_PATH).'auth.conf.dist.php', api_get_path(CONFIGURATION_PATH).'auth.conf.dist.php',
api_get_path(CONFIGURATION_PATH).'auth.conf.php' api_get_path(CONFIGURATION_PATH).'auth.conf.php'
); );
copy(
api_get_path(CONFIGURATION_PATH).'portfolio.conf.dist.php',
api_get_path(CONFIGURATION_PATH).'portfolio.conf.php'
);
} else { } else {
echo 'You are not allowed here !'.__FILE__; echo 'You are not allowed here !'.__FILE__;
} }

@ -1,5 +1,226 @@
<?php <?php
/** /**
* @license see /license.txt * @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/ */
use Chamilo\CoreBundle\Entity\Course;
use Chamilo\CoreBundle\Entity\Portfolio;
use Chamilo\CoreBundle\Entity\PortfolioCategory;
use Chamilo\CoreBundle\Entity\Session;
use Chamilo\UserBundle\Entity\User;
require_once __DIR__.'/../inc/global.inc.php';
api_block_anonymous_users();
if (false === api_get_configuration_value('allow_portfolio_tool')) {
api_not_allowed(true);
}
$em = Database::getManager();
$currentUserId = api_get_user_id();
$userId = isset($_GET['user']) ? (int) $_GET['user'] : $currentUserId;
/** @var User $user */
$user = api_get_user_entity($userId);
/** @var Course $course */
$course = $em->find('ChamiloCoreBundle:Course', api_get_course_int_id());
/** @var Session $session */
$session = $em->find('ChamiloCoreBundle:Session', api_get_session_id());
$action = isset($_GET['action']) ? $_GET['action'] : 'list';
$cidreq = api_get_cidreq();
$baseUrl = api_get_self().'?'.($cidreq ? $cidreq.'&' : '');
$allowEdit = $currentUserId == $user->getId();
if (isset($_GET['preview'])) {
$allowEdit = false;
}
$toolName = get_lang('Portfolio');
$actions = [];
$content = '';
/**
* Check if the portfolio item or category is valid for the current user.
*
* @param $item
*
* @return bool
*/
$isValid = function ($item) use ($user, $course, $session) {
if (!$item) {
return false;
}
if (get_class($item) == Portfolio::class) {
if ($session && $item->getSession()->getId() != $session->getId()) {
return false;
}
if ($course && $item->getCourse()->getId() != $course->getId()) {
return false;
}
}
if ($item->getUser()->getId() != $user->getId()) {
return false;
}
return true;
};
switch ($action) {
case 'add_category':
require 'add_category.php';
break;
case 'edit_category':
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$id) {
break;
}
/** @var PortfolioCategory $category */
$category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id);
if (!$isValid($category)) {
api_not_allowed(true);
}
require 'edit_category.php';
break;
case 'hide_category':
case 'show_category':
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$id) {
break;
}
/** @var PortfolioCategory $category */
$category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id);
if (!$isValid($category)) {
api_not_allowed(true);
}
$category->setIsVisible(!$category->isVisible());
$em->persist($category);
$em->flush();
Display::addFlash(
Display::return_message(get_lang('VisibilityChanged'), 'success')
);
header("Location: $baseUrl");
exit;
case 'delete_category':
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$id) {
break;
}
/** @var PortfolioCategory $category */
$category = $em->find('ChamiloCoreBundle:PortfolioCategory', $id);
if (!$isValid($category)) {
api_not_allowed(true);
}
$em->remove($category);
$em->flush();
Display::addFlash(
Display::return_message(get_lang('PortfolioItemDeleted'), 'success')
);
header("Location: $baseUrl");
exit;
case 'add_item':
require 'add_item.php';
break;
case 'edit_item':
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$id) {
break;
}
/** @var CPortfolio $item */
$item = $em->find('ChamiloCoreBundle:Portfolio', $id);
if (!$isValid($item)) {
api_not_allowed(true);
}
require 'edit_item.php';
break;
case 'hide_item':
case 'show_item':
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$id) {
break;
}
/** @var Portfolio $item */
$item = $em->find('ChamiloCoreBundle:Portfolio', $id);
if (!$isValid($item)) {
api_not_allowed(true);
}
$item->setIsVisible(!$item->isVisible());
$em->persist($item);
$em->flush();
Display::addFlash(
Display::return_message(get_lang('VisibilityChanged'), 'success')
);
header("Location: $baseUrl");
exit;
case 'delete_item':
$id = isset($_GET['id']) ? (int) $_GET['id'] : 0;
if (!$id) {
break;
}
/** @var Portfolio $item */
$item = $em->find('ChamiloCoreBundle:Portfolio', $id);
if (!$isValid($item)) {
api_not_allowed(true);
}
$em->remove($item);
$em->flush();
Display::addFlash(
Display::return_message(get_lang('PortfolioItemDeleted'), 'success')
);
header("Location: $baseUrl");
exit;
case 'list':
default:
require 'list.php';
}
/*
* View
*/
$this_section = $course ? SECTION_COURSES : SECTION_SOCIAL;
$actions = implode(PHP_EOL, $actions);
Display::display_header($toolName);
Display::display_introduction_section(TOOL_PORTFOLIO);
echo $actions ? Display::toolbarAction('portfolio-toolbar', [$actions]) : '';
echo Display::page_header($toolName);
echo $content;
Display::display_footer();

@ -1,14 +0,0 @@
<?php
/**
* @license see /license.txt
* @author Laurent Opprecht <laurent@opprecht.info> for the Univesity of Geneva
*/
require_once __DIR__.'/../inc/global.inc.php';
$has_access = api_protect_course_script();
if (!$has_access) {
exit;
}
Portfolio::controller()->run();

@ -2054,12 +2054,6 @@ function get_work_user_list(
$linkToDownload = '<a href="'.$url.'download.php?id='.$item_id.'&'.api_get_cidreq().'">'.$saveIcon.'</a> '; $linkToDownload = '<a href="'.$url.'download.php?id='.$item_id.'&'.api_get_cidreq().'">'.$saveIcon.'</a> ';
} }
$send_to = Portfolio::share(
'work',
$work['id'],
['style' => 'white-space:nowrap;']
);
$feedback = ''; $feedback = '';
$count = getWorkCommentCount($item_id, $course_info); $count = getWorkCommentCount($item_id, $course_info);
if (!is_null($count) && !empty($count)) { if (!is_null($count) && !empty($count)) {
@ -2238,7 +2232,7 @@ function get_work_user_list(
$qualificator_id = Display::label(get_lang('Revised'), 'success'); $qualificator_id = Display::label(get_lang('Revised'), 'success');
} }
$work['qualificator_id'] = $qualificator_id.' '.$hasCorrection; $work['qualificator_id'] = $qualificator_id.' '.$hasCorrection;
$work['actions'] = '<div class="work-action">'.$send_to.$linkToDownload.$action.'</div>'; $work['actions'] = '<div class="work-action">'.$linkToDownload.$action.'</div>';
$work['correction'] = $correction; $work['correction'] = $correction;
$works[] = $work; $works[] = $work;
} }

@ -76,7 +76,6 @@ class ScriptHandler
__DIR__.'/../../../../main/inc/lib/system/io', __DIR__.'/../../../../main/inc/lib/system/io',
__DIR__.'/../../../../main/inc/lib/system/net', __DIR__.'/../../../../main/inc/lib/system/net',
__DIR__.'/../../../../main/inc/lib/system/text/', __DIR__.'/../../../../main/inc/lib/system/text/',
__DIR__.'/../../../../main/inc/lib/system/portfolio/',
__DIR__.'/../../../../main/inc/lib/icalcreator/', __DIR__.'/../../../../main/inc/lib/icalcreator/',
__DIR__.'/../../../../main/inc/lib/getid3/', __DIR__.'/../../../../main/inc/lib/getid3/',
__DIR__.'/../../../../main/inc/lib/tools/', __DIR__.'/../../../../main/inc/lib/tools/',

Loading…
Cancel
Save