/**
  * Finalizing output processing
  *
  * @param string $a_output
  * @return string
  */
 public function postOutputProcessing($a_output)
 {
     // You can use this to parse placeholders and the like before outputting
     // user view (IL_PAGE_PRESENTATION?)
     if ($this->getOutputMode() == IL_PAGE_PREVIEW) {
         include_once "Services/Form/classes/class.ilPropertyFormGUI.php";
         // :TODO: find a suitable presentation for matched placeholders
         $allp = ilDataCollectionRecordViewViewdefinition::getAvailablePlaceholders($this->table_id, true);
         foreach ($allp as $id => $item) {
             $parsed_item = new ilTextInputGUI("", "fields[" . $item->getId() . "]");
             $parsed_item = $parsed_item->getToolbarHTML();
             $a_output = str_replace($id, $item->getTitle() . ": " . $parsed_item, $a_output);
         }
     } else {
         if ($this->getOutputMode() == IL_PAGE_EDIT) {
             $allp = ilDataCollectionRecordViewViewdefinition::getAvailablePlaceholders($this->table_id);
             // :TODO: find a suitable markup for matched placeholders
             foreach ($allp as $item) {
                 $a_output = str_replace($item, "<span style=\"color:green\">" . $item . "</span>", $a_output);
             }
         }
     }
     return $a_output;
 }
コード例 #2
0
 /**
  * @param ilDataCollectionTable $table
  *
  * @return bool
  */
 public static function hasTableValidViewDefinition(ilDataCollectionTable $table)
 {
     $view = ilDataCollectionRecordViewViewdefinition::getInstanceByTableId($table->getId());
     return $view->getActive() and $view->getId() !== NULL;
 }
コード例 #3
0
 public function cloneStructure($original_id)
 {
     $original = ilDataCollectionCache::getTableCache($original_id);
     $this->setEditByOwner($original->getEditByOwner());
     $this->setAddPerm($original->getAddPerm());
     $this->setEditPerm($original->getEditPerm());
     $this->setDeletePerm($original->getDeletePerm());
     $this->setLimited($original->getLimited());
     $this->setLimitStart($original->getLimitStart());
     $this->setLimitEnd($original->getLimitEnd());
     $this->setTitle($original->getTitle());
     $this->doCreate();
     //clone fields.
     foreach ($original->getRecordFields() as $field) {
         $new_field = new ilDataCollectionField();
         $new_field->setTableId($this->getId());
         $new_field->cloneStructure($field->getId());
     }
     if ($old_view_id = ilDataCollectionRecordViewViewdefinition::getIdByTableId($original_id)) {
         $old_view = new ilDataCollectionRecordViewViewdefinition($old_view_id);
         $old_view->setTableId($original_id);
         $viewdef = new ilDataCollectionRecordViewViewdefinition();
         $viewdef->setTableId($this->id);
         $viewdef->setXMLContent($old_view->getXMLContent(false));
         $viewdef->create();
     }
 }
コード例 #4
0
 /**
  * @param ilDataCollectionTable $original
  */
 public function cloneStructure(ilDataCollectionTable $original)
 {
     $this->setTitle($original->getTitle());
     $this->setDescription($original->getDescription());
     $this->setIsVisible($original->getIsVisible());
     $this->setEditByOwner($original->getEditByOwner());
     $this->setAddPerm($original->getAddPerm());
     $this->setEditPerm($original->getEditPerm());
     $this->setDeletePerm($original->getDeletePerm());
     $this->setLimited($original->getLimited());
     $this->setLimitStart($original->getLimitStart());
     $this->setLimitEnd($original->getLimitEnd());
     $this->setViewOwnRecordsPerm($original->getViewOwnRecordsPerm());
     $this->setExportEnabled($original->getExportEnabled());
     $this->setPublicCommentsEnabled($original->getPublicCommentsEnabled());
     $this->setDefaultSortFieldOrder($original->getDefaultSortFieldOrder());
     $this->doCreate();
     // reset stdFields to get new for the created object
     $default_sort_field = 0;
     // Clone standard-fields
     $org_std_fields = $original->getStandardFields();
     foreach ($this->getStandardFields() as $element_key => $std_field) {
         $std_field->cloneStructure($org_std_fields[$element_key]);
         if ($std_field->getId() == $original->getDefaultSortField()) {
             $default_sort_field = $std_field->getId();
         }
     }
     // Clone fields
     $new_fields = array();
     foreach ($original->getFields() as $orig_field) {
         if (!$orig_field->isStandardField()) {
             $new_field = new ilDataCollectionField();
             $new_field->setTableId($this->getId());
             $new_field->cloneStructure($orig_field->getId());
             $new_fields[$orig_field->getId()] = $new_field;
             if ($orig_field->getId() == $original->getDefaultSortField()) {
                 $default_sort_field = $new_field->getId();
             }
         }
     }
     $this->setDefaultSortField($default_sort_field);
     $this->doUpdate();
     //TODO: Find better way to copy data (include referenced data)
     // Clone Records with recordfields
     /*foreach($original->getRecords() as $orig_record){
     			$new_record = new ilDataCollectionRecord();
     			$new_record->setTableId($this->getId());
     			$new_record->cloneStructure($orig_record->getId(), $new_fields);
     		}*/
     if ($old_view_id = ilDataCollectionRecordViewViewdefinition::getIdByTableId($original->getId())) {
         $old_view = new ilDataCollectionRecordViewViewdefinition($old_view_id);
         $old_view->setTableId($original->getId());
         $viewdef = new ilDataCollectionRecordViewViewdefinition();
         $viewdef->setTableId($this->id);
         $viewdef->setXMLContent($old_view->getXMLContent(false));
         $viewdef->create();
     }
 }
