From f2bf214175308a627d420561ed4f114e9ef1e60c Mon Sep 17 00:00:00 2001 From: Yannick Warnier Date: Wed, 6 Jul 2016 10:17:53 -0500 Subject: [PATCH] Add support for skills tags - refs CT#8318 --- .../Schema/V111/Version20160706145000.php | 36 ++++++++++++++++ main/admin/skill_create.php | 21 ++++++++- main/admin/skill_edit.php | 20 ++++++++- main/inc/lib/extra_field.lib.php | 43 +++++++++++-------- main/install/data.sql | 4 ++ src/Chamilo/CoreBundle/Entity/ExtraField.php | 1 + 6 files changed, 106 insertions(+), 19 deletions(-) create mode 100644 app/Migrations/Schema/V111/Version20160706145000.php diff --git a/app/Migrations/Schema/V111/Version20160706145000.php b/app/Migrations/Schema/V111/Version20160706145000.php new file mode 100644 index 0000000000..66f018ea1a --- /dev/null +++ b/app/Migrations/Schema/V111/Version20160706145000.php @@ -0,0 +1,36 @@ +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'"); + } +} \ No newline at end of file diff --git a/main/admin/skill_create.php b/main/admin/skill_create.php index a3b446e438..b6554e2d43 100644 --- a/main/admin/skill_create.php +++ b/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[] = ''; +} + $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( diff --git a/main/admin/skill_edit.php b/main/admin/skill_edit.php index 59513d99e2..d998faa608 100644 --- a/main/admin/skill_edit.php +++ b/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[] = ''; +} + $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( diff --git a/main/inc/lib/extra_field.lib.php b/main/inc/lib/extra_field.lib.php index 20fd290738..0ce5ad60ed 100755 --- a/main/inc/lib/extra_field.lib.php +++ b/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 .= <<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; diff --git a/main/install/data.sql b/main/install/data.sql index e6137d0d5f..9aa48def47 100644 --- a/main/install/data.sql +++ b/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()); diff --git a/src/Chamilo/CoreBundle/Entity/ExtraField.php b/src/Chamilo/CoreBundle/Entity/ExtraField.php index bdf9949495..c6868f918a 100644 --- a/src/Chamilo/CoreBundle/Entity/ExtraField.php +++ b/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