/** * Start copy * * @return int new template id */ public function start() { $orig = new ilDidacticTemplateSetting($this->getTemplateId()); $copy = clone $orig; $copy->save(); $this->new_tpl_id = $copy->getId(); include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php'; foreach (ilDidacticTemplateActionFactory::getActionsByTemplateId($this->getTemplateId()) as $action) { $action->setTemplateId($this->getNewTemplateId()); $new = clone $action; $new->save(); } }
/** * Apply template * @param int $a_tpl_id */ public function applyDidacticTemplate($a_tpl_id) { if (!$a_tpl_id) { return true; } include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php'; ilDidacticTemplateObjSettings::assignTemplate($this->getRefId(), $this->getId(), (int) $a_tpl_id); include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php'; foreach (ilDidacticTemplateActionFactory::getActionsByTemplateId($a_tpl_id) as $action) { $action->setRefId($this->getRefId()); $action->apply(); } }
/** * Switch Template */ protected function switchTemplate() { global $ilCtrl; $new_tpl_id = (int) $_REQUEST['tplid']; include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateObjSettings.php'; $current_tpl_id = ilDidacticTemplateObjSettings::lookupTemplateId($this->getParentObject()->object->getRefId()); // Revert current template if ($current_tpl_id) { include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php'; foreach (ilDidacticTemplateActionFactory::getActionsByTemplateId($current_tpl_id) as $action) { $action->setRefId($this->getParentObject()->object->getRefId()); $action->revert(); } } if ($new_tpl_id) { include_once './Services/DidacticTemplate/classes/class.ilDidacticTemplateActionFactory.php'; foreach (ilDidacticTemplateActionFactory::getActionsByTemplateId($new_tpl_id) as $action) { $action->setRefId($this->getParentObject()->object->getRefId()); $action->apply(); } } // Assign template id to object ilDidacticTemplateObjSettings::assignTemplate($this->getParentObject()->object->getRefId(), $this->getParentObject()->object->getId(), $new_tpl_id); ilUtil::sendSuccess($this->lng->txt('didactic_template_applied'), true); $ilCtrl->returnToParent($this); }