Merge pull request #5665 from christianbeeznest/fixes-updates35

Internal: Remove special_course field and related data
pull/5671/head
christianbeeznest 4 months ago committed by GitHub
commit f77ee8267d
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
  1. 80
      public/main/inc/lib/course.lib.php
  2. 8
      src/CoreBundle/DataFixtures/ExtraFieldFixtures.php
  3. 37
      src/CoreBundle/Migrations/Schema/V200/Version20240715183456.php

@ -2714,53 +2714,37 @@ class CourseManager
public static function get_special_course_list() public static function get_special_course_list()
{ {
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE); $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$tbl_course_field = Database::get_main_table(TABLE_EXTRA_FIELD);
$tbl_course_field_value = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
$tbl_url_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE); $tbl_url_course = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_COURSE);
$extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
$courseList = []; $courseList = [];
// get course list auto-register
$sql = "SELECT id FROM $tbl_course_field // Get list of special courses (appear to all)
WHERE item_type = $extraFieldType AND $sql = "SELECT id FROM $courseTable WHERE sticky = 1";
variable = 'special_course'";
$result = Database::query($sql); $result = Database::query($sql);
$courseList = []; while ($row = Database::fetch_assoc($result)) {
$courseList[] = $row['id'];
}
if (Database::num_rows($result) > 0) { if (count($courseList) < 1) {
$row = Database::fetch_assoc($result); return $courseList;
// Get list of special courses (appear to all) }
// Note: The value is better indexed as string, so
// using '1' instead of integer is more efficient if (api_get_multiple_access_url()) {
$sql = "SELECT DISTINCT(item_id) as cid // We filter the courses by the active URL
FROM $tbl_course_field_value $coursesSelect = '';
WHERE field_id = ".$row['id']." AND field_value = '1'"; if (1 == count($courseList)) {
$result = Database::query($sql); $coursesSelect = $courseList[0];
while ($row = Database::fetch_assoc($result)) { } else {
$courseList[] = $row['cid']; $coursesSelect = implode(',', $courseList);
}
if (count($courseList) < 1) {
return $courseList;
} }
if (api_get_multiple_access_url()) { $access_url_id = api_get_current_access_url_id();
//we filter the courses by the active URL if (-1 != $access_url_id) {
$coursesSelect = ''; $sql = "SELECT c_id FROM $tbl_url_course
if (1 == count($courseList)) { WHERE access_url_id = $access_url_id
$coursesSelect = $courseList[0]; AND c_id IN ($coursesSelect)";
} else { $result = Database::query($sql);
$coursesSelect = implode(',', $courseList); while ($row = Database::fetch_assoc($result)) {
} $courseList[] = $row['c_id'];
$access_url_id = api_get_current_access_url_id();
if (-1 != $access_url_id) {
$sql = "SELECT c_id FROM $tbl_url_course
WHERE access_url_id = $access_url_id
AND c_id IN ($coursesSelect)";
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$courseList[] = $row['c_id'];
}
} }
} }
} }
@ -3470,16 +3454,14 @@ class CourseManager
*/ */
public static function isSpecialCourse($courseId) public static function isSpecialCourse($courseId)
{ {
$extraFieldValue = new ExtraFieldValue('course'); $courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
$result = $extraFieldValue->get_values_by_handler_and_field_variable(
$courseId,
'special_course'
);
if (!empty($result)) { $sql = "SELECT sticky FROM $courseTable WHERE id = " . intval($courseId);
if (1 == $result['field_value']) { $result = Database::query($sql);
return true; $row = Database::fetch_assoc($result);
}
if (!empty($row) && 1 === (int) $row['sticky']) {
return true;
} }
return false; return false;

@ -76,14 +76,6 @@ class ExtraFieldFixtures extends Fixture implements FixtureGroupInterface
'item_type' => ExtraField::USER_FIELD_TYPE, 'item_type' => ExtraField::USER_FIELD_TYPE,
'value_type' => ExtraField::FIELD_TYPE_TEXT, 'value_type' => ExtraField::FIELD_TYPE_TEXT,
], ],
[
'variable' => 'special_course',
'display_text' => 'Special course',
'item_type' => ExtraField::COURSE_FIELD_TYPE,
'value_type' => ExtraField::FIELD_TYPE_CHECKBOX,
'visible_to_self' => true,
'changeable' => true,
],
[ [
'variable' => 'tags', 'variable' => 'tags',
'display_text' => 'Tags', 'display_text' => 'Tags',

@ -0,0 +1,37 @@
<?php
declare(strict_types=1);
/* For licensing terms, see /license.txt */
namespace Chamilo\CoreBundle\Migrations\Schema\V200;
use Chamilo\CoreBundle\Entity\ExtraField;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
final class Version20240715183456 extends AbstractMigration
{
public function getDescription(): string
{
return 'Remove the special_course field from the extra_field table and related entries in extra_field_values';
}
public function up(Schema $schema): void
{
$extraFieldType = ExtraField::COURSE_FIELD_TYPE;
// Delete entries in extra_field_values
$this->addSql("DELETE FROM extra_field_values WHERE field_id IN (
SELECT id FROM extra_field
WHERE item_type = $extraFieldType AND variable = 'special_course'
)");
// Delete the extra_field
$this->addSql("DELETE FROM extra_field WHERE variable = 'special_course' AND item_type = $extraFieldType");
}
public function down(Schema $schema): void
{
}
}
Loading…
Cancel
Save