Ver Fonte

Add support for skills tags - refs CT#8318

Yannick Warnier há 8 anos atrás
pai
commit
f2bf214175

+ 36 - 0
app/Migrations/Schema/V111/Version20160706145000.php

@@ -0,0 +1,36 @@
+<?php
+/* For licensing terms, see /license.txt */
+
+namespace Application\Migrations\Schema\V111;
+
+use Application\Migrations\AbstractMigrationChamilo;
+use Doctrine\DBAL\Schema\Schema;
+use Doctrine\DBAL\Types\Type;
+
+/**
+ * Class Version20160706145000
+ * Add tag extra field for skills
+ * @package Application\Migrations\Schema\V111
+ */
+class Version20160706145000 extends AbstractMigrationChamilo
+{
+    /**
+     * @param Schema $schema
+     * @throws \Doctrine\DBAL\DBALException
+     * @throws \Doctrine\DBAL\Schema\SchemaException
+     */
+    public function up(Schema $schema)
+    {
+        $this->addSql("INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (8, 10, 'tags', 'Tags', 1, 1, NOW())");
+    }
+
+    /**
+     * @param Schema $schema
+     * @throws \Doctrine\DBAL\DBALException
+     * @throws \Doctrine\DBAL\Schema\SchemaException
+     */
+    public function down(Schema $schema)
+    {
+        $this->addSql("DELETE FROM extra_field WHERE extra_field_type = 8 AND field_type = 10 AND variable = 'tags'");
+    }
+}

+ 20 - 1
main/admin/skill_create.php

@@ -70,13 +70,32 @@ $createForm->addSelect(
     ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
 );
 $createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
