/**
  * @EXT\Route(
  *     "/resources/widget/{widgetInstance}",
  *     name="claro_resources_widget",
  *     options={"expose"=true}
  * )
  * @EXT\Template("ClarolineCoreBundle:Widget:resourcesWidget.html.twig")
  */
 public function resourcesWidgetAction(WidgetInstance $widgetInstance)
 {
     $workspace = $widgetInstance->getWorkspace();
     $workspaceId = !is_null($workspace) ? $workspace->getId() : null;
     $config = $this->resourcesWidgetManager->getResourcesWidgetConfig($widgetInstance);
     $mode = $config->getMode();
     $resourceNodes = [];
     switch ($mode) {
         case ResourcesWidgetConfig::DIRECTORY_MODE:
             $directoriesIds = $config->getDirectories();
             foreach ($directoriesIds as $directoryId) {
                 $parent = $this->resourceManager->getById($directoryId);
                 $children = is_null($workspaceId) || $workspaceId === $parent->getWorkspace()->getId() ? $this->resourcesWidgetManager->getAllResourcesByDirectory($parent) : [];
                 foreach ($children as $child) {
                     array_push($resourceNodes, $child);
                 }
             }
             break;
         case ResourcesWidgetConfig::TAG_MODE:
             $tags = $config->getTags();
             foreach ($tags as $tagName) {
                 $resources = $this->resourcesWidgetManager->getAllResourcesByTag($tagName, $workspaceId);
                 foreach ($resources as $resource) {
                     $resourceNodes[$resource['id']] = $resource;
                 }
             }
             break;
     }
     return ['widgetInstance' => $widgetInstance, 'resourceNodes' => $resourceNodes];
 }
 /**
  * Constructor.
  */
 public function __construct(WidgetInstance $widgetInstance, WidgetHomeTabConfig $whtc = null, WidgetDisplayConfig $wdc = null)
 {
     $workspace = $widgetInstance->getWorkspace();
     $widget = $widgetInstance->getWidget();
     $homeTab = !is_null($whtc) ? $whtc->getHomeTab() : null;
     $details = [];
     if (!is_null($homeTab)) {
         $details['tabId'] = $homeTab->getId();
         $details['tabName'] = $homeTab->getName();
         $details['tabType'] = $homeTab->getType();
         $details['tabIcon'] = $homeTab->getIcon();
     }
     $details['widgetId'] = $widget->getId();
     $details['widgetName'] = $widget->getName();
     $details['widgetIsConfigurable'] = $widget->isConfigurable();
     $details['widgetIsExportable'] = $widget->isExportable();
     $details['widgetIsDisplayableInWorkspace'] = $widget->isDisplayableInWorkspace();
     $details['widgetIsDisplayableInDesktop'] = $widget->isDisplayableInDesktop();
     $details['id'] = $widgetInstance->getId();
     $details['name'] = $widgetInstance->getName();
     $details['icon'] = $widgetInstance->getIcon();
     $details['isAdmin'] = $widgetInstance->isAdmin();
     $details['isDesktop'] = $widgetInstance->isDesktop();
     $details['workspaceId'] = $workspace->getId();
     $details['workspaceCode'] = $workspace->getCode();
     $details['workspaceName'] = $workspace->getName();
     $details['workspaceGuid'] = $workspace->getGuid();
     if (!is_null($whtc)) {
         $details['widgetHomeTabConfigId'] = $whtc->getId();
         $details['order'] = $whtc->getWidgetOrder();
         $details['type'] = $whtc->getType();
         $details['visible'] = $whtc->isVisible();
         $details['locked'] = $whtc->isLocked();
     }
     if (!is_null($wdc)) {
         $details['widgetDisplayConfigId'] = $wdc->getId();
         $details['row'] = $wdc->getRow();
         $details['column'] = $wdc->getColumn();
         $details['width'] = $wdc->getWidth();
         $details['height'] = $wdc->getHeight();
         $details['color'] = $wdc->getColor();
     }
     parent::__construct(self::ACTION, $details, null, null, null, null, $workspace);
 }
