소스 검색

Merge pull request #807 from AngelFQC/BT10181

Add option to enable/disable skills - refs BT#10181
Angel Fernando Quiroz Campos 9 년 전
부모
커밋
f81c4f49fd

+ 45 - 0
app/Migrations/Schema/V110/Version20150819095300.php

@@ -0,0 +1,45 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+namespace Application\Migrations\Schema\V110;
+
+use Application\Migrations\AbstractMigrationChamilo;
+use Doctrine\DBAL\Schema\Schema;
+
+/**
+ * Class Version20150819095300
+ *
+ * @package Application\Migrations\Schema\V11010
+ */
+class Version20150819095300 extends AbstractMigrationChamilo
+{
+
+    /**
+     * @param Schema $schema
+     */
+    public function up(Schema $schema)
+    {
+        $skillTable = $schema->getTable('skill');
+
+        $skillTable->addColumn(
+            'status',
+            \Doctrine\DBAL\Types\Type::INTEGER,
+            ['default' => 1]
+        );
+        $skillTable->addColumn(
+            'updated_at',
+            \Doctrine\DBAL\Types\Type::DATETIME
+        );
+    }
+
+    /**
+     * @param Schema $schema
+     */
+    public function down(Schema $schema)
+    {
+        $skillTable = $schema->getTable('skill');
+        $skillTable->dropColumn('status');
+        $skillTable->dropColumn('updated_at');
+    }
+
+}

+ 138 - 41
main/admin/skill_list.php

@@ -19,44 +19,141 @@ if (api_get_setting('allow_skills_tool') != 'true') {
     api_not_allowed();
 }
 
-$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
-
-$message = Session::has('message') ? Session::read('message') : null;
-
-$toolbar = Display::toolbarButton(
-    get_lang('CreateSkill'),
-    api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
-    'plus',
-    'success',
-    ['title' => get_lang('CreateSkill')]
-);
-$toolbar .= Display::toolbarButton(
-    get_lang('SkillsWheel'),
-    api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php',
-    'bullseye',
-    'primary',
-    ['title' => get_lang('CreateSkill')]
-);
-$toolbar .= Display::toolbarButton(
-    get_lang('BadgesManagement'),
-    api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php',
-    'certificate',
-    'warning',
-    ['title' => get_lang('BadgesManagement')]
-);
-
-/* View */
-$skill = new Skill();
-$skillList = $skill->get_all();
-
-$tpl = new Template(get_lang('ManageSkills'));
-$tpl->assign('message', $message);
-$tpl->assign('skills', $skillList);
-
-$content = $tpl->fetch('default/skill/list.tpl');
-
-$tpl->assign('actions', $toolbar);
-$tpl->assign('content', $content);
-$tpl->display_one_col_template();
-
-Session::erase('message');
+$action = isset($_GET['action']) ? $_GET['action'] : 'list';
+$skillId = isset($_GET['id']) ? intval($_GET['id']): 0;
+
+$entityManager = Database::getManager();
+
+switch ($action) {
+    case 'enable':
+        $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
+        
+        if (is_null($skill)) {
+            Display::addFlash(
+                Display::return_message(
+                    get_lang('SkillNotFound'),
+                    'error'
+                )
+            );
+        } else {
+            $updatedAt = new DateTime(
+                api_get_utc_datetime(),
+                new DateTimeZone(_api_get_timezone())
+            );
+
+            $skill->setStatus(1);
+            $skill->setUpdatedAt($updatedAt);
+
+            $entityManager->persist($skill);
+            $entityManager->flush();
+
+            Display::addFlash(
+                Display::return_message(
+                    sprintf(get_lang('SkillXEnabled'), $skill->getName()),
+                    'success'
+                )
+            );
+        }
+
+        header('Location: ' . api_get_self());
+        exit;
+        break;
+    case 'disable':
+        $skill = $entityManager->find('ChamiloCoreBundle:Skill', $skillId);
+        
+        if (is_null($skill)) {
+            Display::addFlash(
+                Display::return_message(
+                    get_lang('SkillNotFound'),
+                    'error'
+                )
+            );
+        } else {
+            $updatedAt = new DateTime(
+                api_get_utc_datetime(),
+                new DateTimeZone(_api_get_timezone())
+            );
+
+            $skill->setStatus(0);
+            $skill->setUpdatedAt($updatedAt);
+
+            $entityManager->persist($skill);
+
+            $skillObj = new Skill();
+            $childrens = $skillObj->get_children($skill->getId());
+            
+            foreach ($childrens as $children) {
+                $skill = $entityManager->find(
+                    'ChamiloCoreBundle:Skill',
+                    $children['id']
+                );
+
+                if (empty($skill)) {
+                    continue;
+                }
+
+                $skill->setStatus(0);
+                $skill->setUpdatedAt($updatedAt);
+
+                $entityManager->persist($skill);
+            }
+
+            $entityManager->flush();
+
+            Display::addFlash(
+                Display::return_message(
+                    sprintf(get_lang('SkillXDisabled'), $skill->getName()),
+                    'success'
+                )
+            );
+        }
+
+        header('Location: ' . api_get_self());
+        exit;
+        break;
+    case 'list':
+        //no break
+    default:
+        $interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
+
+        $message = Session::has('message') ? Session::read('message') : null;
+
+        $toolbar = Display::toolbarButton(
+            get_lang('CreateSkill'),
+            api_get_path(WEB_CODE_PATH) . 'admin/skill_create.php',
+            'plus',
+            'success',
+            ['title' => get_lang('CreateSkill')]
+        );
+        $toolbar .= Display::toolbarButton(
+            get_lang('SkillsWheel'),
+            api_get_path(WEB_CODE_PATH) . 'admin/skills_wheel.php',
+            'bullseye',
+            'primary',
+            ['title' => get_lang('CreateSkill')]
+        );
+        $toolbar .= Display::toolbarButton(
+            get_lang('BadgesManagement'),
+            api_get_path(WEB_CODE_PATH) . 'admin/skill_badge_list.php',
+            'certificate',
+            'warning',
+            ['title' => get_lang('BadgesManagement')]
+        );
+
+        /* View */
+        $skill = new Skill();
+        $skillList = $skill->get_all();
+
+        $tpl = new Template(get_lang('ManageSkills'));
+        $tpl->assign('message', $message);
+        $tpl->assign('skills', $skillList);
+
+        $content = $tpl->fetch('default/skill/list.tpl');
+
+        $tpl->assign('actions', $toolbar);
+        $tpl->assign('content', $content);
+        $tpl->display_one_col_template();
+
+        Session::erase('message');
+        break;
+}

