static function sendNotification($a_action, $a_type, $a_wiki_ref_id, $a_page_id, $a_comment = null) { global $ilUser, $ilObjDataCache, $ilAccess; include_once "./Services/Notification/classes/class.ilNotification.php"; include_once "./Modules/Wiki/classes/class.ilObjWiki.php"; include_once "./Modules/Wiki/classes/class.ilWikiPage.php"; $wiki_id = $ilObjDataCache->lookupObjId($a_wiki_ref_id); $wiki = new ilObjWiki($a_wiki_ref_id, true); $page = new ilWikiPage($a_page_id); // #11138 $ignore_threshold = $a_action == "comment"; // 1st update will be converted to new - see below if ($a_action == "new") { return; } if ($a_type == ilNotification::TYPE_WIKI_PAGE) { $users = ilNotification::getNotificationsForObject($a_type, $a_page_id, null, $ignore_threshold); $wiki_users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold); $users = array_merge($users, $wiki_users); if (!sizeof($users)) { return; } ilNotification::updateNotificationTime(ilNotification::TYPE_WIKI_PAGE, $a_page_id, $users); } else { $users = ilNotification::getNotificationsForObject(ilNotification::TYPE_WIKI, $wiki_id, $a_page_id, $ignore_threshold); if (!sizeof($users)) { return; } } ilNotification::updateNotificationTime(ilNotification::TYPE_WIKI, $wiki_id, $users, $a_page_id); // #15192 - should always be present if ($a_page_id) { include_once "./Modules/Wiki/classes/class.ilObjWikiGUI.php"; $link = ILIAS_HTTP_PATH . "/" . ilObjWikiGui::getGotoLink($a_wiki_ref_id, $page->getTitle()); } else { include_once "./Services/Link/classes/class.ilLink.php"; $link = ilLink::_getLink($a_wiki_ref_id); } include_once "./Services/Mail/classes/class.ilMail.php"; include_once "./Services/User/classes/class.ilObjUser.php"; include_once "./Services/Language/classes/class.ilLanguageFactory.php"; include_once "./Services/User/classes/class.ilUserUtil.php"; // see ilBlogPostingGUI::getSnippet() // see ilBlogPosting::getNotificationAbstract() include_once "Modules/Wiki/classes/class.ilWikiPageGUI.php"; $pgui = new ilWikiPageGUI($page->getId()); $pgui->setRawPageContent(true); $pgui->setAbstractOnly(true); $pgui->setFileDownloadLink("."); $pgui->setFullscreenLink("."); $pgui->setSourcecodeDownloadScript("."); $snippet = $pgui->showPage(); $snippet = ilPageObject::truncateHTML($snippet, 500, "..."); // making things more readable $snippet = str_replace('<br/>', "\n", $snippet); $snippet = str_replace('<br />', "\n", $snippet); $snippet = str_replace('</p>', "\n", $snippet); $snippet = str_replace('</div>', "\n", $snippet); $snippet = trim(strip_tags($snippet)); // "fake" new (to enable snippet - if any) $current_version = array_shift($page->getHistoryEntries()); $current_version = $current_version["nr"]; if (!$current_version) { $a_type = ilNotification::TYPE_WIKI; $a_action = "new"; } foreach (array_unique($users) as $idx => $user_id) { if ($user_id != $ilUser->getId() && $ilAccess->checkAccessOfUser($user_id, 'read', '', $a_wiki_ref_id)) { // use language of recipient to compose message $ulng = ilLanguageFactory::_getLanguageOfUser($user_id); $ulng->loadLanguageModule('wiki'); $subject = sprintf($ulng->txt('wiki_change_notification_subject'), $wiki->getTitle(), $page->getTitle()); $message = sprintf($ulng->txt('wiki_change_notification_salutation'), ilObjUser::_lookupFullname($user_id)) . "\n\n"; if ($a_type == ilNotification::TYPE_WIKI_PAGE) { // update/delete $message .= $ulng->txt('wiki_change_notification_page_body_' . $a_action) . ":\n\n"; $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n"; $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n"; $message .= $ulng->txt('wiki_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n"; if ($snippet) { $message .= "\n" . $ulng->txt('content') . "\n" . "----------------------------------------\n" . $snippet . "\n" . "----------------------------------------\n"; } // include comment/note text if ($a_comment) { $message .= "\n" . $ulng->txt('comment') . ":\n\"" . trim($a_comment) . "\"\n"; } $message .= "\n" . $ulng->txt('wiki_change_notification_page_link') . ": " . $link; } else { // new $message .= $ulng->txt('wiki_change_notification_body_' . $a_action) . ":\n\n"; $message .= $ulng->txt('wiki') . ": " . $wiki->getTitle() . "\n"; $message .= $ulng->txt('page') . ": " . $page->getTitle() . "\n"; $message .= $ulng->txt('wiki_changed_by') . ": " . ilUserUtil::getNamePresentation($ilUser->getId()) . "\n\n"; if ($snippet) { $message .= $ulng->txt('content') . "\n" . "----------------------------------------\n" . $snippet . "\n" . "----------------------------------------\n\n"; } $message .= $ulng->txt('wiki_change_notification_link') . ": " . $link; } $mail_obj = new ilMail(ANONYMOUS_USER_ID); $mail_obj->appendInstallationSignature(true); $mail_obj->sendMail(ilObjUser::_lookupLogin($user_id), "", "", $subject, $message, array(), array("system")); } else { unset($users[$idx]); } } }
/** * Handle wiki page rating * * @param ilWikiPage $a_page_obj * @param int $a_user_id */ public static function handlePageRating(ilWikiPage $a_page_obj, $a_user_id) { // do page first! $rating = self::getAverageRating($a_page_obj->getWikiId(), $a_page_obj->getId()); // wiki_stat_page: num_ratings, avg_rating self::writeStatPage($a_page_obj->getWikiId(), $a_page_obj->getId(), array("num_ratings" => array("integer", $rating["cnt"]), "avg_rating" => array("integer", $rating["avg"] * 100))); $rating = self::getAverageRating($a_page_obj->getWikiId()); // wiki_stat: avg_rating $is_update = self::writeStat($a_page_obj->getWikiId(), array("avg_rating" => array("integer", $rating["avg"] * 100))); if (!$is_update) { // wiki: num_pages (count) self::writeStat($a_page_obj->getWikiId(), array("num_pages" => array("integer", self::countPages($a_page_obj->getWikiId())))); } }
/** * Standard Version of Fill Row. Most likely to * be overwritten by derived class. */ protected function fillRow($a_set) { global $lng, $ilCtrl, $ilAccess; $usage = $a_set; if (is_int(strpos($usage["type"], ":"))) { $us_arr = explode(":", $usage["type"]); $usage["type"] = $us_arr[1]; $cont_type = $us_arr[0]; } include_once './Services/Link/classes/class.ilLink.php'; switch ($usage["type"]) { case "pg": $item = array(); //$this->tpl->setVariable("TXT_OBJECT", $usage["type"].":".$usage["id"]); switch ($cont_type) { case "sahs": require_once "./Modules/Scorm2004/classes/class.ilSCORM2004Page.php"; $page_obj = new ilSCORM2004Page($usage["id"]); require_once "./Modules/ScormAicc/classes/class.ilObjSAHSLearningModule.php"; require_once "./Modules/Scorm2004/classes/class.ilSCORM2004PageNode.php"; $lm_obj = new ilObjSAHSLearningModule($page_obj->getParentId(), false); $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type); $item["obj_title"] = $lm_obj->getTitle(); $item["sub_txt"] = $this->lng->txt("pg"); $item["sub_title"] = ilSCORM2004PageNode::_lookupTitle($page_obj->getId()); $ref_id = $this->getFirstWritableRefId($lm_obj->getId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "sahs"); } break; case "lm": require_once "./Modules/LearningModule/classes/class.ilLMPage.php"; $page_obj = new ilLMPage($usage["id"]); require_once "./Modules/LearningModule/classes/class.ilObjContentObject.php"; require_once "./Modules/LearningModule/classes/class.ilObjLearningModule.php"; require_once "./Modules/LearningModule/classes/class.ilLMObject.php"; $lm_obj =& new ilObjLearningModule($page_obj->getParentId(), false); $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type); $item["obj_title"] = $lm_obj->getTitle(); $item["sub_txt"] = $this->lng->txt("pg"); $item["sub_title"] = ilLMObject::_lookupTitle($page_obj->getId()); $ref_id = $this->getFirstWritableRefId($lm_obj->getId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "lm"); } break; case "wpg": require_once "./Modules/Wiki/classes/class.ilWikiPage.php"; $page_obj = new ilWikiPage($usage["id"]); $item["obj_type_txt"] = $this->lng->txt("obj_wiki"); $item["obj_title"] = ilObject::_lookupTitle($page_obj->getParentId()); $item["sub_txt"] = $this->lng->txt("pg"); $item["sub_title"] = ilWikiPage::lookupTitle($page_obj->getId()); $ref_id = $this->getFirstWritableRefId($page_obj->getParentId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "wiki"); } break; case "gdf": require_once "./Modules/Glossary/classes/class.ilGlossaryDefPage.php"; $page_obj = new ilGlossaryDefPage($usage["id"]); require_once "./Modules/Glossary/classes/class.ilGlossaryTerm.php"; require_once "./Modules/Glossary/classes/class.ilGlossaryDefinition.php"; $term_id = ilGlossaryDefinition::_lookupTermId($page_obj->getId()); $glo_id = ilGlossaryTerm::_lookGlossaryId($term_id); $item["obj_type_txt"] = $this->lng->txt("obj_glo"); $item["obj_title"] = ilObject::_lookupTitle($glo_id); $item["sub_txt"] = $this->lng->txt("cont_term"); $item["sub_title"] = ilGlossaryTerm::_lookGlossaryTerm($term_id); $ref_id = $this->getFirstWritableRefId($page_obj->getParentId()); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "glo"); } break; case "fold": case "root": case "crs": case "grp": case "cat": $item["obj_type_txt"] = $this->lng->txt("obj_" . $cont_type); $item["obj_title"] = ilObject::_lookupTitle($usage["id"]); $ref_id = $this->getFirstWritableRefId($usage["id"]); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, $cont_type); } break; } break; case "mep": $item["obj_type_txt"] = $this->lng->txt("obj_mep"); $item["obj_title"] = ilObject::_lookupTitle($usage["id"]); $ref_id = $this->getFirstWritableRefId($usage["id"]); if ($ref_id > 0) { $item["obj_link"] = ilLink::_getStaticLink($ref_id, "mep"); } break; case "map": $item["obj_type_txt"] = $this->lng->txt("obj_mob"); $item["obj_title"] = ilObject::_lookupTitle($usage["id"]); $item["sub_txt"] = $this->lng->txt("cont_link_area"); break; } // show versions if (is_array($usage["hist_nr"]) && (count($usage["hist_nr"]) > 1 || $usage["hist_nr"][0] > 0)) { asort($usage["hist_nr"]); $ver = $sep = ""; if ($usage["hist_nr"][0] == 0) { array_shift($usage["hist_nr"]); $usage["hist_nr"][] = 0; } foreach ($usage["hist_nr"] as $nr) { if ($nr > 0) { $ver .= $sep . $nr; } else { $ver .= $sep . $this->lng->txt("cont_current_version"); } $sep = ", "; } $this->tpl->setCurrentBlock("versions"); $this->tpl->setVariable("TXT_VERSIONS", $this->lng->txt("cont_versions")); $this->tpl->setVariable("VAL_VERSIONS", $ver); $this->tpl->parseCurrentBlock(); } if ($item["obj_type_txt"] != "") { $this->tpl->setCurrentBlock("type"); $this->tpl->setVariable("TXT_TYPE", $this->lng->txt("type")); $this->tpl->setVariable("VAL_TYPE", $item["obj_type_txt"]); $this->tpl->parseCurrentBlock(); } if ($usage["type"] != "clip") { if ($item["obj_link"]) { $this->tpl->setCurrentBlock("linked_item"); $this->tpl->setVariable("TXT_OBJECT", $item["obj_title"]); $this->tpl->setVariable("HREF_LINK", $item["obj_link"]); $this->tpl->parseCurrentBlock(); } else { $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $item["obj_title"]); } if ($item["sub_txt"] != "") { $this->tpl->setVariable("SEP", ", "); $this->tpl->setVariable("SUB_TXT", $item["sub_txt"]); if ($item["sub_title"] != "") { $this->tpl->setVariable("SEP2", ": "); $this->tpl->setVariable("SUB_TITLE", $item["sub_title"]); } } } else { $this->tpl->setVariable("TXT_OBJECT_NO_LINK", $this->lng->txt("cont_users_have_mob_in_clip1") . " " . $usage["cnt"] . " " . $this->lng->txt("cont_users_have_mob_in_clip2")); } }
/** * Import record * * @param * @return */ function importRecord($a_entity, $a_types, $a_rec, $a_mapping, $a_schema_version) { //echo $a_entity; //var_dump($a_rec); switch ($a_entity) { case "wiki": include_once "./Modules/Wiki/classes/class.ilObjWiki.php"; if ($new_id = $a_mapping->getMapping('Services/Container', 'objs', $a_rec['Id'])) { $newObj = ilObjectFactory::getInstanceByObjId($new_id, false); } else { $newObj = new ilObjWiki(); $newObj->setType("wiki"); $newObj->create(true); } $newObj->setTitle($a_rec["Title"]); $newObj->setDescription($a_rec["Description"]); $newObj->setShortTitle($a_rec["Short"]); $newObj->setStartPage($a_rec["StartPage"]); $newObj->setRatingOverall($a_rec["RatingOverall"]); $newObj->setRating($a_rec["Rating"]); $newObj->setIntroduction($a_rec["Introduction"]); $newObj->setPublicNotes($a_rec["PublicNotes"]); // >= 4.3 if (isset($a_rec["PageToc"])) { // $newObj->setImportantPages($a_rec["ImpPages"]); $newObj->setPageToc($a_rec["PageToc"]); $newObj->setRatingAsBlock($a_rec["RatingSide"]); $newObj->setRatingForNewPages($a_rec["RatingNew"]); $newObj->setRatingCategories($a_rec["RatingExt"]); } $newObj->update(true); $this->current_obj = $newObj; $a_mapping->addMapping("Modules/Wiki", "wiki", $a_rec["Id"], $newObj->getId()); $a_mapping->addMapping("Services/Rating", "rating_category_parent_id", $a_rec["Id"], $newObj->getId()); $a_mapping->addMapping("Services/AdvancedMetaData", "parent", $a_rec["Id"], $newObj->getId()); break; case "wpg": $wiki_id = $a_mapping->getMapping("Modules/Wiki", "wiki", $a_rec["WikiId"]); include_once "./Modules/Wiki/classes/class.ilWikiPage.php"; $wpage = new ilWikiPage(); $wpage->setWikiId($wiki_id); $wpage->setTitle($a_rec["Title"]); // >= 4.3 if (isset($a_rec["Blocked"])) { $wpage->setBlocked($a_rec["Blocked"]); $wpage->setRating($a_rec["Rating"]); } $wpage->create(true); $a_mapping->addMapping("Modules/Wiki", "wpg", $a_rec["Id"], $wpage->getId()); $a_mapping->addMapping("Services/COPage", "pg", "wpg:" . $a_rec["Id"], "wpg:" . $wpage->getId()); $a_mapping->addMapping("Services/AdvancedMetaData", "advmd_sub_item", "advmd:wpg:" . $a_rec["Id"], $wpage->getId()); break; } }
/** * Create new wiki page * * @param string $a_page_title page title * @param int $a_template_page template page id * @return ilWikiPage new wiki page */ function createWikiPage($a_page_title, $a_template_page = 0) { // check if template has to be used if ($a_template_page == 0) { if (!$this->getEmptyPageTemplate()) { include_once "./Modules/Wiki/classes/class.ilWikiPageTemplate.php"; $wt = new ilWikiPageTemplate($this->getId()); $ts = $wt->getAllInfo(ilWikiPageTemplate::TYPE_NEW_PAGES); if (count($ts) == 1) { $t = current($ts); $a_template_page = $t["wpage_id"]; } } } // create the page $page = new ilWikiPage(); $page->setWikiId($this->getId()); $page->setTitle(ilWikiUtil::makeDbTitle($a_page_title)); if ($this->getRating() && $this->getRatingForNewPages()) { $page->setRating(true); } // needed for notification $page->setWikiRefId($this->getRefId()); $page->create(); // copy template into new page if ($a_template_page > 0) { $orig = new ilWikiPage($a_template_page); $orig->copy($page->getId()); } return $page; }
/** * Clone wiki * * @param int target ref_id * @param int copy id */ public function cloneObject($a_target_id, $a_copy_id = 0) { global $ilDB, $ilUser, $ilias; $new_obj = parent::cloneObject($a_target_id, $a_copy_id); $new_obj->setTitle($this->getTitle()); $new_obj->setStartPage($this->getStartPage()); $new_obj->setShortTitle($this->getShortTitle()); $new_obj->setRating($this->getRating()); $new_obj->setRatingAsBlock($this->getRatingAsBlock()); $new_obj->setRatingForNewPages($this->getRatingForNewPages()); $new_obj->setRatingCategories($this->getRatingCategories()); $new_obj->setPublicNotes($this->getPublicNotes()); $new_obj->setIntroduction($this->getIntroduction()); $new_obj->setImportantPages($this->getImportantPages()); $new_obj->setPageToc($this->getPageToc()); $new_obj->update(); // set/copy stylesheet include_once "./Services/Style/classes/class.ilObjStyleSheet.php"; $style_id = $this->getStyleSheetId(); if ($style_id > 0 && !ilObjStyleSheet::_lookupStandard($style_id)) { $style_obj = $ilias->obj_factory->getInstanceByObjId($style_id); $new_id = $style_obj->ilClone(); $new_obj->setStyleSheetId($new_id); $new_obj->update(); } // copy content include_once "./Modules/Wiki/classes/class.ilWikiPage.php"; $pages = ilWikiPage::getAllPages($this->getId()); if (count($pages) > 0) { // if we have any pages, delete the start page first $pg_id = ilWikiPage::getPageIdForTitle($new_obj->getId(), $new_obj->getStartPage()); $start_page = new ilWikiPage($pg_id); $start_page->delete(); } $map = array(); foreach ($pages as $p) { $page = new ilWikiPage($p["id"]); $new_page = new ilWikiPage(); $new_page->setTitle($page->getTitle()); $new_page->setWikiId($new_obj->getId()); $new_page->setTitle($page->getTitle()); $new_page->setBlocked($page->getBlocked()); $new_page->setRating($page->getRating()); $new_page->create(); $new_page->setXMLContent($page->copyXMLContent(true)); $new_page->buildDom(); $new_page->update(); $map[$p["id"]] = $new_page->getId(); } // copy important pages foreach (ilObjWiki::_lookupImportantPagesList($this->getId()) as $ip) { $new_obj->addImportantPage($map[$ip["page_id"]], $ip["ord"], $ip["indent"]); } // copy rating categories include_once "./Services/Rating/classes/class.ilRatingCategory.php"; foreach (ilRatingCategory::getAllForObject($this->getId()) as $rc) { $new_rc = new ilRatingCategory(); $new_rc->setParentId($new_obj->getId()); $new_rc->setTitle($rc["title"]); $new_rc->setDescription($rc["description"]); $new_rc->save(); } return $new_obj; }