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. 40
      public/main/inc/lib/course.lib.php
  2. 8
      src/CoreBundle/DataFixtures/ExtraFieldFixtures.php
  3. 37
      src/CoreBundle/Migrations/Schema/V200/Version20240715183456.php

@ -2714,38 +2714,23 @@ class CourseManager
public static function get_special_course_list()
{
$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);
$extraFieldType = EntityExtraField::COURSE_FIELD_TYPE;
$courseList = [];
// get course list auto-register
$sql = "SELECT id FROM $tbl_course_field
WHERE item_type = $extraFieldType AND
variable = 'special_course'";
$result = Database::query($sql);
$courseList = [];
if (Database::num_rows($result) > 0) {
$row = Database::fetch_assoc($result);
// 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
$sql = "SELECT DISTINCT(item_id) as cid
FROM $tbl_course_field_value
WHERE field_id = ".$row['id']." AND field_value = '1'";
$sql = "SELECT id FROM $courseTable WHERE sticky = 1";
$result = Database::query($sql);
while ($row = Database::fetch_assoc($result)) {
$courseList[] = $row['cid'];
$courseList[] = $row['id'];
}
if (count($courseList) < 1) {
return $courseList;
}
if (api_get_multiple_access_url()) {
//we filter the courses by the active URL
// We filter the courses by the active URL
$coursesSelect = '';
if (1 == count($courseList)) {
$coursesSelect = $courseList[0];
@ -2763,7 +2748,6 @@ class CourseManager
}
}
}
}
return $courseList;
}
@ -3470,17 +3454,15 @@ class CourseManager
*/
public static function isSpecialCourse($courseId)
{
$extraFieldValue = new ExtraFieldValue('course');
$result = $extraFieldValue->get_values_by_handler_and_field_variable(
$courseId,
'special_course'
);
$courseTable = Database::get_main_table(TABLE_MAIN_COURSE);
if (!empty($result)) {
if (1 == $result['field_value']) {
$sql = "SELECT sticky FROM $courseTable WHERE id = " . intval($courseId);
$result = Database::query($sql);
$row = Database::fetch_assoc($result);
if (!empty($row) && 1 === (int) $row['sticky']) {
return true;
}
}
return false;
}

@ -76,14 +76,6 @@ class ExtraFieldFixtures extends Fixture implements FixtureGroupInterface
'item_type' => ExtraField::USER_FIELD_TYPE,
'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',
'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