+ 2 - 1
main/inc/lib/skill.lib.php

@@ -612,7 +612,8 @@ class Skill extends Model
                     ss.parent_id,
                     ss.relation_type,
                     s.icon,
-                    s.short_code
+                    s.short_code,
+                    s.status
                 FROM {$this->table} s
                 INNER JOIN {$this->table_skill_rel_skill} ss
                 ON (s.id = ss.skill_id) $id_condition

+ 48 - 36
main/template/default/skill/list.tpl

@@ -2,41 +2,53 @@
     <h1>{{ "ManageSkills" | get_lang }}</h1>
 </header>
 
-<table class="table table-hover table-striped">
-    <thead>
-        <tr>
-            <th>{{ "Name" | get_lang }}</th>
-            <th>{{ "ShortCode" | get_lang }}</th>
-            <th>{{ "Description" | get_lang }}</th>
-            <th>{{ "Options" | get_lang }}</th>
-        </tr>
-    </thead>
-    <tfoot>
-        <tr>
-            <th>{{ "Name" | get_lang }}</th>
-            <th>{{ "ShortName" | get_lang }}</th>
-            <th>{{ "Description" | get_lang }}</th>
-            <th>{{ "Options" | get_lang }}</th>
-        </tr>
-    </tfoot>
-    <tbody>
-        {% for skill in skills %}
+<div class="table table-responsive">
+    <table class="table table-hover table-striped">
+        <thead>
             <tr>
