PageRenderTime 77ms CodeModel.GetById 17ms app.highlight 51ms RepoModel.GetById 1ms app.codeStats 1ms

/php/lib/course/course.class.php

https://bitbucket.org/chamilo/chamilo-app-weblcms/
PHP | 1477 lines | 1127 code | 167 blank | 183 comment | 151 complexity | dc406d6b0120fc15712b260126cf7209 MD5 | raw file

Large files files are truncated, but you can click here to view the full file

   1<?php
   2
   3namespace application\weblcms;
   4
   5use user\UserDataManager;
   6use common\libraries\Session;
   7use common\libraries\Utilities;
   8use common\libraries\ObjectTableOrder;
   9use common\libraries\EqualityCondition;
  10use common\libraries\Path;
  11use common\libraries\DataClass;
  12use common\libraries\Translation;
  13
  14/**
  15 * $Id: course.class.php 216 2009-11-13 14:08:06Z kariboe $
  16 * @package application.lib.weblcms.course
  17 */
  18
  19/**
  20 * This class represents a course in the weblcms.
  21 *
  22 * courses have a number of default properties:
  23 * - id: the numeric ID of the course object;
  24 * - visual: the visual code of the course;
  25 * - name: the name of the course object;
  26 * - path: the course's path;
  27 * - titular: the titular of this course object;
  28 * - language: the language of the course object;
  29 * - extlink url: the URL department;
  30 * - extlink name: the name of the department;
  31 * - category code: the category code of the object;
  32 * - category name: the name of the category;
  33 *
  34 * To access the values of the properties, this class and its subclasses
  35 * should provide accessor methods. The names of the properties should be
  36 * defined as class constants, for standardization purposes. It is recommended
  37 * that the names of these constants start with the string "PROPERTY_".
  38 *
  39 */
  40class Course extends DataClass
  41{
  42    const CLASS_NAME = __CLASS__;
  43
  44    const PROPERTY_COURSE_TYPE_ID = 'course_type_id';
  45    const PROPERTY_VISUAL = 'visual_code';
  46    const PROPERTY_NAME = 'title';
  47    const PROPERTY_TITULAR = 'titular_id';
  48    const PROPERTY_EXTERNAL_URL = 'external_url';
  49    const PROPERTY_EXTERNAL_NAME = 'external_name';
  50    const PROPERTY_CATEGORY = 'category_id';
  51
  52    // Remnants from the old Chamilo system
  53    const PROPERTY_LAST_VISIT = 'last_visit';
  54    const PROPERTY_LAST_EDIT = 'last_edit';
  55    const PROPERTY_CREATION_DATE = 'creation_date';
  56    const PROPERTY_EXPIRATION_DATE = 'expiration_date';
  57
  58    private $settings;
  59    private $layout;
  60    private $tools;
  61    private $rights;
  62    private $request;
  63    private $course_type = false;
  64
  65    function __construct($defaultProperties = array(), $optionalProperties = array())
  66    {
  67        parent :: __construct($defaultProperties, $optionalProperties);
  68    }
  69
  70    /**
  71     * Get the default properties of all courses.
  72     * @return array The property names.
  73     */
  74    static function get_default_property_names($extended_property_names = array())
  75    {
  76        return parent :: get_default_property_names(array(
  77            self :: PROPERTY_COURSE_TYPE_ID, self :: PROPERTY_VISUAL, self :: PROPERTY_CATEGORY, self :: PROPERTY_NAME, self :: PROPERTY_TITULAR, self :: PROPERTY_EXTERNAL_URL, self :: PROPERTY_EXTERNAL_NAME,
  78            self :: PROPERTY_CREATION_DATE, self :: PROPERTY_EXPIRATION_DATE, self :: PROPERTY_LAST_EDIT, self :: PROPERTY_LAST_VISIT));
  79    }
  80
  81    /**
  82     * inherited
  83     */
  84    function get_data_manager()
  85    {
  86        return WeblcmsDataManager :: get_instance();
  87    }
  88
  89    /**
  90     * Returns the course type id of this course object
  91     * @return string the course type id
  92     */
  93    function get_course_type_id()
  94    {
  95        return $this->get_default_property(self :: PROPERTY_COURSE_TYPE_ID);
  96    }
  97
  98    /**
  99     * Returns the visual code of this course object
 100     * @return string the visual code
 101     */
 102    function get_visual()
 103    {
 104        return $this->get_default_property(self :: PROPERTY_VISUAL);
 105    }
 106
 107    /**
 108     * Returns the category code of this course object
 109     * @return string the category code
 110     */
 111    function get_category()
 112    {
 113        return $this->get_default_property(self :: PROPERTY_CATEGORY);
 114    }
 115
 116    /**
 117     * Returns the name (Title) of this course object
 118     * @return string The Name
 119     */
 120    function get_name()
 121    {
 122        return $this->get_default_property(self :: PROPERTY_NAME);
 123    }
 124
 125    /**
 126     * Returns the titular of this course object
 127     * @return String The Titular
 128     */
 129    function get_titular()
 130    {
 131        return $this->get_default_property(self :: PROPERTY_TITULAR);
 132    }
 133
 134    /**
 135     * Returns the titular as a string
 136     */
 137    function get_titular_string()
 138    {
 139        $titular_id = $this->get_titular();
 140
 141        if (!is_null($titular_id))
 142        {
 143            $udm = UserDataManager :: get_instance();
 144            $user = $udm->retrieve_user($titular_id);
 145            return $user->get_lastname() . ' ' . $user->get_firstname();
 146        }
 147        else
 148        {
 149            return null;
 150        }
 151    }
 152
 153    /**
 154     * Returns the ext url of this course object
 155     * @return String The URL
 156     */
 157    function get_external_url()
 158    {
 159        return $this->get_default_property(self :: PROPERTY_EXTERNAL_URL);
 160    }
 161
 162    /**
 163     * Returns the ext link name of this course object
 164     * @return String The Name
 165     */
 166    function get_external_name()
 167    {
 168        return $this->get_default_property(self :: PROPERTY_EXTERNAL_NAME);
 169    }
 170
 171    function get_creation_date()
 172    {
 173        return $this->get_default_property(self :: PROPERTY_CREATION_DATE);
 174    }
 175
 176    function get_expiration_date()
 177    {
 178        return $this->get_default_property(self :: PROPERTY_EXPIRATION_DATE);
 179    }
 180
 181    function get_last_edit()
 182    {
 183        return $this->get_default_property(self :: PROPERTY_LAST_EDIT);
 184    }
 185
 186    function get_last_visit()
 187    {
 188        return $this->get_default_property(self :: PROPERTY_LAST_VISIT);
 189    }
 190
 191    function get_settings()
 192    {
 193        if (is_null($this->settings))
 194        {
 195            $settings = $this->get_data_manager()->retrieve_course_settings($this->get_id());
 196            if (empty($settings))
 197            {
 198                $settings = new CourseSettings();
 199                $settings->set_course_id($this->get_id());
 200                if (!is_null($this->get_id()))
 201                    $settings->create();
 202            }
 203            $this->set_settings($settings);
 204        }
 205        return $this->settings;
 206    }
 207
 208    function get_request()
 209    {
 210        return $this->request;
 211    }
 212
 213    function get_layout_settings()
 214    {
 215        if (is_null($this->layout))
 216        {
 217            $layout = $this->get_data_manager()->retrieve_course_layout($this->get_id());
 218            if (empty($layout))
 219            {
 220                $layout = new CourseLayout();
 221                $layout->set_course_id($this->get_id());
 222                if (!is_null($this->get_id()))
 223                    $layout->create();
 224            }
 225            $this->set_layout_settings($layout);
 226        }
 227        return $this->layout;
 228    }
 229
 230    function get_tools($require = true)
 231    {
 232        if (!$this->tools)
 233        {
 234            $wdm = WeblcmsDataManager :: get_instance();
 235            $this->tools = $wdm->get_course_modules($this->get_id());
 236
 237            if ($require)
 238            {
 239                foreach ($this->tools as $index => $tool)
 240                {
 241                    require_once Path :: get_application_path() . 'weblcms/tool/' . $tool->name . '/php/' . $tool->name . '_tool.class.php';
 242                }
 243            }
 244        }
 245
 246        return $this->tools;
 247    }
 248
 249    function get_rights()
 250    {
 251        if (is_null($this->rights))
 252        {
 253            $rights = $this->get_data_manager()->retrieve_course_rights($this->get_id());
 254            if (empty($rights))
 255            {
 256                $rights = new CourseRights();
 257                $rights->set_course_id($this->get_id());
 258                if (!is_null($this->get_id()))
 259                    $rights->create();
 260            }
 261            $this->set_rights($rights);
 262        }
 263        return $this->rights;
 264    }
 265
 266    function get_course_type()
 267    {
 268        if ($this->course_type === false)
 269        {
 270            $course_type = $this->get_data_manager()->retrieve_course_type($this->get_course_type_id());
 271            if (empty($course_type))
 272            {
 273                $course_type = NULL;
 274            }
 275            $this->set_course_type($course_type);
 276        }
 277        return $this->course_type;
 278    }
 279
 280    /**
 281     * Sets the course type id of this course object
 282     * @param int $type The course type id
 283     */
 284    function set_course_type_id($type)
 285    {
 286        $this->set_default_property(self :: PROPERTY_COURSE_TYPE_ID, $type);
 287    }
 288
 289    /**
 290     * Sets the visual code of this course object
 291     * @param String $visual The visual code
 292     */
 293    function set_visual($visual)
 294    {
 295        $this->set_default_property(self :: PROPERTY_VISUAL, $visual);
 296    }
 297
 298    /**
 299     * Sets the category code of this course object
 300     * @param String $visual The category code
 301     */
 302    function set_category($category)
 303    {
 304        $this->set_default_property(self :: PROPERTY_CATEGORY, $category);
 305    }
 306
 307    /**
 308     * Sets the course name of this course object
 309     * @param String $name The name of this course object
 310     */
 311    function set_name($name)
 312    {
 313        $this->set_default_property(self :: PROPERTY_NAME, $name);
 314    }
 315
 316    /**
 317     * Sets the titular of this course object
 318     * @param String $titular The titular of this course object
 319     */
 320    function set_titular($titular)
 321    {
 322        $this->set_default_property(self :: PROPERTY_TITULAR, $titular);
 323    }
 324
 325    /**
 326     * Sets the extlink URL of this course object
 327     * @param String $url The URL if the extlink
 328     */
 329    function set_external_url($url)
 330    {
 331        if(!empty($url))
 332        {
 333            $url = self :: complete_url($url);
 334        }
 335        $this->set_default_property(self :: PROPERTY_EXTERNAL_URL, $url);
 336    }
 337
 338    /**
 339     * Sets the extlink Name of this course object
 340     * @param String $name The name of the exlink
 341     */
 342    function set_external_name($name)
 343    {
 344        $this->set_default_property(self :: PROPERTY_EXTERNAL_NAME, $name);
 345    }
 346
 347    function set_creation_date($creation_date)
 348    {
 349        $this->set_default_property(self :: PROPERTY_CREATION_DATE, $creation_date);
 350    }
 351
 352    function set_expiration_date($expiration_date)
 353    {
 354        $this->set_default_property(self :: PROPERTY_EXPIRATION_DATE, $expiration_date);
 355    }
 356
 357    function set_last_edit($last_edit)
 358    {
 359        $this->set_default_property(self :: PROPERTY_LAST_EDIT, $last_edit);
 360    }
 361
 362    function set_last_visit($last_visit)
 363    {
 364        $this->set_default_property(self :: PROPERTY_LAST_VISIT, $last_visit);
 365    }
 366
 367    /**
 368     * Sets the settings of this course object
 369     * @param CourseSettings $settings the settings of this course object
 370     */
 371    function set_settings($settings)
 372    {
 373        $this->settings = $settings;
 374    }
 375
 376    function set_request($request)
 377    {
 378        $this->request = $request;
 379    }
 380
 381    /**
 382     * Sets the layout of this course object
 383     * @param CourseLayout $layout the layout of this course object
 384     */
 385    function set_layout_settings($layout)
 386    {
 387        $this->layout = $layout;
 388    }
 389
 390    /**
 391     * Sets the tools of this course object
 392     * @param array $tools the tools of this course object
 393     */
 394    function set_tools($tools)
 395    {
 396        $this->tools = $tools;
 397    }
 398
 399    /**
 400     * Sets the rights of this course object
 401     * @param array $rights the rights of this course object
 402     */
 403    function set_rights($rights)
 404    {
 405        $this->rights = $rights;
 406    }
 407
 408    /**
 409     * Sets the course_type of this course object
 410     * @param array $course_type the course_type of this course object
 411     */
 412    function set_course_type($course_type)
 413    {
 414        $this->course_type = $course_type;
 415    }
 416
 417    /**
 418     * Direct access to the setters and getters for the course settings
 419     * All setters include a validation to see whether or not the property is writeable
 420     */
 421    /*
 422     * Getters and validation whether or not the property is readable from the course's own settings
 423     */
 424
 425    function get_language()
 426    {
 427        if (!$this->get_language_fixed())
 428        {
 429            return $this->get_settings()->get_language();
 430        }
 431        else
 432            return $this->get_course_type()->get_settings()->get_language();
 433    }
 434
 435    function get_visibility()
 436    {
 437        if (!$this->get_visibility_fixed())
 438            return $this->get_settings()->get_visibility();
 439        else
 440            return $this->get_course_type()->get_settings()->get_visibility();
 441    }
 442
 443    /**
 444     *
 445     * @return int access_type
 446     */
 447    function get_access()
 448    {
 449        if (!$this->get_access_fixed())
 450        {
 451            return $this->get_settings()->get_access();
 452        }
 453        else
 454        {
 455            return $this->get_course_type()->get_settings()->get_access();
 456        }
 457    }
 458
 459    function get_max_number_of_members()
 460    {
 461        if (!$this->get_max_number_of_members_fixed())
 462            return $this->get_settings()->get_max_number_of_members();
 463        else
 464            return $this->get_course_type()->get_settings()->get_max_number_of_members();
 465    }
 466
 467    /**
 468     * Setters and validation to see whether they are writable
 469     */
 470    function get_titular_fixed()
 471    {
 472        if (!is_null($this->get_course_type()))
 473            return $this->get_course_type()->get_settings()->get_titular_fixed();
 474        else
 475            return 0;
 476    }
 477
 478    function get_language_fixed()
 479    {
 480        if (!is_null($this->get_course_type()))
 481            return $this->get_course_type()->get_settings()->get_language_fixed();
 482        else
 483            return 0;
 484    }
 485
 486    function set_language($language)
 487    {
 488        if (!$this->get_language_fixed())
 489            $this->get_settings()->set_language($language);
 490        else
 491            $this->get_settings()->set_language($this->get_course_type()->get_settings()->get_language());
 492    }
 493
 494    function get_visibility_fixed()
 495    {
 496        if (!is_null($this->get_course_type()))
 497            return $this->get_course_type()->get_settings()->get_visibility_fixed();
 498        else
 499            return 0;
 500    }
 501
 502    function set_visibility($visibility)
 503    {
 504        if (!$this->get_visibility_fixed())
 505            $this->get_settings()->set_visibility($visibility);
 506        else
 507            $this->get_settings()->set_visibility($this->get_course_type()->get_settings()->get_visibility());
 508    }
 509
 510    function get_access_fixed()
 511    {
 512        if (!is_null($this->get_course_type()))
 513            return $this->get_course_type()->get_settings()->get_access_fixed();
 514        else
 515            return 0;
 516    }
 517
 518    function set_access($access)
 519    {
 520        if (!$this->get_access_fixed())
 521            $this->get_settings()->set_access($access);
 522        else
 523            $this->get_settings()->set_access($this->get_course_type()->get_settings()->get_access());
 524    }
 525
 526    function get_max_number_of_members_fixed()
 527    {
 528        if (!is_null($this->get_course_type()))
 529            return $this->get_course_type()->get_settings()->get_max_number_of_members_fixed();
 530        else
 531            return 0;
 532    }
 533
 534    function set_max_number_of_members($max_number_of_members)
 535    {
 536        if (!$this->get_max_number_of_members_fixed())
 537            $this->get_settings()->set_max_number_of_members($max_number_of_members);
 538        else
 539            $this->get_settings()->set_max_number_of_members($this->get_course_type()->get_settings()->get_max_number_of_members());
 540    }
 541
 542    /**
 543     * Direct access to the setters and getters for the course layout
 544     * All setters include a validation to see whether or not the property is writeable
 545     */
 546    /*
 547     * Getters and validation whether or not the property is readable from the course's own settings
 548     */
 549    function get_intro_text()
 550    {
 551        if (!$this->get_intro_text_fixed())
 552            return $this->get_layout_settings()->get_intro_text();
 553        else
 554            return $this->get_course_type()->get_layout_settings()->get_intro_text();
 555    }
 556
 557    function get_student_view()
 558    {
 559        if (!$this->get_student_view_fixed())
 560            return $this->get_layout_settings()->get_student_view();
 561        else
 562            return $this->get_course_type()->get_layout_settings()->get_student_view();
 563    }
 564
 565    function get_layout()
 566    {
 567        if (!$this->get_layout_fixed())
 568            return $this->get_layout_settings()->get_layout();
 569        else
 570            return $this->get_course_type()->get_layout_settings()->get_layout();
 571    }
 572
 573    function get_tool_shortcut()
 574    {
 575        if (!$this->get_tool_shortcut_fixed())
 576            return $this->get_layout_settings()->get_tool_shortcut();
 577        else
 578            return $this->get_course_type()->get_layout_settings()->get_tool_shortcut();
 579    }
 580
 581    function get_menu()
 582    {
 583        if (!$this->get_menu_fixed())
 584            return $this->get_layout_settings()->get_menu();
 585        else
 586            return $this->get_course_type()->get_layout_settings()->get_menu();
 587    }
 588
 589    function get_breadcrumb()
 590    {
 591        if (!$this->get_breadcrumb_fixed())
 592            return $this->get_layout_settings()->get_breadcrumb();
 593        else
 594            return $this->get_course_type()->get_layout_settings()->get_breadcrumb();
 595    }
 596
 597    function get_feedback()
 598    {
 599        if (!$this->get_feedback_fixed())
 600            return $this->get_layout_settings()->get_feedback();
 601        else
 602            return $this->get_course_type()->get_layout_settings()->get_feedback();
 603    }
 604
 605    function get_course_code_visible()
 606    {
 607        if (!$this->get_course_code_visible_fixed())
 608            return $this->get_layout_settings()->get_course_code_visible();
 609        else
 610            return $this->get_course_type()->get_layout_settings()->get_course_code_visible();
 611    }
 612
 613    function get_course_manager_name_visible()
 614    {
 615        if (!$this->get_course_manager_name_visible_fixed())
 616            return $this->get_layout_settings()->get_course_manager_name_visible();
 617        else
 618            return $this->get_course_type()->get_layout_settings()->get_course_manager_name_visible();
 619    }
 620
 621    function get_course_languages_visible()
 622    {
 623        if (!$this->get_course_languages_visible_fixed())
 624            return $this->get_layout_settings()->get_course_languages_visible();
 625        else
 626            return $this->get_course_type()->get_layout_settings()->get_course_languages_visible();
 627    }
 628
 629    /**
 630     * Setters and validation to see whether they are writable
 631     */
 632    function get_feedback_fixed()
 633    {
 634        if (!is_null($this->get_course_type()))
 635            return $this->get_course_type()->get_layout_settings()->get_feedback_fixed();
 636        else
 637            return 0;
 638    }
 639
 640    function set_feedback($feedback)
 641    {
 642        if (!$this->get_feedback_fixed())
 643            $this->get_layout_settings()->set_feedback($feedback);
 644        else
 645            $this->get_layout_settings()->set_feedback($this->get_course_type()->get_layout_settings()->get_feedback());
 646    }
 647
 648    function get_layout_fixed()
 649    {
 650        if (!is_null($this->get_course_type()))
 651            return $this->get_course_type()->get_layout_settings()->get_layout_fixed();
 652        else
 653            return 0;
 654    }
 655
 656    function set_layout($layout)
 657    {
 658        if (!$this->get_layout_fixed())
 659            $this->get_layout_settings()->set_layout($layout);
 660        else
 661            $this->get_layout_settings()->set_layout($this->get_course_type()->get_layout_settings()->get_layout());
 662    }
 663
 664    function get_tool_shortcut_fixed()
 665    {
 666        if (!is_null($this->get_course_type()))
 667            return $this->get_course_type()->get_layout_settings()->get_tool_shortcut_fixed();
 668        else
 669            return 0;
 670    }
 671
 672    function set_tool_shortcut($tool_shortcut)
 673    {
 674        if (!$this->get_tool_shortcut_fixed())
 675            $this->get_layout_settings()->set_tool_shortcut($tool_shortcut);
 676        else
 677            $this->get_layout_settings()->set_tool_shortcut($this->get_course_type()->get_layout_settings()->get_tool_shortcut());
 678    }
 679
 680    function get_menu_fixed()
 681    {
 682        if (!is_null($this->get_course_type()))
 683            return $this->get_course_type()->get_layout_settings()->get_menu_fixed();
 684        else
 685            return 0;
 686    }
 687
 688    function set_menu($menu)
 689    {
 690        if (!$this->get_menu_fixed())
 691            $this->get_layout_settings()->set_menu($menu);
 692        else
 693            $this->get_layout_settings()->set_menu($this->get_course_type()->get_layout_settings()->get_menu());
 694    }
 695
 696    function get_breadcrumb_fixed()
 697    {
 698        if (!is_null($this->get_course_type()))
 699            return $this->get_course_type()->get_layout_settings()->get_breadcrumb_fixed();
 700        else
 701            return 0;
 702    }
 703
 704    function set_breadcrumb($breadcrumb)
 705    {
 706        if (!$this->get_breadcrumb_fixed())
 707            $this->get_layout_settings()->set_breadcrumb($breadcrumb);
 708        else
 709            $this->get_layout_settings()->set_breadcrumb($this->get_course_type()->get_layout_settings()->get_breadcrumb());
 710    }
 711
 712    function get_intro_text_fixed()
 713    {
 714        if (!is_null($this->get_course_type()))
 715            return $this->get_course_type()->get_layout_settings()->get_intro_text_fixed();
 716        else
 717            return 0;
 718    }
 719
 720    function set_intro_text($intro_text)
 721    {
 722        if (!$this->get_intro_text_fixed())
 723            $this->get_layout_settings()->set_intro_text($intro_text);
 724        else
 725            $this->get_layout_settings()->set_intro_text($this->get_course_type()->get_layout_settings()->get_intro_text());
 726    }
 727
 728    function get_student_view_fixed()
 729    {
 730        if (!is_null($this->get_course_type()))
 731            return $this->get_course_type()->get_layout_settings()->get_student_view_fixed();
 732        else
 733            return 0;
 734    }
 735
 736    function set_student_view($student_view)
 737    {
 738        if (!$this->get_student_view_fixed())
 739            $this->get_layout_settings()->set_student_view($student_view);
 740        else
 741            $this->get_layout_settings()->set_student_view($this->get_course_type()->get_layout_settings()->get_student_view());
 742    }
 743
 744    function get_course_code_visible_fixed()
 745    {
 746        if (!is_null($this->get_course_type()))
 747            return $this->get_course_type()->get_layout_settings()->get_course_code_visible_fixed();
 748        else
 749            return 0;
 750    }
 751
 752    function set_course_code_visible($course_code_visible)
 753    {
 754        if (!$this->get_course_code_visible_fixed())
 755            $this->get_layout_settings()->set_course_code_visible($course_code_visible);
 756        else
 757            $this->get_layout_settings()->set_course_code_visible($this->get_course_type()->get_layout_settings()->get_course_code_visible());
 758    }
 759
 760    function get_course_manager_name_visible_fixed()
 761    {
 762        if (!is_null($this->get_course_type()))
 763            return $this->get_course_type()->get_layout_settings()->get_course_manager_name_visible_fixed();
 764        else
 765            return 0;
 766    }
 767
 768    function set_course_manager_name_visible($course_manager_name_visible)
 769    {
 770        if (!$this->get_course_manager_name_visible_fixed())
 771            $this->get_layout_settings()->set_course_manager_name_visible($course_manager_name_visible);
 772        else
 773            $this->get_layout_settings()->set_course_manager_name_visible($this->get_course_type()->get_layout_settings()->get_course_manager_name_visible());
 774    }
 775
 776    function get_course_languages_visible_fixed()
 777    {
 778        if (!is_null($this->get_course_type()))
 779            return $this->get_course_type()->get_layout_settings()->get_course_languages_visible_fixed();
 780        else
 781            return 0;
 782    }
 783
 784    function set_course_languages_visible($course_languages_visible)
 785    {
 786        if (!$this->get_course_languages_visible_fixed())
 787            $this->get_layout_settings()->set_course_languages_visible($course_languages_visible);
 788        else
 789            $this->get_layout_settings()->set_course_languages_visible($this->get_course_type()->get_layout_settings()->get_course_languages_visible());
 790    }
 791
 792    /**
 793     * Direct access to the setters and getters for the rights settings
 794     * All setters include a validation to see whether or not the property is writeable
 795     */
 796    /*
 797     * Getters and validation whether or not the property is readable from the course's own settings
 798     */
 799
 800    function can_user_subscribe($user)
 801    {
 802        $max_members = $this->get_max_number_of_members();
 803        if ($max_members != 0)
 804        {
 805            $subscribed_users = $this->has_subscribed_users();
 806            if ($subscribed_users >= $max_members)
 807            {
 808                return CourseGroupSubscribeRight :: SUBSCRIBE_NONE;
 809            }
 810        }
 811        $current_right = $this->can_group_subscribe(0);
 812        $group_ids = $user->get_groups(true);
 813        foreach ($group_ids as $group_id)
 814        {
 815            $right = $this->can_group_subscribe($group_id);
 816
 817            if ($right > $current_right)
 818                $current_right = $right;
 819        }
 820        return $current_right;
 821    }
 822
 823    function can_user_unsubscribe($user)
 824    {
 825        //TODO : remove 0 !!
 826        $current_right = $this->can_group_unsubscribe(0);
 827        $group_ids = $user->get_groups(true);
 828        foreach ($group_ids as $group_id)
 829        {
 830            $right = $this->can_group_unsubscribe($group_id);
 831
 832            if ($right > $current_right)
 833                $current_right = $right;
 834        }
 835        return $current_right;
 836    }
 837
 838    function can_group_subscribe($group_id)
 839    {
 840        $right = $this->get_rights()->can_group_subscribe($group_id);
 841        switch ($right)
 842        {
 843            case CourseGroupSubscribeRight :: SUBSCRIBE_DIRECT :
 844                if (!$this->get_direct_subscribe_available())
 845                    return CourseGroupSubscribeRight :: SUBSCRIBE_NONE;
 846                break;
 847            case CourseGroupSubscribeRight :: SUBSCRIBE_REQUEST :
 848                if (!$this->get_request_subscribe_available())
 849                    return CourseGroupSubscribeRight :: SUBSCRIBE_NONE;
 850                break;
 851            case CourseGroupSubscribeRight :: SUBSCRIBE_CODE :
 852                if (!$this->get_code_subscribe_available())
 853                    return CourseGroupSubscribeRight :: SUBSCRIBE_NONE;
 854                break;
 855            default :
 856                return CourseGroupSubscribeRight :: SUBSCRIBE_NONE;
 857        }
 858        return $right;
 859    }
 860
 861    function can_group_unsubscribe($group_id)
 862    {
 863        if ($this->get_unsubscribe_available())
 864            return $this->get_rights()->can_group_unsubscribe($group_id);
 865        else
 866            return 0;
 867    }
 868
 869    function get_code()
 870    {
 871        return $this->get_rights()->get_code();
 872    }
 873
 874    function get_direct_subscribe_available()
 875    {
 876        if (!$this->get_direct_subscribe_fixed())
 877            return $this->get_rights()->get_direct_subscribe_available();
 878        else
 879            return $this->get_course_type()->get_rights()->get_direct_subscribe_available();
 880    }
 881
 882    function get_request_subscribe_available()
 883    {
 884        if (!$this->get_request_subscribe_fixed())
 885            return $this->get_rights()->get_request_subscribe_available();
 886        else
 887            return $this->get_course_type()->get_rights()->get_request_subscribe_available();
 888    }
 889
 890    function get_code_subscribe_available()
 891    {
 892        if (!$this->get_code_subscribe_fixed())
 893            return $this->get_rights()->get_code_subscribe_available();
 894        else
 895            return $this->get_course_type()->get_rights()->get_code_subscribe_available();
 896    }
 897
 898    function get_unsubscribe_available()
 899    {
 900        if (!$this->get_unsubscribe_fixed())
 901            return $this->get_rights()->get_unsubscribe_available();
 902        else
 903            return $this->get_course_type()->get_rights()->get_unsubscribe_available();
 904    }
 905
 906    /**
 907     * Setters and validation to see whether they are writable
 908     */
 909    function set_code($code)
 910    {
 911        if ($this->get_code_subscribe_available())
 912            $this->get_rights()->set_code($code);
 913        else
 914            $this->get_rights()->set_code(null);
 915    }
 916
 917    function get_direct_subscribe_fixed()
 918    {
 919        if (!is_null($this->get_course_type()))
 920            return $this->get_course_type()->get_rights()->get_direct_subscribe_fixed();
 921        else
 922            return 0;
 923    }
 924
 925    function set_direct_subscribe_available($direct)
 926    {
 927        if (!$this->get_direct_subscribe_fixed())
 928            $this->get_rights()->set_direct_subscribe_available($direct);
 929        else
 930            $this->get_rights()->set_direct_subscribe_available($this->get_course_type()->get_rights()->get_direct_subscribe_available());
 931    }
 932
 933    function get_request_subscribe_fixed()
 934    {
 935        if (!is_null($this->get_course_type()))
 936            return $this->get_course_type()->get_rights()->get_request_subscribe_fixed();
 937        else
 938            return 0;
 939    }
 940
 941    function set_request_subscribe_available($request)
 942    {
 943        if (!$this->get_request_subscribe_fixed())
 944            $this->get_rights()->set_request_subscribe_available($request);
 945        else
 946            $this->get_rights()->set_request_subscribe_available($this->get_course_type()->get_rights()->get_request_subscribe_available());
 947    }
 948
 949    function get_code_subscribe_fixed()
 950    {
 951        if (!is_null($this->get_course_type()))
 952            return $this->get_course_type()->get_rights()->get_code_subscribe_fixed();
 953        else
 954            return 0;
 955    }
 956
 957    function set_code_subscribe_available($code)
 958    {
 959        if (!$this->get_code_subscribe_fixed())
 960            $this->get_rights()->set_code_subscribe_available($code);
 961        else
 962            $this->get_rights()->set_code_subscribe_available($this->get_course_type()->get_rights()->get_code_subscribe_available());
 963    }
 964
 965    function get_unsubscribe_fixed()
 966    {
 967        if (!is_null($this->get_course_type()))
 968            return $this->get_course_type()->get_rights()->get_unsubscribe_fixed();
 969        else
 970            return 0;
 971    }
 972
 973    function set_unsubscribe_available($code)
 974    {
 975        if (!$this->get_unsubscribe_fixed())
 976            $this->get_rights()->set_unsubscribe_available($code);
 977        else
 978            $this->get_rights()->set_unsubscribe_available($this->get_course_type()->get_rights()->get_unsubscribe_available());
 979    }
 980
 981    /**
 982     * Creates the course object in persistent storage
 983     * @return boolean
 984     */
 985    function create($automated_values = true, $create_in_batch = false)
 986    {
 987        if ($automated_values)
 988        {
 989            $now = time();
 990            $this->set_last_visit($now);
 991            $this->set_last_edit($now);
 992            $this->set_creation_date($now);
 993            $this->set_expiration_date($now);
 994        }
 995
 996        $wdm = WeblcmsDataManager :: get_instance();
 997
 998        if (!$wdm->create_course($this))
 999        {
1000            return false;
1001        }
1002
1003        $settings = $this->get_settings();
1004        $settings->set_course_id($this->get_id());
1005        if (!$settings->create())
1006        {
1007            return false;
1008        }
1009
1010        $layout = $this->get_layout_settings();
1011        $layout->set_course_id($this->get_id());
1012        if (!$layout->create())
1013        {
1014            return false;
1015        }
1016
1017        $rights = $this->get_rights();
1018        $rights->set_course_id($this->get_id());
1019        if (!$rights->create())
1020        {
1021            return false;
1022        }
1023
1024        if (!$this->initialize_course_sections())
1025        {
1026            return false;
1027        }
1028
1029        if (!$this->create_location($create_in_batch))
1030        {
1031            return false;
1032        }
1033
1034        if (!$this->tools)
1035        {
1036            $course_type_id = $this->get_course_type_id();
1037            if (!empty($course_type_id))
1038            {
1039                $this->tools = CourseModule :: convert_tools($this->get_course_type()->get_tools(), $this->get_id(), true);
1040            }
1041            else
1042            {
1043                $this->tools = CourseModule :: convert_tools(WeblcmsDataManager :: get_tools('basic'), $this->get_id());
1044            }
1045        }
1046        else
1047        {
1048            foreach ($this->tools as $tool)
1049            {
1050                $tool->set_course_code($this->get_id());
1051            }
1052        }
1053
1054        if (!$wdm->create_course_modules($this->tools, $this->get_id()))
1055        {
1056            return false;
1057        }
1058
1059        foreach ($this->tools as $tool)
1060        {
1061            if ($tool->get_name() == 'document')
1062            {
1063                require_once (dirname(__FILE__) . '/../category_manager/content_object_publication_category.class.php');
1064                $dropbox = new ContentObjectPublicationCategory();
1065                $dropbox->create_dropbox($this->get_id());
1066            }
1067        }
1068        
1069        if (!$this->create_root_course_group())
1070        {
1071            return false;
1072        }
1073
1074        //give everyone (subscribed in course) the view right
1075        if(!WeblcmsRights :: get_instance()->invert_location_entity_right(WeblcmsManager::APPLICATION_NAME,
1076                WeblcmsRights::VIEW_RIGHT, 0, 0,
1077                WeblcmsRights :: get_instance()->get_courses_subtree_root_id($this->get_id())))
1078        {
1079            return false;
1080        }
1081
1082        return true;
1083    }
1084
1085    function create_all()
1086    {
1087        return $this->create(false);
1088    }
1089
1090    function create_location($create_in_batch = false)
1091    {
1092        $parent_id = WeblcmsRights :: get_instance()->get_weblcms_location_id_by_identifier(WeblcmsRights :: TYPE_CATEGORY, $this->get_category());
1093        if (!$parent_id)
1094        {
1095            $parent_id = WeblcmsRights :: get_instance()->get_courses_subtree_root_id(0);
1096        }
1097
1098        $succes = WeblcmsRights :: get_instance()->create_location_in_courses_subtree(WeblcmsRights :: TYPE_COURSE,
1099		$this->get_id(), $parent_id, 0, $create_in_batch);
1100        if (!$succes)
1101        {
1102            return false;
1103        }
1104
1105        return WeblcmsRights::get_instance()-> create_subtree_root_location(
1106		$this->get_id(), WeblcmsRights :: TREE_TYPE_COURSE);
1107    }
1108
1109    function delete()
1110    {
1111        $location = WeblcmsRights :: get_instance()->get_courses_subtree_root($this->get_id());
1112        if ($location)
1113        {
1114            if (!$location->delete())
1115            {
1116                return false;
1117            }
1118        }
1119
1120        $dm = $this->get_data_manager();
1121        return $dm->delete_course($this->get_id());
1122    }
1123
1124    private $is_course_admin_cache;
1125    /**
1126     * Checks whether the given user is a course admin in this course
1127     * @param int $user_id
1128     * @return boolean
1129     */
1130    function is_course_admin($user)
1131    {
1132        if (is_null($this->is_course_admin_cache[$user->get_id()]))
1133        {
1134            $studentview = Session :: retrieve('studentview');
1135
1136            if ($studentview)
1137            {
1138                return false;
1139            }
1140
1141            if ($user->is_platform_admin())
1142            {
1143                return true;
1144            }
1145            $wdm = WeblcmsDataManager :: get_instance();
1146            if ($wdm->is_course_admin($this, $user->get_id()))
1147            {
1148                $this->is_course_admin_cache[$user->get_id()] = true;
1149            }
1150            else
1151                $this->is_course_admin_cache[$user->get_id()] = WeblcmsDataManager :: is_teacher_through_platform_groups($this, $user);
1152        }
1153        return $this->is_course_admin_cache[$user->get_id()];
1154    }
1155    
1156    private $course_admin_users_cache;
1157    private $course_admin_groups_cache;
1158    /**
1159     * Retrieves the course admins for this course
1160     * @return Array
1161     */
1162    function get_course_admin_users()
1163    {
1164        if(!$this->course_admin_users_cache)
1165        {
1166            $this->course_admin_users_cache = WeblcmsDataManager :: retrieve_course_admin_users($this->get_id());
1167        }
1168        return $this->course_admin_users_cache;
1169    }
1170    function get_course_admin_groups()
1171    {
1172        if(!$this->course_admin_groups_cache)
1173        {
1174            $this->course_admin_groups_cache = WeblcmsDataManager :: retrieve_course_admin_groups($this->get_id());
1175        }
1176        return $this->course_admin_groups_cache;
1177    }
1178
1179    /**
1180     * Determines if this course has a theme
1181     * @return boolean
1182     */
1183    function has_theme()
1184    {
1185        return (!is_null($this->get_layout()->get_theme()) ? true : false);
1186    }
1187
1188    function has_subscribed_users()
1189    {
1190        $relation_condition = new EqualityCondition(CourseUserRelation :: PROPERTY_COURSE, $this->get_id());
1191        return $this->get_data_manager()->count_course_user_relations($relation_condition);
1192    }
1193
1194    /**
1195     * Gets the subscribed users of this course
1196     * @return array An array of CourseUserRelation objects
1197     */
1198    function get_subscribed_users()
1199    {
1200        $relation_condition = new EqualityCondition(CourseUserRelation :: PROPERTY_COURSE, $this->get_id());
1201        return $this->get_data_manager()->retrieve_course_user_relations($relation_condition)->as_array();
1202    }
1203
1204    function has_subscribed_groups()
1205    {
1206        $relation_condition = new EqualityCondition(CourseGroupRelation :: PROPERTY_COURSE_ID, $this->get_id());
1207        return $this->get_data_manager()->count_course_group_relations($relation_condition);
1208    }
1209
1210    /**
1211     * Gets the subscribed groups of this course
1212     * @return array An array of CourseGroupRelation objects
1213     */
1214    function get_subscribed_groups()
1215    {
1216        $relation_condition = new EqualityCondition(CourseGroupRelation :: PROPERTY_COURSE_ID, $this->get_id());
1217        return $this->get_data_manager()->retrieve_course_group_relations($relation_condition)->as_array();
1218    }
1219
1220    /**
1221     * Gets the course_groups defined in this course
1222     * @return array An array of CourseGroup objects
1223     */
1224    function get_course_groups($as_array = true)
1225    {
1226        $wdm = WeblcmsDataManager :: get_instance();
1227        $condition = new EqualityCondition(CourseGroup :: PROPERTY_COURSE_CODE, $this->get_id());
1228        $result = $wdm->retrieve_course_groups($condition, null, null, array(new ObjectTableOrder(CourseGroup :: PROPERTY_NAME)));
1229        return ($as_array ? $result->as_array() : $result);
1230    }
1231
1232    static function get_table_name()
1233    {
1234        return Utilities :: get_classname_from_namespace(self :: CLASS_NAME, true);
1235    }
1236
1237    function initialize_course_sections()
1238    {
1239        $sections = array();
1240        $sections[] = array('name' => Translation :: get('SectionTools'), 'type' => 1, 'order' => 1);
1241        $sections[] = array('name' => Translation :: get('SectionLinks'), 'type' => 2, 'order' => 2);
1242        $sections[] = array('name' => Translation :: get('SectionDisabled'), 'type' => 0, 'order' => 3);
1243        $sections[] = array('name' => Translation :: get('SectionCourseAdministration'), 'type' => 3, 'order' => 4);
1244
1245        foreach ($sections as $section)
1246        {
1247            $course_section = new CourseSection();
1248            $course_section->set_course_code($this->get_id());
1249            $course_section->set_name($section['name']);
1250            $course_section->set_type($section['type']);
1251            $course_section->set_visible(true);
1252            if (!$course_section->create())
1253            {
1254                return false;
1255            }
1256        }
1257
1258        return true;
1259    }
1260
1261    function create_root_course_group()
1262    {
1263        $group = new CourseGroup();
1264        $group->set_course_code($this->get_id());
1265        $group->set_name($this->get_name());
1266        return $group->create();
1267    }
1268
1269    function update_by_course_type($course_type)
1270    {
1271        if (is_numeric($course_type))
1272            $course_type = $this->get_data_manager()->retrieve_course_type($course_type);
1273        $this->course_type = $course_type;
1274
1275        $this->set_course_type_id($course_type->get_id());
1276        if (!$this->update())
1277            return false;
1278
1279        $this->fill_settings($course_type);
1280        if (!$this->get_settings()->update())
1281            return false;
1282        $this->fill_layout_settings($course_type);
1283        if (!$this->get_layout_settings()->update())
1284            return false;
1285        $this->fill_rights($course_type);
1286        if (!$this->get_rights()->update())
1287            return false;
1288
1289        $selected_tools = $course_type->get_tools();
1290        $course_tools = $this->get_tools();
1291        $course_modules = array();
1292
1293        foreach ($selected_tools as $tool)
1294        {
1295            $sub_validation = false;
1296            foreach ($course_tools as $index => $course_tool)
1297            {
1298                if ($tool->get_name() == $course_tool->name)
1299                {
1300                    $sub_validation = true;
1301                    unset($course_tools[$index]);
1302                    break;
1303                }
1304            }
1305            if (!$sub_validation)
1306            {
1307                $course_module = new CourseModule();
1308                $course_module->set_course_code($this->get_id());
1309                $course_module->set_name($tool->get_name());
1310                $course_module->set_visible($tool->get_visible_default());
1311                $course_module->set_section("basic");
1312                $course_modules[] = $course_module;
1313            }
1314        }
1315
1316        foreach ($course_tools as $tool)
1317        {
1318            if (!$this->get_data_manager()->delete_course_module($tool->course_id, $tool->name))
1319                return false;
1320        }
1321
1322        if (!$this->get_data_manager()->create_course_modules($course_modules, $this->get_id()))
1323            return false;
1324
1325        for ($i = 0; $i < 4; $i++)
1326        {
1327            $method = null;
1328            $right = null;
1329            $course_type_rights = null;
1330            switch ($i)
1331            {
1332                case 0 :
1333                    $method = get_direct_subscribe_fixed;
1334                    $right = CourseGroupSubscribeRight :: SUBSCRIBE_DIRECT;
1335                    break;
1336                case 1 :
1337                    $method = get_request_subscribe_fixed;
1338                    $right = CourseGroupSubscribeRight :: SUBSCRIBE_REQUEST;
1339                    break;
1340                case 2 :
1341                    $method = get_code_subscribe_fixed;
1342                    $right = CourseGroupSubscribeRight :: SUBSCRIBE_CODE;
1343                    break;
1344                case 3 :
1345                    $method = get_unsubscribe_fixed;
1346                    $right = CourseGroupSubscribeRight :: UNSUBSCRIBE;
1347                    break;
1348            }
1349            if ($course_type->get_rights()->$method())
1350            {
1351                $course_type_rights = $this->get_data_manager()->retrieve_course_type_group_rights_by_type($course_type->get_id(), $right);
1352                $course_rights = $this->get_data_manager()->retrieve_course_group_rights_by_type($this->get_id(), $right)->as_array();
1353                $course_type_rights_to_add = array();
1354                while ($course_type_right = $course_type_rights->next_result())
1355                {
1356                    $validation = true;
1357                    foreach ($course_rights as $index => $right)
1358                    {
1359                        if ($right->get_group_id() == $course_type_right->get_group_id())
1360                        {
1361                            $validation = false;
1362                            unset($course_rights[$index]);
1363                        }
1364                    }
1365                    if ($validation)
1366                        $course_type_rights_to_add[] = $course_type_right;
1367                }
1368
1369                foreach ($course_type_rights_to_add as $course_type_right)
1370                {
1371                    if ($right != CourseGroupSubscribeRight :: UNSUBSCRIBE)
1372                    {
1373                        $course_right = CourseGroupSubscribeRight :: convert_course_type_right_to_course_right($course_type_right, $this->get_id());
1374                        $this->get_data_manager()->delete_course_group_subscribe_right($course_right);
1375                        $this->get_data_manager()->create_course_group_subscribe_right($course_right);
1376                    }
1377                    else
1378                        $this->get_data_manager()->create_course_group_unsubscribe_right(CourseGroupUnsubscribeRight :: convert_course_type_right_to_course_right($course_type_right, $this->get_id()));
1379                }
1380
1381                foreach ($course_rights as $right)
1382                {
1383                    if ($right != CourseGroupSubscribeRight :: UNSUBSCRIBE)
1384                        $this->get_data_manager()->delete_course_group_subscribe_right($right);
1385                    else
1386                        $this->get_data_manager()->delete_course_group_unsubscribe_right($right);
1387                }
1388            }
1389        }
1390
1391        return true;
1392    }
1393
1394    private function fill_settings($course_type)
1395    {
1396        if ($course_type->get_settings()->get_language_fixed())
1397            $this->get_settings()->set_language($course_type->get_settings()->get_language());
1398        if ($course_type->get_settings()->get_visibility_fixed())
1399            $this->get_settings()->set_visibility($course_type->get_settings()->get_visibility());
1400        if ($course_type->get_settings()->get_access_fixed())
1401            $this->get_settings()->set_access($course_type->get_settings()->get_access());
1402        if ($course_type->get_settings()->get_max_number_of_members_fixed())
1403            $this->get_settings()->set_max_number_of_members($course_type->get_settings()->get_max_number_of_members());
1404    }
1405
1406    private function fill_layout_settings($course_type)
1407    {
1408        if ($course_type->get_layout_settings()->get_intro_text_fixed())
1409            $this->get_layout_settings()->set_intro_text($course_type->get_layout_settings()->get_intro_text());
1410        if ($course_type->get_layout_settings()->get_student_view_fixed())
1411            $this->get_layout_settings()->set_student_view($course_type->get_layout_settings()->get_student_view());
1412        if ($course_type->get_layout_settings()->get_layout_fixed())
1413            $this->get_layout_settings()->set_layout($course_type->get_layout_settings()->get_layout());
1414        if ($course_type->get_layout_settings()->get_tool_shortcut_fixed())
1415            $this->get_layout_settings()->set_tool_shortcut($course_type->get_layout_settings()->get_tool_shortcut());
1416        if ($course_type->get_layout_settings()->get_menu_fixed())
1417            $this->get_layout_settings()->set_menu($course_type->get_layout_settings()->get_menu());
1418        if ($course_type->get_layout_settings()->get_breadcrumb_fixed())
1419            $this->get_layout_settings()->set_breadcrumb($course_type->get_layout_settings()->get_breadcrumb());
1420        if ($course_type->get_layout_settings()->get_feedback_fixed())
1421            $this->get_layout_settings()->set_feedback($course_type->get_layout_settings()->get_feedback());
1422        if ($course_type->get_layout_settings()->get_course_code_visible_fixed())
1423            $this->get_layout_settings()->set_course_code_visible($course_type->get_layout_settings()->get_course_code_visible());
1424        if ($course_type->get_layout_settings()->get_course_manager_name_visible_fixed())
1425            $this->get_layout_settings()->set_course_manager_name_visible($course_type->get_layout_settings()->get_course_manager_name_visible());
1426        if ($course_type->get_layout_settings()->get_course_languages_visible_fixed())
1427            $this->get_layout_settings()->set_course_languages_visible($course_type->get_layout_settings()->get_course_languages_visible());
1428    }
1429
1430    private function fill_rights($course_type)
1431    {
1432        if ($course_type->get_rights()->get_direct_subscribe_fixed())
1433            $this->get_rights()->set_direct_subscribe_available($course_type->get_rights()->get_direct_subscribe_available());
1434        if ($course_type->get_rights()->get_request_subscribe_fixed())
1435            $this->get_rights()->set_request_subscribe_available($course_type->get_rights()->get_request_subscribe_available());
1436        if ($course_type->get_rights()->get_code_subscribe_fixed())
1437            $this->get_rights()->set_code_subscribe_available($course_type->get_rights()->get_code_subscribe_available());
1438        if ($course_type->get_rights()->get_unsubscribe_fixed())
1439            $this->get_rights()->set_unsubscribe_available($course_type->get_rights()->get_unsubscribe_available());
1440    }
1441
1442    function update()
1443    {
1444        $course_group = $this->get_data_manager()->retrieve_course_group_root($this->get_id());
1445
1446        if($course_group)
1447        {
1448            if($course_group->get_name() != $this->get_name())
1449            {
1450                $course_group->set_name($this->get_name());
1451                $course_group->update();
1452            }
1453        }
1454        return parent :: update();
1455    }
1456    
1457    /**
1458     * Validates the url, URL beginning with / are internal URL's and considere…

Large files files are truncated, but you can click here to view the full file