/**
  * Parse template action from xml
  * @param ilDidacticTemplateSetting $set
  * @param SimpleXMLElement $root
  * @return void
  */
 protected function parseActions(ilDidacticTemplateSetting $set, SimpleXMLElement $actions = NULL)
 {
     include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php';
     if ($actions === NULL) {
         return void;
     }
     ////////////////////////////////////////////////
     // Local role action
     ///////////////////////////////////////////////
     foreach ($actions->localRoleAction as $ele) {
         include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalRoleAction.php';
         $act = new ilDidacticTemplateLocalRoleAction();
         $act->setTemplateId($set->getId());
         foreach ($ele->roleTemplate as $tpl) {
             // extract role
             foreach ($tpl->role as $roleDef) {
                 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
                 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
                 $role_id = $rimporter->importSimpleXml($roleDef);
                 $act->setRoleTemplateId($role_id);
             }
             $act->save();
         }
     }
     ////////////////////////////////////////////////
     // Block role action
     //////////////////////////////////////////////
     foreach ($actions->blockRoleAction as $ele) {
         include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateBlockRoleAction.php';
         $act = new ilDidacticTemplateBlockRoleAction();
         $act->setTemplateId($set->getId());
         // Role filter
         foreach ($ele->roleFilter as $rfi) {
             $act->setFilterType((string) $rfi->attributes()->source);
             foreach ($rfi->includePattern as $pat) {
                 // @TODO other subtypes
                 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
                 $pattern = new ilDidacticTemplateIncludeFilterPattern();
                 $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
                 $pattern->setPattern((string) $pat->attributes()->preg);
                 $act->addFilterPattern($pattern);
             }
             foreach ($rfi->excludePattern as $pat) {
                 // @TODO other subtypes
                 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
                 $pattern = new ilDidacticTemplateExcludeFilterPattern();
                 $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
                 $pattern->setPattern((string) $pat->attributes()->preg);
                 $act->addFilterPattern($pattern);
             }
         }
         $act->save();
     }
     ////////////////////////////////////////////
     // Local policy action
     /////////////////////////////////////////////
     foreach ($actions->localPolicyAction as $ele) {
         include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateLocalPolicyAction.php';
         $act = new ilDidacticTemplateLocalPolicyAction();
         $act->setTemplateId($set->getId());
         // Role filter
         foreach ($ele->roleFilter as $rfi) {
             $act->setFilterType((string) $rfi->attributes()->source);
             foreach ($rfi->includePattern as $pat) {
                 // @TODO other subtypes
                 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateIncludeFilterPattern.php';
                 $pattern = new ilDidacticTemplateIncludeFilterPattern();
                 $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
                 $pattern->setPattern((string) $pat->attributes()->preg);
                 $act->addFilterPattern($pattern);
             }
             foreach ($rfi->excludePattern as $pat) {
                 // @TODO other subtypes
                 include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateExcludeFilterPattern.php';
                 $pattern = new ilDidacticTemplateExcludeFilterPattern();
                 $pattern->setPatternSubType(ilDidacticTemplateFilterPattern::PATTERN_SUBTYPE_REGEX);
                 $pattern->setPattern((string) $pat->attributes()->preg);
                 $act->addFilterPattern($pattern);
             }
         }
         // role template assignment
         foreach ($ele->localPolicyTemplate as $lpo) {
             $act->setFilterType(ilDidacticTemplateLocalPolicyAction::FILTER_SOURCE_TITLE);
             switch ((string) $lpo->attributes()->type) {
                 case 'overwrite':
                     $act->setRoleTemplateType(ilDidacticTemplateLocalPolicyAction::TPL_ACTION_OVERWRITE);
                     break;
                 case 'union':
                     $act->setRoleTemplateType(ilDidacticTemplateLocalPolicyAction::TPL_ACTION_UNION);
                     break;
                 case 'intersect':
                     $act->setRoleTemplateType(ilDidacticTemplateLocalPolicyAction::TPL_ACTION_INTERSECT);
                     break;
             }
             // extract role
             foreach ($lpo->role as $roleDef) {
                 include_once './Services/AccessControl/classes/class.ilRoleXmlImporter.php';
                 $rimporter = new ilRoleXmlImporter(ROLE_FOLDER_ID);
                 $role_id = $rimporter->importSimpleXml($roleDef);
                 $act->setRoleTemplateId($role_id);
             }
         }
         // Save action including all filter patterns
         $act->save();
     }
 }
 protected function confirmTemplateSwitch()
 {
     global $ilCtrl, $ilTabs, $tpl;
     include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php';
     // Check if template is changed
     $new_tpl_id = (int) $_REQUEST['tplid'];
     if ($new_tpl_id == ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId())) {
         $GLOBALS['ilLog']->write(__METHOD__ . ': Template id: ' . $new_tpl_id);
         ilUtil::sendInfo($this->lng->txt('didactic_not_changed'), true);
         $ilCtrl->returnToParent($this);
     }
     $ilTabs->clearTargets();
     $ilTabs->clearSubTabs();
     include_once './Services/Utilities/classes/class.ilConfirmationGUI.php';
     $confirm = new ilConfirmationGUI();
     $confirm->setFormAction($ilCtrl->getFormAction($this));
     $confirm->setHeaderText($this->lng->txt('didactic_confirm_apply_new_template'));
     $confirm->setConfirm($this->lng->txt('apply'), 'switchTemplate');
     $confirm->setCancel($this->lng->txt('cancel'), 'cancel');
     if ($new_tpl_id) {
         include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateSetting.php';
         $dtpl = new ilDidacticTemplateSetting($new_tpl_id);
         $confirm->addItem('tplid', $new_tpl_id, $dtpl->getTitle() . '<div class="il_Description">' . $dtpl->getDescription() . ' ' . '</div>');
     } else {
         $confirm->addItem('tplid', $new_tpl_id, $this->lng->txt('default') . ' ' . '<div class="il_Description">' . sprintf($this->lng->txt('didactic_default_type_info'), $this->lng->txt('objs_' . $this->getParentObject()->object->getType())) . '</div>');
     }
     $tpl->setContent($confirm->getHTML());
 }
 /**
  * Activate didactic templates
  * @global ilErrorHandling $ilErr
  * @global ilCtrl $ilCtrl
  * @return void
  */
 protected function deactivateTemplates()
 {
     global $ilErr, $ilCtrl;
     if (!$_REQUEST['tpls']) {
         ilUtil::sendFailure($this->lng->txt('select_one'));
         return $ilCtrl->redirect($this, 'overview');
     }
     foreach ($_REQUEST['tpls'] as $tplid) {
         $tpl = new ilDidacticTemplateSetting($tplid);
         $tpl->enable(false);
         $tpl->update();
     }
     ilUtil::sendSuccess($this->lng->txt('didactic_deactivated_msg'), true);
     $ilCtrl->redirect($this, 'overview');
 }