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

1.10.x
aragonc 10 years ago
commit 0857c7b1d8
  1. 12
      main/admin/statistics/index.php
  2. 6
      main/inc/lib/statistics.lib.php
  3. 9
      main/inc/lib/zombie/zombie_report.class.php
  4. 71
      tests/scripts/userfields_to_groups.php

@ -81,19 +81,19 @@ switch ($_REQUEST['report']) {
break;
case 'users':
// total amount of users
$teachers = $students = array();
$countInvisible = isset($_GET['count_invisible_courses']) ? intval($_GET['count_invisible_courses']) : null;
Statistics::printStats(
get_lang('NumberOfUsers'),
array(
get_lang('Teachers') => Statistics::countUsers(1, null, $_GET['count_invisible_courses']),
get_lang('Students') => Statistics::countUsers(5, null, $_GET['count_invisible_courses'])
get_lang('Teachers') => Statistics::countUsers(COURSEMANAGER, null, $countInvisible),
get_lang('Students') => Statistics::countUsers(STUDENT, null, $countInvisible)
)
);
$teachers = $students = array();
$countInvisible = isset($_GET['count_invisible_courses']) ? $_GET['count_invisible_courses'] : null;
foreach ($course_categories as $code => $name) {
$name = str_replace(get_lang('Department'), "", $name);
$teachers[$name] = Statistics::countUsers(1, $code, $countInvisible);
$students[$name] = Statistics::countUsers(5, $code, $countInvisible);
$teachers[$name] = Statistics::countUsers(COURSEMANAGER, $code, $countInvisible);
$students[$name] = Statistics::countUsers(STUDENT, $code, $countInvisible);
}
// docents for each course category
Statistics::printStats(get_lang('Teachers'), $teachers);

@ -247,7 +247,7 @@ class Statistics
$row[2] = $row[2];
} else {
if (!empty($row[2])) {
$originalData = $row[2];
$originalData = str_replace('\\', '', $row[2]);
$row[2] = unserialize($originalData);
if (is_array($row[2]) && !empty($row[2])) {
$row[2] = implode_with_key(', ', $row[2]);
@ -596,8 +596,8 @@ class Statistics
$table = new SortableTable(
'activities',
array('Statistics', 'get_number_of_activities'),
array('Statistics','get_activities_data'),
array('Statistics', 'getNumberOfActivities'),
array('Statistics','getActivitiesData'),
5,
50,
'DESC'

@ -40,8 +40,8 @@ class ZombieReport implements Countable
array(
'name' => 'ceiling',
'label' => get_lang('LastAccess'),
'type' => 'datepickerdate',
'default' => $this->get_ceiling(),
'type' => 'date_picker',
'default' => $this->get_ceiling('Y-m-d'),
'rules' => array(
// array(
// 'type' => 'required',
@ -121,7 +121,7 @@ class ZombieReport implements Countable
return $form->isSubmitted() == false || $form->validate();
}
function get_ceiling()
function get_ceiling($format = null)
{
$result = Request::get('ceiling');
$result = $result ? $result : ZombieManager::last_year();
@ -130,6 +130,9 @@ class ZombieReport implements Countable
$result = is_array($result) ? mktime(0, 0, 0, $result['F'], $result['d'], $result['Y']) : $result;
$result = is_numeric($result) ? (int) $result : $result;
$result = is_string($result) ? strtotime($result) : $result;
if ($format) {
$result = date($format, $result);
}
return $result;
}

@ -0,0 +1,71 @@
<?php
/**
* Move user fields "ruc" and "razon_social" to (social) groups (create groups)
* and assign the related users to those groups.
*/
if (PHP_SAPI != 'cli') {
die('This script can only be launched from the command line');
}
require __DIR__ . '/../../main/inc/global.inc.php';
// We assume all these fields represent the same value, so they are on a 1-1
// relationship.
$referenceFields = array('razon_social', 'ruc');
$tUserField = Database::get_main_table(TABLE_MAIN_USER_FIELD);
$tUserFieldValue = Database::get_main_table(TABLE_MAIN_USER_FIELD_VALUES);
$tUser = Database::get_main_table(TABLE_MAIN_USER);
$tGroup = Database::get_main_table(TABLE_MAIN_GROUP);
$tGroupUser = Database::get_main_table(TABLE_MAIN_USER_REL_GROUP);
// First get the IDs of the selected fields
$sql = "SELECT id, field_type, field_variable FROM $tUserField";
$result = Database::query($sql);
$foundFields = array();
$fieldsNames = array();
while ($row = Database::fetch_assoc($result)) {
if ($row['field_type'] == 1 && in_array($row['field_variable'], $referenceFields)) {
$foundFields[$row['field_variable']] = array('id' => $row['id']);
$fieldsNames[$row['id']] = $row['field_variable'];
}
}
// Second get all the possible values of this field (in user data)
$usersData = array();
foreach ($foundFields as $key => $value) {
$sql = "SELECT user_id, field_value FROM $tUserFieldValue WHERE field_id = " . $value['id'];
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$foundFields[$key]['options'][$row['field_value']][] = $row['user_id'];
if (empty($usersData[$row['user_id']])) {
$usersData[$row['user_id']] = '';
}
if ($referenceFields[0] == $key) {
$usersData[$row['user_id']] = $row['field_value'] . ' - ' . $usersData[$row['user_id']];
} else {
$usersData[$row['user_id']] .= $row['field_value'] . ' - ';
}
}
}
// Clean the user string
$distinctGroups = array();
foreach ($usersData as $userId => $value) {
$usersData[$userId] = substr($usersData[$userId], 0, -3);
$distinctGroups[$usersData[$userId]][] = $userId;
}
// Third, we create groups based on the combined strings by user and insert
// users in them (as reader)
foreach ($distinctGroups as $name => $usersList) {
$now = api_get_utc_datetime();
$sql = "INSERT INTO $tGroup (name, visibility, updated_on, created_on) VALUES ('$name', 1, '$now', '$now')";
echo $sql . PHP_EOL;
$result = Database::query($sql);
$groupId = Database::insert_id();
echo $groupId . PHP_EOL;
foreach ($usersList as $user) {
$sql = "INSERT INTO $tGroupUser (group_id, user_id, relation_type) VALUES ($groupId, $user, 2)";
echo $sql . PHP_EOL;
$result = Database::query($sql);
}
}
Loading…
Cancel
Save