diff --git a/.codeclimate.yml b/.codeclimate.yml index 8c71208ef9..bb72e946f7 100644 --- a/.codeclimate.yml +++ b/.codeclimate.yml @@ -85,7 +85,6 @@ exclude_patterns: - main/inc/lib/pear/ - main/inc/lib/phpmailer/ - main/inc/lib/phpseclib/ - - main/inc/lib/portfolio.class.php - main/inc/lib/svg-edit/ - main/inc/lib/swfobject/ - main/inc/lib/wami-recorder/ diff --git a/.gitignore b/.gitignore index 9220a0677d..a297bf8d35 100755 --- a/.gitignore +++ b/.gitignore @@ -15,7 +15,6 @@ var/log/* /app/config/course_info.conf.php /app/config/events.conf.php /app/config/mail.conf.php -/app/config/portfolio.conf.php /app/config/profile.conf.php /app/config/configuration.php diff --git a/app/config/portfolio.conf.dist.php b/app/config/portfolio.conf.dist.php deleted file mode 100644 index 0686c1ad75..0000000000 --- a/app/config/portfolio.conf.dist.php +++ /dev/null @@ -1,19 +0,0 @@ -set_title(get_lang('Download')); -//$portfolios[] = $download_portfolio; \ No newline at end of file diff --git a/main/inc/lib/portfolio.class.php b/main/inc/lib/portfolio.class.php deleted file mode 100755 index 00fbf0fd88..0000000000 --- a/main/inc/lib/portfolio.class.php +++ /dev/null @@ -1,637 +0,0 @@ - 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 boolean - */ - 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'; - - /** - * - * @return \PortfolioController - */ - public static function instance() - { - static $result = null; - if (empty($result)) { - $result = new self(); - } - return $result; - } - - protected $message = ''; - - protected function __construct() - { - } - - 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 boolean - */ - 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 -{ - - /** - * 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; - } - - protected $id = 0; - protected $attributes = []; - protected $tool = ''; - - public function __construct($tool, $id, $attributes = []) - { - $this->tool = $tool; - $this->id = (int) $id; - $this->attributes = $attributes; - } - - /** - * 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[] = ''; - $result[] = ''; - $result[] = ''; - $result[] = Display::return_icon('document_send.png', get_lang('Send'), [], ICON_SIZE_SMALL).''; - $result[] = ''; - $result[] = ''; - $result[] = ''; - $result[] = ''; - return implode("\n", $result); - } - - public function __toString() - { - return $this->display(); - } -} - -/** - * 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 -{ - - /** - * - * @param \Portfolio\Portfolio $portfolio - * @return PortfolioBulkAction - */ - public static function create($portfolio) - { - return new self($portfolio); - } - - 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; - } - - 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; - } -} diff --git a/main/install/install_files.inc.php b/main/install/install_files.inc.php index 352596ae46..a608a5eab6 100755 --- a/main/install/install_files.inc.php +++ b/main/install/install_files.inc.php @@ -50,10 +50,6 @@ if (defined('SYSTEM_INSTALLATION')) { api_get_path(CONFIGURATION_PATH).'auth.conf.dist.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 { echo 'You are not allowed here !'.__FILE__; } diff --git a/main/work/work.lib.php b/main/work/work.lib.php index 66d2e0c280..062c06a23e 100755 --- a/main/work/work.lib.php +++ b/main/work/work.lib.php @@ -2222,12 +2222,7 @@ function get_work_user_list( $link_to_download = ''.$saveIcon.' '; } - $send_to = Portfolio::share( - 'work', - $work['id'], - ['style' => 'white-space:nowrap;'] - ); - + $send_to = ''; $feedback = ''; $count = getWorkCommentCount($item_id, $course_info); if (!is_null($count) && !empty($count)) {