Ejemplo n.º 3
0
 /**
  * @param WidgetInstance $widgetInstance
  *
  * @return \Claroline\ForumBundle\Entity\Message[]
  */
 public function getLastMessages(WidgetInstance $widgetInstance)
 {
     $workspace = $widgetInstance->getWorkspace();
     $config = $this->getConfig($widgetInstance);
     $forum = null;
     $participateOnly = false;
     $mySubjects = [];
     if (!is_null($config)) {
         $resourceNode = $config->getForum();
         $participateOnly = $config->getDisplayMyLastMessages();
         if (!is_null($resourceNode)) {
             $forum = $this->resourceManager->getResourceFromNode($resourceNode);
         }
     }
     $token = $this->tokenStorage->getToken();
     $roles = $this->securityUtilities->getRoles($token);
     if ($participateOnly) {
         $mySubjects = $this->getSubjectsByParticipant($token->getUser());
     }
     if (is_null($forum)) {
         $messages = is_null($workspace) ? $this->getLastMessagesByRoles($roles, 10, $mySubjects) : $this->getLastMessagesByWorkspacesAndRoles([$workspace], $roles, 10, $mySubjects);
     } else {
         $messages = $this->getLastMessagesByForumAndRoles($forum, $roles, 10, $mySubjects);
     }
     return $messages;
 }
Ejemplo n.º 4
0
 private function checkAdminAccessForWidgetInstance(WidgetInstance $widgetInstance)
 {
     if (!is_null($widgetInstance->getUser()) || !is_null($widgetInstance->getWorkspace())) {
         throw new AccessDeniedException();
     }
 }
 private function checkWorkspaceWidgetInstance(Workspace $workspace, WidgetInstance $widgetInstance)
 {
     $htWorkspace = $widgetInstance->getWorkspace();
     if ($workspace !== $htWorkspace) {
         $exception = new WorkspaceAccessDeniedException();
         $exception->setWorkspace($workspace);
         throw $exception;
     }
 }
Ejemplo n.º 6
0
 private function hasWorkspaceAccessToWidgetInstance(WidgetInstance $widgetInstance, Workspace $workspace)
 {
     $widgetWorkspace = $widgetInstance->getWorkspace();
     if (is_null($widgetWorkspace) || $widgetWorkspace->getId() !== $workspace->getId()) {
         return false;
     }
     return true;
 }
 /**
  * @EXT\Route(
  *     "/announcement/widget/{widgetInstance}/page/{page}",
  *     name="claro_announcement_widget_pager",
  *     defaults={"page"=1},
  *     options={"expose"=true}
  * )
  * @EXT\Method("GET")
  *
  * Renders announcements in a pager.
  *
  * @param WidgetInstance $widgetInstance
  * @param int            $page
  *
  * @return Response
  */
 public function announcementsWidgetPagerAction(WidgetInstance $widgetInstance, $page = 1)
 {
     $workspace = $widgetInstance->getWorkspace();
     $isDesktop = is_null($workspace);
     $config = $this->announcementManager->getAnnouncementsWidgetConfig($widgetInstance);
     $selectedResourcesIds = $config->getAnnouncements();
     $token = $this->tokenStorage->getToken();
     $roles = $this->utils->getRoles($token);
     $announcements = [];
     if ($isDesktop) {
         $workspaces = $this->workspaceManager->getOpenableWorkspacesByRoles($roles);
         $data = $this->announcementManager->getVisibleAnnouncementsByWorkspaces($workspaces, $roles);
         $template = 'ClarolineAnnouncementBundle::announcementsDesktopWidgetPager.html.twig';
     } else {
         $data = $this->announcementManager->getVisibleAnnouncementsByWorkspace($workspace, $roles);
         $template = 'ClarolineAnnouncementBundle::announcementsWorkspaceWidgetPager.html.twig';
     }
     if (count($selectedResourcesIds) > 0) {
         foreach ($data as $announcement) {
             if (in_array($announcement['resourceNodeId'], $selectedResourcesIds)) {
                 $announcements[] = $announcement;
             }
         }
     } else {
         $announcements = $data;
     }
     $pager = $this->pagerFactory->createPagerFromArray($announcements, $page, 5);
     return new Response($this->templating->render($template, ['widgetInstance' => $widgetInstance, 'datas' => $pager]));
 }