コード例 #5
0
 /**
  * function parses stored value in database to a html output for eg. the record list gui.
  *
  * @param                             $value
  * @param ilDataCollectionRecordField $record_field
  *
  * @return mixed
  */
 public function parseHTML($value, ilDataCollectionRecordField $record_field, $link = true)
 {
     global $ilAccess, $ilCtrl, $lng;
     switch ($this->id) {
         case self::INPUTFORMAT_DATETIME:
             $html = ilDatePresentation::formatDate(new ilDate($value, IL_CAL_DATETIME));
             break;
         case self::INPUTFORMAT_FILE:
             if (!ilObject2::_exists($value) || ilObject2::_lookupType($value, false) != "file") {
                 $html = "";
                 break;
             }
             $file_obj = new ilObjFile($value, false);
             $ilCtrl->setParameterByClass("ildatacollectionrecordlistgui", "record_id", $record_field->getRecord()->getId());
             $ilCtrl->setParameterByClass("ildatacollectionrecordlistgui", "field_id", $record_field->getField()->getId());
             $html = '<a href="' . $ilCtrl->getLinkTargetByClass("ildatacollectionrecordlistgui", "sendFile") . '">' . $file_obj->getFileName() . '</a>';
             if (ilPreview::hasPreview($file_obj->getId())) {
                 ilPreview::createPreview($file_obj);
                 // Create preview if not already existing
                 $preview = new ilPreviewGUI((int) $_GET['ref_id'], ilPreviewGUI::CONTEXT_REPOSITORY, $file_obj->getId(), $ilAccess);
                 $preview_status = ilPreview::lookupRenderStatus($file_obj->getId());
                 $preview_status_class = "";
                 $preview_text_topic = "preview_show";
                 if ($preview_status == ilPreview::RENDER_STATUS_NONE) {
                     $preview_status_class = "ilPreviewStatusNone";
                     $preview_text_topic = "preview_none";
                 }
                 $wrapper_html_id = 'record_field_' . $record_field->getId();
                 $script_preview_click = $preview->getJSCall($wrapper_html_id);
                 $preview_title = $lng->txt($preview_text_topic);
                 $preview_icon = ilUtil::getImagePath("preview.png", "Services/Preview");
                 $html = '<div id="' . $wrapper_html_id . '">' . $html;
                 $html .= '<span class="il_ContainerItemPreview ' . $preview_status_class . '"><a href="javascript:void(0);" onclick="' . $script_preview_click . '" title="' . $preview_title . '"><img src="' . $preview_icon . '" height="16" width="16"></a></span></div>';
             }
             break;
         case self::INPUTFORMAT_MOB:
             $mob = new ilObjMediaObject($value, false);
             $med = $mob->getMediaItem('Standard');
             if (!$med->location) {
                 $html = "";
                 break;
             }
             $arr_properties = $record_field->getField()->getProperties();
             $is_linked_field = $arr_properties[ilDataCollectionField::PROPERTYID_LINK_DETAIL_PAGE_MOB];
             $has_view = ilDataCollectionRecordViewViewdefinition::getIdByTableId($record_field->getRecord()->getTableId());
             if (in_array($med->getSuffix(), array('jpg', 'jpeg', 'png', 'gif'))) {
                 // Image
                 $dir = ilObjMediaObject::_getDirectory($mob->getId());
                 $width = (int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH];
                 $height = (int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT];
                 $html = ilUtil::img($dir . "/" . $med->location, '', $width, $height);
                 if ($is_linked_field and $has_view and $link) {
                     $ilCtrl->setParameterByClass('ildatacollectionrecordviewgui', 'record_id', $record_field->getRecord()->getId());
                     $html = '<a href="' . $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord') . '">' . $html . '</a>';
                 }
             } else {
                 // Video/Audio
                 $mpl = new ilMediaPlayerGUI($med->getId(), '');
                 $mpl->setFile(ilObjMediaObject::_getURL($mob->getId()) . "/" . $med->getLocation());
                 $mpl->setMimeType($med->getFormat());
                 $mpl->setDisplayWidth((int) $arr_properties[ilDataCollectionField::PROPERTYID_WIDTH] . 'px');
                 $mpl->setDisplayHeight((int) $arr_properties[ilDataCollectionField::PROPERTYID_HEIGHT] . 'px');
                 $mpl->setVideoPreviewPic($mob->getVideoPreviewPic());
                 $html = $mpl->getPreviewHtml();
                 if ($is_linked_field and $has_view) {
                     global $lng;
                     $ilCtrl->setParameterByClass('ildatacollectionrecordviewgui', 'record_id', $record_field->getRecord()->getId());
                     $html = $html . '<a href="' . $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord') . '">' . $lng->txt('details') . '</a>';
                 }
             }
             break;
         case self::INPUTFORMAT_BOOLEAN:
             switch ($value) {
                 case 0:
                     $im = ilUtil::getImagePath('icon_not_ok.svg');
                     break;
                 case 1:
                     $im = ilUtil::getImagePath('icon_ok.svg');
                     break;
             }
             $html = "<img src='" . $im . "'>";
             break;
         case ilDataCollectionDatatype::INPUTFORMAT_TEXT:
             //Property URL
             $arr_properties = $record_field->getField()->getProperties();
             if ($arr_properties[ilDataCollectionField::PROPERTYID_URL]) {
                 $link = $value;
                 if (preg_match("/^[a-z0-9!#\$%&'*+=?^_`{|}~-]+(?:\\.[a-z0-9!#\$%&'*+=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\$/i", $value)) {
                     $value = "mailto:" . $value;
                 } elseif (!preg_match('~(^(news|(ht|f)tp(s?)\\://){1}\\S+)~i', $value)) {
                     return $link;
                 }
                 $link = $this->shortenLink($link);
                 $html = "<a target='_blank' href='" . $value . "'>" . $link . "</a>";
             } elseif ($arr_properties[ilDataCollectionField::PROPERTYID_LINK_DETAIL_PAGE_TEXT] and $link and ilDataCollectionRecordViewViewdefinition::getIdByTableId($record_field->getRecord()->getTableId())) {
                 $ilCtrl->setParameterByClass('ildatacollectionrecordviewgui', 'record_id', $record_field->getRecord()->getId());
                 $html = '<a href="' . $ilCtrl->getLinkTargetByClass("ildatacollectionrecordviewgui", 'renderRecord') . '">' . $value . '</a>';
             } else {
                 $html = $value;
             }
             break;
         default:
             $html = $value;
             break;
     }
     return $html;
 }
