Minor - format code, add int casting

pull/3173/head
Julio Montoya 7 years ago
parent 0b994ddc1e
commit 70138a2cae
  1. 54
      main/inc/lib/message.lib.php
  2. 19
      main/inc/lib/notebook.lib.php
  3. 2
      main/inc/lib/online.inc.php
  4. 3
      main/inc/lib/promotion.lib.php

@ -92,6 +92,7 @@ class MessageManager
* @param int $number_of_items * @param int $number_of_items
* @param string $column * @param string $column
* @param string $direction * @param string $direction
* @param int $userId
* *
* @return array * @return array
*/ */
@ -106,12 +107,12 @@ class MessageManager
$number_of_items = (int) $number_of_items; $number_of_items = (int) $number_of_items;
$userId = empty($userId) ? api_get_user_id() : (int) $userId; $userId = empty($userId) ? api_get_user_id() : (int) $userId;
//forcing this order // Forcing this order.
if (!isset($direction)) { if (!isset($direction)) {
$column = 2; $column = 2;
$direction = 'DESC'; $direction = 'DESC';
} else { } else {
$column = intval($column); $column = (int) $column;
if (!in_array($direction, ['ASC', 'DESC'])) { if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC'; $direction = 'ASC';
} }
@ -144,7 +145,7 @@ class MessageManager
LIMIT $from, $number_of_items"; LIMIT $from, $number_of_items";
$result = Database::query($sql); $result = Database::query($sql);
$message_list = []; $messageList = [];
$newMessageLink = api_get_path(WEB_CODE_PATH).'messages/new_message.php'; $newMessageLink = api_get_path(WEB_CODE_PATH).'messages/new_message.php';
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
$messageId = $row['col0']; $messageId = $row['col0'];
@ -156,10 +157,9 @@ class MessageManager
$title = Security::remove_XSS($title, STUDENT, true); $title = Security::remove_XSS($title, STUDENT, true);
$title = cut($title, 80, true); $title = cut($title, 80, true);
$class = 'class = "read"';
if ($status == 1) { if ($status == 1) {
$class = 'class = "unread"'; $class = 'class = "unread"';
} else {
$class = 'class = "read"';
} }
$userInfo = api_get_user_info($senderId); $userInfo = api_get_user_info($senderId);
@ -201,10 +201,10 @@ class MessageManager
foreach ($message as $key => $value) { foreach ($message as $key => $value) {
$message[$key] = api_xml_http_response_encode($value); $message[$key] = api_xml_http_response_encode($value);
} }
$message_list[] = $message; $messageList[] = $message;
} }
return $message_list; return $messageList;
} }
/** /**
@ -1120,6 +1120,7 @@ class MessageManager
* @param int * @param int
* @param int * @param int
* @param string * @param string
* @param string
* *
* @return array * @return array
*/ */
@ -1129,13 +1130,13 @@ class MessageManager
$column, $column,
$direction $direction
) { ) {
$from = intval($from); $from = (int) $from;
$number_of_items = intval($number_of_items); $number_of_items = (int) $number_of_items;
if (!isset($direction)) { if (!isset($direction)) {
$column = 2; $column = 2;
$direction = 'DESC'; $direction = 'DESC';
} else { } else {
$column = intval($column); $column = (int) $column;
if (!in_array($direction, ['ASC', 'DESC'])) { if (!in_array($direction, ['ASC', 'DESC'])) {
$direction = 'ASC'; $direction = 'ASC';
} }
@ -1168,13 +1169,12 @@ class MessageManager
ORDER BY col$column $direction ORDER BY col$column $direction
LIMIT $from, $number_of_items"; LIMIT $from, $number_of_items";
$result = Database::query($sql); $result = Database::query($sql);
$i = 0;
$message_list = []; $message_list = [];
while ($row = Database::fetch_array($result, 'ASSOC')) { while ($row = Database::fetch_array($result, 'ASSOC')) {
$messageId = $row['col0']; $messageId = $row['col0'];
$title = $row['col1']; $title = $row['col1'];
$sendDate = $row['col2']; $sendDate = $row['col2'];
$status = $row['msg_status'];
$senderId = $row['user_sender_id']; $senderId = $row['user_sender_id'];
if ($request === true) { if ($request === true) {
@ -1212,7 +1212,6 @@ class MessageManager
} }
$message_list[] = $message; $message_list[] = $message;
$i++;
} }
return $message_list; return $message_list;
@ -1331,7 +1330,7 @@ class MessageManager
} }
$message_content .= '<tr>'; $message_content .= '<tr>';
if (api_get_setting('allow_social_tool') == 'true') { if (api_get_setting('allow_social_tool') === 'true') {
$message_content .= '<div class="row">'; $message_content .= '<div class="row">';
if ($source == 'outbox') { if ($source == 'outbox') {
$message_content .= '<div class="col-md-12">'; $message_content .= '<div class="col-md-12">';
@ -1419,16 +1418,17 @@ class MessageManager
*/ */
public static function get_user_id_by_email($user_email) public static function get_user_id_by_email($user_email)
{ {
$tbl_user = Database::get_main_table(TABLE_MAIN_USER); $table = Database::get_main_table(TABLE_MAIN_USER);
$sql = 'SELECT user_id FROM '.$tbl_user.' $sql = 'SELECT user_id
FROM '.$table.'
WHERE email="'.Database::escape_string($user_email).'";'; WHERE email="'.Database::escape_string($user_email).'";';
$rs = Database::query($sql); $rs = Database::query($sql);
$row = Database::fetch_array($rs, 'ASSOC'); $row = Database::fetch_array($rs, 'ASSOC');
if (isset($row['user_id'])) { if (isset($row['user_id'])) {
return $row['user_id']; return $row['user_id'];
} else {
return null;
} }
return null;
} }
/** /**
@ -1566,12 +1566,10 @@ class MessageManager
* *
* @param $groupId * @param $groupId
* @param $topic_id * @param $topic_id
* @param $is_member
* @param $messageId
* *
* @return string * @return string
*/ */
public static function display_message_for_group($groupId, $topic_id, $is_member, $messageId) public static function display_message_for_group($groupId, $topic_id)
{ {
global $my_group_role; global $my_group_role;
$main_message = self::get_message_by_id($topic_id); $main_message = self::get_message_by_id($topic_id);
@ -2055,12 +2053,9 @@ class MessageManager
} }
/** /**
* @param $id
* @param array $params
*
* @return string * @return string
*/ */
public static function generate_invitation_form($id, $params = []) public static function generate_invitation_form()
{ {
$form = new FormValidator('send_invitation'); $form = new FormValidator('send_invitation');
$form->addTextarea( $form->addTextarea(
@ -2072,8 +2067,6 @@ class MessageManager
return $form->returnForm(); return $form->returnForm();
} }
//@todo this functions should be in the message class
/** /**
* @param string $keyword * @param string $keyword
* *
@ -2242,8 +2235,8 @@ class MessageManager
*/ */
public static function getMessagesFromLastReceivedMessage($userId, $lastId = 0) public static function getMessagesFromLastReceivedMessage($userId, $lastId = 0)
{ {
$userId = intval($userId); $userId = (int) $userId;
$lastId = intval($lastId); $lastId = (int) $lastId;
if (empty($userId)) { if (empty($userId)) {
return []; return [];
@ -2462,7 +2455,6 @@ class MessageManager
// Get the reason of mail fail // Get the reason of mail fail
$iX = 1; $iX = 1;
while (!feof($mailFile)) { while (!feof($mailFile)) {
$mailLine = fgets($mailFile); $mailLine = fgets($mailFile);
//if ($iX == 4 && preg_match('/(.*):\s(.*)$/', $mailLine, $matches)) { //if ($iX == 4 && preg_match('/(.*):\s(.*)$/', $mailLine, $matches)) {
@ -2471,7 +2463,6 @@ class MessageManager
) { ) {
$mail_queue[$i]['reason'] = $detailsMatches[3]; $mail_queue[$i]['reason'] = $detailsMatches[3];
} }
$iX++; $iX++;
} }
@ -2569,6 +2560,7 @@ class MessageManager
if (empty($courseInfo)) { if (empty($courseInfo)) {
return false; return false;
} }
$senderId = api_get_user_id(); $senderId = api_get_user_id();
if (empty($senderId)) { if (empty($senderId)) {
return false; return false;

@ -116,6 +116,7 @@ class NotebookManager
// Database table definition // Database table definition
$table = Database::get_course_table(TABLE_NOTEBOOK); $table = Database::get_course_table(TABLE_NOTEBOOK);
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$notebook_id = (int) $notebook_id;
$sql = "SELECT $sql = "SELECT
notebook_id AS notebook_id, notebook_id AS notebook_id,
@ -123,7 +124,7 @@ class NotebookManager
description AS note_comment, description AS note_comment,
session_id AS session_id session_id AS session_id
FROM $table FROM $table
WHERE c_id = $course_id AND notebook_id = '".intval($notebook_id)."' "; WHERE c_id = $course_id AND notebook_id = '".$notebook_id."' ";
$result = Database::query($sql); $result = Database::query($sql);
if (Database::num_rows($result) != 1) { if (Database::num_rows($result) != 1) {
return []; return [];
@ -146,9 +147,10 @@ class NotebookManager
*/ */
public static function update_note($values) public static function update_note($values)
{ {
if (!is_array($values) or empty($values['note_title'])) { if (!is_array($values) || empty($values['note_title'])) {
return false; return false;
} }
// Database table definition // Database table definition
$table = Database::get_course_table(TABLE_NOTEBOOK); $table = Database::get_course_table(TABLE_NOTEBOOK);
@ -194,7 +196,9 @@ class NotebookManager
*/ */
public static function delete_note($notebook_id) public static function delete_note($notebook_id)
{ {
if (empty($notebook_id) || $notebook_id != strval(intval($notebook_id))) { $notebook_id = (int) $notebook_id;
if (empty($notebook_id)) {
return false; return false;
} }
@ -205,10 +209,11 @@ class NotebookManager
$sql = "DELETE FROM $table $sql = "DELETE FROM $table
WHERE WHERE
c_id = $course_id AND c_id = $course_id AND
notebook_id='".intval($notebook_id)."' AND notebook_id='".$notebook_id."' AND
user_id = '".api_get_user_id()."'"; user_id = '".api_get_user_id()."'";
$result = Database::query($sql); $result = Database::query($sql);
$affected_rows = Database::affected_rows($result); $affected_rows = Database::affected_rows($result);
if ($affected_rows != 1) { if ($affected_rows != 1) {
return false; return false;
} }
@ -217,7 +222,7 @@ class NotebookManager
api_item_property_update( api_item_property_update(
api_get_course_info(), api_get_course_info(),
TOOL_NOTEBOOK, TOOL_NOTEBOOK,
intval($notebook_id), $notebook_id,
'delete', 'delete',
api_get_user_id() api_get_user_id()
); );
@ -271,12 +276,12 @@ class NotebookManager
// Database table definition // Database table definition
$table = Database::get_course_table(TABLE_NOTEBOOK); $table = Database::get_course_table(TABLE_NOTEBOOK);
$order_by = " ORDER BY ".$notebookView." $sort_direction "; $order_by = ' ORDER BY '.$notebookView." $sort_direction ";
// Condition for the session // Condition for the session
$condition_session = api_get_session_condition($sessionId); $condition_session = api_get_session_condition($sessionId);
$cond_extra = $notebookView == 'update_date' ? " AND update_date <> ''" : " "; $cond_extra = $notebookView == 'update_date' ? " AND update_date <> ''" : ' ';
$course_id = api_get_course_int_id(); $course_id = api_get_course_int_id();
$sql = "SELECT * FROM $table $sql = "SELECT * FROM $table

@ -207,7 +207,7 @@ function user_is_online($user_id)
$online_time = time() - $time_limit * 60; $online_time = time() - $time_limit * 60;
$limit_date = api_get_utc_datetime($online_time); $limit_date = api_get_utc_datetime($online_time);
$user_id = intval($user_id); $user_id = (int) $user_id;
$query = " SELECT login_user_id, login_date $query = " SELECT login_user_id, login_date
FROM $track_online_table track FROM $track_online_table track

@ -226,7 +226,8 @@ class Promotion extends Model
if ($action == 'edit') { if ($action == 'edit') {
$header = get_lang('Modify'); $header = get_lang('Modify');
} }
$id = isset($_GET['id']) ? intval($_GET['id']) : '';
$id = isset($_GET['id']) ? (int) $_GET['id'] : '';
$form->addElement('header', '', $header); $form->addElement('header', '', $header);
$form->addElement('hidden', 'id', $id); $form->addElement('hidden', 'id', $id);

Loading…
Cancel
Save