public function resolve(ResourceLocator $locator) { if ($locator->hasResourceId()) { $context = Claro_Context::getCurrentContext(); $context[CLARO_CONTEXT_COURSE] = $locator->getCourseId(); if ($locator->inGroup()) { $context[CLARO_CONTEXT_GROUP] = $locator->getGroupId(); } $path = get_path('coursesRepositorySys') . claro_get_course_path($locator->getCourseId()); // in a group if ($locator->inGroup()) { $groupData = claro_get_group_data($context); $path .= '/group/' . $groupData['directory']; $groupId = $locator->getGroupId(); } else { $path .= '/document'; } $path .= '/' . ltrim($locator->getResourceId(), '/'); $resourcePath = '/' . ltrim($locator->getResourceId(), '/'); $path = secure_file_path($path); if (!file_exists($path)) { throw new Exception("Resource not found {$path}"); } elseif (is_dir($path)) { $url = new Url(get_module_entry_url('CLDOC')); $url->addParam('cmd', 'exChDir'); $url->addParam('file', base64_encode($resourcePath)); return $url->toUrl(); } else { return get_module_url('CLDOC') . '/connector/cllp.frames.cnr.php'; return claro_get_file_download_url($resourcePath, Claro_Context::getUrlContext($context)); } } else { return get_module_entry_url('CLDOC'); } }
public function getResourceList(ResourceLocator $locator) { $groupId = null; if ($locator->inGroup()) { $groupData = claro_get_group_data(array(CLARO_CONTEXT_COURSE => $locator->getCourseId(), CLARO_CONTEXT_GROUP => $locator->getGroupId())); $groupId = $locator->getGroupId(); } $path = $this->getPath($locator); if (!$this->isPathNavigable($path)) { throw new Exception("{$path} does not exists or is not a directory"); } else { $tbl = get_module_course_tbl(array('document'), $locator->getCourseId()); $fileProperties = array(); if (!$locator->inGroup()) { $sql = "SELECT `path`, `visibility`, `comment`\n" . "FROM `{$tbl['document']}`\n" . "WHERE 1"; $res = Claroline::getDatabase()->query($sql); foreach ($res as $row) { $fileProperties[$row['path']] = $row; } } $it = new DirectoryIterator($path); $dirList = array(); $fileList = array(); foreach ($it as $file) { if ($file->isDir() && $file->isDot()) { continue; } $relativePath = str_replace('\\', '/', str_replace($file->getPath(), '', $file->getPathname())); if ($locator->hasResourceId()) { $relativePath = '/' . ltrim(ltrim($locator->getResourceId(), '/') . '/' . ltrim($relativePath, '/'), '/'); } if ($file->isDir()) { $dirList[] = $relativePath; } elseif ($file->isFile()) { $fileList[] = $relativePath; } } natcasesort($dirList); natcasesort($fileList); $resourceList = new LinkerResourceIterator(); foreach ($dirList as $relativePath) { $isVisible = true; if (array_key_exists($relativePath, $fileProperties)) { $isVisible = $fileProperties[$relativePath]['visibility'] != 'i' ? true : false; } $resourceList->addResource($this->createResourceLocator($locator->getCourseId(), $relativePath, $isVisible, true, $groupId)); } foreach ($fileList as $relativePath) { $isVisible = true; if (array_key_exists($relativePath, $fileProperties)) { $isVisible = $fileProperties[$relativePath]['visibility'] != 'i' ? true : false; } $resourceList->addResource($this->createResourceLocator($locator->getCourseId(), $relativePath, $isVisible, false, $groupId)); } return $resourceList; } }
public function getResourceList(ResourceLocator $locator) { $tbl = get_module_course_tbl(array('wiki_properties', 'wiki_pages'), $locator->getCourseId()); if ($locator->inGroup()) { $groupSql = "WHERE group_id = " . Claroline::getDatabase()->escape($locator->getGroupId()); } else { $groupSql = "WHERE group_id = 0"; } $resourceList = new LinkerResourceIterator(); if ($locator->hasResourceId()) { $parts = explode('/', ltrim($locator->getResourceId(), '/')); if (count($parts) == 1) { $sql = "SELECT `title`\n" . "FROM `{$tbl['wiki_pages']}`\n" . "WHERE wiki_id = " . Claroline::getDatabase()->escape($parts[0]); $res = Claroline::getDatabase()->query($sql); foreach ($res as $page) { $pageLoc = new ClarolineResourceLocator($locator->getCourseId(), 'CLWIKI', (int) $parts[0] . '/' . rawurlencode($page['title'])); $pageResource = new LinkerResource($page['title'] == '__MainPage__' ? get_lang('Main page') : $page['title'], $pageLoc, true, true, false); $resourceList->addResource($pageResource); } } } else { $sql = "SELECT `id`, `title`\n" . "FROM `{$tbl['wiki_properties']}`\n" . $groupSql; $res = Claroline::getDatabase()->query($sql); foreach ($res as $wiki) { $wikiLoc = new ClarolineResourceLocator($locator->getCourseId(), 'CLWIKI', (int) $wiki['id']); $wikiResource = new LinkerResource($wiki['title'], $wikiLoc, true, true, true); $resourceList->addResource($wikiResource); } } return $resourceList; }
public function getResourceList(ResourceLocator $locator) { $resourceList = new LinkerResourceIterator(); $tbl = get_module_course_tbl(array('bb_topics', 'bb_forums'), $locator->getCourseId()); if (!$locator->hasResourceId()) { if (!$locator->inGroup()) { $sql = "SELECT `forum_id`, `forum_name`, `group_id`\n" . "FROM `{$tbl['bb_forums']}`\n"; $forumList = Claroline::getDatabase()->query($sql); foreach ($forumList as $forum) { $forumLoc = new ClarolineResourceLocator($locator->getCourseId(), 'CLFRM', empty($forum['group_id']) ? (int) $forum['forum_id'] : null, empty($forum['group_id']) ? null : $forum['group_id']); $topicResource = new LinkerResource(empty($forum['forum_name']) ? get_lang('Untitled') : $forum['forum_name'], $forumLoc, true, true, true); $resourceList->addResource($topicResource); } } else { $sql = "SELECT `forum_id` AS `id`, `forum_name` AS `name`\n" . "FROM `{$tbl['bb_forums']}`\n" . "WHERE `group_id` = " . Claroline::getDatabase()->escape($locator->getGroupId()); $res = Claroline::getDatabase()->query($sql); if (count($res)) { $groupForum = $res->fetch(Database_ResultSet::FETCH_OBJECT); $sql = "SELECT `topic_id`, `topic_title`, `forum_id`\n" . "FROM `{$tbl['bb_topics']}`\n" . "WHERE `forum_id` = " . Claroline::getDatabase()->escape($groupForum->id); $topicList = Claroline::getDatabase()->query($sql); foreach ($topicList as $topic) { $topicLoc = new ClarolineResourceLocator($locator->getCourseId(), 'CLFRM', (int) $topic['topic_id'], $locator->getGroupId()); $topicResource = new LinkerResource(empty($topic['topic_title']) ? get_lang('Untitled') : $topic['topic_title'], $topicLoc, true, true, false); $resourceList->addResource($topicResource); } } } } else { if ($locator->inGroup()) { } else { $elems = explode('/', ltrim($locator->getResourceId(), '/')); if (count($elems) == 1) { $sql = "SELECT `topic_id`, `topic_title`, `forum_id`\n" . "FROM `{$tbl['bb_topics']}`\n" . "WHERE `forum_id` = " . Claroline::getDatabase()->escape($elems[0]); $topicList = Claroline::getDatabase()->query($sql); foreach ($topicList as $topic) { $topicLoc = new ClarolineResourceLocator($locator->getCourseId(), 'CLFRM', (int) $topic['forum_id'] . '/' . (int) $topic['topic_id']); $topicResource = new LinkerResource(empty($topic['topic_title']) ? get_lang('Untitled') : $topic['topic_title'], $topicLoc, true, true, false); $resourceList->addResource($topicResource); } } else { // not navigable } } } return $resourceList; }
public function resolve(ResourceLocator $locator) { if ($locator instanceof ExternalResourceLocator) { return $locator->__toString(); } else { // 1 . get most accurate resolver // 1.1 if Module if ($locator->inModule()) { $resolver = $this->loadModuleResolver($locator->getModuleLabel()); if (!$resolver) { $resolver = new ToolResolver(); } } elseif ($locator->inGroup()) { $resolver = new GroupResolver(); } elseif ($locator->inCourse()) { $resolver = new CourseResolver(); } // 1.4 get base url if ($resolver) { $url = $resolver->resolve($locator); } else { $url = get_path('rootWeb'); } $urlObj = new Url($url); // 2. add context information $context = Claro_Context::getCurrentContext(); if ($locator->inGroup()) { $context[CLARO_CONTEXT_GROUP] = $locator->getGroupId(); } else { if (isset($context[CLARO_CONTEXT_GROUP])) { unset($context[CLARO_CONTEXT_GROUP]); } } if ($locator->inCourse()) { $context[CLARO_CONTEXT_COURSE] = $locator->getCourseId(); } else { if (isset($context[CLARO_CONTEXT_COURSE])) { unset($context[CLARO_CONTEXT_COURSE]); } } $urlObj->relayContext(Claro_Context::getUrlContext($context)); return $urlObj->toUrl(); } }