vendor/uvdesk/support-center-bundle/Repository/Article.php line 111

Open in your IDE?
  1. <?php
  2. namespace Webkul\UVDesk\SupportCenterBundle\Repository;
  3. use Doctrine\ORM\Query;
  4. use Doctrine\ORM\EntityRepository;
  5. use Doctrine\Common\Collections\Criteria;
  6. use Symfony\Component\HttpFoundation\Request;
  7. use Webkul\UVDesk\SupportCenterBundle\Entity as SupportEntites;
  8. use Webkul\UVDesk\CoreFrameworkBundle\Entity as CoreEntites;
  9. class Article extends EntityRepository
  10. {
  11.     const LIMIT 10;
  12.     private $defaultSort 'a.id';
  13.     private $searchAllowed = ['tag'];
  14.     private $direction = ['asc''desc'];
  15.     private $sorting = ['a.name''a.dateAdded''a.viewed'];
  16.     private $safeFields = ['page''limit''sort''order''direction'];
  17.     private $allowedFormFields = ['search''query''name''description''viewed''status'];
  18.     private function validateSorting($sorting)
  19.     {
  20.         return in_array($sorting$this->sorting) ? $sorting $this->defaultSort;
  21.     }
  22.     private function validateDirection($direction)
  23.     {
  24.         return in_array($direction$this->direction) ? $direction Criteria::DESC;
  25.     }
  26.     private function presetting(&$data)
  27.     {
  28.         $data['sort'] = $_GET['sort'] = $this->validateSorting(isset($data['sort']) ? $data['sort'] : false);
  29.         $data['direction'] = $_GET['direction'] = $this->validateDirection(isset($data['direction']) ? $data['direction'] : false);
  30.         $this->cleanAllData($data);
  31.     }
  32.     private function cleanAllData(&$data)
  33.     {
  34.         if(isset($data['isActive'])){
  35.             $data['status'] = $data['isActive'];
  36.             unset($data['isActive']);
  37.         }
  38.         unset($data['categoryId']);
  39.         unset($data['solutionId']);
  40.     }
  41.     public function getTotalArticlesBySupportTag($supportTag)
  42.     {
  43.         $result $this->getEntityManager()->createQueryBuilder()
  44.             ->select('COUNT(articleTags) as totalArticle')
  45.             ->from(SupportEntites\ArticleTags::class, 'articleTags')
  46.             ->where('articleTags.tagId = :supportTag')->setParameter('supportTag'$supportTag)
  47.             ->getQuery()->getResult();
  48.         
  49.         return !empty($result) ? $result[0]['totalArticle'] : 0;
  50.     }
  51.     public function getAllHistoryByArticle($params)
  52.     {
  53.         $qbS $this->getEntityManager()->createQueryBuilder();
  54.         $results $qbS->select('a.id, a.dateAdded, a.content')
  55.                         ->from('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleHistory''a')
  56.                         ->leftJoin('Webkul\UVDesk\CoreFrameworkBundle\Entity\User','u','WITH''a.userId = u.id')
  57.                         ->leftJoin('u.userInstance''ud')
  58.                         ->addSelect("CONCAT(u.firstName,' ',u.lastName) AS name")
  59.                         ->andwhere('a.articleId = :articleId')
  60.                         ->andwhere('ud.supportRole IN (:roleId)')
  61.                         ->orderBy(
  62.                             'a.id',
  63.                             Criteria::DESC
  64.                         )
  65.                         ->setParameters([
  66.                             'articleId' => $params['articleId'],
  67.                             'roleId' => [123],
  68.                         ])
  69.                         ->getQuery()
  70.                         ->getResult();
  71.         return $results;
  72.     }
  73.     public function getAllRelatedyByArticle($params$status = [01])
  74.     {
  75.         $qbS $this->getEntityManager()->createQueryBuilder();
  76.         $qbS->select('DISTINCT a.id, a.relatedArticleId as articleId, aR.name, aR.stared, aR.status, aR.slug')
  77.             ->from('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleRelatedArticle''a')
  78.             ->leftJoin('Webkul\UVDesk\SupportCenterBundle\Entity\Article','aR','WITH''a.relatedArticleId = aR.id')
  79.             
  80.             ->andwhere('a.articleId = :articleId')
  81.             ->andwhere('aR.status IN (:status)')
  82.             ->orderBy(
  83.                 'a.id',
  84.                 Criteria::DESC
  85.             )
  86.             ->setParameters([
  87.                 'articleId' => $params['articleId'],
  88.                 'status' => $status,
  89.             ]);
  90.         $results $qbS->getQuery()->getResult();
  91.         return $results;
  92.     }
  93.     public function getAllArticles(\Symfony\Component\HttpFoundation\ParameterBag $obj null$container$allResult false)
  94.     {
  95.         $json = array();
  96.        
  97.         $qb $this->getEntityManager()->createQueryBuilder();
  98.         $qb->select('a')->from($this->getEntityName(), 'a');
  99.         $data $obj $obj->all() : [];
  100.         $data array_reverse($data);
  101.         $articles = [];
  102.         if(isset($data['categoryId']))
  103.         {
  104.             $qbS $this->getEntityManager()->createQueryBuilder();
  105.             $qbS->select('a.articleId')->from('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleCategory''a');
  106.             $qbS->where('a.categoryId = :categoryId');
  107.             $qbS->setParameter('categoryId'$data['categoryId']);
  108.             $articles $qbS->getQuery()->getResult();
  109.             $articles $articles $articles : [0];
  110.         }
  111.         
  112.         if (isset($data['solutionId'])) {
  113.             $qbS $this->getEntityManager()->createQueryBuilder();
  114.             $qbS->select('DISTINCT ac.articleId')->from('Webkul\UVDesk\SupportCenterBundle\Entity\SolutionCategoryMapping''scm');
  115.             $qbS->leftJoin('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleCategory''ac''with''scm.categoryId = ac.categoryId');
  116.             $qbS->where('scm.solutionId = :solutionId');
  117.             $qbS->setParameter('solutionId'$data['solutionId']);
  118.             $articles $qbS->getQuery()->getResult();
  119.             $articles $articles $articles : [0];
  120.         }
  121.         if(isset($data['search'])){
  122.             $search explode(':'$data['search']);
  123.             if(isset($search[0]) && isset($search[1])){
  124.                 if(in_array($search[0], $this->searchAllowed)){
  125.                     if($search[0] == 'tag'){
  126.                         $qbS $this->getEntityManager()->createQueryBuilder();
  127.                         $qbS->select('at.articleId')->from('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleTags''at');
  128.                           
  129.                         $articlesTag $qbS->getQuery()->getResult();
  130.                         if($articlesTag){
  131.                             if($articles){
  132.                                 $oldArticles $articles;
  133.                                 $articles = [0];
  134.                                 foreach($oldArticles as $article){
  135.                                     if(in_array($article$articlesTag)){
  136.                                         $articles[] = $article;
  137.                                     }
  138.                                 }
  139.                             }else
  140.                                 $articles $articlesTag;
  141.                         }else
  142.                             $articles = [0];
  143.                     }
  144.                     unset($data['search']);
  145.                 }
  146.             }
  147.         }
  148.         $this->presetting($data);
  149.         
  150.         foreach ($data as $key => $value) {
  151.             if(!in_array($key,$this->safeFields) && in_array($key$this->allowedFormFields)) {
  152.                 if($key!='dateUpdated' AND $key!='dateAdded' AND $key!='search' AND $key!='query') {
  153.                         $qb->Andwhere('a.'.$key.' = :'.$key);
  154.                         $qb->setParameter($key$value);
  155.                 } else {
  156.                     if($key == 'search' || $key == 'query') {
  157.                         $qb->orwhere('a.name'.' LIKE :name');
  158.                         $qb->setParameter('name''%'.urldecode(trim($value)).'%');
  159.                         $qb->orwhere('a.content'.' LIKE :content'); //can use regexBundle for it so that it can\'t match html
  160.                         $qb->setParameter('content''%'.urldecode(trim($value)).'%');
  161.                     }
  162.                 }
  163.             }
  164.         }
  165.         if($articles){
  166.             $qb->Andwhere('a.id IN (:articles)');
  167.             $qb->setParameter('articles'$articles);
  168.         }
  169.         // dump($qb);die;
  170.         if(!$allResult){
  171.             $paginator  $container->get('knp_paginator');
  172.             $results $paginator->paginate(
  173.                 $qb,
  174.                 isset($data['page']) ? $data['page'] : 1,
  175.                 self::LIMIT,
  176.                 array('distinct' => true)
  177.             );
  178.         }else{
  179.             $qb->select($allResult);
  180.             $results $qb->getQuery()->getResult();
  181.             return $results;
  182.         }
  183.         $newResult = [];
  184.         // dump($results);die;
  185.         foreach ($results as $key => $result) {
  186.             // dump($result['id']);
  187.             $newResult[] = array(
  188.                 'id'                   => $result->getId(),
  189.                 'name'                 => $result->getName(),
  190.                 'slug'                 => $result->getSlug(),
  191.                 'status'               => $result->getStatus(),
  192.                 'viewed'               => $result->getViewed(),
  193.                 'dateAdded'            => date_format($result->getDateAdded(),'d-M h:i A'),
  194.                 'categories'           => ($articles $this->getCategoryByArticle($result->getId()) : $this->getCategoryByArticle($result->getId())),
  195.             );
  196.         }
  197.         // die;
  198.         $paginationData $results->getPaginationData();
  199.         $queryParameters $results->getParams();
  200.        
  201.         unset($queryParameters['solution']);
  202.         if(isset($queryParameters['category']))
  203.             unset($queryParameters['category']);
  204.         $paginationData['url'] = '#'.$container->get('uvdesk.service')->buildPaginationQuery($queryParameters);
  205.         $json['results'] = $newResult;
  206.         $json['pagination_data'] = $paginationData;
  207.         // dump($json);die;
  208.         return $json;
  209.     }
  210.    
  211.     public function getCategoryByArticle($id)
  212.     {
  213.         $queryBuilder $this->createQueryBuilder('a');
  214.         $results $queryBuilder->select('c.id, c.name')
  215.                  ->leftJoin('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleCategory','ac','WITH''ac.articleId = a.id')
  216.                  ->leftJoin('Webkul\UVDesk\SupportCenterBundle\Entity\SolutionCategory','c','WITH''ac.categoryId = c.id')
  217.                  ->andwhere('ac.articleId = :articleId')
  218.                  ->setParameters([
  219.                      'articleId' => $id,
  220.                  ])
  221.                  ->getQuery()
  222.                  ->getResult()
  223.         ;
  224.         return $results;
  225.     }
  226.     public function getTagsByArticle($id)
  227.     {
  228.         $queryBuilder $this->createQueryBuilder('a');
  229.         $results $queryBuilder->select('DISTINCT t.id, t.name')
  230.                 ->leftJoin('Webkul\UVDesk\SupportCenterBundle\Entity\ArticleTags','at','WITH''at.articleId = a.id')
  231.                 ->leftJoin('Webkul\UVDesk\CoreFrameworkBundle\Entity\Tag','t','WITH''at.tagId = t.id')
  232.                 ->andwhere('at.articleId = :articleId')
  233.                 ->setParameters([
  234.                     'articleId' => $id,
  235.                 ])
  236.                 ->getQuery()
  237.                 ->getResult()
  238.         ;
  239.         return $results;
  240.     }
  241.     public function removeCategoryByArticle($articleId$categories = [])
  242.     {
  243.         $where is_array($categories) ? 'ac.categoryId IN (:id)' 'ac.categoryId = :id';
  244.         $queryBuilder $this->createQueryBuilder('ac');
  245.         $queryBuilder->delete(SupportEntites\ArticleCategory::class,'ac')
  246.                  ->andwhere('ac.articleId = :articleId')
  247.                  ->andwhere($where)
  248.                  ->setParameters([
  249.                      'articleId' => $articleId,
  250.                      'id' => $categories ,
  251.                  ])
  252.                  ->getQuery()
  253.                  ->execute()
  254.         ;
  255.     }
  256.     public function removeTagByArticle($articleId$tags = [])
  257.     {
  258.         $where is_array($tags) ? 'ac.tagId IN (:id)' 'ac.tagId = :id';
  259.         $queryBuilder $this->createQueryBuilder('ac');
  260.         $queryBuilder->delete(SupportEntites\ArticleTags::class,'ac')
  261.             ->andwhere('ac.articleId = :articleId')
  262.             ->andwhere($where)
  263.             ->setParameters(['articleId' => $articleId,'id' => $tags])
  264.             ->getQuery()
  265.             ->execute();
  266.     }
  267.     public function removeRelatedByArticle($articleId$ids = [])
  268.     {
  269.         $where is_array($ids) ? 'ac.id IN (:id)' 'ac.id = :id';
  270.         $queryBuilder $this->createQueryBuilder('ac');
  271.         $queryBuilder->delete(SupportEntites\ArticleRelatedArticle::class,'ac')
  272.             ->andwhere('ac.articleId = :articleId')
  273.             ->andwhere($where)
  274.             ->setParameters(['articleId' => $articleId,'id' => $ids])
  275.             ->getQuery()
  276.             ->execute();
  277.     }
  278.     public function removeEntryByArticle($id)
  279.     {
  280.         $where is_array($id) ? 'ac.articleId IN (:id)' 'ac.articleId = :id';
  281.         $queryBuilder $this->createQueryBuilder('ac');
  282.         $queryBuilder->delete(SupportEntites\ArticleCategory::class,'ac')
  283.                  ->andwhere($where)
  284.                  ->setParameters([
  285.                      'id' => $id ,
  286.                  ])
  287.                  ->getQuery()
  288.                  ->execute();
  289.     
  290.     }
  291.     public function bulkArticleStatusUpdate($ids$status)
  292.     {
  293.         $query 'UPDATE Webkul\UVDesk\SupportCenterBundle\Entity\Article a SET a.status = '. (int)$status .' WHERE a.id IN ('.implode(','$ids).')';
  294.         $this->getEntityManager()->createQuery($query)->execute();
  295.     }
  296.     private function getStringToOrder($string)
  297.     {
  298.         Switch($string){
  299.             case 'ascending':
  300.                 return 'ASC';
  301.                 break;
  302.             case 'decending':
  303.             case 'popularity':
  304.                 return 'DESC';
  305.                 break;
  306.             Default:
  307.                 return 'DESC';
  308.                 break;
  309.         }
  310.     }
  311.     public function getArticlesByCategory(Request $request$companyId)
  312.     {
  313.         $queryBuilder $this->createQueryBuilder('a');
  314.         $prams = array(
  315.                         'solutionId' => (int)$request->attributes->get('solution'),
  316.                         'categoryId' => (int)$request->attributes->get('category'),
  317.                     );
  318.         $results $queryBuilder->select('a')
  319.                  ->leftJoin('Webkul\SupportCenterBundle\Entity\ArticleCategory','ac','WITH''ac.articleId = a.id')
  320.                  ->andwhere('a.solutionId = :solutionId')
  321.                  ->andwhere('ac.categoryId = :categoryId')
  322.                  ->orderBy(
  323.                         $request->query->get('sort') ? 'a.'.$request->query->get('sort') : 'a.id',
  324.                         $request->query->get('direction') ? $request->query->get('direction') : Criteria::DESC
  325.                     )
  326.                  ->setParameters($prams)
  327.                  ->getQuery()
  328.                  ->getResult()
  329.         ;
  330.         return $results;
  331.     }
  332.     public function getSolutionArticles(Request $request$companyId)
  333.     {
  334.         $queryBuilder $this->createQueryBuilder('a');
  335.         $prams = array(
  336.                         'solutionId' => (int)$request->attributes->get('solution'),
  337.                     );
  338.         $results $queryBuilder->select('a')
  339.                  ->andwhere('a.solutionId = :solutionId')
  340.                  ->orderBy(
  341.                         $request->query->get('sort') ? 'a.'.$request->query->get('sort') : 'a.id',
  342.                         $request->query->get('direction') ? $request->query->get('direction') : Criteria::DESC
  343.                     )
  344.                  ->setParameters($prams)
  345.                  ->getQuery()
  346.                  ->getResult()
  347.         ;
  348.         return $results;
  349.     }
  350.     public function getArticlesByCategoryFront($category)
  351.     {
  352.         $queryBuilder $this->createQueryBuilder('a');
  353.         $prams = array(
  354.                         'solutionId' => $category->getSolution(),
  355.                         'categoryId' => $category->getId(),
  356.                     );
  357.         $results $queryBuilder->select('a')
  358.                  ->leftJoin('Webkul\SupportCenterBundle\Entity\ArticleCategory','ac','WITH''ac.articleId = a.id')
  359.                  ->andwhere('a.solutionId = :solutionId')
  360.                  ->andwhere('ac.categoryId = :categoryId')
  361.                  ->andwhere('a.status = 1')
  362.                  ->orderBy(
  363.                         $category->getSorting() == 'popularity' 'a.viewed' 'a.name',
  364.                         $this->getStringToOrder($category->getSorting())
  365.                     )
  366.                  ->setParameters($prams)
  367.                  ->getQuery()
  368.                  ->getResult()
  369.         ;
  370.         return $results;
  371.     }
  372.     public function getArticleCategory(Request $request)
  373.     {
  374.         $queryBuilder $this->createQueryBuilder('a');
  375.         $prams = array(
  376.                         'articleId' => (int)$request->attributes->get('article'),
  377.                     );
  378.         $results $queryBuilder->select('ac')
  379.                  ->leftJoin('Webkul\SupportCenterBundle\Entity\ArticleCategory','ac','WITH''ac.articleId = a.id')
  380.                  ->andwhere('ac.articleId = :articleId')
  381.                  ->orderBy(
  382.                         $request->query->get('sort') ? 'a.'.$request->query->get('sort') : 'a.id',
  383.                         $request->query->get('direction') ? $request->query->get('direction') : Criteria::DESC
  384.                     )
  385.                  ->setParameters($prams)
  386.                  ->getQuery()
  387.                  ->getResult()
  388.         ;
  389.         return $results;
  390.     }
  391.     public function getArticleBySearch(Request $request)
  392.     {
  393.         $sort $request->query->get('sort');
  394.         $direction $request->query->get('direction');
  395.         $searchQuery $request->query->get('s');
  396.         $searchTagList explode(' 'trim($searchQuery));
  397.         $params = [
  398.             'name' => '%' trim($searchQuery) . '%',
  399.             'status' => 1,
  400.         ];
  401.         $results $this->createQueryBuilder('a')
  402.                  ->select('a.id, a.name, a.slug, a.content, a.metaDescription, a.keywords, a.metaTitle, a.status, a.viewed, a.stared, a.dateAdded, a.dateUpdated')
  403.                  ->andwhere('a.name LIKE :name OR a.content LIKE :name')
  404.                  ->andwhere('a.status = :status')
  405.                  ->orderBy((!empty($sort)) ? 'a.' $sort 'a.id', (!empty($direction)) ? $direction Criteria::DESC)
  406.                  ->setParameters($params)
  407.                  ->getQuery()
  408.                  ->getResult();
  409.      
  410.         return $results;
  411.     }
  412.     public function getArticleByTags(array $tagList = [], $sort null$direction null)
  413.     {
  414.       
  415.         if (empty($tagList))
  416.             return [];
  417.         $queryBuilder $this->getEntityManager()->createQueryBuilder()
  418.             ->select('a')
  419.             ->from(SupportEntites\Article::class, 'a')
  420.             ->leftJoin(SupportEntites\ArticleTags::class, 'at''WITH''at.articleId = a.id')
  421.             ->leftJoin(CoreEntites\Tag::class, 't''WITH''t.id = at.tagId')
  422.             ->andwhere('a.status = :status')->setParameter('status'1)
  423.             ->orderBy(
  424.                 (!empty($sort)) ? 'a.' $sort 'a.id',
  425.                 (!empty($direction)) ? $direction Criteria::DESC
  426.             );
  427.         // Build the sub-query
  428.         $subQuery '';
  429.         foreach ($tagList as $index => $tag) {
  430.             $queryBuilder->setParameter('tag' $index'%' $tag '%');
  431.             $subQuery .= ($index == 0) ? 't.name LIKE :tag' $index ' OR t.name LIKE :tag' $index;
  432.         }
  433.         $queryBuilder->andWhere($subQuery);
  434.         $articleCollection $queryBuilder->getQuery()->getResult();
  435.         return (!empty($articleCollection)) ? $articleCollection : [];
  436.     }
  437.     
  438.     public function getArticleAuthorDetails($articleId null$companyId null)
  439.     {
  440.         if (empty($articleId))
  441.             throw new \Exception('Article::getArticleAuthorDetails() expects parameter 1 to be defined.');
  442.         $queryBuilder $this->getEntityManager()->createQueryBuilder()
  443.             ->select('ud')
  444.             ->from(CoreEntites\UserInstance::class, 'ud')
  445.             ->leftJoin(SupportEntites\ArticleHistory::class, 'ah''WITH''ah.userId = ud.user')
  446.             ->where('ah.articleId = :articleId')->setParameter('articleId'$articleId)
  447.             // ->andWhere('ud.companyId = :companyId')->setParameter('companyId', $companyId)
  448.             ->andWhere('ud.supportRole != :userRole')->setParameter('userRole'4)
  449.             ->orderBy('ah.dateAdded''ASC')
  450.             ->setMaxResults(1);
  451.         $articleAuthorCollection $queryBuilder->getQuery()->getResult();
  452.         if (!empty($articleAuthorCollection) && count($articleAuthorCollection) > 1) {
  453.             // Parse through the collection and priorotize entity which have the designation field. This case
  454.             // will occur when the user is mapped with more than one userData entity with differing userRoles.
  455.             // If none is found, return the very first element in collection. It doesn't matter then.
  456.             $defaultArticleAuthor $articleAuthorCollection[0];
  457.             foreach ($articleAuthorCollection as $articleAuthor) {
  458.                 if (!empty($articleAuthor->getJobTitle())) {
  459.                     $defaultArticleAuthor $articleAuthor;
  460.                     break;
  461.                 }
  462.             }
  463.             return (!empty($defaultArticleAuthor)) ? $defaultArticleAuthor $articleAuthorCollection[0];
  464.         } else {
  465.             return (!empty($articleAuthorCollection)) ? $articleAuthorCollection[0] : null;
  466.         }
  467.     }
  468.     /**
  469.     * search company articles by keyword and returns articles array
  470.     *
  471.     * @param string $keyword
  472.     *
  473.     * @return array Articles
  474.     */
  475.     public function SearchCompanyArticles($company$keyword)
  476.     {
  477.         $qb $this->getEntityManager()->createQueryBuilder()
  478.             ->select('a')
  479.             ->from('SupportCenterBundle:Article''a')
  480.             // ->leftJoin('SupportCenterBundle:ArticleTags', 'at', 'WITH', 'at.articleId = a.id')
  481.             ->where('a.companyId = :companyId')->setParameter('companyId'$company->getId())
  482.             ->andwhere('a.status = :status')->setParameter('status'1)
  483.             ->andWhere('a.name LIKE :keyword OR a.slug LIKE :keyword OR a.content LIKE :keyword')->setParameter('keyword''%' $keyword '%')
  484.             ->orderBy(
  485.                 'a.dateUpdated'
  486.             );
  487.         $articles $qb->getQuery()->getArrayResult();
  488.         return $articles;
  489.     }
  490.     public function getArticleFeedbacks($article)
  491.     {
  492.         $response = ['positiveFeedbacks' => 0'negativeFeedbacks' => 0'collection' => []];
  493.         $nativeQuery strtr('SELECT user_id, is_helpful, description FROM uv_article_feedback WHERE article_id = {ARTICLE_ID}', [
  494.             '{ARTICLE_ID}' => $article->getId(),
  495.         ]);
  496.         $preparedDBStatment $this->getEntityManager()->getConnection()->prepare($nativeQuery);
  497.         $preparedDBStatment->execute();
  498.         $feedbackCollection $preparedDBStatment->fetchAll();
  499.         if (!empty($feedbackCollection)) {
  500.             $response['collection'] = array_map(function($feedback) {
  501.                 return ['user' => $feedback['user_id'], 'direction' => ((int) $feedback['is_helpful'] === 1) ? 'positive' 'negative''feedbackMessage' => $feedback['description']];
  502.             }, $feedbackCollection);
  503.             $ratings array_count_values(array_column($response['collection'], 'direction'));
  504.             $response['positiveFeedbacks'] = !empty($ratings['positive']) ? $ratings['positive'] : 0;
  505.             $response['negativeFeedbacks'] = !empty($ratings['negative']) ? $ratings['negative'] : 0;
  506.         }
  507.         return $response;
  508.     }
  509.     
  510.     public function getPopularTranslatedArticles($locale)
  511.     {
  512.         $qb $this->getEntityManager()->createQueryBuilder()
  513.             ->select('a.id''a.name''a.slug''a.content''a.stared')
  514.             ->from($this->getEntityName(), 'a')
  515.             ->andwhere('a.status = :status')
  516.             ->setParameter('status'1)
  517.             ->addOrderBy('a.viewed'Criteria::DESC)
  518.             ->setMaxResults(10);
  519.        
  520.         return $qb->getQuery()->getArrayResult();
  521.     }
  522. }