/**
  * Constructor
  * @access public
  */
 function ilObjMediaCastGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output = true)
 {
     global $ilCtrl, $lng;
     $this->type = "mcst";
     $this->ilObjectGUI($a_data, $a_id, $a_call_by_reference, $a_prepare_output);
     $lng->loadLanguageModule("mcst");
     $lng->loadLanguageModule("news");
     $ilCtrl->saveParameter($this, "item_id");
     include_once "./Modules/MediaCast/classes/class.ilMediaCastSettings.php";
     $settings = ilMediaCastSettings::_getInstance();
     $this->purposeSuffixes = $settings->getPurposeSuffixes();
     $this->mimeTypes = array();
     $mime_types = $settings->getMimeTypes();
     foreach ($mime_types as $mt) {
         $this->mimeTypes[$mt] = $mt;
     }
     include_once "./Services/Utilities/classes/class.ilMimeTypeUtil.php";
     foreach (ilMimeTypeUtil::getExt2MimeMap() as $mt) {
         $this->mimeTypes[$mt] = $mt;
     }
     asort($this->mimeTypes);
 }
 /**
  * iniitialize settings storage for media cast
  *
  */
 protected function initMediaCastSettings()
 {
     include_once 'Modules/MediaCast/classes/class.ilMediaCastSettings.php';
     $this->settings = ilMediaCastSettings::_getInstance();
 }
 /**
  * Handle the event
  *
  * @param    string        component, e.g. "Services/User"
  * @param    event         event, e.g. "afterUpdate"
  * @param    array         array of event specific parameters
  */
 public function handleEvent($a_component, $a_event, $a_parameter)
 {
     // Adds access rights for standard participants to courses
     // Only needed for Soziale Arbeit
     // create course part of code
     if ($a_component == 'Modules/Course' && $a_event == 'create') {
         $crs = $a_parameter['object'];
         //activation unlimited, not offline
         $crs->setActivationType(IL_CRS_ACTIVATION_UNLIMITED);
         $crs->setOfflineStatus(false);
         global $affected_crs;
         $affected_crs = $a_parameter['obj_id'];
     }
     // Adds access rights for standard participants to courses
     // Only needed for Soziale Arbeit
     // update course part of code
     if ($a_component == 'Modules/Course' && $a_event == 'update') {
         global $tree, $rbacreview, $rbacadmin, $affected_crs;
         $crs = $a_parameter['object'];
         $ref_id = $crs->getRefId();
         //check if new Course is in "Soziale Arbeit -> Bachelor"
         if ($affected_crs == $a_parameter['obj_id'] && in_array(4781, $obj_path = $tree->getPathId($ref_id))) {
             //Get the current access rights on the course
             $user_role = $this->_getGlobalUserRoleId();
             $local_ops = $rbacreview->getRoleOperationsOnObject($user_role, $ref_id);
             $local_ops = array_map('strval', $local_ops);
             //Get the access rights of the standard course user and remove rights that the standard user doesn't have
             $non_member_template_id = $this->__getCrsNonMemberTemplateId();
             $template_ops = $rbacreview->getOperationsOfRole($non_member_template_id, 'crs', ROLE_FOLDER_ID);
             $role_folders = array_intersect($obj_path, $rbacreview->getFoldersAssignedToRole($user_role));
             end($role_folders);
             $parent_role_folder = prev($role_folders);
             $parent_ops = $this->__getTemplatePolicies($user_role, $parent_role_folder, 'crs');
             $template_ops = $this->__intersectPolicies($template_ops, $parent_ops);
             //Get the local and the next higher policies
             $local_policies = $this->__getTemplatePolicies($user_role, $ref_id);
             $parent_policies = $this->__getTemplatePolicies($user_role, $parent_role_folder);
             $non_member_policies = $this->__getTemplatePolicies($non_member_template_id, '');
             $non_member_policies = array_values($this->__intersectPolicies($non_member_policies, $parent_policies));
             if ($local_ops == $template_ops && $local_policies == $non_member_policies) {
                 $rbacadmin->copyRoleTemplatePermissions($user_role, $parent_role_folder, $ref_id, $user_role);
                 $local_policies = $this->__getTemplatePolicies($user_role, $ref_id, 'crs');
                 $rbacadmin->grantPermission($user_role, $local_policies, $ref_id);
             }
         }
     }
     // FFMPEG Conversion of media files
     if ($a_component == 'Services/MediaObjects' && $a_event == 'update' && isset($a_parameter) && count($a_parameter) > 0 && isset($a_parameter['object'])) {
         $allMediaItems = $a_parameter['object']->getMediaItems();
         $ffmpegQueue = 'ffmpegQueue.txt';
         foreach ($allMediaItems as $media_item) {
             $filename = $media_item->location;
             include_once "./Modules/MediaCast/classes/class.ilMediaCastSettings.php";
             $settings = ilMediaCastSettings::_getInstance();
             $purposeSuffixes = $settings->getPurposeSuffixes();
             if (in_array(mb_strtolower(substr($filename, strrpos($filename, '.') + 1)), $purposeSuffixes['VideoPortable'])) {
                 global $ilUser;
                 $folder = ilObjMediaObject::_getDirectory($a_parameter['object']->getId());
                 if (substr($filename, -3) != 'mp4') {
                     $numofLines = ilHSLUObjectDefaultsPlugin::lineCount($ffmpegQueue);
                     ilUtil::sendSuccess('Ihre Datei wurde hochgeladen und wird nun in ein Streaming-kompatibles Format konvertiert. Sie werden via Mail informiert, sobald die Konvertierung abgeschlossen ist. Vor der aktuell hochgeladenen Datei hat es ' . $numofLines . ' andere in der Warteschlange. Besten Dank für Ihre Geduld.', true);
                 }
                 file_put_contents($ffmpegQueue, $folder . '/' . $filename . '|' . $folder . '/' . substr($filename, 0, strrpos($filename, '.')) . '.mp4|' . $ilUser->getEmail() . "\n", FILE_APPEND);
                 //geht nicht wegen client cache
                 //@copy('Customizing/mob_vpreview.png', $folder.'/mob_vpreview.png');
                 @chmod($folder, 0775);
                 //set new media format
                 $media_item->setFormat('video/mp4');
                 $media_item->setLocation(substr($filename, 0, strrpos($filename, '.')) . '.mp4');
                 $media_item->update();
             } else {
                 if (in_array(mb_strtolower(substr($filename, strrpos($filename, '.') + 1)), $purposeSuffixes['AudioPortable']) && substr($filename, -3) != 'mp3') {
                     global $ilUser;
                     $folder = ilObjMediaObject::_getDirectory($a_parameter['object']->getId());
                     $numofLines = ilHSLUObjectDefaultsPlugin::lineCount($ffmpegQueue);
                     ilUtil::sendSuccess('Ihre Datei wurde hochgeladen und wird nun in ein Streaming-kompatibles Format konvertiert. Sie werden via Mail informiert, sobald die Konvertierung abgeschlossen ist. Vor der aktuell hochgeladenen Datei hat es ' . $numofLines . ' andere in der Warteschlange. Besten Dank für Ihre Geduld.', true);
                     file_put_contents($ffmpegQueue, $folder . '/' . $filename . '|' . $folder . '/' . substr($filename, 0, strrpos($filename, '.')) . '.mp3|' . $ilUser->getEmail() . "\n", FILE_APPEND);
                     //geht nicht wegen client cache
                     //@copy('Customizing/mob_vpreview.png', $folder.'/mob_vpreview.png');
                     @chmod($folder, 0775);
                     //set new media format
                     $media_item->setFormat('audio/mpeg');
                     $media_item->setLocation(substr($filename, 0, strrpos($filename, '.')) . '.mp3');
                     $media_item->update();
                 }
             }
         }
     }
 }