Minor - format code.

pull/2487/head
jmontoyaa 8 years ago
parent 2ed53d3f72
commit b8df71bbbe
  1. 87
      main/gradebook/lib/be/evaluation.class.php
  2. 1
      main/gradebook/lib/scoredisplay.class.php
  3. 52
      main/inc/lib/course_description.lib.php
  4. 80
      main/inc/lib/image.lib.php
  5. 21
      main/inc/lib/system_announcements.lib.php
  6. 47
      main/upload/upload.document.php
  7. 16
      src/Chamilo/ThemeBundle/Theme/ThemeManager.php

@ -221,8 +221,8 @@ class Evaluation implements GradebookItem
$visible = null,
$locked = null
) {
$tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = 'SELECT * FROM '.$tbl_grade_evaluations;
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = 'SELECT * FROM '.$table;
$paramcount = 0;
if (isset($id)) {
@ -231,36 +231,51 @@ class Evaluation implements GradebookItem
}
if (isset($user_id)) {
if ($paramcount != 0) $sql .= ' AND';
else $sql .= ' WHERE';
if ($paramcount != 0) {
$sql .= ' AND';
} else {
$sql .= ' WHERE';
}
$sql .= ' user_id = '.intval($user_id);
$paramcount++;
}
if (isset($course_code) && $course_code <> '-1') {
if ($paramcount != 0) $sql .= ' AND';
else $sql .= ' WHERE';
if ($paramcount != 0) {
$sql .= ' AND';
} else {
$sql .= ' WHERE';
}
$sql .= " course_code = '".Database::escape_string($course_code)."'";
$paramcount++;
}
if (isset($category_id)) {
if ($paramcount != 0) $sql .= ' AND';
else $sql .= ' WHERE';
if ($paramcount != 0) {
$sql .= ' AND';
} else {
$sql .= ' WHERE';
}
$sql .= ' category_id = '.intval($category_id);
$paramcount++;
}
if (isset($visible)) {
if ($paramcount != 0) $sql .= ' AND';
else $sql .= ' WHERE';
if ($paramcount != 0) {
$sql .= ' AND';
} else {
$sql .= ' WHERE';
}
$sql .= ' visible = '.intval($visible);
$paramcount++;
}
if (isset($locked)) {
if ($paramcount != 0) $sql .= ' AND';
else $sql .= ' WHERE';
if ($paramcount != 0) {
$sql .= ' AND';
} else {
$sql .= ' WHERE';
}
$sql .= ' locked = '.intval($locked);
}
@ -312,9 +327,9 @@ class Evaluation implements GradebookItem
isset($this->eval_max) &&
isset($this->visible)
) {
$tbl_grade_evaluations = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = 'INSERT INTO '.$tbl_grade_evaluations
$sql = 'INSERT INTO '.$table
.' (name, user_id, weight, max, visible';
if (isset($this->description)) {
$sql .= ',description';
@ -635,10 +650,9 @@ class Evaluation implements GradebookItem
// -> movable to root or other course independent categories
// - evaluation inside a course
// -> movable to root, independent categories or categories inside the course
$user = (api_is_platform_admin() ? null : api_get_user_id());
$user = api_is_platform_admin() ? null : api_get_user_id();
$targets = array();
$level = 0;
$root = array(0, get_lang('RootCat'), $level);
$targets[] = $root;
@ -646,14 +660,22 @@ class Evaluation implements GradebookItem
$crscats = Category::load(null, null, $this->course_code, 0);
foreach ($crscats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
$targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
}
}
$indcats = Category::load(null, $user, 0, 0);
foreach ($indcats as $cat) {
$targets[] = array($cat->get_id(), $cat->get_name(), $level + 1);
$targets = $this->add_target_subcategories($targets, $level + 1, $cat->get_id());
$targets = $this->add_target_subcategories(
$targets,
$level + 1,
$cat->get_id()
);
}
return $targets;
@ -733,16 +755,17 @@ class Evaluation implements GradebookItem
public function get_not_subscribed_students($first_letter_user = '')
{
$tbl_user = Database::get_main_table(TABLE_MAIN_USER);
$tbl_grade_results = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
$table = Database::get_main_table(TABLE_MAIN_GRADEBOOK_RESULT);
$sql = 'SELECT user_id,lastname,firstname,username FROM '.$tbl_user
." WHERE lastname LIKE '".Database::escape_string($first_letter_user)."%'"
.' AND status = '.STUDENT
.' AND user_id NOT IN'
.' (SELECT user_id FROM '.$tbl_grade_results
.' WHERE evaluation_id = '.intval($this->id)
.' )'
.' ORDER BY lastname';
$sql = "SELECT user_id,lastname,firstname,username
FROM $tbl_user
WHERE
lastname LIKE '".Database::escape_string($first_letter_user)."%' AND
status = ".STUDENT." AND user_id NOT IN (
SELECT user_id FROM $table
WHERE evaluation_id = ".intval($this->id)."
)
ORDER BY lastname";
$result = Database::query($sql);
$users = Database::store_result($result);
@ -759,7 +782,10 @@ class Evaluation implements GradebookItem
public function find_evaluations($name_mask, $selectcat)
{
$rootcat = Category::load($selectcat);
$evals = $rootcat[0]->get_evaluations((api_is_allowed_to_create_course() ? null : api_get_user_id()), true);
$evals = $rootcat[0]->get_evaluations(
(api_is_allowed_to_create_course() ? null : api_get_user_id()),
true
);
$foundevals = array();
foreach ($evals as $eval) {
if (!(api_strpos(api_strtolower($eval->get_name()), api_strtolower($name_mask)) === false)) {
@ -787,7 +813,9 @@ class Evaluation implements GradebookItem
public function lock($locked)
{
$table_evaluation = Database::get_main_table(TABLE_MAIN_GRADEBOOK_EVALUATION);
$sql = "UPDATE $table_evaluation SET locked = '".intval($locked)."' WHERE id='".intval($this->id)."'";
$sql = "UPDATE $table_evaluation
SET locked = '".intval($locked)."'
WHERE id='".intval($this->id)."'";
Database::query($sql);
}
@ -804,7 +832,6 @@ class Evaluation implements GradebookItem
public function delete_linked_data()
{
}
public function getStudentList()

@ -20,6 +20,7 @@ class ScoreDisplay
/**
* Get the instance of this class
* @param int $category_id
* @return ScoreDisplay
*/
public static function instance($category_id = 0)
{

@ -29,7 +29,6 @@ class CourseDescription
*/
public function __construct()
{
}
/**
@ -75,16 +74,23 @@ class CourseDescription
*/
public function get_description_data()
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$condition_session = api_get_session_condition($this->session_id, true, true);
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$condition_session = api_get_session_condition(
$this->session_id,
true,
true
);
$course_id = api_get_course_int_id();
$sql = "SELECT * FROM $tbl_course_description
$sql = "SELECT * FROM $table
WHERE c_id = $course_id $condition_session
ORDER BY id ";
$rs = Database::query($sql);
$data = array();
while ($description = Database::fetch_array($rs)) {
$data['descriptions'][$description['id']] = Security::remove_XSS($description, STUDENT);
$data['descriptions'][$description['id']] = Security::remove_XSS(
$description,
STUDENT
);
}
return $data;
@ -103,7 +109,7 @@ class CourseDescription
$courseId = null,
$session_id = null
) {
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
if (empty($courseId)) {
$courseId = api_get_course_int_id();
}
@ -113,8 +119,11 @@ class CourseDescription
}
$condition_session = api_get_session_condition($session_id);
$description_type = intval($description_type);
$sql = "SELECT * FROM $tbl_course_description
WHERE c_id = $courseId AND description_type='$description_type' $condition_session ";
$sql = "SELECT * FROM $table
WHERE
c_id = $courseId AND
description_type = '$description_type'
$condition_session ";
$rs = Database::query($sql);
$data = array();
if ($description = Database::fetch_array($rs)) {
@ -136,7 +145,7 @@ class CourseDescription
*/
public function get_data_by_id($id, $course_code = '', $session_id = null)
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
if (!isset($session_id)) {
@ -148,7 +157,7 @@ class CourseDescription
$course_id = $course_info['real_id'];
}
$id = intval($id);
$sql = "SELECT * FROM $tbl_course_description
$sql = "SELECT * FROM $table
WHERE c_id = $course_id AND id='$id' $condition_session ";
$rs = Database::query($sql);
$data = array();
@ -170,11 +179,11 @@ class CourseDescription
*/
public function get_max_description_type()
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "SELECT MAX(description_type) as MAX
FROM $tbl_course_description
FROM $table
WHERE c_id = $course_id AND session_id='".$this->session_id."'";
$rs = Database::query($sql);
$max = Database::fetch_array($rs);
@ -244,7 +253,7 @@ class CourseDescription
*/
public function insert_stats($description_type)
{
$tbl_stats_item_property = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
$table = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ITEM_PROPERTY);
$description_id = $this->get_id_by_description_type($description_type);
$course_id = api_get_course_int_id();
$course_code = api_get_course_id();
@ -266,7 +275,7 @@ class CourseDescription
'session_id' => $this->session_id,
];
$result = Database::insert($tbl_stats_item_property, $params);
$result = Database::insert($table, $params);
return $result ? 1 : 0;
}
@ -279,7 +288,6 @@ class CourseDescription
public function update()
{
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$params = [
'title' => $this->title,
'content' => $this->content,
@ -319,9 +327,9 @@ class CourseDescription
*/
public function delete()
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "DELETE FROM $tbl_course_description
$sql = "DELETE FROM $table
WHERE
c_id = $course_id AND
id = '".intval($this->id)."' AND
@ -350,11 +358,13 @@ class CourseDescription
*/
public function get_id_by_description_type($description_type)
{
$tbl_course_description = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$table = Database::get_course_table(TABLE_COURSE_DESCRIPTION);
$course_id = api_get_course_int_id();
$sql = "SELECT id FROM $tbl_course_description
WHERE c_id = $course_id AND description_type = '".intval($description_type)."'";
$sql = "SELECT id FROM $table
WHERE
c_id = $course_id AND
description_type = '".intval($description_type)."'";
$rs = Database::query($sql);
$row = Database::fetch_array($rs);
$description_id = $row['id'];
@ -497,7 +507,6 @@ class CourseDescription
}
/**
*
* Set description session id
*
* @param int $session_id
@ -517,7 +526,6 @@ class CourseDescription
}
/**
*
* Set progress of a description
*
* @param string $progress

@ -24,7 +24,10 @@ class Image
if (class_exists('Imagick')) {
$this->image_wrapper = new ImagickWrapper($path);
} else {
echo Display::return_message('Class Imagick not found', 'warning');
echo Display::return_message(
'Class Imagick not found',
'warning'
);
exit;
}
}
@ -39,13 +42,21 @@ class Image
if ($width >= $max_size_for_picture) {
// scale height
$new_height = round($height * ($max_size_for_picture / $width));
$this->image_wrapper->resize($max_size_for_picture, $new_height, 0);
$this->image_wrapper->resize(
$max_size_for_picture,
$new_height,
0
);
}
} else { // height > $width
if ($height >= $max_size_for_picture) {
// scale width
$new_width = round($width * ($max_size_for_picture / $height));
$this->image_wrapper->resize($new_width, $max_size_for_picture, 0);
$this->image_wrapper->resize(
$new_width,
$max_size_for_picture,
0
);
}
}
}
@ -61,10 +72,23 @@ class Image
$width = intval($cropParameters[2]);
$height = intval($cropParameters[3]);
$image = $this->image_wrapper->crop($x, $y, $width, $height, $src_width, $src_height);
$image = $this->image_wrapper->crop(
$x,
$y,
$width,
$height,
$src_width,
$src_height
);
return $image;
}
/**
* @param string $file
* @param int $compress
* @param null $convert_file_to
* @return bool
*/
public function send_image(
$file = '',
$compress = -1,
@ -77,11 +101,17 @@ class Image
);
}
/**
* @return array
*/
public function get_image_size()
{
return $this->image_wrapper->get_image_size();
}
/**
* @return array
*/
public function get_image_info()
{
return $this->image_wrapper->get_image_info();
@ -124,6 +154,9 @@ abstract class ImageWrapper
abstract function crop($x, $y, $width, $height, $src_width, $src_height);
abstract function send_image($file = '', $compress = -1, $convert_file_to = null);
/**
* @return array
*/
public function get_image_info()
{
return array(
@ -155,6 +188,9 @@ class ImagickWrapper extends ImageWrapper
parent::__construct($path);
}
/**
*
*/
public function set_image_wrapper()
{
if ($this->debug) error_log('Image::set_image_wrapper loaded');
@ -175,11 +211,10 @@ class ImagickWrapper extends ImageWrapper
public function fill_image_info()
{
$image_info = $this->image->identifyImage();
$this->width = $image_info['geometry']['width'];
$this->height = $image_info['geometry']['height'];
$this->type = strtolower($this->image->getImageFormat());
$image_info = $this->image->identifyImage();
$this->width = $image_info['geometry']['width'];
$this->height = $image_info['geometry']['height'];
$this->type = strtolower($this->image->getImageFormat());
if (in_array($this->type, $this->allowed_extensions)) {
$this->image_validated = true;
@ -233,8 +268,11 @@ class ImagickWrapper extends ImageWrapper
$this->height = $height;
}
public function send_image($file = '', $compress = -1, $convert_file_to = null)
{
public function send_image(
$file = '',
$compress = -1,
$convert_file_to = null
) {
if (!$this->image_validated) {
return false;
}
@ -323,6 +361,9 @@ class GDWrapper extends ImageWrapper
}
}
/**
* @return array
*/
public function get_image_size()
{
$return_array = array('width'=>0, 'height'=>0);
@ -448,6 +489,12 @@ class GDWrapper extends ImageWrapper
@imagedestroy($src);
}
/**
* @param string $file
* @param int $compress
* @param null $convert_file_to
* @return bool|int
*/
public function send_image($file = '', $compress = -1, $convert_file_to = null)
{
if (!$this->image_validated) {
@ -515,7 +562,16 @@ class GDWrapper extends ImageWrapper
imagealphablending($dest_img, false);
imagesavealpha($dest_img, true);
imagecolortransparent($dest_img, $transparent);
imagecopy($dest_img, $this->bg, 0, 0, 0, 0, imagesx($this->bg), imagesx($this->bg));
imagecopy(
$dest_img,
$this->bg,
0,
0,
0,
0,
imagesx($this->bg),
imagesx($this->bg)
);
imagefilter($dest_img, IMG_FILTER_GRAYSCALE);
$this->bg = $dest_img;

@ -136,8 +136,12 @@ class SystemAnnouncementManager
* @param string $user_id
* @return string
*/
public static function displayAllAnnouncements($visibility, $id = -1, $start = 0, $user_id = '')
{
public static function displayAllAnnouncements(
$visibility,
$id = -1,
$start = 0,
$user_id = ''
) {
$user_selected_language = api_get_interface_language();
$start = intval($start);
$userGroup = new UserGroup();
@ -342,7 +346,9 @@ class SystemAnnouncementManager
$db_table = Database::get_main_table(TABLE_MAIN_SYSTEM_ANNOUNCEMENTS);
if (!checkdate($date_start_to_compare[1], $date_start_to_compare[2], $date_start_to_compare[0])) {
Display::addFlash(Display::return_message(get_lang('InvalidStartDate'), 'warning'));
Display::addFlash(
Display::return_message(get_lang('InvalidStartDate'), 'warning')
);
return false;
}
@ -352,13 +358,17 @@ class SystemAnnouncementManager
$date_end_to_compare[0]) &&
!checkdate($date_end_to_compare[1], $date_end_to_compare[2], $date_end_to_compare[0])
) {
Display::addFlash(Display::return_message(get_lang('InvalidEndDate'), 'warning'));
Display::addFlash(
Display::return_message(get_lang('InvalidEndDate'), 'warning')
);
return false;
}
if (strlen(trim($title)) == 0) {
Display::addFlash(Display::return_message(get_lang('InvalidTitle'), 'warning'));
Display::addFlash(
Display::return_message(get_lang('InvalidTitle'), 'warning')
);
return false;
}
@ -879,7 +889,6 @@ class SystemAnnouncementManager
ALTER TABLE sys_announcement ADD COLUMN visible_session_admin INT DEFAULT 0;
ALTER TABLE sys_announcement ADD COLUMN visible_boss INT DEFAULT 0;
*/
return api_get_configuration_value('system_announce_extra_roles');
}

@ -47,9 +47,9 @@ api_display_tool_title($nameTools.$add_group_to_title);
*/
//user has submitted a file
if (isset($_FILES['user_upload'])) {
$upload_ok = process_uploaded_file($_FILES['user_upload']);
if ($upload_ok) {
//file got on the server without problems, now process it
$upload_ok = process_uploaded_file($_FILES['user_upload']);
if ($upload_ok) {
//file got on the server without problems, now process it
$new_path = handle_uploaded_document(
$_course,
$_FILES['user_upload'],
@ -61,21 +61,21 @@ if (isset($_FILES['user_upload'])) {
$_POST['unzip'],
$_POST['if_exists']
);
$new_comment = isset($_POST['comment']) ? Database::escape_string(trim($_POST['comment'])) : '';
$new_title = isset($_POST['title']) ? Database::escape_string(trim($_POST['title'])) : '';
$new_comment = isset($_POST['comment']) ? Database::escape_string(trim($_POST['comment'])) : '';
$new_title = isset($_POST['title']) ? Database::escape_string(trim($_POST['title'])) : '';
if ($new_path && ($new_comment || $new_title))
if (($docid = DocumentManager::get_document_id($_course, $new_path))) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$ct = '';
if ($new_path && ($new_comment || $new_title))
if (($docid = DocumentManager::get_document_id($_course, $new_path))) {
$table_document = Database::get_course_table(TABLE_DOCUMENT);
$ct = '';
if ($new_comment) {
$ct .= ", comment='$new_comment'";
}
if ($new_title) {
$ct .= ", title='$new_title'";
}
Database::query("UPDATE $table_document SET".substr($ct, 1)." WHERE id = '$docid'");
}
Database::query("UPDATE $table_document SET".substr($ct, 1)." WHERE id = '$docid'");
}
//check for missing images in html files
$missing_files = check_for_missing_files($base_work_dir.$_POST['curdirpath'].$new_path);
if ($missing_files) {
@ -133,7 +133,7 @@ if (isset($_POST['submit_image'])) {
//they want to create a directory
if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
$added_slash = $path == '/' ? '' : '/';
$dir_name = $path.$added_slash.api_replace_dangerous_char($_POST['dirname']);
$dir_name = $path.$added_slash.api_replace_dangerous_char($_POST['dirname']);
$created_dir = create_unexisting_directory(
$_course,
api_get_user_id(),
@ -153,18 +153,19 @@ if (isset($_POST['create_dir']) && $_POST['dirname'] != '') {
}
if (isset($_GET['createdir'])) {
//create the form that asks for the directory name
$new_folder_text = '<form action="'.api_get_self().'" method="POST">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
$new_folder_text .= get_lang('NewDir').' ';
$new_folder_text .= '<input type="text" name="dirname"/>';
$new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>';
$new_folder_text .= '</form>';
//show the form
echo Display::return_message($new_folder_text, 'normal');
} else { //give them a link to create a directory
//create the form that asks for the directory name
$new_folder_text = '<form action="'.api_get_self().'" method="POST">';
$new_folder_text .= '<input type="hidden" name="curdirpath" value="'.$path.'"/>';
$new_folder_text .= get_lang('NewDir').' ';
$new_folder_text .= '<input type="text" name="dirname"/>';
$new_folder_text .= '<input type="submit" name="create_dir" value="'.get_lang('Ok').'"/>';
$new_folder_text .= '</form>';
//show the form
echo Display::return_message($new_folder_text, 'normal');
} else {
//give them a link to create a directory
?>
<p>
<p>
<a href="<?php echo api_get_self(); ?>?path=<?php echo $path; ?>&amp;createdir=1">
<?php echo Display::return_icon('new_folder.gif'); ?>
<?php echo(get_lang('CreateDir')); ?>

@ -7,7 +7,6 @@
namespace Chamilo\ThemeBundle\Theme;
use Assetic\Asset\AssetCollection;
use Assetic\Asset\AssetReference;
use Assetic\Factory\AssetFactory;
@ -19,9 +18,12 @@ use Symfony\Component\DependencyInjection\Container;
use Chamilo\FoundationBundle\Util\DependencyResolver;
use Symfony\Component\HttpKernel\Config\FileLocator;
/**
* Class ThemeManager
* @package Chamilo\ThemeBundle\Theme
*/
class ThemeManager
{
/** @var Container */
protected $container;
@ -29,11 +31,16 @@ class ThemeManager
protected $javascripts = array();
protected $locations = array();
protected $locations = array();
protected $resolverClass;
function __construct($container, $resolverClass = null)
/**
* ThemeManager constructor.
* @param $container
* @param null $resolverClass
*/
public function __construct($container, $resolverClass = null)
{
$this->container = $container;
$this->resolverClass = $resolverClass ?: 'Chamilo\ThemeBundle\Util\DependencyResolver';
@ -105,5 +112,4 @@ class ThemeManager
{
return $this->container->get('file_locator');
}
}

Loading…
Cancel
Save