Portfolio: Allow reuse items - refs BT#18201

pull/4368/head
Angel Fernando Quiroz Campos 3 years ago
parent 0583dc8952
commit e45cbf1d05
  1. BIN
      main/img/icons/32/wizard_na.png
  2. 49
      main/inc/ajax/portfolio.ajax.php
  3. 73
      main/inc/lib/PortfolioController.php
  4. 1
      main/install/configuration.dist.php
  5. 12
      main/portfolio/index.php
  6. 19
      src/Chamilo/CoreBundle/Entity/Portfolio.php

Binary file not shown.

After

Width:  |  Height:  |  Size: 6.9 KiB

@ -0,0 +1,49 @@
<?php
/* For licensing terms, see /license.txt */
use Chamilo\CoreBundle\Entity\Portfolio;
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request as HttpRequest;
use Symfony\Component\HttpFoundation\Response;
require_once __DIR__.'/../global.inc.php';
$httpRequest = HttpRequest::createFromGlobals();
$action = $httpRequest->query->has('a') ? $httpRequest->query->get('a') : $httpRequest->request->get('a');
$user_id = api_get_user_id();
$em = Database::getManager();
$item = null;
if ($httpRequest->query->has('item')) {
/** @var Portfolio $item */
$item = $em->find(
Portfolio::class,
$httpRequest->query->getInt('item')
);
}
$httpResponse = Response::create();
switch ($action) {
case 'find_template':
if (!$item
|| !$item->isTemplate()
) {
$httpResponse->setStatusCode(Response::HTTP_NOT_FOUND);
break;
}
$httpResponse = JsonResponse::create(
[
'title' => $item->getTitle(),
'content' => $item->getContent(),
]
);
break;
}
$httpResponse->send();

@ -460,7 +460,30 @@ class PortfolioController
{
global $interbreadcrumb;
$templates = $this->em
->getRepository(Portfolio::class)
->findBy(
[
'isTemplate' => true,
'course' => $this->course,
'session' => $this->session,
]
);
$form = new FormValidator('add_portfolio', 'post', $this->baseUrl.'action=add_item');
$form->addSelectFromCollection(
'template',
[
get_lang('Template'),
null,
'<span id="portfolio-spinner" class="fa fa-fw fa-spinner fa-spin" style="display: none;"
aria-hidden="true" aria-label="'.get_lang('Loading').'"></span>',
],
$templates,
[],
true,
'getTitle'
);
if (api_get_configuration_value('save_titles_as_html')) {
$form->addHtmlEditor('title', get_lang('Title'), true, false, ['ToolbarSet' => 'TitleAsHtml']);
@ -608,6 +631,21 @@ class PortfolioController
$(window).on("load", function () {
$("input[name=\'title\']").focus();
});
$(\'#add_portfolio_template\').on(\'change\', function () {
$(\'#portfolio-spinner\').show();
$.getJSON(_p.web_ajax + \'portfolio.ajax.php?a=find_template&item=5\').done(function(response) {
if (CKEDITOR.instances.title) {
CKEDITOR.instances.title.setData(response.title);
} else {
document.getElementById(\'add_portfolio_title\').value = response.title;
}
CKEDITOR.instances.content.setData(response.content);
$(\'#portfolio-spinner\').hide();
});
});
'.$extra['jquery_ready_content'].'
});
</script>';
@ -1220,7 +1258,7 @@ class PortfolioController
$interbreadcrumb[] = ['name' => get_lang('Portfolio'), 'url' => $this->baseUrl];
$editLink = $actions[] = Display::url(
$editLink = Display::url(
Display::return_icon('edit.png', get_lang('Edit'), [], ICON_SIZE_MEDIUM),
$this->baseUrl.http_build_query(['action' => 'edit_item', 'id' => $item->getId()])
);
@ -1234,6 +1272,16 @@ class PortfolioController
if ($this->itemBelongToOwner($item)) {
$actions[] = $editLink;
$actions[] = Display::url(
Display::return_icon(
$item->isTemplate() ? 'wizard.png' : 'wizard_na.png',
$item->isTemplate() ? get_lang('RemoveAsTemplate') : get_lang('AddAsTemplate'),
[],
ICON_SIZE_MEDIUM
),
$this->baseUrl.http_build_query(['action' => 'template', 'id' => $item->getId()])
);
$visibilityUrl = $this->baseUrl.http_build_query(['action' => 'visibility', 'id' => $item->getId()]);
if ($item->getVisibility() === Portfolio::VISIBILITY_HIDDEN) {
@ -2510,6 +2558,29 @@ class PortfolioController
exit;
}
public function markAsTemplate(Portfolio $item)
{
if (!$this->itemBelongToOwner($item)) {
api_not_allowed(true);
}
$item->setIsTemplate(
!$item->isTemplate()
);
Database::getManager()->flush($item);
Display::addFlash(
Display::return_message(
$item->isTemplate() ? get_lang('PortfolioItemSetAsTemplate') : get_lang('PortfolioItemUnsetAsTemplate'),
'success'
)
);
header("Location: $this->baseUrl".http_build_query(['action' => 'view', 'id' => $item->getId()]));
exit;
}
/**
* @param bool $showHeader
*/

@ -1056,6 +1056,7 @@ ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED1062613FECDF FOREIGN KEY (session_id
ALTER TABLE portfolio ADD CONSTRAINT FK_A9ED106212469DE2 FOREIGN KEY (category_id) REFERENCES portfolio_category (id) ON DELETE SET NULL;
ALTER TABLE portfolio CHANGE is_visible visibility SMALLINT DEFAULT 1 NOT NULL;
ALTER TABLE portfolio ADD is_highlighted TINYINT(1) DEFAULT '0' NOT NULL;
ALTER TABLE portfolio ADD is_template TINYINT(1) DEFAULT '0' NOT NULL;
ALTER TABLE portfolio_category ADD CONSTRAINT FK_7AC64359A76ED395 FOREIGN KEY (user_id) REFERENCES user (id) ON DELETE CASCADE;
ALTER TABLE portfolio_comment ADD CONSTRAINT FK_C2C17DA2F675F31B FOREIGN KEY (author_id) REFERENCES user (id) ON DELETE CASCADE;
ALTER TABLE portfolio_comment ADD CONSTRAINT FK_C2C17DA2126F525E FOREIGN KEY (item_id) REFERENCES portfolio (id) ON DELETE CASCADE;

@ -284,6 +284,18 @@ switch ($action) {
$controller->markAsHighlighted($item);
break;
case 'template':
$id = $httpRequest->query->getInt('id');
/** @var Portfolio $item */
$item = $em->find('ChamiloCoreBundle:Portfolio', $id);
if (empty($item)) {
break;
}
$controller->markAsTemplate($item);
break;
case 'list':
default:
$controller->index($httpRequest);

@ -144,6 +144,13 @@ class Portfolio
*/
private $isHighlighted = false;
/**
* @var bool
*
* @ORM\Column(name="is_template", type="boolean", options={"default": false})
*/
private $isTemplate = false;
/**
* Portfolio constructor.
*/
@ -434,4 +441,16 @@ class Portfolio
return $this;
}
public function isTemplate(): bool
{
return $this->isTemplate;
}
public function setIsTemplate(bool $isTemplate): Portfolio
{
$this->isTemplate = $isTemplate;
return $this;
}
}

Loading…
Cancel
Save