Browse Source

Merge branch '1.11.x' of github.com:chamilo/chamilo-lms into 1.11.x

Yannick Warnier 8 years ago
parent
commit
0d77174c6f

+ 92 - 0
app/Migrations/Schema/V111/Version20160610142700.php

@@ -0,0 +1,92 @@
+<?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 Version20160610142700
+ * Integrate the Skype plugin and create new settings current to enable it
+ * @package Application\Migrations\Schema\V111
+ */
+class Version20160610142700 extends AbstractMigrationChamilo
+{
+    /**
+     * @param Schema $schema
+     * @throws \Doctrine\DBAL\DBALException
+     * @throws \Doctrine\DBAL\Schema\SchemaException
+     */
+    public function up(Schema $schema)
+    {
+        $dataList = $this
+            ->connection
+            ->executeQuery("
+                SELECT id FROM extra_field
+                WHERE variable = 'skype' AND extra_field_type = 1 
+            ")
+            ->fetchAll();
+
+        if (empty($dataList)) {
+            $this->addSql("
+                INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
+                VALUES (1, 1, 'skype', 'Skype', 1, 1, now())
+            ");
+        }
+
+        $this->addSql("
+            INSERT INTO extra_field (extra_field_type, field_type, variable, display_text, visible, changeable, created_at)
+            VALUES (1, 1, 'linkedin_url', 'LinkedInUrl', 1, 1, now())
+        ");
+
+        $this->addSettingCurrent(
+            'allow_show_skype_account',
+            null,
+            'radio',
+            'Platform',
+            'true',
+            'AllowShowSkypeAccountTitle',
+            'AllowShowSkypeAccountComment',
+            null,
+            null,
+            1,
+            true,
+            false,
+            [
+                ['value' => 'false', 'text' => 'No'],
+                ['value' => 'true', 'text' => 'Yes']
+            ]
+        );
+
+        $this->addSettingCurrent(
+            'allow_show_linkedin_url',
+            null,
+            'radio',
+            'Platform',
+            'true',
+            'AllowShowLinkedInUrlTitle',
+            'AllowShowLinkedInUrlComment',
+            null,
+            null,
+            1,
+            true,
+            false,
+            [
+                ['value' => 'false', 'text' => 'No'],
+                ['value' => 'true', 'text' => 'Yes']
+            ]
+        );
+    }
+
+    /**
+     * @param Schema $schema
+     * @throws \Doctrine\DBAL\DBALException
+     * @throws \Doctrine\DBAL\Schema\SchemaException
+     */
+    public function down(Schema $schema)
+    {
+
+    }
+}

+ 1 - 1
main/admin/extra_field_options.php

@@ -172,7 +172,7 @@ switch ($action) {
             if ($check) {
                 $values = $form->exportValues();
                 $res = $obj->update($values);
-                Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['name']), false);
+                Display::display_confirmation_message(sprintf(get_lang('ItemUpdated'), $values['display_text']), false);
             }
             $obj->display();
         } else {

+ 2 - 1
main/extrafield/translate.php

@@ -10,6 +10,7 @@ api_protect_admin_script();
 $em = Database::getManager();
 
 $extraFieldInfo = null;
+$extraFieldOptionInfo = null;
 $variableLanguage = null;
 $originalName = null;
 
@@ -23,7 +24,7 @@ if (isset($_GET['extra_field'])) {
     $originalName = $extraFieldOptionInfo['display_text'];
 }
 
-if (empty($extraFieldInfo) || empty($variableLanguage) || empty($originalName)) {
+if ((empty($extraFieldInfo) && empty($extraFieldOptionInfo)) || empty($variableLanguage) || empty($originalName)) {
     api_not_allowed(true);
 }
 

+ 5 - 9
main/inc/ajax/model.ajax.php

@@ -1526,15 +1526,11 @@ switch ($action) {
     case 'get_extra_field_options':
         $obj = new ExtraFieldOption($type);
         $columns = array('display_text', 'option_value', 'option_order');
-        $result = Database::select(
-            '*',
-            $obj->table,
-            array(
-                'where' => array("field_id = ? " => $field_id),
-                'order' => "$sidx $sord",
-                'LIMIT' => "$start , $limit",
-            )
-        );
+        $result = $obj->get_all([
+            'where' => array("field_id = ? " => $field_id),
+            'order' => "$sidx $sord",
+            'LIMIT' => "$start , $limit"
+        ]);
         break;
     case 'get_usergroups_teacher':
         $columns = array('name', 'users', 'status', 'group_type', 'actions');

+ 13 - 8
main/inc/lib/extra_field.lib.php

@@ -1763,14 +1763,19 @@ EOF;
 
         $form->addElement('header', $header);
 
-        $translateUrl = api_get_path(WEB_CODE_PATH) . 'extrafield/translate.php?' . http_build_query([
-            'extra_field' => $id
-        ]);
-        $translateButton = Display::toolbarButton(get_lang('TranslateThisTerm'), $translateUrl, 'language', 'link');
-        $form->addText(
-            'display_text',
-            [get_lang('Name'), $translateButton]
-        );
+        if ($action == 'edit') {
+            $translateUrl = api_get_path(WEB_CODE_PATH) . 'extrafield/translate.php?' . http_build_query([
+                'extra_field' => $id
+            ]);
+            $translateButton = Display::toolbarButton(get_lang('TranslateThisTerm'), $translateUrl, 'language', 'link');
+
+            $form->addText(
+                'display_text',
+                [get_lang('Name'), $translateButton]
+            );
+        } else {
+            $form->addElement('text', 'display_text', get_lang('Name'));
+        }
 
         // Field type
         $types = self::get_field_types();

+ 71 - 25
main/inc/lib/extra_field_option.lib.php

@@ -411,36 +411,70 @@ class ExtraFieldOption extends Model
      * Gets an array of options for a specific field
      * @param int $field_id The field ID
      * @param bool $add_id_in_array Whether to add the row ID in the result
-     * @param string $ordered_by Extra ordering query bit
-     * @result mixed Row on success, false on failure
-     * @assert (0, '') === false
+     * @param null $ordered_by Extra ordering query bit
+     * @return array The options if they exists. Otherwise return false
      */
     public function get_field_options_by_field($field_id, $add_id_in_array = false, $ordered_by = null)
     {
         $field_id = intval($field_id);
 
-        $sql = "SELECT * FROM {$this->table}
-                WHERE field_id = $field_id ";
+        $orderBy = null;
+
+        switch ($ordered_by) {
+            case 'id':
+                $orderBy = ['id' => 'ASC'];
+                break;
+            case 'field_id':
+                $orderBy = ['fieldId' => 'ASC'];
+                break;
+            case 'option_value':
+                $orderBy = ['optionValue' => 'ASC'];
+                break;
+            case 'display_text':
+                $orderBy = ['displayText' => 'ASC'];
+                break;
+            case 'priority':
+                $orderBy = ['priority' => 'ASC'];
+                break;
+            case 'priority_message':
+                $orderBy = ['priorityMessage' => 'ASC'];
+                break;
+            case 'option_order':
+                $orderBy = ['optionOrder' => 'ASC'];
+                break;
+        }
+
+        $result = Database::getManager()
+            ->getRepository('ChamiloCoreBundle:ExtraFieldOptions')
+            ->findBy(['field' => $field_id], $orderBy);
 
-        if (!empty($ordered_by)) {
-            $sql .= " ORDER BY $ordered_by ";
+        if (!$result) {
+            return false;
         }
 
-        $result = Database::query($sql);
-        if (Database::num_rows($result) > 0) {
+        $options = [];
+
+        foreach ($result as $row) {
+            $option = [
+                'id' => $row->getId(),
+                'field_id' => $row->getField()->getId(),
+                'option_value' => $row->getValue(),
+                'display_text' => $row->getDisplayText(),
+                'priority' => $row->getPriority(),
+                'priority_message' => $row->getPriorityMessage(),
+                'option_order' => $row->getOptionOrder()
+            ];
+
             if ($add_id_in_array) {
-                $options = array();
-                while ($row = Database::fetch_array($result, 'ASSOC')) {
-                    $options[$row['id']] = $row;
-                }
+                $options[$row->getId()] = $option;
 
-                return $options;
-            } else {
-                return Database::store_result($result, 'ASSOC');
+                continue;
             }
+
+            $options[] = $option;
         }
 
-        return false;
+        return $options;
     }
 
     /**
@@ -616,18 +650,15 @@ class ExtraFieldOption extends Model
         $form->addElement('hidden', 'field_id', $this->field_id);
 
         if ($action == 'edit') {
-            $platformLanguage = api_get_setting('platformLanguage');
-            $languageId = api_get_language_id($platformLanguage);
-            $languageInfo = api_get_language_info($languageId);
-            $translateUrl = api_get_path(WEB_CODE_PATH) . 'admin/sub_language.php?' . http_build_query([
-                'id' => $languageInfo['parent_id'],
-                'action' => 'registersublanguage',
-                'sub_language_id' => $languageInfo['id'],
+            $translateUrl = api_get_path(WEB_CODE_PATH) . 'extrafield/translate.php?' . http_build_query([
                 'extra_field_option' => $id
             ]);
             $translateButton = Display::toolbarButton(get_lang('TranslateThisTerm'), $translateUrl, 'language', 'link');
 
-            $form->addElement('text', 'display_text', [get_lang('Name'), $translateButton]);
+            $form->addText(
+                'display_text',
+                [get_lang('Name'), $translateButton]
+            );
         } else {
             $form->addElement('text', 'display_text', get_lang('Name'));
         }
@@ -775,4 +806,19 @@ class ExtraFieldOption extends Model
 
         return $objExtraField->get($extraField->getId(), $translateDisplayText);
     }
+
+    /**
+     * @param null $options
+     * @return array
+     */
+    public function get_all($options = null)
+    {
+        $result = parent::get_all($options);
+
+        foreach ($result as &$row) {
+            $row['display_text'] = self::translateDisplayName($row['display_text']);
+        }
+
+        return $result;
+    }
 }

+ 1 - 0
main/inc/lib/social.lib.php

@@ -1735,6 +1735,7 @@ class SocialManager extends UserManager
         $template->assign('chat_enabled', $chatEnabled);
         $template->assign('user_relation', $userRelationType);
         $template->assign('user_relation_type_friend', USER_RELATION_TYPE_FRIEND);
+        $template->assign('show_full_profile', $show_full_profile);
         $templateName = $template->get_template('social/user_block.tpl');
 
         if (in_array($groupBlock, ['groups', 'group_edit', 'member_list'])) {

+ 8 - 9
main/social/profile.php

@@ -346,6 +346,9 @@ if ($show_full_profile) {
         $extra_information_value = '<ul class="list-group">';
         $extraField = new ExtraField('user');
         foreach ($extra_user_data as $key => $data) {
+            if (empty($data)) {
+                continue;
+            }
             // Avoiding parameters
             if (in_array(
                 $key,
@@ -364,6 +367,10 @@ if ($show_full_profile) {
                 $field_variable
             );
 
+            if (in_array($extraFieldInfo['variable'], ['skype', 'linkedin_url'])) {
+                break;
+            }
+
             if ($extraFieldInfo['visible'] != 1) {
                 continue;
             }
@@ -420,15 +427,7 @@ if ($show_full_profile) {
                         $extra_information_value .= '<li class="list-group-item">'.$data.'</li>';
                         break;
                     default:
-                        if (!empty($data)) {
-                            $extra_field_title = ucfirst($extraFieldInfo['display_text']);
-                            if ($extra_field_title == 'Skype') {
-                                $data = '<a href="skype:' . $data . '?chat">' . get_lang('Chat') . '</a>';
-                                $extra_information_value .= '<li class="list-group-item">'.Display::return_icon('skype.png', $extraFieldInfo['display_text'], null, ICON_SIZE_TINY, false) . ' ' . $data.'</li>';
-                            } else {
-                                $extra_information_value .= '<dt>'.ucfirst($extraFieldInfo['display_text']).':</dt><dd>'.$data.'</dd>';
-                            }
-                        }
+                        $extra_information_value .= '<li class="list-group-item">'.ucfirst($extraFieldInfo['display_text']) . ': ' . $data . '</li>';
                     break;
                 }
             }

+ 30 - 2
main/template/default/social/user_block.tpl

@@ -17,7 +17,7 @@
                             <li class="item">
                                 {{ user.complete_name }}
                             </li>
-                            {% if vcard_user_link  %}
+                            {% if show_full_profile  %}
                                 <li class="item">
                                     <a href="{{ _p.web }}main/messages/new_message.php">
                                     <img src="{{ "instant_message.png" | icon }}" alt="{{ "Email" | get_lang }}">
@@ -30,6 +30,34 @@
                                     {{ "BusinessCard" | get_lang }}
                                     </a>
                                 </li>
+
+                                {% set skype_account = '' %}
+                                {% set linkedin_url = '' %}
+                                {% for extra in user.extra %}
+                                    {% if extra.value.getField().getVariable() == 'skype' %}
+                                        {% set skype_account = extra.value.getValue() %}
+                                    {% endif %}
+
+                                    {% if extra.value.getField().getVariable() == 'linkedin_url' %}
+                                        {% set linkedin_url = extra.value.getValue() %}
+                                    {% endif %}
+                                {% endfor %}
+
+                                {% if 'allow_show_skype_account'|get_setting == 'true' and not skype_account is empty %}
+                                    <li class="item">
+                                        <a href="skype:{{ skype_account }}?chat">
+                                            <span class="fa fa-skype fa-fw" aria-hidden="true"></span> {{ 'Skype'|get_lang }}
+                                        </a>
+                                    </li>
+                                {% endif %}
+
+                                {% if 'allow_show_linkedin_url'|get_setting == 'true' and not linkedin_url is empty %}
+                                    <li class="item">
+                                        <a href="{{ linkedin_url }}" target="_blank">
+                                            <span class="fa fa-linkedin fa-fw" aria-hidden="true"></span> {{ 'LinkedIn'|get_lang }}
+                                        </a>
+                                    </li>
+                                {% endif %}
                             {% endif %}
                         {% if chat_enabled == 1 %}
                             {% if user.user_is_online_in_chat != 0 %}
@@ -49,7 +77,7 @@
                         
                         {% if not profile_edition_link is empty %}
                         <li class="item">
-                            <a class="btn link btn-sm btn-block" href="{{ profile_edition_link }}">
+                            <a class="btn btn-link btn-sm btn-block" href="{{ profile_edition_link }}">
                             <em class="fa fa-edit"></em>{{ "EditProfile" | get_lang }}
                             </a>
                         </li>

+ 0 - 4
plugin/skype/README.md

@@ -1,4 +0,0 @@
-Skype Plugin
-==============
-
-Create Skype user field

+ 0 - 9
plugin/skype/config.php

@@ -1,9 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Config the plugin
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-
-require_once api_get_path(SYS_PATH) . 'main/inc/global.inc.php';

+ 0 - 8
plugin/skype/index.php

@@ -1,8 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Config the plugin
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-require_once __DIR__ . '/config.php';

+ 0 - 10
plugin/skype/install.php

@@ -1,10 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Initialization install
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-require_once __DIR__ . '/config.php';
-
-Skype::create()->install();

+ 0 - 9
plugin/skype/lang/english.php

@@ -1,9 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Strings to english L10n
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-$strings['plugin_title'] = 'Skype';
-$strings['plugin_comment'] = 'This plugin creates a Skype user field.';

+ 0 - 9
plugin/skype/lang/spanish.php

@@ -1,9 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Strings to spanish L10n
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-$strings['plugin_title'] = 'Skype';
-$strings['plugin_comment'] = 'Este plugin crea un campo de usuario Skype.';

+ 0 - 10
plugin/skype/plugin.php

@@ -1,10 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Get the plugin info
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-require_once __DIR__.'/config.php';
-
-$plugin_info = Skype::create()->get_info();

+ 0 - 34
plugin/skype/src/HookSkype.php

@@ -1,34 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
- * Create Skype user field
- *
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-class HookObserverSkype extends HookObserver implements HookSkypeObserverInterface
-{
-
-    /**
-     * Class constructor
-     */
-    public function __construct()
-    {
-        parent::__construct(
-            'plugin/skype/src/Skype.php', 'skype'
-        );
-    }
-
-    /**
-     * Create Skype user field when plugin is enabled
-     * @param HookSkypeEventInterface $hook The hook
-     */
-    public function hookEventSkype(HookSkypeEventInterface $hook)
-    {
-        $data = $hook->getEventData();
-        if ($data['type'] === HOOK_EVENT_TYPE_PRE) {
-            // Code
-        }
-    }
-}

+ 0 - 91
plugin/skype/src/Skype.php

@@ -1,91 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-
-/**
- * Create Skype user field
- *
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-class Skype extends Plugin implements HookPluginInterface
-{
-
-    /**
-     * Class constructor
-     */
-    protected function __construct()
-    {
-        parent::__construct('0.1', 'Imanol Losada Oriol');
-    }
-
-    /**
-     * Instance the plugin
-     * @staticvar null $result
-     * @return Skype
-     */
-    static function create()
-    {
-        static $result = null;
-
-        return $result ? $result : $result = new self();
-    }
-
-    /**
-     * Install the plugin
-     */
-    public function install()
-    {
-        $this->installHook();
-
-        $result = Database::select(
-            'variable',
-            Database::get_main_table(TABLE_EXTRA_FIELD),
-            array(
-                'where'=> array(
-                    'variable = ?' => array(
-                        'skype'
-                    )
-                )
-            )
-        );
-
-        if (empty($result)) {
-            $extraField = new ExtraField('user');
-            $extraField->save(array(
-                'field_type' => ExtraField::FIELD_TYPE_TEXT,
-                'variable' => 'skype',
-                'display_text' => 'Skype',
-                'visible' => 1,
-                'changeable' => 1
-            ));
-        }
-    }
-
-    /**
-     * Uninstall the plugin
-     * @return void
-     */
-    public function uninstall()
-    {
-        $this->uninstallHook();
-    }
-
-    /**
-     * Install the Skype hook
-     */
-    public function installHook()
-    {
-        $hook = HookObserverSkype::create();
-        HookEventSkype::create()->attach($hook);
-    }
-
-    /**
-     * Uninstall the Skype hook
-     */
-    public function uninstallHook()
-    {
-        $hook = HookObserverSkype::create();
-        HookEventSkype::create()->detach($hook);
-    }
-
-}

+ 0 - 10
plugin/skype/uninstall.php

@@ -1,10 +0,0 @@
-<?php
-/* For licensing terms, see /license.txt */
-/**
- * Initialization uninstall
- * @author Imanol Losada Oriol <imanol.losada@beeznest.com>
- * @package chamilo.plugin.skype
- */
-require_once __DIR__ . '/config.php';
-
-Skype::create()->uninstall();

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

@@ -185,7 +185,7 @@ class ExtraField extends BaseAttribute
      */
     public function getDisplayText()
     {
-        return $this->displayText;
+        return \ExtraField::translateDisplayName($this->variable, $this->displayText);
     }
 
     /**

+ 1 - 1
src/Chamilo/CoreBundle/Entity/ExtraFieldOptions.php

@@ -139,7 +139,7 @@ class ExtraFieldOptions
      */
     public function getDisplayText()
     {
-        return $this->displayText;
+        return \ExtraFieldOption::translateDisplayName($this->displayText);
     }
 
     /**