diff --git a/main/img/icons/64/wiki_task_na.png b/main/img/icons/64/wiki_task_na.png new file mode 100644 index 0000000000..8bebe42634 Binary files /dev/null and b/main/img/icons/64/wiki_task_na.png differ diff --git a/main/portfolio/add_category.php b/main/portfolio/add_category.php new file mode 100644 index 0000000000..321ab55c5b --- /dev/null +++ b/main/portfolio/add_category.php @@ -0,0 +1,41 @@ +addText('title', get_lang('Title')); +$form->addHtmlEditor('description', get_lang('Description'), false, false, ['ToolbarSet' => 'Minimal']); +$form->addButtonCreate(get_lang('Create')); + +if ($form->validate()) { + $values = $form->exportValues(); + + $category = new PortfolioCategory(); + $category + ->setTitle($values['title']) + ->setDescription($values['description']) + ->setUser($user); + + $em->persist($category); + $em->flush(); + + Display::addFlash( + Display::return_message(get_lang('CategoryAdded'), 'success') + ); + + header("Location: $baseUrl"); + exit; +} + +$toolName = get_lang('AddCategory'); +$interbreadcrumb[] = [ + 'name' => get_lang('Portfolio'), + 'url' => $baseUrl, +]; + +$actions[] = Display::url( + Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM), + $baseUrl +); +$content = $form->returnForm(); diff --git a/main/portfolio/add_item.php b/main/portfolio/add_item.php new file mode 100644 index 0000000000..27107b69ea --- /dev/null +++ b/main/portfolio/add_item.php @@ -0,0 +1,59 @@ +getRepository('ChamiloCoreBundle:PortfolioCategory') + ->findBy([ + 'user' => $user, + ]); + +$form = new FormValidator('add_portfolio', 'post', $baseUrl.'action=add_item'); +$form->addText('title', get_lang('Title')); +$form->addHtmlEditor('content', get_lang('Content'), true, false, ['ToolbarSet' => 'NotebookStudent']); +$form->addSelectFromCollection('category', get_lang('Category'), $categories, [], true); +$form->addButtonCreate(get_lang('Create')); + +if ($form->validate()) { + $values = $form->exportValues(); + $currentTime = new DateTime( + api_get_utc_datetime(), + new DateTimeZone('UTC') + ); + + $portfolio = new Portfolio(); + $portfolio + ->setTitle($values['title']) + ->setContent($values['content']) + ->setUser($user) + ->setCourse($course) + ->setSession($session) + ->setCategory( + $em->find('ChamiloCoreBundle:PortfolioCategory', $values['category']) + ) + ->setCreationDate($currentTime) + ->setUpdateDate($currentTime); + + $em->persist($portfolio); + $em->flush(); + + Display::addFlash( + Display::return_message(get_lang('PortfolioItemAdded'), 'success') + ); + + header("Location: $baseUrl"); + exit; +} + +$toolName = get_lang('AddPortfolioItem'); +$interbreadcrumb[] = [ + 'name' => get_lang('Portfolio'), + 'url' => $baseUrl, +]; + +$actions[] = Display::url( + Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM), + $baseUrl +); +$content = $form->returnForm(); diff --git a/main/portfolio/edit_category.php b/main/portfolio/edit_category.php new file mode 100644 index 0000000000..2fdaf402a9 --- /dev/null +++ b/main/portfolio/edit_category.php @@ -0,0 +1,40 @@ +getId()}"); +$form->addText('title', get_lang('Title')); +$form->addHtmlEditor('description', get_lang('Description'), false, false, ['ToolbarSet' => 'Minimal']); +$form->addButtonUpdate(get_lang('Update')); +$form->setDefaults([ + 'title' => $category->getTitle(), + 'description' => $category->getDescription(), +]); + +if ($form->validate()) { + $values = $form->exportValues(); + + $category + ->setTitle($values['title']) + ->setDescription($values['description']); + + $em->persist($category); + $em->flush(); + + Display::addFlash( + Display::return_message(get_lang('Updated'), 'success') + ); + + header("Location: $baseUrl"); + exit; +} + +$toolName = get_lang('EditCategory'); +$interbreadcrumb[] = [ + 'name' => get_lang('Portfolio'), + 'url' => $baseUrl, +]; +$actions[] = Display::url( + Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM), + $baseUrl +); +$content = $form->returnForm(); diff --git a/main/portfolio/edit_item.php b/main/portfolio/edit_item.php new file mode 100644 index 0000000000..7b560919fd --- /dev/null +++ b/main/portfolio/edit_item.php @@ -0,0 +1,53 @@ +getRepository('ChamiloCoreBundle:PortfolioCategory') + ->findBy([ + 'user' => $user, + ]); + +$form = new FormValidator('edit_portfolio', 'post', $baseUrl."action=edit_item&id={$item->getId()}"); +$form->addText('title', get_lang('Title')); +$form->addHtmlEditor('content', get_lang('Content'), true, false, ['ToolbarSet' => 'NotebookStudent']); +$form->addSelectFromCollection('category', get_lang('Category'), $categories, [], true, '__toString'); +$form->addButtonUpdate(get_lang('Update')); +$form->setDefaults([ + 'title' => $item->getTitle(), + 'content' => $item->getContent(), + 'category' => $item->getCategory() ? $item->getCategory()->getId() : '', +]); + +if ($form->validate()) { + $values = $form->exportValues(); + $currentTime = new DateTime(api_get_utc_datetime(), new DateTimeZone('UTC')); + + $item + ->setTitle($values['title']) + ->setContent($values['content']) + ->setUpdateDate($currentTime) + ->setCategory( + $em->find('ChamiloCoreBundle:PortfolioCategory', $values['category']) + ); + + $em->persist($item); + $em->flush(); + + Display::addFlash( + Display::return_message(get_lang('Updated'), 'success') + ); + + header("Location: $baseUrl"); + exit; +} + +$toolName = get_lang('EditPortfolioItem'); +$interbreadcrumb[] = [ + 'name' => get_lang('Portfolio'), + 'url' => $baseUrl, +]; +$actions[] = Display::url( + Display::return_icon('back.png', get_lang('Back'), [], ICON_SIZE_MEDIUM), + $baseUrl +); +$content = $form->returnForm(); diff --git a/main/portfolio/list.php b/main/portfolio/list.php new file mode 100644 index 0000000000..3b28641761 --- /dev/null +++ b/main/portfolio/list.php @@ -0,0 +1,59 @@ +getId()) { + if ($allowEdit) { + $actions[] = Display::url( + Display::return_icon('add.png', get_lang('Add'), [], ICON_SIZE_MEDIUM), + $baseUrl.'action=add_item' + ); + $actions[] = Display::url( + Display::return_icon('folder.png', get_lang('AddCategory'), [], ICON_SIZE_MEDIUM), + $baseUrl.'action=add_category' + ); + $actions[] = Display::url( + Display::return_icon('shared_setting.png', get_lang('Preview'), [], ICON_SIZE_MEDIUM), + $baseUrl.'preview=&user='.$user->getId() + ); + } else { + $actions[] = Display::url( + Display::return_icon('shared_setting_na.png', get_lang('Preview'), [], ICON_SIZE_MEDIUM), + $baseUrl + ); + } +} + +$form = new FormValidator('a'); +$form->addUserAvatar('user', get_lang('User'), 'medium'); +$form->setDefaults(['user' => $user]); + +$criteria = ['user' => $user]; + +if (!$allowEdit) { + $criteria['isVisible'] = true; +} + +$categories = $em + ->getRepository('ChamiloCoreBundle:PortfolioCategory') + ->findBy($criteria); + +if ($course) { + $criteria['course'] = $course; + $criteria['session'] = $session; +} + +$criteria['category'] = null; + +$items = $em + ->getRepository('ChamiloCoreBundle:Portfolio') + ->findBy($criteria); + +$template = new Template(null, false, false, false, false, false, false); +$template->assign('user', $user); +$template->assign('course', $course); +$template->assign('session', $session); +$template->assign('allow_edit', $allowEdit); +$template->assign('portfolio', $categories); +$template->assign('uncategorized_items', $items); +$layout = $template->get_template('portfolio/list.html.twig'); +$content = $template->fetch($layout); diff --git a/main/template/default/portfolio/items.html.twig b/main/template/default/portfolio/items.html.twig new file mode 100644 index 0000000000..54943948a1 --- /dev/null +++ b/main/template/default/portfolio/items.html.twig @@ -0,0 +1,67 @@ +{% macro display(items, category_id, allow_edit, _c) %} + {% set edit_img = 'edit.png'|img(22, 'Edit'|get_lang) %} + {% set visible_img = 'visible.png'|img(22, 'Invisible'|get_lang) %} + {% set invisible_img = 'invisible.png'|img(22, 'Visible'|get_lang) %} + {% set delete_img = 'delete.png'|img(22, 'Delete'|get_lang) %} + {% set baseurl = _p.web_self ~ '?' ~ (_p.web_cid_query ? _p.web_cid_query ~ '&' : '') %} + +
+ {% for item in items %} +
+ +
+
+ {{ item.content }} +
+
+ +
+ {% endfor %} +
+{% endmacro %} diff --git a/main/template/default/portfolio/list.html.twig b/main/template/default/portfolio/list.html.twig new file mode 100644 index 0000000000..bd9a1dbc98 --- /dev/null +++ b/main/template/default/portfolio/list.html.twig @@ -0,0 +1,65 @@ +{% set edit_img = 'edit.png'|img(22, 'Edit'|get_lang) %} +{% set visible_img = 'visible.png'|img(22, 'Invisible'|get_lang) %} +{% set invisible_img = 'invisible.png'|img(22, 'Visible'|get_lang) %} +{% set delete_img = 'delete.png'|img(22, 'Delete'|get_lang) %} +{% set baseurl = _p.web_self ~ '?' ~ (_p.web_cid_query ? _p.web_cid_query ~ '&' : '') %} + +{% import template ~ '/portfolio/items.html.twig' as items %} + +{% if not allow_edit %} +

