Add support for skills tags - refs CT#8318

pull/2487/head
Yannick Warnier 9 years ago
parent f17126f869
commit f2bf214175
  1. 36
      app/Migrations/Schema/V111/Version20160706145000.php
  2. 21
      main/admin/skill_create.php
  3. 20
      main/admin/skill_edit.php
  4. 43
      main/inc/lib/extra_field.lib.php
  5. 4
      main/install/data.sql
  6. 1
      src/Chamilo/CoreBundle/Entity/ExtraField.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'");
}
}

@ -70,13 +70,32 @@ $createForm->addSelect(
['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10] ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
); );
$createForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]); $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->addButtonSave(get_lang('Save'));
$createForm->addHidden('id', null); $createForm->addHidden('id', null);
$createForm->setDefaults($formDefaultValues); $createForm->setDefaults($formDefaultValues);
if ($createForm->validate()) { 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) { if ($created) {
Session::write( Session::write(

@ -74,13 +74,31 @@ $editForm->addSelect(
['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10] ['id' => 'gradebook_id', 'multiple' => 'multiple', 'size' => 10]
); );
$editForm->addTextarea('description', get_lang('Description'), ['id' => 'description', 'rows' => 7]); $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->addButtonSave(get_lang('Save'));
$editForm->addHidden('id', null); $editForm->addHidden('id', null);
$editForm->setDefaults($skillDefaultInfo); $editForm->setDefaults($skillDefaultInfo);
if ($editForm->validate()) { if ($editForm->validate()) {
$updated = $objSkill->edit($editForm->getSubmitValues()); $skillValues = $editForm->getSubmitValues();
$updated = $objSkill->edit($skillValues);
$extraFieldValue = new ExtraFieldValue('skill');
$extraFieldValue->saveFieldValues($skillValues);
if ($updated) { if ($updated) {
Session::write( Session::write(

@ -122,6 +122,8 @@ class ExtraField extends Model
case 'lp_item': case 'lp_item':
$this->extraFieldType = EntityExtraField::LP_ITEM_FIELD_TYPE; $this->extraFieldType = EntityExtraField::LP_ITEM_FIELD_TYPE;
break; break;
case 'skill':
$this->extraFieldType = EntityExtraField::SKILL_FIELD_TYPE;
} }
$this->pageUrl = 'extra_fields.php?type='.$this->type; $this->pageUrl = 'extra_fields.php?type='.$this->type;
@ -149,7 +151,8 @@ class ExtraField extends Model
'question', 'question',
'lp', 'lp',
'calendar_event', '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 * @param string $variable
* *
* @return array|bool * @return array|bool
@ -410,8 +413,12 @@ class ExtraField extends Model
switch ($handler) { switch ($handler) {
case 'course': case 'course':
// no break
case 'session': case 'session':
// no break
case 'user': case 'user':
// no break
case 'skill':
break; break;
} }
@ -594,9 +601,9 @@ class ExtraField extends Model
* France:Paris;Bretagne;Marseille;Lyon|Belgique:Bruxelles;Namur;Liège;Bruges|Peru:Lima;Piura; * France:Paris;Bretagne;Marseille;Lyon|Belgique:Bruxelles;Namur;Liège;Bruges|Peru:Lima;Piura;
* into * into
* array( * array(
* 'France' => * 'France' =>
* array('Paris', 'Bregtane', 'Marseille'), * array('Paris', 'Bregtane', 'Marseille'),
* 'Belgique' => * 'Belgique' =>
* array('Namur', 'Liège') * array('Namur', 'Liège')
* ), etc * ), etc
* @param string $string * @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 FormValidator $form
* @param array $extraData * @param array $extraData
* @param bool $admin_permissions * @param bool $admin_permissions
* @param int $user_id
* @param array $extra * @param array $extra
* @param int $itemId * @param int $itemId
* @param array $exclude variables of extra field to exclude * @param array $exclude variables of extra field to exclude
* @param array * @param bool $useTagAsSelect
* @return array * @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( public function set_extra_fields_in_form(
$form, $form,
@ -1348,16 +1357,16 @@ class ExtraField extends Model
//if cache is set to true the jquery will be called 1 time //if cache is set to true the jquery will be called 1 time
$jquery_ready_content .= <<<EOF $jquery_ready_content .= <<<EOF
$("#extra_$variable").fcbkcomplete({ $("#extra_$variable").fcbkcomplete({
json_url: "$url?a=search_tags&field_id=$field_id&type={$this->type}", json_url: "$url?a=search_tags&field_id=$field_id&type={$this->type}",
cache: false, cache: false,
filter_case: true, filter_case: true,
filter_hide: true, filter_hide: true,
complete_text:"$complete_text", complete_text:"$complete_text",
firstselected: false, firstselected: false,
filter_selected: true, filter_selected: true,
newel: true newel: true
}); });
EOF; EOF;
} }
break; break;

@ -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, 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, 2);
INSERT INTO access_url_rel_course_category (access_url_id, course_category_id) VALUES (1, 3); 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());

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

Loading…
Cancel
Save