Enh: Added searchable flags to profile fields

This commit is contained in:
Lucas Bartholemy 2016-05-23 13:03:50 +02:00
parent c846a02193
commit 5c8ce9bc1b
3 changed files with 43 additions and 2 deletions

View File

@ -0,0 +1,29 @@
<?php
use yii\db\Migration;
class m160523_105732_profile_searchable extends Migration
{
public function up()
{
$this->addColumn('profile_field', 'searchable', $this->boolean()->defaultValue(true));
}
public function down()
{
echo "m160523_105732_profile_searchable cannot be reverted.\n";
return false;
}
/*
// Use safeUp/safeDown to run migration code within a transaction
public function safeUp()
{
}
public function safeDown()
{
}
*/
}

View File

@ -1,5 +1,11 @@
<?php
/**
* @link https://www.humhub.org/
* @copyright Copyright (c) 2016 HumHub GmbH & Co. KG
* @license https://www.humhub.com/licences
*/
namespace humhub\modules\user\models;
use Yii;
@ -53,7 +59,7 @@ class ProfileField extends \yii\db\ActiveRecord
{
return array(
array(['profile_field_category_id', 'field_type_class', 'internal_name', 'title', 'sort_order'], 'required'),
array(['profile_field_category_id', 'required', 'editable', 'show_at_registration', 'visible', 'sort_order', 'created_by', 'updated_by'], 'integer'),
array(['profile_field_category_id', 'required', 'editable', 'searchable', 'show_at_registration', 'visible', 'sort_order', 'created_by', 'updated_by'], 'integer'),
array(['module_id', 'field_type_class', 'title'], 'string', 'max' => 255),
array('internal_name', 'string', 'max' => 100),
array(['ldap_attribute', 'translation_category'], 'string', 'max' => 255),
@ -92,6 +98,7 @@ class ProfileField extends \yii\db\ActiveRecord
'show_at_registration' => Yii::t('UserModule.models_ProfileField', 'Show at registration'),
'translation_category' => Yii::t('UserModule.models_ProfileField', 'Translation Category ID'),
'required' => Yii::t('UserModule.models_ProfileField', 'Required'),
'searchable' => Yii::t('UserModule.models_ProfileField', 'Searchable'),
'title' => Yii::t('UserModule.models_ProfileField', 'Title'),
'description' => Yii::t('UserModule.models_ProfileField', 'Description'),
'sort_order' => Yii::t('UserModule.models_ProfileField', 'Sort order'),
@ -204,6 +211,9 @@ class ProfileField extends \yii\db\ActiveRecord
'editable' => array(
'type' => 'checkbox',
),
'searchable' => array(
'type' => 'checkbox',
),
'profile_field_category_id' => array(
'type' => 'dropdownlist',
'items' => \yii\helpers\ArrayHelper::map($categories, 'id', 'title'),

View File

@ -553,7 +553,9 @@ class User extends ContentContainerActiveRecord implements \yii\web\IdentityInte
if (!$this->profile->isNewRecord) {
foreach ($this->profile->getProfileFields() as $profileField) {
$attributes['profile_' . $profileField->internal_name] = $profileField->getUserValue($this, true);
if ($profileField->searchable) {
$attributes['profile_' . $profileField->internal_name] = $profileField->getUserValue($this, true);
}
}
}