Ejemplo n.º 1
0
 public function findWidgetPaths(array $userRoles, array $roots = array(), PathWidgetConfig $config = null)
 {
     $builder = new ResourceQueryBuilder();
     $builder->selectAsEntity(false, 'Innova\\PathBundle\\Entity\\Path\\Path');
     if (!empty($roots)) {
         $builder->whereRootIn($roots);
     }
     $builder->whereTypeIn(array('innova_path'));
     $builder->whereRoleIn($userRoles);
     // Add filters if defined
     if ($config) {
         // Add widget STATUS filters
         $statusList = $config->getStatus();
         if (!empty($statusList)) {
             $whereStatus = array();
             foreach ($statusList as $status) {
                 switch ($status) {
                     case 'draft':
                         $whereStatus[] = 'node.published = 0';
                         break;
                     case 'published':
                         $whereStatus[] = '(node.published = 1 AND resource.modified = 0)';
                         break;
                     case 'modified':
                         $whereStatus[] = '(node.published = 1 AND resource.modified = 1)';
                         break;
                 }
             }
             if (!empty($whereStatus)) {
                 $builder->addWhereClause(implode($whereStatus, ' OR '));
             }
         }
         // Add widget TAG filters
         $tagList = $config->getTags();
         if (0 < count($tagList)) {
             $tags = array();
             foreach ($tagList as $tag) {
                 $tags[] = $tag->getId();
             }
             // Join with the corresponding TaggedObject entities
             $builder->addJoinClause('LEFT JOIN ClarolineTagBundle:TaggedObject AS t WITH t.objectId = node.id');
             $builder->addWhereClause('t.id IS NOT NULL');
             $builder->addWhereClause('t.tag IN (' . implode($tags, ', ') . ')');
         }
     }
     $builder->orderByName();
     $dql = $builder->getDql();
     $query = $this->_em->createQuery($dql);
     $query->setParameters($builder->getParameters());
     $resources = $query->getResult();
     return $resources;
 }
Ejemplo n.º 2
0
 /**
  * @param WidgetInstance $widgetInstance
  * @param \Symfony\Component\HttpFoundation\Request $request
  * @throws \Symfony\Component\Security\Core\Exception\AccessDeniedException
  * @return array
  *
  * @Route(
  *      "/widget/config/{widgetInstance}",
  *      name= "innova_path_widget_config"
  * )
  * @Method("POST")
  * @Template("InnovaPathBundle:Widget:config.html.twig")
  */
 public function updateWidgetAction(WidgetInstance $widgetInstance, Request $request)
 {
     // User can not edit the Widget
     if (!$this->authorizationChecker->isGranted('edit', $widgetInstance)) {
         throw new AccessDeniedException();
     }
     $config = $this->pathManager->getWidgetConfig($widgetInstance);
     if (null === $config) {
         $config = new PathWidgetConfig();
         $config->setWidgetInstance($widgetInstance);
     }
     $form = $this->formFactory->create('innova_path_widget_config', $config);
     $form->bind($request);
     if ($form->isValid()) {
         // Remove tags
         $tagsToRemove = $form->get('removeTags')->getData();
         if (!empty($tagsToRemove)) {
             // Search the Tag by ID
             $existingTags = $config->getTags()->toArray();
             $toRemoveArray = array_filter($existingTags, function ($entry) use($tagsToRemove) {
                 return in_array($entry->getId(), $tagsToRemove);
             });
             foreach ($toRemoveArray as $toRemove) {
                 $config->removeTag($toRemove);
             }
         }
         // Add tags
         $tags = $form->get('tags')->getData();
         if (!empty($tags)) {
             // Ge the list of Tags from data String
             $tags = explode(',', $tags);
             $uniqueTags = array();
             foreach ($tags as $tag) {
                 $value = trim($tag);
                 if (!empty($value)) {
                     $uniqueTags[strtolower($value)] = $value;
                 }
             }
             foreach ($uniqueTags as $tagName) {
                 $tagObject = $this->tagManager->getOnePlatformTagByName($tagName);
                 if (!empty($tagObject)) {
                     $config->addTag($tagObject);
                 }
             }
         }
         $this->om->persist($config);
         $this->om->flush();
         return new Response('success', 204);
     }
     return array('form' => $form->createView(), 'instance' => $widgetInstance, 'tags' => $this->tagManager->getPlatformTags());
 }