-                <td>{{ skill.name }}</td>
-                <td>{{ skill.short_code }}</td>
-                <td>{{ skill.description }}</td>
-                <td>
-                    <a href="{{ _p.web_main }}admin/skill_edit.php?id={{ skill.id }}" class="btn btn-default">
-                        <i class="fa fa-edit"></i> {{ "Edit" | get_lang }}
-                    </a>
-                    <a href="{{ _p.web_main }}admin/skill_create.php?parent={{ skill.id }}" class="btn btn-default">
-                        <i class="fa fa-plus"></i> {{ "CreateChildSkill" | get_lang }}
-                    </a>
-                    <a href="{{ _p.web_main }}admin/skill_badge_create.php?id={{ skill.id }}" class="btn btn-default">
-                        <i class="fa fa-plus"></i> {{ "CreateBadge" | get_lang }}
-                    </a>
-                </td>
+                <th>{{ "Name" | get_lang }}</th>
+                <th>{{ "ShortCode" | get_lang }}</th>
+                <th>{{ "Description" | get_lang }}</th>
+                <th>{{ "Options" | get_lang }}</th>
             </tr>
-        {% endfor %}
-    </tbody>
-</table>
+        </thead>
+        <tfoot>
+            <tr>
+                <th width="200">{{ "Name" | get_lang }}</th>
+                <th class="text-center">{{ "ShortName" | get_lang }}</th>
+                <th width="300">{{ "Description" | get_lang }}</th>
+                <th class="text-right">{{ "Options" | get_lang }}</th>
+            </tr>
+        </tfoot>
+        <tbody>
+            {% for skill in skills %}
+                <tr>
+                    <td width="200">{{ skill.name }}</td>
+                    <td class="text-center">{{ skill.short_code }}</td>
+                    <td width="300">{{ skill.description }}</td>
+                    <td class="text-right">
+                        <a href="{{ _p.web_main }}admin/skill_edit.php?id={{ skill.id }}" class="btn btn-primary btn-sm">
+                            <i class="fa fa-edit"></i> {{ "Edit" | get_lang }}
+                        </a>
+                        <a href="{{ _p.web_main }}admin/skill_create.php?parent={{ skill.id }}" class="btn btn-primary btn-sm">
+                            <i class="fa fa-plus"></i> {{ "CreateChildSkill" | get_lang }}
+                        </a>
+                        <a href="{{ _p.web_main }}admin/skill_badge_create.php?id={{ skill.id }}" class="btn btn-primary btn-sm">
+                            <i class="fa fa-shield"></i> {{ "CreateBadge" | get_lang }}
+                        </a>
+
+                        {% if skill.status == 0 %}
+                            <a href="{{ _p.web_self ~ '?' ~ {"action": "enable", "id": skill.id}|url_encode() }}" class="btn btn-success btn-sm">
+                                <i class="fa fa-shield"></i> {{ 'Enable' }}
+                            </a>
+                        {% else %}
+                            <a href="{{ _p.web_self ~ '?' ~ {"action": "disable", "id": skill.id}|url_encode() }}" class="btn btn-danger btn-sm">
+                                <i class="fa fa-shield"></i> {{ 'Disable' }}
+                            </a>
+                        {% endif %}
+                    </td>
+                </tr>
+            {% endfor %}
+        </tbody>
+    </table>
+</div>

+ 56 - 0
src/Chamilo/CoreBundle/Entity/Skill.php

@@ -54,6 +54,20 @@ class Skill
      */
     private $criteria;
 
+    /**
+     * @var integer
+     *
+     * @ORM\Column(name="status", type="integer", nullable=false, options={"default": 1})
+     */
+    private $status;
+
+    /**
+     * @var \DateTime
+     *
+     * @ORM\Column(name="updated_at", type="datetime", nullable=false)
+     */
+    private $updatedAt;
+
     /**
      * @var integer
      *
@@ -203,6 +217,48 @@ class Skill
         return $this->criteria;
     }
 
+    /**
+     * Set status
+     * @param integer $status
+     * @return \Chamilo\CoreBundle\Entity\Skill
+     */
+    public function setStatus($status)
+    {
+        $this->status = $status;
+
+        return $this;
+    }
+
+    /**
+     * Get status
+     * @return integer
+     */
+    public function getStatus()
+    {
+        return $this->status;
+    }
+
+    /**
+     * Set updatedAt
+     * @param \DateTime $updatedAt The update datetime
+     * @return \Chamilo\CoreBundle\Entity\Skill
+     */
+    public function setUpdatedAt(\DateTime $updatedAt)
+    {
+        $this->updatedAt = $updatedAt;
+
+        return $this;
+    }
+
+    /**
+     * Get updatedAt
+     * @return \DateTime
+     */
+    public function getUpdatedAt()
+    {
+        return $this->updatedAt;
+    }
+
     /**
      * Get id
      *