{{ user.completeName }} {{ user.username }}

+{% endif %} + +{{ items.display(uncategorized_items, 0, allow_edit, _c) }} + +{% for category in portfolio %} +
+
+ + +
+ {{ category.description }} +
+ +
+ {{ items.display(category.items(course, session, not allow_edit), category.id, allow_edit, _c) }} +
+
+
+{% endfor %} + + diff --git a/src/Chamilo/CoreBundle/Entity/Portfolio.php b/src/Chamilo/CoreBundle/Entity/Portfolio.php new file mode 100644 index 0000000000..4de91c5ebb --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/Portfolio.php @@ -0,0 +1,336 @@ +category = new PortfolioCategory(); + } + + /** + * Set user. + * + * @param User $user + * + * @return Portfolio + */ + public function setUser(User $user) + { + $this->user = $user; + + return $this; + } + + /** + * Get user. + * + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * Set course. + * + * @param Course|null $course + * + * @return Portfolio + */ + public function setCourse(Course $course = null) + { + $this->course = $course; + + return $this; + } + + /** + * Get course. + * + * @return Course + */ + public function getCourse() + { + return $this->course; + } + + /** + * Get session. + * + * @return Session + */ + public function getSession() + { + return $this->session; + } + + /** + * Set session. + * + * @param Session|null $session + * + * @return Portfolio + */ + public function setSession(Session $session = null) + { + $this->session = $session; + + return $this; + } + + /** + * Set title. + * + * @param string $title + * + * @return Portfolio + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get title. + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Set content. + * + * @param string $content + * + * @return Portfolio + */ + public function setContent($content) + { + $this->content = $content; + + return $this; + } + + /** + * Get content. + * + * @return string + */ + public function getContent() + { + return $this->content; + } + + /** + * Set creationDate. + * + * @param \DateTime $creationDate + * + * @return Portfolio + */ + public function setCreationDate(\DateTime $creationDate) + { + $this->creationDate = $creationDate; + + return $this; + } + + /** + * Get creationDate. + * + * @return \DateTime + */ + public function getCreationDate() + { + return $this->creationDate; + } + + /** + * Set updateDate. + * + * @param \DateTime $updateDate + * + * @return Portfolio + */ + public function setUpdateDate(\DateTime $updateDate) + { + $this->updateDate = $updateDate; + + return $this; + } + + /** + * Get updateDate. + * + * @return \DateTime + */ + public function getUpdateDate() + { + return $this->updateDate; + } + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * Set isVisible. + * + * @param bool $isVisible + * + * @return Portfolio + */ + public function setIsVisible($isVisible) + { + $this->isVisible = $isVisible; + + return $this; + } + + /** + * Get isVisible. + * + * @return bool + */ + public function isVisible() + { + return $this->isVisible; + } + + /** + * Get category. + * + * @return PortfolioCategory + */ + public function getCategory() + { + return $this->category; + } + + /** + * Set category. + * + * @param PortfolioCategory|null $category + * + * @return Portfolio + */ + public function setCategory(PortfolioCategory $category = null) + { + $this->category = $category; + + return $this; + } +} diff --git a/src/Chamilo/CoreBundle/Entity/PortfolioCategory.php b/src/Chamilo/CoreBundle/Entity/PortfolioCategory.php new file mode 100644 index 0000000000..2d40f58c8d --- /dev/null +++ b/src/Chamilo/CoreBundle/Entity/PortfolioCategory.php @@ -0,0 +1,251 @@ +items = new ArrayCollection(); + } + + /** + * @return string + */ + public function __toString() + { + return $this->title; + } + + /** + * Get id. + * + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + * + * @return PortfolioCategory + */ + public function setId($id) + { + $this->id = $id; + + return $this; + } + + /** + * Get title. + * + * @return string + */ + public function getTitle() + { + return $this->title; + } + + /** + * Set title. + * + * @param string $title + * + * @return PortfolioCategory + */ + public function setTitle($title) + { + $this->title = $title; + + return $this; + } + + /** + * Get description. + * + * @return string|null + */ + public function getDescription() + { + return $this->description; + } + + /** + * Set description. + * + * @param string|null $description + * + * @return PortfolioCategory + */ + public function setDescription($description) + { + $this->description = $description; + + return $this; + } + + /** + * Get user. + * + * @return User + */ + public function getUser() + { + return $this->user; + } + + /** + * Set user. + * + * @param User $user + * + * @return PortfolioCategory + */ + public function setUser(User $user) + { + $this->user = $user; + + return $this; + } + + /** + * Get isVisible. + * + * @return bool + */ + public function isVisible() + { + return $this->isVisible; + } + + /** + * Set isVisible. + * + * @param bool $isVisible + * + * @return PortfolioCategory + */ + public function setIsVisible($isVisible) + { + $this->isVisible = $isVisible; + + return $this; + } + + /** + * Get items. + * + * @param Course|null $course + * @param Session|null $session + * @param bool $onlyVisibles + * + * @return ArrayCollection + */ + public function getItems(Course $course = null, Session $session = null, $onlyVisibles = false) + { + $criteria = Criteria::create(); + + if ($onlyVisibles) { + $criteria->andWhere( + Criteria::expr()->eq('isVisible', true) + ); + } + + if ($course) { + $criteria + ->andWhere( + Criteria::expr()->eq('course', $course) + ) + ->andWhere( + Criteria::expr()->eq('session', $session) + ); + } + + return $this->items->matching($criteria); + } + + /** + * Set items. + * + * @param ArrayCollection $items + * + * @return PortfolioCategory + */ + public function setItems(ArrayCollection $items) + { + $this->items = $items; + + return $this; + } +}