コード例 #6
0
 /**
  * @param string          $a_entity
  * @param                 $a_types
  * @param array           $a_rec
  * @param ilImportMapping $a_mapping
  * @param string          $a_schema_version
  */
 public function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version)
 {
     switch ($a_entity) {
         case 'dcl':
             // Calling new_obj->create() will create the main table for us
             $new_obj = new ilObjDataCollection();
             $new_obj->setTitle($a_rec['title']);
             $new_obj->setDescription($a_rec['description']);
             $new_obj->setApproval($a_rec['approval']);
             $new_obj->setPublicNotes($a_rec['public_notes']);
             $new_obj->setNotification($a_rec['notification']);
             $new_obj->setPublicNotes($a_rec['public_notes']);
             $new_obj->setOnline(false);
             $new_obj->setRating($a_rec['rating']);
             $new_obj->create();
             $this->import_dc_object = $new_obj;
             $a_mapping->addMapping('Modules/DataCollection', 'dcl', $a_rec['id'], $new_obj->getId());
             break;
         case 'il_dcl_table':
             // If maintable, update. Other tables must be created as well
             $table = $this->count_imported_tables > 0 ? new ilDataCollectionTable() : ilDataCollectionCache::getTableCache($this->import_dc_object->getMainTableId());
             $table->setTitle($a_rec['title']);
             $table->setObjId($this->import_dc_object->getId());
             $table->setDescription($a_rec['description']);
             $table->setAddPerm($a_rec['add_perm']);
             $table->setEditPerm($a_rec['edit_perm']);
             $table->setDeletePerm($a_rec['delete_perm']);
             $table->setEditByOwner($a_rec['edit_by_owner']);
             $table->setLimited($a_rec['limited']);
             $table->setLimitStart($a_rec['limit_start']);
             $table->setLimitEnd($a_rec['limit_end']);
             $table->setIsVisible($a_rec['is_visible']);
             $table->setExportEnabled($a_rec['export_enabled']);
             $table->setDefaultSortField($a_rec['default_sort_field_id']);
             $table->setDefaultSortFieldOrder($a_rec['default_sort_field_order']);
             $table->setPublicCommentsEnabled($a_rec['public_comments']);
             $table->setViewOwnRecordsPerm($a_rec['view_own_records_perm']);
             if ($this->count_imported_tables > 0) {
                 $table->doCreate(false);
                 // false => Do not create views! They are imported later
             } else {
                 $table->doUpdate();
                 $this->count_imported_tables++;
                 // Delete views from maintable because we want to import them from the xml data
                 $set = $this->db->query('SELECT * FROM il_dcl_view WHERE table_id = ' . $this->db->quote($table->getId(), 'integer'));
                 $view_ids = array();
                 while ($row = $this->db->fetchObject($set)) {
                     $view_ids[] = $row->id;
                 }
                 if (count($view_ids)) {
                     $this->db->manipulate("DELETE FROM il_dcl_viewdefinition WHERE view_id IN (" . implode(',', $view_ids) . ")");
                 }
                 $this->db->manipulate("DELETE FROM il_dcl_view WHERE table_id = " . $this->db->quote($table->getId(), 'integer'));
             }
             $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['id'], $table->getId());
             break;
         case 'il_dcl_field':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 $field = new ilDataCollectionField();
                 $field->setTableId($new_table_id);
                 $field->setDatatypeId($a_rec['datatype_id']);
                 $field->setTitle($a_rec['title']);
                 $field->setDescription($a_rec['description']);
                 $field->setRequired($a_rec['required']);
                 $field->setUnique($a_rec['is_unique']);
                 $field->setLocked($a_rec['is_locked']);
                 $field->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['id'], $field->getId());
                 // Check if this field was used as default order by, if so, update to new id
                 $table = ilDataCollectionCache::getTableCache($new_table_id);
                 if ($table && $table->getDefaultSortField() == $a_rec['id']) {
                     $table->setDefaultSortField($field->getId());
                     $table->doUpdate();
                 }
             }
             break;
         case 'il_dcl_record':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 $record = new ilDataCollectionRecord();
                 $record->setTableId($new_table_id);
                 $datetime = new ilDateTime(time(), IL_CAL_UNIX);
                 $record->setCreateDate($datetime);
                 $record->setLastUpdate($datetime);
                 $record->setOwner($this->user->getId());
                 $record->setLastEditBy($this->user->getId());
                 $record->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['id'], $record->getId());
             }
             break;
         case 'il_dcl_view':
             $new_table_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_table', $a_rec['table_id']);
             if ($new_table_id) {
                 if ($a_rec['type'] == 0 && $a_rec['formtype'] == 0) {
                     // RecordViewViewDefinition: Create a new RecordViewViewdefinition. Note that the associated Page object is NOT created.
                     // Creation of the Page object is handled by the import of Services/COPage
                     $definition = new ilDataCollectionRecordViewViewdefinition();
                     $definition->setTableId($new_table_id);
                     $definition->create(true);
                     // DO not create DB entries for page object
                     // This mapping is needed for the import handled by Services/COPage
                     $a_mapping->addMapping('Services/COPage', 'pg', 'dclf:' . $a_rec['id'], 'dclf:' . $definition->getId());
                     $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $definition->getId());
                 } else {
                     // Other definitions - grab next ID from il_dcl_view
                     $view_id = $this->db->nextId("il_dcl_view");
                     $sql = "INSERT INTO il_dcl_view (id, table_id, type, formtype) VALUES (" . $this->db->quote($view_id, "integer") . ", " . $this->db->quote($new_table_id, "integer") . ", " . $this->db->quote($a_rec['type'], "integer") . ", " . $this->db->quote($a_rec['formtype'], "integer") . ")";
                     $this->db->manipulate($sql);
                     $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['id'], $view_id);
                 }
             }
             break;
         case 'il_dcl_viewdefinition':
             $new_view_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_view', $a_rec['view_id']);
             $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field']);
             $field = $new_field_id ? $new_field_id : $a_rec['field'];
             if ($new_view_id) {
                 $sql = 'INSERT INTO il_dcl_viewdefinition (view_id, field, field_order, is_set) VALUES (' . $this->db->quote($new_view_id, 'integer') . ', ' . $this->db->quote($field, 'text') . ', ' . $this->db->quote($a_rec['field_order'], 'integer') . ', ' . $this->db->quote($a_rec['is_set'], 'integer') . ')';
                 $this->db->manipulate($sql);
             }
             break;
         case 'il_dcl_field_prop':
             $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
             if ($new_field_id) {
                 $prop = new ilDataCollectionFieldProp();
                 $prop->setFieldId($new_field_id);
                 $prop->setDatatypePropertyId($a_rec['datatype_prop_id']);
                 // For field references, we need to get the new field id of the referenced field
                 // If the field_id does not yet exist (e.g. referenced table not yet created), store temp info and fix before finishing import
                 $value = $a_rec['value'];
                 $refs = array(ilDataCollectionField::PROPERTYID_REFERENCE, ilDataCollectionField::PROPERTYID_N_REFERENCE);
                 $fix_refs = false;
                 if (in_array($prop->getDatatypePropertyId(), $refs)) {
                     $new_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['value']);
                     if ($new_field_id === false) {
                         $value = NULL;
                         $fix_refs = true;
                     }
                 }
                 $prop->setValue($value);
                 $prop->doCreate();
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_field_prop', $a_rec['id'], $prop->getId());
                 if ($fix_refs) {
                     $this->import_temp_refs_props[$prop->getId()] = $a_rec['value'];
                 }
             }
             break;
         case 'il_dcl_record_field':
             $record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['record_id']);
             $field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_field', $a_rec['field_id']);
             if ($record_id && $field_id) {
                 $record = ilDataCollectionCache::getRecordCache($record_id);
                 $field = ilDataCollectionCache::getFieldCache($field_id);
                 $record_field = new ilDataCollectionRecordField($record, $field);
                 // Created in constructor if not existing
                 $a_mapping->addMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['id'], $record_field->getId());
                 $this->import_record_field_cache[$record_field->getId()] = $record_field;
             }
             break;
         case 'il_dcl_stloc1_value':
         case 'il_dcl_stloc2_value':
         case 'il_dcl_stloc3_value':
             $new_record_field_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record_field', $a_rec['record_field_id']);
             if ($new_record_field_id) {
                 /** @var ilDataCollectionRecordField $record_field */
                 $record_field = $this->import_record_field_cache[$new_record_field_id];
                 if (is_object($record_field)) {
                     // Need to rewrite internal references and lookup new objects if MOB or File
                     // For some fieldtypes it's better to reset the value, e.g. ILIAS_REF
                     switch ($record_field->getField()->getDatatypeId()) {
                         case ilDataCollectionDatatype::INPUTFORMAT_MOB:
                             // Check if we got a mapping from old object
                             $new_mob_id = $a_mapping->getMapping('Services/MediaObjects', 'mob', $a_rec['value']);
                             $value = $new_mob_id ? (int) $new_mob_id : NULL;
                             $this->import_temp_new_mob_ids[] = $new_mob_id;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_FILE:
                             $new_file_id = $a_mapping->getMapping('Modules/File', 'file', $a_rec['value']);
                             $value = $new_file_id ? (int) $new_file_id : NULL;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_REFERENCE:
                         case ilDataCollectioNDatatype::INPUTFORMAT_REFERENCELIST:
                             // If we are referencing to a record from a table that is not yet created, return value is always false because the record does exist neither
                             // Solution: Temporary store all references and fix them before finishing the import.
                             $new_record_id = $a_mapping->getMapping('Modules/DataCollection', 'il_dcl_record', $a_rec['value']);
                             if ($new_record_id === false) {
                                 $this->import_temp_refs[$new_record_field_id] = $a_rec['value'];
                             }
                             $value = $new_record_id ? (int) $new_record_id : NULL;
                             break;
                         case ilDataCollectionDatatype::INPUTFORMAT_ILIAS_REF:
                             $value = NULL;
                             break;
                         default:
                             $value = $a_rec['value'];
                             if ($a_entity == 'il_dcl_stloc3_value' && (is_null($value) || empty($value))) {
                                 $value = '0000-00-00 00:00:00';
                             }
                     }
                     $record_field->setValue($value, true);
                     $record_field->doUpdate();
                 }
             }
             break;
     }
 }
 /**
  * @param $record_obj ilDataCollectionRecord
  * @return int|NULL returns the id of the viewdefinition if one is declared and NULL otherwise
  */
 public static function _getViewDefinitionId($record_obj)
 {
     return ilDataCollectionRecordViewViewdefinition::getIdByTableId($record_obj->getTableId());
 }