Add extra fields (user tag+dropdown) in user list see BT#8303

pull/2487/head
jmontoyaa 9 years ago
parent 67108bb799
commit f0fece9919
  1. 232
      main/admin/user_list.php
  2. 2
      main/cron/import_csv.php
  3. 5
      main/inc/ajax/user_manager.ajax.php
  4. 3
      main/inc/lib/certificate.lib.php
  5. 31
      main/inc/lib/extra_field.lib.php
  6. 11
      main/inc/lib/extra_field_value.lib.php
  7. 109
      main/inc/lib/usermanager.lib.php

@ -1,14 +1,14 @@
<?php
/* For licensing terms, see /license.txt */
use ChamiloSession as Session;
/**
* @author Bart Mollet
* @author Julio Montoya <gugli100@gmail.com> BeezNest 2011
* @package chamilo.admin
*/
use ChamiloSession as Session;
$cidReset = true;
require_once '../inc/global.inc.php';
@ -25,6 +25,24 @@ if (api_get_configuration_value('deny_delete_users')) {
$url = api_get_path(WEB_AJAX_PATH).'course.ajax.php?a=get_user_courses';
$urlSession = api_get_path(WEB_AJAX_PATH).'session.ajax.php?a=get_user_sessions';
$extraField = new ExtraField('user');
$variables = $extraField->get_all_extra_field_by_type(ExtraField::FIELD_TYPE_TAG);
$variablesSelect = $extraField->get_all_extra_field_by_type(ExtraField::FIELD_TYPE_SELECT);
if (!empty($variablesSelect)) {
$variables = array_merge($variables, $variablesSelect);
}
$variablesToShow = [];
if ($variables) {
foreach ($variables as $variableId) {
$extraFieldInfo = $extraField->get($variableId);
$variablesToShow[] = $extraFieldInfo['variable'];
}
}
Session::write('variables_to_show', $variablesToShow);
$htmlHeadXtra[] = '<script>
function load_course_list (div_course,my_user_id) {
$.ajax({
@ -117,7 +135,6 @@ function display_advanced_search_form () {
$(document).ready(function() {
var select_val = $("#input_select_extra_data").val();
if ( document.getElementById(\'extra_data_text\')) {
if (select_val != 0) {
document.getElementById(\'extra_data_text\').style.display="block";
if (document.getElementById(\'input_extra_text\'))
@ -159,7 +176,7 @@ api_protect_admin_script(true);
*/
function prepare_user_sql_query($is_count)
{
$sql = "";
$sql = '';
$user_table = Database::get_main_table(TABLE_MAIN_USER);
$admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
@ -259,15 +276,13 @@ function prepare_user_sql_query($is_count)
$keyword_extra_value = " AND ufv.field_value LIKE '%".trim($keyword_extra_data_text)."%' ";
}
*/
$sql .= " $query_admin_table
WHERE (
u.firstname LIKE '". Database::escape_string("%".$keywordListValues['keyword_firstname']."%")."' AND
u.lastname LIKE '". Database::escape_string("%".$keywordListValues['keyword_lastname']."%")."' AND
u.username LIKE '". Database::escape_string("%".$keywordListValues['keyword_username']."%")."' AND
u.email LIKE '". Database::escape_string("%".$keywordListValues['keyword_email']."%")."' AND
u.status LIKE '".Database::escape_string($keywordListValues['keyword_status'])."'
";
u.status LIKE '".Database::escape_string($keywordListValues['keyword_status'])."' ";
if (!empty($keywordListValues['keyword_officialcode'])) {
$sql .= " AND u.official_code LIKE '" . Database::escape_string("%" . $keywordListValues['keyword_officialcode'] . "%") . "' ";
}
@ -284,6 +299,44 @@ function prepare_user_sql_query($is_count)
$sql .= " ) ";
}
$variables = Session::read('variables_to_show');
$extraField = new ExtraField('user');
$extraFieldResult = [];
foreach ($variables as $variable) {
if (isset($_GET['extra_'.$variable])) {
if (is_array($_GET['extra_'.$variable])) {
$values = $_GET['extra_'.$variable];
} else {
$values = [$_GET['extra_'.$variable]];
}
$info = $extraField->get_handler_field_info_by_field_variable($variable);
if (empty($info)) {
continue;
}
foreach ($values as $value) {
if ($info['field_type'] == ExtraField::FIELD_TYPE_TAG) {
$result = $extraField->getAllUserPerTag($info['id'], $value);
$result = empty($result) ? [] : array_column($result, 'user_id');
} else {
$result = UserManager::get_extra_user_data_by_value(
$variable,
$value
);
}
if (!empty($result)) {
$extraFieldResult = array_merge($extraFieldResult, $result);
}
}
}
}
if (!empty($extraFieldResult)) {
$sql .= " AND (u.id IN ('".implode("','", $extraFieldResult)."')) ";
}
// adding the filter to see the user's only of the current access_url
if ((api_is_platform_admin() || api_is_session_admin())
&& api_get_multiple_access_url()
@ -355,13 +408,12 @@ function loginUser($userId)
Session::write('login_as', true);
$target_url = api_get_path(WEB_PATH)."user_portal.php";
$message .= '<br />'.sprintf(get_lang('LoginSuccessfulGoToX'),'<a href="'.$target_url.'">'.$target_url.'</a>');
$message .= '<br />'.sprintf(get_lang('LoginSuccessfulGoToX'), '<a href="'.$target_url.'">'.$target_url.'</a>');
Display :: display_header(get_lang('UserList'));
Display :: display_normal_message($message, false);
Display :: display_footer();
exit;
}
}
}
/**
@ -374,6 +426,7 @@ function get_number_of_users()
$res = Database::query($sql);
$obj = Database::fetch_object($res);
return $obj->total_number_of_items;
}
@ -385,7 +438,8 @@ function get_number_of_users()
* @param string Order (ASC,DESC)
* @see SortableTable#get_table_data($from)
*/
function get_user_data($from, $number_of_items, $column, $direction) {
function get_user_data($from, $number_of_items, $column, $direction)
{
$sql = prepare_user_sql_query(false);
/* @todo will not work because now we use the salt field
@ -403,7 +457,7 @@ function get_user_data($from, $number_of_items, $column, $direction) {
$direction = 'ASC';
}
$column = intval($column);
$from = intval($from);
$from = intval($from);
$number_of_items = intval($number_of_items);
$preventSessionAdminsToManageAllUsers = api_get_setting('prevent_session_admins_to_manage_all_users');
@ -445,9 +499,9 @@ function get_user_data($from, $number_of_items, $column, $direction) {
api_get_local_time($user[9]),
$user[0]
);
}
}
return $users;
return $users;
}
/**
@ -455,7 +509,8 @@ function get_user_data($from, $number_of_items, $column, $direction) {
* @param string $email An email-address
* @return string HTML-code with a mailto-link
*/
function email_filter($email) {
function email_filter($email)
{
return Display :: encrypted_mailto_link($email, $email);
}
@ -464,7 +519,8 @@ function email_filter($email) {
* @param string $email An email-address
* @return string HTML-code with a mailto-link
*/
function user_filter($name, $params, $row) {
function user_filter($name, $params, $row)
{
return '<a href="'.api_get_path(WEB_PATH).'whoisonline.php?origin=user_list&id='.$row[0].'">'.$name.'</a>';
}
@ -475,11 +531,12 @@ function user_filter($name, $params, $row) {
* @param array Row of elements to alter
* @return string Some HTML-code with modify-buttons
*/
function modify_filter($user_id, $url_params, $row) {
function modify_filter($user_id, $url_params, $row)
{
global $charset, $_admins_list;
$is_admin = in_array($user_id,$_admins_list);
$statusname = api_get_status_langvars();
$user_is_anonymous = false;
$is_admin = in_array($user_id, $_admins_list);
$statusname = api_get_status_langvars();
$user_is_anonymous = false;
$current_user_status_label = $row['7'];
if ($current_user_status_label == $statusname[ANONYMOUS]) {
@ -503,44 +560,43 @@ function modify_filter($user_id, $url_params, $row) {
$result .= Display::return_icon('course_na.png',get_lang('Sessions')).'&nbsp;&nbsp;';
}
if (api_is_platform_admin()) {
if (!$user_is_anonymous) {
$result .= '<a href="user_information.php?user_id='.$user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
} else {
$result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
}
}
if (api_is_platform_admin()) {
if (!$user_is_anonymous) {
$result .= '<a href="user_information.php?user_id='.$user_id.'">'.Display::return_icon('synthese_view.gif', get_lang('Info')).'</a>&nbsp;&nbsp;';
} else {
$result .= Display::return_icon('synthese_view_na.gif', get_lang('Info')).'&nbsp;&nbsp;';
}
}
//only allow platform admins to login_as, or session admins only for students (not teachers nor other admins)
if (api_is_platform_admin() || (api_is_session_admin() && $current_user_status_label == $statusname[STUDENT])) {
if (!$user_is_anonymous) {
if (!$user_is_anonymous) {
if (api_global_admin_can_edit_admin($user_id)) {
$result .= '<a href="user_list.php?action=login_as&user_id='.$user_id.'&sec_token='.$_SESSION['sec_token'].'">'.Display::return_icon('login_as.png', get_lang('LoginAs')).'</a>&nbsp;&nbsp;';
} else {
$result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
}
} else {
$result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
}
} else {
$result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
}
} else {
$result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
$result .= Display::return_icon('login_as_na.png', get_lang('LoginAs')).'&nbsp;&nbsp;';
}
if ($current_user_status_label != $statusname[STUDENT]) {
$result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).'&nbsp;&nbsp;';
} else {
$result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;&nbsp;';
}
if ($current_user_status_label != $statusname[STUDENT]) {
$result .= Display::return_icon('statistics_na.gif', get_lang('Reporting')).'&nbsp;&nbsp;';
} else {
$result .= '<a href="../mySpace/myStudents.php?student='.$user_id.'">'.Display::return_icon('statistics.gif', get_lang('Reporting')).'</a>&nbsp;&nbsp;';
}
if (api_is_platform_admin(true)) {
if (api_is_platform_admin(true)) {
$editProfileUrl = Display::getProfileEditionLink($user_id, true);
if (!$user_is_anonymous && api_global_admin_can_edit_admin($user_id, null, true)) {
$result .= '<a href="' . $editProfileUrl . '">'.Display::return_icon('edit.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
} else {
} else {
$result .= Display::return_icon('edit_na.png', get_lang('Edit'), array(), ICON_SIZE_SMALL).'</a>&nbsp;';
}
}
}
}
$allowAssignSkill = api_is_platform_admin(false, true);
@ -609,7 +665,6 @@ function modify_filter($user_id, $url_params, $row) {
return $result;
}
/**
* Build the active-column of the table to lock or unlock a certain user
* lock = the user can no longer use this account
@ -636,12 +691,13 @@ function active_filter($active, $params, $row)
$result = '';
if ($action == 'edit') {
if ($action === 'edit') {
$result = Display::return_icon($image.'.png', get_lang('AccountExpired'), array(), 16);
} elseif ($row['0']<>$_user['user_id']) {
} elseif ($row['0'] <> $_user['user_id']) {
// you cannot lock yourself out otherwise you could disable all the accounts including your own => everybody is locked out and nobody can change it anymore.
$result = Display::return_icon($image.'.png', get_lang(ucfirst($action)), array('onclick'=>'active_user(this);', 'id'=>'img_'.$row['0']), 16).'</a>';
}
return $result;
}
@ -660,11 +716,11 @@ function status_filter($status) {
}
if (isset($_GET['keyword']) || isset($_GET['keyword_firstname'])) {
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array ("url" => 'user_list.php', "name" => get_lang('UserList'));
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array("url" => 'user_list.php', "name" => get_lang('UserList'));
$tool_name = get_lang('SearchUsers');
} else {
$interbreadcrumb[] = array ("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$interbreadcrumb[] = array("url" => 'index.php', "name" => get_lang('PlatformAdmin'));
$tool_name = get_lang('UserList');
}
@ -729,10 +785,11 @@ $form = new FormValidator('search_simple', 'get', null, null, null, 'inline');
$form->addText('keyword', get_lang('Search'), false);
$form->addButtonSearch(get_lang('Search'));
$searchAdvanced = '<a id="advanced_params" href="javascript://" class = "btn btn-default advanced_options" onclick="display_advanced_search_form();">
<span id="img_plus_and_minus">&nbsp;'. Display::returnFontAwesomeIcon('arrow-right') . ' '.get_lang('AdvancedSearch').'
</span>
</a>';
$searchAdvanced = '
<a id="advanced_params" href="javascript://" class = "btn btn-default advanced_options" onclick="display_advanced_search_form();">
<span id="img_plus_and_minus">&nbsp;'. Display::returnFontAwesomeIcon('arrow-right') . ' '.get_lang('AdvancedSearch').'
</span>
</a>';
$actionsLeft = '';
$actionsCenter = '';
$actionsRight = '';
@ -741,45 +798,36 @@ if (api_is_platform_admin()) {
Display::return_icon('new_user.png',get_lang('AddUsers'),'',ICON_SIZE_MEDIUM).'</a>';
}
$actionsLeft .= $form->return_form();
$actionsLeft .= $form->returnForm();
$actionsCenter .= $searchAdvanced;
if (isset ($_GET['keyword'])) {
$parameters = array ('keyword' => Security::remove_XSS($_GET['keyword']));
if (isset($_GET['keyword'])) {
$parameters = array('keyword' => Security::remove_XSS($_GET['keyword']));
} elseif (isset ($_GET['keyword_firstname'])) {
$parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
$parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
$parameters['keyword_username'] = Security::remove_XSS($_GET['keyword_username']);
$parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
$parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
$parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
$parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
$parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
$parameters['keyword_firstname'] = Security::remove_XSS($_GET['keyword_firstname']);
$parameters['keyword_lastname'] = Security::remove_XSS($_GET['keyword_lastname']);
$parameters['keyword_username'] = Security::remove_XSS($_GET['keyword_username']);
$parameters['keyword_email'] = Security::remove_XSS($_GET['keyword_email']);
$parameters['keyword_officialcode'] = Security::remove_XSS($_GET['keyword_officialcode']);
$parameters['keyword_status'] = Security::remove_XSS($_GET['keyword_status']);
$parameters['keyword_active'] = Security::remove_XSS($_GET['keyword_active']);
$parameters['keyword_inactive'] = Security::remove_XSS($_GET['keyword_inactive']);
}
// Create a sortable table with user-data
$parameters['sec_token'] = Security::get_token();
// get the list of all admins to mark them in the users list
$admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
$sql_admin = "SELECT user_id FROM $admin_table";
$res_admin = Database::query($sql_admin);
$_admins_list = array();
while ($row_admin = Database::fetch_row($res_admin)) {
$_admins_list[] = $row_admin[0];
}
$_admins_list = array_keys(UserManager::get_all_administrators());
// Display Advanced search form.
$form = new FormValidator('advanced_search', 'get', '', '', array(), FormValidator::LAYOUT_HORIZONTAL);
$form->addElement('html','<div id="advanced_search_form" style="display:none;">');
$form->addElement('header', get_lang('AdvancedSearch'));
$form->addText('keyword_firstname',get_lang('FirstName'),false);
$form->addText('keyword_lastname',get_lang('LastName'),false);
$form->addText('keyword_username',get_lang('LoginName'),false);
$form->addText('keyword_email',get_lang('Email'),false);
$form->addText('keyword_officialcode',get_lang('OfficialCode'),false);
$form->addText('keyword_firstname', get_lang('FirstName'), false);
$form->addText('keyword_lastname', get_lang('LastName'), false);
$form->addText('keyword_username', get_lang('LoginName'), false);
$form->addText('keyword_email', get_lang('Email'), false);
$form->addText('keyword_officialcode', get_lang('OfficialCode'), false);
$status_options = array();
$status_options['%'] = get_lang('All');
@ -789,17 +837,26 @@ $status_options[DRH] = get_lang('Drh');
$status_options[SESSIONADMIN] = get_lang('SessionsAdmin');
$status_options[PLATFORM_ADMIN] = get_lang('Administrator');
$form->addElement('select','keyword_status',get_lang('Profile'), $status_options );
$form->addElement('select', 'keyword_status', get_lang('Profile'), $status_options);
$active_group = array();
$active_group[] = $form->createElement('checkbox','keyword_active','', get_lang('Active'));
$active_group[] = $form->createElement('checkbox','keyword_inactive','', get_lang('Inactive'));
$form->addGroup($active_group,'',get_lang('ActiveAccount'), '<br/>',false);
$active_group[] = $form->createElement('checkbox', 'keyword_active', '', get_lang('Active'));
$active_group[] = $form->createElement('checkbox', 'keyword_inactive', '', get_lang('Inactive'));
$form->addGroup($active_group, '', get_lang('ActiveAccount'), '<br/>', false);
$form->addElement('checkbox', 'check_easy_passwords', null, get_lang('CheckEasyPasswords'));
$form->addButtonSearch(get_lang('SearchUsers'));
$data = $extraField->addElements($form, 0, [], true, false, $variablesToShow);
$htmlHeadXtra[] = '
<script>
$(document).ready(function() {
'.$data['jquery_ready_content'].'
})
</script>
';
$form->addButtonSearch(get_lang('SearchUsers'));
$defaults = array();
$defaults['keyword_active'] = 1;
@ -853,7 +910,6 @@ $extra_search_options = '';
//Try to search the user everywhere
if ($table->get_total_number_of_items() == 0) {
if (api_get_multiple_access_url() && isset($_REQUEST['keyword'])) {
$keyword = Database::escape_string($_REQUEST['keyword']);
$conditions = array('username' => $keyword);
@ -906,7 +962,11 @@ if ($table->get_total_number_of_items() == 0) {
}
}
}
$toolbarActions = Display::toolbarAction('toolbarUser', array(0 => $actionsLeft, 1 => $actionsCenter, 2 => $actionsRight), 3);
$toolbarActions = Display::toolbarAction(
'toolbarUser',
array($actionsLeft, $actionsCenter, $actionsRight),
3
);
$tpl = new Template($tool_name);
$tpl->assign('actions', $toolbarActions);

@ -838,7 +838,7 @@ class ImportCsv
$item = null;
foreach ($items as $tempItem) {
if ($tempItem['c_id'] == $event['course_id']) {
if ($tempItem['item_id'] == $event['course_id']) {
$item = $tempItem;
}
}

@ -1,14 +1,15 @@
<?php
/* For licensing terms, see /chamilo_license.txt */
/* For licensing terms, see /license.txt */
/**
* Responses to AJAX calls
*/
require_once '../global.inc.php';
$action = $_GET['a'];
switch ($action) {
case 'get_user_like':
$query = $_REQUEST['q'];
$conditions = [
'username' => $query,

@ -47,7 +47,6 @@ class Certificate extends Model
public function __construct($certificate_id = 0, $userId = 0)
{
$this->table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_CERTIFICATE);
unset($this->certificate_data);
$this->user_id = !empty($userId) ? $userId : api_get_user_id();
@ -163,7 +162,7 @@ class Certificate extends Model
$params['hide_print_button'] = isset($params['hide_print_button']) ? true : false;
if (isset($this->certificate_data)) {
if (isset($this->certificate_data) && isset($this->certificate_data['cat_id'])) {
$my_category = Category :: load($this->certificate_data['cat_id']);
}

@ -86,7 +86,7 @@ class ExtraField extends Model
public function __construct($type)
{
parent::__construct();
$this->type = $type;
$this->table = Database::get_main_table(TABLE_EXTRA_FIELD);
@ -463,9 +463,8 @@ class ExtraField extends Model
if ($field['field_type'] == ExtraField::FIELD_TYPE_TAG) {
$tags = UserManager::get_user_tags_to_string($itemId, $field['id'], false);
$extra_data['extra_'.$field['variable']] = $tags;
continue;
}
@ -776,7 +775,6 @@ class ExtraField extends Model
foreach ($extra as $field_details) {
if (!empty($showOnlyThisFields)) {
if (!in_array($field_details['variable'], $showOnlyThisFields)) {
continue;
}
@ -2213,7 +2211,7 @@ JAVASCRIPT;
//filter can be all/any = and/or
$inject_joins = null;
$inject_where = null;
$where = null;
$where = null;
if (!empty($options['where'])) {
if (!empty($options['extra'])) {
@ -2540,4 +2538,27 @@ JAVASCRIPT;
return isset($GLOBALS[$camelCase]) ? $GLOBALS[$camelCase] : $defaultDisplayText;
}
/**
* @param int $fieldId
* @param string $tag
*
* @return array
*/
public function getAllUserPerTag($fieldId, $tag)
{
$tagRelUserTable = Database::get_main_table(TABLE_MAIN_USER_REL_TAG);
$tag = Database::escape_string($tag);
$fieldId = (int) $fieldId;
$sql = "SELECT user_id
FROM {$this->table_field_tag} f INNER JOIN $tagRelUserTable ft
ON tag_id = f.id
WHERE tag = '$tag' AND f.field_id = $fieldId;
";
$result = Database::query($sql);
return Database::store_result($result, 'ASSOC');
}
}

@ -692,7 +692,8 @@ class ExtraFieldValue extends Model
$field_variable,
$field_value,
$transform = false,
$last = false
$last = false,
$all = false
) {
$field_value = Database::escape_string($field_value);
$field_variable = Database::escape_string($field_variable);
@ -707,7 +708,7 @@ class ExtraFieldValue extends Model
sf.extra_field_type = $extraFieldType
ORDER BY item_id
";
if ($last) {
// If we want the last element instead of the first
// This is useful in special cases where there might
@ -717,7 +718,11 @@ class ExtraFieldValue extends Model
$result = Database::query($sql);
if ($result !== false && Database::num_rows($result)) {
$result = Database::fetch_array($result, 'ASSOC');
if ($all) {
$result = Database::store_result($result, 'ASSOC');
} else {
$result = Database::fetch_array($result, 'ASSOC');
}
return $result;
} else {

@ -145,14 +145,9 @@ class UserManager
*/
public static function isPasswordValid($encoded, $raw, $salt)
{
//$encoder = self::getEncoder($user);
$encoder = new \Chamilo\UserBundle\Security\Encoder(self::getPasswordEncryption());
/*$user->getPassword(),
$password,
$user->getSalt()*/
$validPassword = $encoder->isPasswordValid($encoded, $raw, $salt);
return $validPassword;
}
@ -2313,28 +2308,39 @@ class UserManager
}
/** Get extra user data by value
* @param string $field_variable the internal variable name of the field
* @param string $field_value the internal value of the field
* @param string $variable the internal variable name of the field
* @param string $value the internal value of the field
* @param bool $all_visibility
*
* @return array with extra data info of a user i.e array('field_variable'=>'value');
*/
public static function get_extra_user_data_by_value($field_variable, $field_value, $all_visibility = true)
public static function get_extra_user_data_by_value($variable, $value, $all_visibility = true)
{
$extraField = new ExtraFieldValue('user');
$extraFieldValue = new ExtraFieldValue('user');
$extraField = new ExtraField('user');
$data = $extraField->get_values_by_handler_and_field_variable(
$field_variable,
$field_value,
null,
true,
intval($all_visibility)
);
$info = $extraField->get_handler_field_info_by_field_variable($variable);
if (false === $info) {
return [];
}
if ($info['field_type'] === ExtraField::FIELD_TYPE_TAG) {
} else {
$data = $extraFieldValue->get_item_id_from_field_variable_and_field_value(
$variable,
$value,
false,
false,
true
);
}
$result = [];
if (!empty($data)) {
foreach ($data as $data) {
$result[] = $data['item_id'];
foreach ($data as $item) {
$result[] = $item['item_id'];
}
}
@ -3154,28 +3160,27 @@ class UserManager
}
}
/*
/**
*
* Gets the tags of a specific field_id
* USER TAGS
*
* Intructions to create a new user tag by Julio Montoya <gugli100@gmail.com>
* Instructions to create a new user tag by Julio Montoya <gugli100@gmail.com>
*
* 1. Create a new extra field in main/admin/user_fields.php with the "TAG" field type make it available and visible. Called it "books" for example.
* 1. Create a new extra field in main/admin/user_fields.php with the "TAG" field type make it available and visible.
* Called it "books" for example.
* 2. Go to profile main/auth/profile.php There you will see a special input (facebook style) that will show suggestions of tags.
* 3. All the tags are registered in the user_tag table and the relationship between user and tags is in the user_rel_tag table
* 4. Tags are independent this means that tags can't be shared between tags + book + hobbies.
* 5. Test and enjoy.
*
*/
/**
* Gets the tags of a specific field_id
* @param string $tag
* @param int $field_id field_id
* @param string $return_format how we are going to result value in array or in a string (json)
* @param $limit
*
* @param int field_id
* @param string how we are going to result value in array or in a string (json)
* @return mixed
* @since Nov 2009
* @version 1.8.6.2
*
*/
public static function get_tags($tag, $field_id, $return_format = 'json', $limit = 10)
{
@ -3192,18 +3197,20 @@ class UserManager
$return = array();
if (Database::num_rows($result) > 0) {
while ($row = Database::fetch_array($result, 'ASSOC')) {
$return[] = array('caption' => $row['tag'], 'value' => $row['tag']);
$return[] = array('key' => $row['tag'], 'value' => $row['tag']);
}
}
if ($return_format == 'json') {
if ($return_format === 'json') {
$return = json_encode($return);
}
return $return;
}
/**
* @param int $field_id
* @param int $limit
*
* @return array
*/
public static function get_top_tags($field_id, $limit = 100)
@ -3233,8 +3240,9 @@ class UserManager
/**
* Get user's tags
* @param int field_id
* @param int user_id
* @param int $user_id
* @param int $field_id
*
* @return array
*/
public static function get_user_tags($user_id, $field_id)
@ -3265,9 +3273,10 @@ class UserManager
/**
* Get user's tags
* @param int user_id
* @param int field_id
* @param bool show links or not
* @param int $user_id
* @param int $field_id
* @param bool $show_links show links or not
*
* @return array
*/
public static function get_user_tags_to_string($user_id, $field_id, $show_links = true)
@ -3301,18 +3310,21 @@ class UserManager
$tag_tmp[] = $tag['tag'];
}
}
if (is_array($user_tags) && count($user_tags) > 0) {
$return = implode(', ', $tag_tmp);
} else {
return '';
}
return $return;
}
/**
* Get the tag id
* @param int tag
* @param int field_id
* @param int $tag
* @param int $field_id
* @return int returns 0 if fails otherwise the tag id
*/
public static function get_tag_id($tag, $field_id)
@ -3326,16 +3338,19 @@ class UserManager
$result = Database::query($sql);
if (Database::num_rows($result) > 0) {
$row = Database::fetch_array($result, 'ASSOC');
return $row['id'];
} else {
return 0;
}
}
/**
* Get the tag id
* @param int tag
* @param int field_id
* @param int $tag_id
* @param int $field_id
*
* @return int 0 if fails otherwise the tag id
*/
public static function get_tag_id_from_id($tag_id, $field_id)
@ -3356,9 +3371,9 @@ class UserManager
/**
* Adds a user-tag value
* @param mixed tag
* @param int The user id
* @param int field id of the tag
* @param mixed $tag
* @param int $user_id
* @param int $field_id field id of the tag
* @return bool
*/
public static function add_tag($tag, $user_id, $field_id)
@ -3388,8 +3403,6 @@ class UserManager
$result = Database::query($sql);
$last_insert_id = Database::insert_id();
} */
} else {
}
//this is a new tag
@ -3420,8 +3433,8 @@ class UserManager
/**
* Deletes an user tag
* @param int user id
* @param int field id
* @param int $user_id
* @param int $field_id
*
*/
public static function delete_user_tags($user_id, $field_id)
@ -3467,7 +3480,7 @@ class UserManager
/**
* Returns a list of all administrators
* @author jmontoya
*
* @return array
*/
public static function get_all_administrators()

Loading…
Cancel
Save