Ejemplo n.º 1
0
 public function testWebResourceParameters()
 {
     include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
     $appender = new ilParameterAppender(999);
     $appender->setName('first');
     $appender->setValue(1);
     $appender->add(888);
     $params = ilParameterAppender::_getParams(888);
     foreach ($params as $key => $data) {
         $appender->delete($key);
         $this->assertEquals($data['name'], 'first');
         $this->assertEquals($data['value'], 1);
     }
 }
Ejemplo n.º 2
0
 public static function _append($a_link_data)
 {
     global $ilUser;
     if (!is_array($a_link_data)) {
         return false;
     }
     if (count($params = ilParameterAppender::_getParams($a_link_data['link_id']))) {
         // Check for prefix
         foreach ($params as $param_data) {
             if (!strpos($a_link_data['target'], '?')) {
                 $a_link_data['target'] .= "?";
             } else {
                 $a_link_data['target'] .= "&";
             }
             $a_link_data['target'] .= $param_data['name'] . "=";
             switch ($param_data['value']) {
                 case LINKS_LOGIN:
                     $a_link_data['target'] .= urlencode($ilUser->getLogin());
                     break;
                 case LINKS_SESSION_ID:
                     $a_link_data['target'] .= session_id();
                     break;
                 case LINKS_USER_ID:
                     $a_link_data['target'] .= $ilUser->getId();
                     break;
                 case LINKS_MATRICULATION:
                     $a_link_data['target'] .= $ilUser->getMatriculation();
                     break;
             }
         }
     }
     return $a_link_data;
 }
 /**
  * Parse Links
  * @return 
  */
 public function parse()
 {
     $rows = array();
     $items = $this->getWebResourceItems()->sortItems($this->getWebResourceItems()->getAllItems());
     foreach ($items as $link) {
         $tmp['id'] = $link['link_id'];
         $tmp['title'] = $link['title'];
         $tmp['description'] = $link['description'];
         $tmp['target'] = $link['target'];
         $tmp['link_id'] = $link['link_id'];
         $tmp['active'] = $link['active'];
         $tmp['disable_check'] = $link['disable_check'];
         $tmp['valid'] = $link['valid'];
         $tmp['last_check'] = $link['last_check'];
         $tmp['params'] = ilParameterAppender::_getParams($link['link_id']);
         $rows[] = $tmp;
     }
     $this->setData($rows);
 }
 /**
  * Show create/edit single link
  * @param int form mode
  * @return 
  */
 protected function initFormLink($a_mode)
 {
     global $ilTabs;
     $ilTabs->activateTab("id_content");
     include_once './Services/Form/classes/class.ilPropertyFormGUI.php';
     $this->form = new ilPropertyFormGUI();
     switch ($a_mode) {
         case self::LINK_MOD_CREATE:
             // Header
             $this->ctrl->setParameter($this, 'new_type', 'webr');
             $this->form->setTitle($this->lng->txt('webr_new_link'));
             $this->form->setTableWidth('600px');
             // Buttons
             $this->form->addCommandButton('save', $this->lng->txt('webr_add'));
             $this->form->addCommandButton('cancel', $this->lng->txt('cancel'));
             break;
         case self::LINK_MOD_ADD:
             // Header
             $this->form->setTitle($this->lng->txt('webr_new_link'));
             // Buttons
             $this->form->addCommandButton('saveAddLink', $this->lng->txt('webr_add'));
             $this->form->addCommandButton('view', $this->lng->txt('cancel'));
             break;
         case self::LINK_MOD_EDIT:
             // Header
             $this->ctrl->setParameter($this, 'link_id', (int) $_REQUEST['link_id']);
             $this->form->setTitle($this->lng->txt('webr_edit'));
             // Buttons
             $this->form->addCommandButton('updateLink', $this->lng->txt('save'));
             $this->form->addCommandButton('view', $this->lng->txt('cancel'));
             break;
     }
     $this->form->setFormAction($this->ctrl->getFormAction($this));
     if ($a_mode == self::LINK_MOD_ADD and $this->isContainerMetaDataRequired()) {
         ilUtil::sendInfo($this->lng->txt('webr_container_info'));
         $this->form->setTitle($this->lng->txt('webr_edit_list'));
         // List Title
         $title = new ilTextInputGUI($this->lng->txt('webr_list_title'), 'lti');
         $title->setRequired(true);
         $title->setSize(40);
         $title->setMaxLength(127);
         $this->form->addItem($title);
         // List Description
         $desc = new ilTextAreaInputGUI($this->lng->txt('webr_list_desc'), 'tde');
         $desc->setRows(3);
         $desc->setCols(40);
         $this->form->addItem($desc);
         // Addtional section
         $sect = new ilFormSectionHeaderGUI();
         $sect->setTitle($this->lng->txt('webr_add'));
         $this->form->addItem($sect);
     }
     // Target
     /*
     $tar = new ilTextInputGUI($this->lng->txt('webr_link_target'),'tar');
     $tar->setValue("http://");
     
     $tar->setSize(40);
     $tar->setMaxLength(500);
     */
     include_once 'Services/Form/classes/class.ilLinkInputGUI.php';
     $tar = new ilLinkInputGUI($this->lng->txt('webr_link_target'), 'tar');
     $tar->setInternalLinkFilterTypes(array("PageObject", "GlossaryItem", "RepositoryItem"));
     $tar->setRequired(true);
     $this->form->addItem($tar);
     // Title
     $tit = new ilTextInputGUI($this->lng->txt('webr_link_title'), 'tit');
     $tit->setRequired(true);
     $tit->setSize(40);
     $tit->setMaxLength(127);
     $this->form->addItem($tit);
     // Description
     $des = new ilTextAreaInputGUI($this->lng->txt('description'), 'des');
     $des->setRows(3);
     $des->setCols(40);
     $this->form->addItem($des);
     if ($a_mode != self::LINK_MOD_CREATE) {
         // Active
         $act = new ilCheckboxInputGUI($this->lng->txt('active'), 'act');
         $act->setChecked(true);
         $act->setValue(1);
         $this->form->addItem($act);
         // Check
         $che = new ilCheckboxInputGUI($this->lng->txt('webr_disable_check'), 'che');
         $che->setValue(1);
         $this->form->addItem($che);
     }
     // Valid
     if ($a_mode == self::LINK_MOD_EDIT) {
         $val = new ilCheckboxInputGUI($this->lng->txt('valid'), 'vali');
         $this->form->addItem($val);
     }
     if (ilParameterAppender::_isEnabled() && $a_mode != self::LINK_MOD_CREATE) {
         $dyn = new ilNonEditableValueGUI($this->lng->txt('links_dyn_parameter'));
         $dyn->setInfo($this->lng->txt('links_dynamic_info'));
         if (count($links = ilParameterAppender::_getParams((int) $_GET['link_id']))) {
             $ex = new ilCustomInputGUI($this->lng->txt('links_existing_params'), 'ex');
             $dyn->addSubItem($ex);
             foreach ($links as $id => $link) {
                 $p = new ilCustomInputGUI();
                 $ptpl = new ilTemplate('tpl.link_dyn_param_edit.html', true, true, 'Modules/WebResource');
                 $ptpl->setVariable('INFO_TXT', ilParameterAppender::parameterToInfo($link['name'], $link['value']));
                 $this->ctrl->setParameter($this, 'param_id', $id);
                 $ptpl->setVariable('LINK_DEL', $this->ctrl->getLinkTarget($this, 'deleteParameterForm'));
                 $ptpl->setVariable('LINK_TXT', $this->lng->txt('delete'));
                 $p->setHtml($ptpl->get());
                 $dyn->addSubItem($p);
             }
         }
         // Existing parameters
         // New parameter
         if ($a_mode != self::LINK_MOD_CREATE) {
             #$new = new ilCustomInputGUI($this->lng->txt('links_add_param'),'');
             #$dyn->addSubItem($new);
         }
         // Dynyamic name
         $nam = new ilTextInputGUI($this->lng->txt('links_name'), 'nam');
         $nam->setSize(12);
         $nam->setMaxLength(128);
         $dyn->addSubItem($nam);
         // Dynamic value
         $val = new ilSelectInputGUI($this->lng->txt('links_value'), 'val');
         $val->setOptions(ilParameterAppender::_getOptionSelect());
         $val->setValue(0);
         $dyn->addSubItem($val);
         $this->form->addItem($dyn);
     }
 }
 /**
  * Write link XML
  * @param ilXmlWriter $writer
  * @return 
  */
 public function toXML(ilXmlWriter $writer)
 {
     foreach (self::getAllItemIds($this->getLinkResourceId()) as $link_id) {
         $link = self::lookupItem($this->getLinkResourceId(), $link_id);
         $writer->xmlStartTag('WebLink', array('id' => $link['link_id'], 'active' => $link['active'] ? 1 : 0, 'valid' => $link['valid'] ? 1 : 0, 'disableValidation' => $link['disable_check'] ? 1 : 0));
         $writer->xmlElement('Title', array(), $link['title']);
         $writer->xmlElement('Description', array(), $link['description']);
         $writer->xmlElement('Target', array(), $link['target']);
         // Dynamic parameters
         include_once './Modules/WebResource/classes/class.ilParameterAppender.php';
         foreach (ilParameterAppender::_getParams($link_id) as $param_id => $param) {
             $value = '';
             switch ($param['value']) {
                 case LINKS_USER_ID:
                     $value = 'userId';
                     break;
                 case LINKS_LOGIN:
                     $value = 'userName';
                     break;
                 case LINKS_MATRICULATION:
                     $value = 'matriculation';
                     break;
             }
             if (!$value) {
                 // Fix for deprecated LINKS_SESSION
                 continue;
             }
             $writer->xmlElement('DynamicParameter', array('id' => $param_id, 'name' => $param['name'], 'type' => $value));
         }
         $writer->xmlEndTag('WebLink');
     }
     return true;
 }