+// EXTRA FIELDS
+$extraField = new ExtraField('skill');
+$returnParams = $extraField->addElements($createForm);
+$jquery_ready_content = $returnParams['jquery_ready_content'];
+
+// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
+if (!empty($jquery_ready_content)) {
+    $htmlHeadXtra[] = '<script>
+    $(document).ready(function(){
+        ' . $jquery_ready_content . '
+    });
+    </script>';
+}
+
 $createForm->addButtonSave(get_lang('Save'));
 $createForm->addHidden('id', null);
 
 $createForm->setDefaults($formDefaultValues);
 
 if ($createForm->validate()) {
-    $created = $objSkill->add($createForm->getSubmitValues());
+    $skillValues = $createForm->getSubmitValues();
+    $created = $objSkill->add($skillValues);
+
+    $skillValues['item_id'] = $created;
+    $extraFieldValue = new ExtraFieldValue('skill');
+    $extraFieldValue->saveFieldValues($skillValues);
 
     if ($created) {
         Session::write(

+ 19 - 1
main/admin/skill_edit.php

@@ -74,13 +74,31 @@ $editForm->addSelect(
     ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
 );
 $editForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]);
+// EXTRA FIELDS
+$extraField = new ExtraField('skill');
+$returnParams = $extraField->addElements($editForm, $skillId);
+$jquery_ready_content = $returnParams['jquery_ready_content'];
+
+// the $jquery_ready_content variable collects all functions that will be load in the $(document).ready javascript function
+if (!empty($jquery_ready_content)) {
+    $htmlHeadXtra[] = '<script>
+    $(document).ready(function(){
+        ' . $jquery_ready_content . '
+    });
+    </script>';
+}
+
 $editForm->addButtonSave(get_lang('Save'));
 $editForm->addHidden('id', null);
 
 $editForm->setDefaults($skillDefaultInfo);
 
 if ($editForm->validate()) {
-    $updated = $objSkill->edit($editForm->getSubmitValues());
+    $skillValues = $editForm->getSubmitValues();
+    $updated = $objSkill->edit($skillValues);
+
+    $extraFieldValue = new ExtraFieldValue('skill');
+    $extraFieldValue->saveFieldValues($skillValues);
 
     if ($updated) {
         Session::write(

+ 26 - 17
main/inc/lib/extra_field.lib.php

@@ -122,6 +122,8 @@ class ExtraField extends Model
             case 'lp_item':
                 $this->extraFieldType = EntityExtraField::LP_ITEM_FIELD_TYPE;
                 break;
+            case 'skill':
+                $this->extraFieldType = EntityExtraField::SKILL_FIELD_TYPE;
         }
 
         $this->pageUrl  = 'extra_fields.php?type='.$this->type;
@@ -149,7 +151,8 @@ class ExtraField extends Model
             'question',
             'lp',
             'calendar_event',
-            'lp_item'
+            'lp_item',
+            'skill'
         );
     }
 
@@ -286,7 +289,7 @@ class ExtraField extends Model
     }
 
     /**
-     * Get all the field info for User Tags
+     * Get all the field info for tags
      * @param string $variable
      *
      * @return array|bool
@@ -410,8 +413,12 @@ class ExtraField extends Model
 
         switch ($handler) {
             case 'course':
+                // no break
             case 'session':
+                // no break
             case 'user':
+                // no break
+            case 'skill':
                 break;
         }
 
@@ -594,9 +601,9 @@ class ExtraField extends Model
      * France:Paris;Bretagne;Marseille;Lyon|Belgique:Bruxelles;Namur;Liège;Bruges|Peru:Lima;Piura;
      * into
      * array(
- *      'France' =>
+     *   'France' =>
      *      array('Paris', 'Bregtane', 'Marseille'),
-     *  'Belgique' =>
+     *   'Belgique' =>
      *      array('Namur', 'Liège')
      * ), etc
      * @param string $string
@@ -769,15 +776,17 @@ class ExtraField extends Model
     }
 
     /**
+     * Add an element that matches the given extra field to the given $form object
      * @param FormValidator $form
      * @param array $extraData
      * @param bool $admin_permissions
-     * @param int $user_id
      * @param array $extra
      * @param int $itemId
      * @param array $exclude variables of extra field to exclude
-     * @param array
-     * @return array
+     * @param bool $useTagAsSelect
+     * @param array $showOnlyThisFields
+     * @param array $orderFields
+     * @return array If relevant, returns a one-element array with JS code to be added to the page HTML headers
      */
     public function set_extra_fields_in_form(
         $form,
@@ -1348,16 +1357,16 @@ class ExtraField extends Model
                         //if cache is set to true the jquery will be called 1 time
 
                         $jquery_ready_content .= <<<EOF
-                    $("#extra_$variable").fcbkcomplete({
-                        json_url: "$url?a=search_tags&field_id=$field_id&type={$this->type}",
-                        cache: false,
-                        filter_case: true,
-                        filter_hide: true,
-                        complete_text:"$complete_text",
-                        firstselected: false,
-                        filter_selected: true,                        
-                        newel: true
-                    });
+                            $("#extra_$variable").fcbkcomplete({
+                                json_url: "$url?a=search_tags&field_id=$field_id&type={$this->type}",
+                                cache: false,
+                                filter_case: true,
+                                filter_hide: true,
+                                complete_text:"$complete_text",
+                                firstselected: false,
+                                filter_selected: true,                        
+                                newel: true
+                            });
 EOF;
                         }
                         break;

+ 4 - 0
main/install/data.sql

@@ -1885,3 +1885,7 @@ INSERT INTO settings_options (variable, value, display_text) VALUES ('show_offic
 INSERT INTO access_url_rel_course_category (access_url_id, course_category_id) VALUES (1, 1);
 INSERT INTO access_url_rel_course_category (access_url_id, course_category_id) VALUES (1, 2);
 INSERT INTO access_url_rel_course_category (access_url_id, course_category_id) VALUES (1, 3);
+
+UPDATE settings_current SET selected_value = '1.11.0.5' WHERE variable = 'chamilo_database_version';
+
+INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at) VALUES (8, 10, 'tags', 'Tags', 1, 1, NOW());

+ 1 - 0
src/Chamilo/CoreBundle/Entity/ExtraField.php

@@ -24,6 +24,7 @@ class ExtraField extends BaseAttribute
     const CALENDAR_FIELD_TYPE = 5;
     const LP_FIELD_TYPE = 6;
     const LP_ITEM_FIELD_TYPE = 7;
+    const SKILL_FIELD_TYPE = 8;
 
     /**
      * @var integer