From 95b4ffa9e4fdba6a27c5f5e6e10233442b6985aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jos=C3=A9=20Loguercio?= Date: Tue, 17 May 2016 18:04:18 -0500 Subject: [PATCH] Added new profile, level, skill admin management - Refs BT#10651 --- .../Schema/V111/Version20160405112100.php | 46 +++++++ main/admin/index.php | 1 + main/admin/skill.php | 92 ++++++++++++++ main/admin/skill_level.php | 112 ++++++++++++++++ main/admin/skill_profile.php | 120 ++++++++++++++++++ main/admin/user_list.php | 9 ++ 6 files changed, 380 insertions(+) create mode 100644 app/Migrations/Schema/V111/Version20160405112100.php create mode 100644 main/admin/skill.php create mode 100644 main/admin/skill_level.php create mode 100644 main/admin/skill_profile.php diff --git a/app/Migrations/Schema/V111/Version20160405112100.php b/app/Migrations/Schema/V111/Version20160405112100.php new file mode 100644 index 0000000000..4ab6db513e --- /dev/null +++ b/app/Migrations/Schema/V111/Version20160405112100.php @@ -0,0 +1,46 @@ +addSql( + 'CREATE TABLE skill_level_profile (id INT AUTO_INCREMENT NOT NULL, name VARCHAR(255) NOT NULL, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' + ); + $this->addSql( + 'CREATE TABLE skill_level (id INT AUTO_INCREMENT NOT NULL, profile_id INT NOT NULL, name VARCHAR(255) NOT NULL, position INT, short_name VARCHAR(255), PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' + ); + $this->addSql( + 'ALTER TABLE skill_rel_user ADD acquired_level INT, ADD argumentation TEXT, ADD argumentation_author_id INT, MODIFY course_id INT, MODIFY session_id INT' + ); + $this->addSql( + 'CREATE TABLE skill_rel_user_comment (id INT AUTO_INCREMENT NOT NULL, skill_rel_user_id INT NOT NULL, feedback_giver_id INT NOT NULL, feedback_text TEXT, feedback_value INT, feedback_datetime DATETIME, PRIMARY KEY(id)) DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = InnoDB' + ); + $this->addSql( + 'ALTER TABLE skill ADD profile_id INT' + ); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->addSql( + 'ALTER TABLE skill_rel_user DROP COLUMN acquired_level, DROP COLUMN argumentation, DROP COLUMN argumentation_author_id, MODIFY course_id INT NOT NULL, MODIFY session_id INT NOT NULL' + ); + $this->addSql( + 'ALTER TABLE skill DROP COLUMN profile_id' + ); + $this->addSql('DROP TABLE skill_level'); + $this->addSql('DROP TABLE skill_level_profile'); + } +} \ No newline at end of file diff --git a/main/admin/index.php b/main/admin/index.php index 7eb109625c..a00ee73a40 100644 --- a/main/admin/index.php +++ b/main/admin/index.php @@ -386,6 +386,7 @@ if (api_is_platform_admin()) { $items[] = array('url' => 'skills_wheel.php', 'label' => get_lang('SkillsWheel')); $items[] = array('url' => 'skills_import.php', 'label' => get_lang('SkillsImport')); $items[] = array('url' => 'skill_list.php', 'label' => get_lang('ManageSkills')); + $items[] = array('url'=>'skill.php', 'label' => get_lang('ManageSkillsLevels')); //$items[] = array('url'=>'skills_profile.php', 'label' => get_lang('SkillsProfile')); $items[] = array( 'url' => api_get_path(WEB_CODE_PATH) . 'social/skills_ranking.php', diff --git a/main/admin/skill.php b/main/admin/skill.php new file mode 100644 index 0000000000..47e65cff3e --- /dev/null +++ b/main/admin/skill.php @@ -0,0 +1,92 @@ +getRepository('ChamiloSkillBundle:Profile')->findAll(); +$list = $em->getRepository('ChamiloCoreBundle:Skill')->findAll(); + +$listAction = api_get_self(); + +$action = ''; +if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete'])) { + $action = $_GET['action']; +} + +$id = isset($_GET['id']) ? $_GET['id'] : ''; + +$item = null; +if (!empty($id)) { + /** @var \Chamilo\CoreBundle\Entity\Skill $item */ + $item = $em->getRepository('ChamiloCoreBundle:Skill')->find($id); + if (!$item) { + api_not_allowed(); + } +} + +$form = new FormValidator('Skill', 'GET', api_get_self().'?action='.$action.'&id='.$id); +$form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles, null, true); +$form->addHidden('action', $action); +$form->addHidden('id', $id); +$form->addButtonSave(get_lang('Update')); + +if (!empty($item)) { + $profile = $item->getProfile(); + if ($profile) { + $form->setDefaults( + [ + 'profile_id' => $item->getProfile()->getId(), + ] + ); + } + $form->addHeader($item->getName()); +} +$formToDisplay = $form->returnForm(); + +$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('Skill')); + +$tpl = new Template($action); +switch ($action) { + case 'edit': + $tpl->assign('form', $formToDisplay); + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + + if ($form->validate()) { + $values = $form->exportValues(); + + $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']); + $item->setProfile($profile); + + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + } + + break; + case 'delete': + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + $em->remove($item); + $em->flush(); + header('Location: '.$listAction); + exit; + + break; + default: + break; +} + +$tpl->assign('list', $list); + +$contentTemplate = $tpl->fetch('default/admin/skill.tpl'); +$tpl->assign('content', $contentTemplate); +$tpl->display_one_col_template(); diff --git a/main/admin/skill_level.php b/main/admin/skill_level.php new file mode 100644 index 0000000000..52a7baa6fe --- /dev/null +++ b/main/admin/skill_level.php @@ -0,0 +1,112 @@ +getRepository('ChamiloSkillBundle:Profile')->findAll(); +$list = $em->getRepository('ChamiloSkillBundle:Level')->findAll(); + +$listAction = api_get_self(); + +$action = ''; +if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete', 'add_level'])) { + $action = $_GET['action']; +} + +$id = isset($_GET['id']) ? $_GET['id'] : ''; + +$item = null; +if (!empty($id)) { + /** @var \Chamilo\SkillBundle\Entity\Level $item */ + $item = $em->getRepository('ChamiloSkillBundle:Level')->find($id); + if (!$item) { + api_not_allowed(); + } +} + +$form = new FormValidator('Level', 'GET', api_get_self().'?action='.$action.'&id='.$id); +$form->addText('name', get_lang('Name')); +$form->addText('short_name', get_lang('ShortName')); +$form->addSelectFromCollection('profile_id', get_lang('Profile'), $profiles); +$form->addHidden('action', $action); +$form->addHidden('id', $id); +$form->addButtonSave(get_lang('Save')); + +if (!empty($item)) { + $form->setDefaults([ + 'name' => $item->getName(), + 'short_name' => $item->getShortName(), + 'profile_id' => $item->getProfile()->getId(), + ]); +} +$formToDisplay = $form->returnForm(); + +$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('SkillProfile')); + +$tpl = new Template($action); +switch ($action) { + case 'add': + $tpl->assign('form', $formToDisplay); + if ($form->validate()) { + $values = $form->exportValues(); + $item = new \Chamilo\SkillBundle\Entity\Level(); + $item->setName($values['name']); + $item->setShortName($values['short_name']); + $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']); + $item->setProfile($profile); + + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + } + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + break; + case 'edit': + $tpl->assign('form', $formToDisplay); + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + + if ($form->validate()) { + $values = $form->exportValues(); + + $item->setName($values['name']); + $item->setShortName($values['short_name']); + $profile = $em->getRepository('ChamiloSkillBundle:Profile')->find($values['profile_id']); + $item->setProfile($profile); + + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + } + + break; + case 'delete': + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + $em->remove($item); + $em->flush(); + header('Location: '.$listAction); + exit; + + break; + default: + $tpl->assign('actions', Display::url(get_lang('Add'), api_get_self().'?action=add')); +} + +$tpl->assign('list', $list); + +$contentTemplate = $tpl->fetch('default/admin/skill_level.tpl'); +$tpl->assign('content', $contentTemplate); +$tpl->display_one_col_template(); diff --git a/main/admin/skill_profile.php b/main/admin/skill_profile.php new file mode 100644 index 0000000000..2cbcddec0e --- /dev/null +++ b/main/admin/skill_profile.php @@ -0,0 +1,120 @@ +getRepository('ChamiloSkillBundle:Profile')->findAll(); + +$listAction = api_get_self(); + +$action = ''; +if (isset($_GET['action']) && in_array($_GET['action'], ['add', 'edit', 'delete', 'move_up', 'move_down'])) { + $action = $_GET['action']; +} + +$id = isset($_GET['id']) ? $_GET['id'] : ''; + +$item = null; +if (!empty($id)) { + $item = $em->getRepository('ChamiloSkillBundle:Profile')->find($id); + if (!$item) { + api_not_allowed(); + } +} + +$form = new FormValidator('Profile', 'GET', api_get_self().'?action='.$action.'&id='.$id); +$form->addText('name', get_lang('Name')); +$form->addHidden('action', $action); +$form->addHidden('id', $id); +$form->addButtonSave(get_lang('Save')); + +if (!empty($item)) { + $form->setDefaults(['name' => $item->getName()]); +} +$formToDisplay = $form->returnForm(); + +$interbreadcrumb[] = array ('url' => 'index.php', 'name' => get_lang('PlatformAdmin')); +$interbreadcrumb[] = array ('url' => api_get_self(), 'name' => get_lang('SkillProfile')); + +$tpl = new Template($action); +switch ($action) { + case 'move_up': + /** @var \Chamilo\SkillBundle\Entity\Level $item */ + $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']); + + $position = $item->getPosition(); + + if (!empty($position)) { + $item->setPosition($position-1); + } + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + break; + case 'move_down': + /** @var \Chamilo\SkillBundle\Entity\Level $item */ + $item = $em->getRepository('ChamiloSkillBundle:Level')->find($_GET['level_id']); + + $position = $item->getPosition(); + + $item->setPosition($position+1); + + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + break; + case 'add': + $tpl->assign('form', $formToDisplay); + if ($form->validate()) { + $values = $form->exportValues(); + $item = new \Chamilo\SkillBundle\Entity\Profile(); + $item->setName($values['name']); + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + } + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + break; + case 'edit': + $tpl->assign('form', $formToDisplay); + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + + if ($form->validate()) { + $values = $form->exportValues(); + $item->setName($values['name']); + $em->persist($item); + $em->flush(); + header('Location: '.$listAction); + exit; + } + + break; + case 'delete': + $tpl->assign('actions', Display::url(get_lang('List'), $listAction)); + $em->remove($item); + $em->flush(); + header('Location: '.$listAction); + exit; + + break; + default: + $tpl->assign('actions', Display::url(get_lang('Add'), api_get_self().'?action=add')); +} + +$tpl->assign('list', $list); + +$contentTemplate = $tpl->fetch('default/admin/skill_profile.tpl'); +$tpl->assign('content', $contentTemplate); +$tpl->display_one_col_template(); diff --git a/main/admin/user_list.php b/main/admin/user_list.php index 1d2a7f3cd5..d1f8848291 100755 --- a/main/admin/user_list.php +++ b/main/admin/user_list.php @@ -530,6 +530,15 @@ function modify_filter($user_id, $url_params, $row) { } } + $allowAssignSkill = api_is_platform_admin(false, true); + + if ($allowAssignSkill) { + $result .= Display::url( + Display::return_icon('skill-badges.png', get_lang('AssignSkill'), null, ICON_SIZE_SMALL), + api_get_path(WEB_CODE_PATH) . 'badge/assign.php?' . http_build_query(['user' => $user_id]) + ); + } + if ($is_admin) { $result .= Display::return_icon('admin_star.png', get_lang('IsAdministrator'),array('width'=> ICON_SIZE_SMALL, 'heigth'=> ICON_SIZE_SMALL)); } else {