Explorar el Código

Added new profile, level, skill admin management - Refs BT#10651

José Loguercio hace 8 años
padre
commit
95b4ffa9e4

+ 46 - 0
app/Migrations/Schema/V111/Version20160405112100.php

@@ -0,0 +1,46 @@
+<?php
+
+namespace Application\Migrations\Schema\V111;
+
+use Doctrine\DBAL\Migrations\AbstractMigration;
+use Doctrine\DBAL\Schema\Schema;
+
+class Version20160405112100 extends AbstractMigration
+{
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $this->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');
+    }
+}

+ 1 - 0
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',

+ 92 - 0
main/admin/skill.php

@@ -0,0 +1,92 @@
+<?php
+
+/* For license terms, see /license.txt */
+
+/**
+ * This script manages the skills, levels and profiles assignments.
+ * @package chamilo.skills
+ */
+
+$cidReset = true;
+require_once '../inc/global.inc.php';
+api_protect_admin_script();
+$em = Database::getManager();
+$profiles = $em->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();

+ 112 - 0
main/admin/skill_level.php

@@ -0,0 +1,112 @@
+<?php
+
+/* For licensing terms, see /license.txt */
+
+/**
+ * Add a skill Level
+ * @package chamilo.skills
+ */
+
+$cidReset = true;
+
+require_once '../inc/global.inc.php';
+
+api_protect_admin_script();
+
+$em = Database::getManager();
+$profiles = $em->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();

+ 120 - 0
main/admin/skill_profile.php

@@ -0,0 +1,120 @@
+<?php
+
+/* For licensing terms, see /license.txt */
+
+/**
+ * Add a skill Profile
+ * @package chamilo.skills
+ */
+
+$cidReset = true;
+require_once '../inc/global.inc.php';
+
+api_protect_admin_script();
+$em = Database::getManager();
+$list = $em->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();

+ 9 - 0
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 {