Documentation

CCourse::Add

int
CCourse::Add(
 array arFields
);

The Add method adds a new course.

Parameters

ParameterDescription
arFields The array Array("field"=>"value", ...). Contains values of all the course fields. Required fields must be present.
Additionally, SITE_ID should contain an array of ID's of sites to which the course is to be bound.
You can assign access permissions to user groups to access the course by passing an array of mappings between the group ID's and the access permissions in the GROUP_ID field (see also CCourse::SetPermission).

Return Values

The method returns the ID of the added course on success, or false otherwise. If an error occurs, the exception will contain the error description.

See Also

  • CCourse::Update
  • Course fields

    Example

    
    <?
    
    if (CModule::IncludeModule("learning"))
    {
        $arFields = Array(
            "ACTIVE" => "Y",
            "NAME" => "My First Course",
            "SITE_ID" => Array("ru", "en"), //Sites
            "GROUP_ID" => Array("2" => "R"), //Permissions: Everyone can read my course
            "SORT" => "100",
            "DESCRIPTION" => "It's my first e-Learning course",
            "DESCRIPTION_TYPE" => "text",
        );
    
        $course = new CCourse;
        $ID = $course->Add($arFields);
        $success = ($ID>0);
    
        if($success)
        {
            echo "Ok!";
        }
        else
        {
            if($e = $APPLICATION->GetException())
                echo "Error: ".$e->GetString();
            
        }
    
    }
    ?>
  • © «Bitrix24», 2001-2024
    Up