コード例 #1
0
 /**
  * Render item
  */
 function render()
 {
     global $lng, $ilCtrl;
     // parse settings
     $has_int = $has_ext = $has_radio = false;
     switch ($this->getAllowedLinkTypes()) {
         case self::EXT:
             $has_ext = true;
             break;
         case self::INT:
             $has_int = true;
             break;
         case self::BOTH:
             $has_int = true;
             $has_ext = true;
             $has_radio = true;
             break;
     }
     // external
     if ($has_ext) {
         $title = $has_radio ? $lng->txt("url") : "";
         // external
         $ti = new ilTextInputGUI($title, $this->getPostVar());
         $ti->setMaxLength(200);
         $ti->setSize(50);
     }
     // internal
     if ($has_int) {
         $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", $this->getPostVar());
         $link = array(get_class($this->getParent()), "ilformpropertydispatchgui", get_class($this), "ilinternallinkgui");
         $link = $ilCtrl->getLinkTargetByClass($link, "", false, true, false);
         $ilCtrl->setParameterByClass("ilformpropertydispatchgui", "postvar", "");
         $no_disp_class = strpos($this->getValue(), "|") ? "" : " ilNoDisplay";
         $itpl = new ilTemplate('tpl.prop_link.html', true, true, 'Services/Form');
         $itpl->setVariable("VAL_ID", $this->getPostVar());
         $itpl->setVariable("URL_EDIT", $link);
         $itpl->setVariable("TXT_EDIT", $lng->txt("form_get_link"));
         $itpl->setVariable("CSS_REMOVE", $no_disp_class);
         $itpl->setVariable("TXT_REMOVE", $lng->txt("remove"));
         $ne = new ilNonEditableValueGUI($lng->txt("object"), $this->getPostVar() . "_val", true);
         // hidden field for selected value
         $hidden_type = new ilHiddenInputGUI($this->getPostVar() . "_ajax_type");
         $hidden_id = new ilHiddenInputGUI($this->getPostVar() . "_ajax_id");
         $hidden_target = new ilHiddenInputGUI($this->getPostVar() . "_ajax_target");
     }
     // mode
     if ($has_radio) {
         $ext = new ilRadioOption($lng->txt("form_link_external"), "ext");
         $ext->addSubItem($ti);
         $int = new ilRadioOption($lng->txt("form_link_internal"), "int");
         $int->addSubItem($ne);
         $mode = new ilRadioGroupInputGUI("", $this->getPostVar() . "_mode");
         $mode->addOption($ext);
         $mode->addOption($int);
     } else {
         $mode = new ilHiddenInputGUI($this->getPostVar() . "_mode");
         if ($has_int) {
             $mode->setValue("int");
         } else {
             $mode->setValue("ext");
         }
     }
     // value
     $value = $this->getValue();
     if ($value) {
         if ($has_int && strpos($value, "|")) {
             $mode->setValue("int");
             $value_trans = self::getTranslatedValue($value);
             $value = explode("|", $value);
             $hidden_type->setValue($value[0]);
             $hidden_id->setValue($value[1]);
             $hidden_target->setValue($value[2]);
             $itpl->setVariable("VAL_OBJECT_TYPE", $value_trans["type"]);
             $itpl->setVariable("VAL_OBJECT_NAME", $value_trans["name"]);
         } else {
             if ($has_ext) {
                 $mode->setValue("ext");
                 $ti->setValue($value);
             }
         }
     }
     // #10185 - default for external urls
     if ($has_ext && !$ti->getValue()) {
         $ti->setValue("http://");
     }
     $ne->setValue($itpl->get());
     // to html
     if ($has_radio) {
         $html = $mode->render();
     } else {
         $html = $mode->getToolbarHTML();
         if ($has_ext) {
             $html .= $ti->getToolbarHTML();
         } else {
             $html .= $ne->render() . '<div class="help-block">' . $ne->getInfo() . '</div>';
         }
     }
     // js for internal link
     if ($has_int) {
         include_once "./Services/Link/classes/class.ilInternalLinkGUI.php";
         $html .= $hidden_type->getToolbarHTML() . $hidden_id->getToolbarHTML() . $hidden_target->getToolbarHTML();
     }
     return $html;
 }