Ejemplo n.º 8
0
 public function getWorkspaceWidgetList(WidgetInstance $instance)
 {
     $workspace = $instance->getWorkspace();
     if (!$this->isAllowedToViewLogs($workspace)) {
         return null;
     }
     $em = $this->container->get('doctrine.orm.entity_manager');
     /** @var \Claroline\CoreBundle\Repository\Log\LogRepository $repository */
     $repository = $em->getRepository('ClarolineCoreBundle:Log\\Log');
     $config = $this->getLogConfig($instance);
     if ($config === null) {
         $defaultConfig = $em->getRepository('ClarolineCoreBundle:Widget\\WidgetInstance')->findOneBy(array('isDesktop' => false, 'isAdmin' => true));
         $config = new LogWidgetConfig();
         if ($defaultConfig !== null) {
             $config->copy($this->getLogConfig($defaultConfig));
         }
         $config->setRestrictions($this->container->get('claroline.log.manager')->getDefaultWorkspaceConfigRestrictions());
         $widgetInstance = new WidgetInstance();
         $widgetInstance->setWorkspace($workspace);
         $config->setWidgetInstance($widgetInstance);
     }
     /** @var \Claroline\CoreBundle\Manager\EventManager $eventManager */
     $eventManager = $this->container->get('claroline.event.manager');
     if ($config->hasNoRestriction()) {
         return null;
     }
     $query = $repository->findLogsThroughConfigs(array($config), $config->getAmount());
     $logs = $query->getResult();
     $chartData = $repository->countByDayThroughConfigs(array($config), $this->getDefaultRange());
     //List item delegation
     $views = $this->renderLogs($logs);
     $workspaceEvents = $eventManager->getEvents(LogGenericEvent::DISPLAYED_WORKSPACE);
     if ($config->hasAllRestriction(count($workspaceEvents))) {
         $title = $this->container->get('translator')->trans('recent_all_workspace_activities_overview', array('%workspaceName%' => $workspace->getName()), 'platform');
     } else {
         $title = $this->container->get('translator')->trans('Overview of recent activities in %workspaceName%', array('%workspaceName%' => $workspace->getName()), 'platform');
     }
     return array('logs' => $logs, 'listItemViews' => $views, 'chartData' => $chartData, 'workspace' => $workspace, 'logAmount' => $config->getAmount(), 'title' => $title, 'isDesktop' => false);
 }
Ejemplo n.º 9
0
 /**
  * @EXT\Route(
  *     "/resources/widget/{widgetInstance}",
  *     name="claro_tag_resources_widget",
  *     options={"expose"=true}
  * )
  * @EXT\ParamConverter("authenticatedUser", options={"authenticatedUser" = true})
  * @EXT\Template("ClarolineTagBundle:Widget:resourcesTagsWidget.html.twig")
  */
 public function resourcesTagsWidgetAction(WidgetInstance $widgetInstance)
 {
     $workspace = $widgetInstance->getWorkspace();
     $user = $this->tokenStorage->getToken()->getUser();
     $roles = $this->tokenStorage->getToken()->getRoles();
     $roleNames = array();
     foreach ($roles as $role) {
         $roleNames[] = $role->getRole();
     }
     $config = $this->tagManager->getResourcesTagsWidgetConfig($widgetInstance);
     $details = $config->getDetails();
     $nbTags = !empty($details) && isset($details['nb_tags']) ? $details['nb_tags'] : 10;
     $taggedObjects = $this->tagManager->getTaggedResourcesByWorkspace($workspace, $user, $roleNames);
     $tags = array();
     $sorted = array();
     $datas = array();
     // Sort all tagged objects by tag
     foreach ($taggedObjects as $taggedObject) {
         $tag = $taggedObject->getTag();
         $tagId = $tag->getId();
         if (!isset($tags[$tagId])) {
             $tags[$tagId] = array();
             $tags[$tagId]['tag'] = $tag->getName();
             $tags[$tagId]['tag_id'] = $tag->getId();
             $tags[$tagId]['objects'] = array();
         }
         $tags[$tagId]['objects'][] = array('id' => $taggedObject->getObjectId(), 'name' => $taggedObject->getObjectName());
     }
     // Sort all tags by number of tagged objects
     foreach ($tags as $tag) {
         $nbObjects = count($tag['objects']);
         if (!isset($sorted[$nbObjects])) {
             $sorted[$nbObjects] = array();
         }
         $sorted[$nbObjects][] = $tag;
     }
     // Sort most used tags DESC
     krsort($sorted);
     $index = 0;
     // Keep X ($nbTags) most used tags
     foreach ($sorted as $contents) {
         if ($index === $nbTags) {
             break;
         } else {
             foreach ($contents as $content) {
                 if ($index === $nbTags) {
                     break;
                 } else {
                     $datas[] = $content;
                     $index++;
                 }
             }
         }
     }
     return array('widgetInstance' => $widgetInstance, 'nbTags' => $nbTags, 'datas' => $datas);
 }