src/NCBS/WebsiteBundle/Controller/ExpositionController.php line 133

Open in your IDE?
  1. <?php
  2. namespace NCBS\WebsiteBundle\Controller;
  3. use Doctrine\ORM\EntityManager;
  4. use Doctrine\ORM\Query\ResultSetMapping;
  5. use NCBS\WebsiteBundle\Controller\SearchController;
  6. use NCBS\WebsiteBundle\Entity\Exposition;
  7. use NCBS\WebsiteBundle\Tools\DataAssembly;
  8. use NCBS\WebsiteBundle\Tools\PostgresSearch;
  9. use Symfony\Component\HttpFoundation\Response;
  10. use Symfony\Component\HttpFoundation\Request;
  11. class ExpositionController extends NCBSWController
  12. {
  13.   
  14.     protected $prefix 'Exposition';
  15.     // Overriding this to automatically pass list of Swedenborg works to every template
  16.     // (easier to program than trying to figure out which ones need it and which don't)
  17.     public function renderView($view, array $parameters = array(), Response $response null)
  18.     {    
  19.         return parent::renderView($view$parameters$response);
  20.     }
  21.     // Given a Work or Translation, checks whether it would be better to view as some other entity type
  22.     // (currently can redirect only to concepts)
  23.     // Returns null if no redirect is necessary or a null argument is provided, or false if an unknown argument type is supplied
  24.     // Otherwise, returns url to redirect to
  25.     protected function checkRedirect($target)
  26.     {
  27.    /*     if($target === null) {
  28.             return null;
  29.         } elseif($target instanceof Exposition\Translation) {
  30.             $targetTranslation = $target;
  31.         } elseif($target instanceof Exposition\Work) {
  32.             $targetTranslation = $target->selectTranslation();
  33.         } else {
  34.             return null;
  35.         }
  36.         
  37.         if($targetTranslation == null)
  38.             return null;
  39.             
  40.         $sConceptUrl = $this->checkConcept($targetTranslation->getId());    
  41.         if(!empty($sConceptUrl))
  42.         {
  43.             $url = $this->get('router')->generate('concept', array(
  44.                     'conceptUrl' => $sConceptUrl
  45.                 ));
  46.                 
  47.             $args = @$_SERVER['QUERY_STRING'];
  48.             if(!empty($args)) 
  49.             {                
  50.                 $url .= '?'.$args;                   
  51.             } 
  52.             
  53.             return $url;
  54.         }    */
  55.                     
  56.         return null;
  57.     }
  58.     protected function selectSelectorList($work$languageName 'English'$currentTranslation null)
  59.     {
  60.         if($work === null) {
  61.             return null;
  62.         }
  63.         if($work->getSwedenborgType() !== null) {
  64.             return $this->buildSwedenborgSelectorList($languageName$currentTranslation);
  65.         }
  66.         $list = array();
  67.         foreach($work->getCategories() as $category) {
  68.             if($category->getIndexPage() !== null) {
  69.                 $catName $category->getName();
  70.                 $list[$catName] = array();
  71.                 foreach($category->getWorks() as $w) {
  72.                     $t $w->selectTranslation($languageName);
  73.                     if($t != null)
  74.                         $list[$catName][$t->getTranslatedTitle()] = ($work == $w) ? null $t;
  75.                 }
  76.                 ksort($list[$catName]);
  77.             }
  78.         }
  79.         if(empty($list)) {
  80.             return null;
  81.         } else {
  82.             return $list;
  83.         }
  84.     }
  85.     protected function buildSwedenborgSelectorList($languageName 'English'$currentTranslation null)
  86.     {
  87.         $allWorks $this->expositionData('Work')->findByIsPublic(true);
  88.         $swedenborgBooks = array(
  89. //            'Published Theological Works' => array(),
  90. //            'Posthumous Theological Works' => array(),
  91. //            'Pre-Revelatory Works' => array()
  92.         );
  93.         foreach($allWorks as $work) {
  94.             if($work->getSwedenborgType() !== null) {
  95.                 if($currentTranslation !== null && $currentTranslation->getWork() == $work) {
  96.                     $translation $currentTranslation;
  97.                 } else {
  98.                     $translation $work->selectTranslation($languageName);
  99.                 }
  100.                 if($translation !== null) {
  101.                     $title $translation->getTranslatedTitle();
  102.                     $swedenborgBooks[$title] = $translation;
  103. /*
  104.                     if($work->getSwedenborgType() == 'published revelatory') {
  105.                         $swedenborgBooks['Published Theological Works'][$title] = $translation;
  106.                     } elseif($work->getSwedenborgType() == 'posthumous revelatory') {
  107.                         $swedenborgBooks['Posthumous Theological Works'][$title] = $translation;
  108.                     } else { // 'published pre-revelatory' or 'posthumous pre-revelatory'
  109.                         $swedenborgBooks['Pre-Revelatory Works'][$title] = $translation;
  110.                     }
  111. */
  112.                 }
  113.             }
  114.         }
  115.         ksort($swedenborgBooks);
  116. //        ksort($swedenborgBooks['Published Theological Works']);
  117. //        ksort($swedenborgBooks['Posthumous Theological Works']);
  118. //        ksort($swedenborgBooks['Pre-Revelatory Works']);
  119.         return array("Swedenborg's Theological Works" => $swedenborgBooks);
  120.     }
  121.     public function swedenborgIndexAction(Request $request)
  122.     {
  123.     /*    
  124.         $locale = $request->getLocale();
  125.         $nLanguageID = $this->getLanguageIDByShortCode($locale);
  126.         return $this->renderView('index/swedenborg', array(          
  127.             'selector_data' => $this->getCategorizedSwedenborgWorks($request, $nLanguageID),
  128.             'illustration' => $this->getRepository('Media\Image')->findOneByFile('quill-pen.jpg'),
  129.             'index_path' => 'swedenborg'
  130.         )); */
  131.         
  132.         $this->setCurrentUrl($request); 
  133.         $this->onloadPage($request);
  134.         $locale $request->getLocale();
  135.         $nLocaleLanguageID $this->getLanguageIDByShortCode($locale);
  136.         
  137.         $nSelectedLangID $request->query->get('l');
  138.         
  139.         return $this->renderView('index/swedenborg', array(          
  140.             'works' => $this->getSwedenborgWorks($request$nLocaleLanguageID$nSelectedLangID),
  141.             'works2' => $this->getSwedenborgWorks2($request$nLocaleLanguageID$nSelectedLangID),
  142.             'languages' => $this->getSwedenborgWorkLanguages($request),
  143.             'selected_language_id' => $nSelectedLangID,
  144.             'search_domain' => 'w'
  145.         ));
  146.     }
  147.     public function conceptsIndexAction(Request $request)
  148.     {        
  149.         $this->setCurrentUrl($request); 
  150.         $this->onloadPage($request);
  151.         return $this->renderView('index/concepts', array('index_path' => 'concepts''selector_data' => array('Bible Words Explained' => $conceptSelection)));
  152.     }
  153.         
  154.     public function considerIndexAction(Request $request)
  155.     {                       
  156.         $this->setCurrentUrl($request); 
  157.         $this->onloadPage($request);
  158.         $locale $request->getLocale();
  159.         $aPathway $this->getTopPathList($locale);
  160.         return $this->renderView('index/spiritual_topics', array(     
  161.             'pathway_list' => $aPathway            
  162.         ));
  163.     }
  164.     public function educationalMaterialsIndexAction(Request $request)
  165.     {
  166.         $this->setCurrentUrl($request); 
  167.         $this->onloadPage($request);
  168.         $categoryUrls = array('vineyard-collection-concept-articles');
  169.         $selectorData = array();
  170.         foreach($categoryUrls as $url) {
  171.             $category $this->expositionData('Category')->findOneByUrl($url);
  172.             $selectorData[$category->getName()] = $this->singleCategorySelectorData($category);
  173.         }
  174.         return $this->renderView('index/educational_materials', array(
  175.             'index_path' => 'educational_materials',
  176.             'selector_data' => $selectorData,
  177.             'illustration' => $this->getRepository('Media\Image')->findOneByFile('nc-vineyard.jpg')
  178.         ));
  179.     }
  180.     function singleCategorySelectorData($category)
  181.     {
  182.         if($category === null) {
  183.             return array();
  184.         }
  185.         $categoryData = array();
  186.         foreach($category->getWorks() as $work) {
  187.             $translation $work->selectTranslation();
  188.             $categoryData[$translation->getTranslatedTitle()] = $translation;
  189.         }
  190.         foreach($category->getTranslations() as $translation) {
  191.             $categoryData[$translation->getTranslatedTitle()] = $translation;
  192.         }
  193.         ksort($categoryData);
  194.         return $categoryData;
  195.     }
  196.     public function categoryAction($categoryUrlRequest $request)
  197.     {
  198.         $category $this->expositionData('Category')->findOneByUrl($categoryUrl);
  199.         $response null;
  200.         if($category === null) {
  201.             $response = new Response();
  202.             $response->setStatusCode(404);
  203.             return $this->renderView('no_work_content', array(), $response);
  204.         }
  205.         $this->setCurrentUrl($request); 
  206.         $this->onloadPage($request);
  207.         return $this->renderView('category', array('category' => $category), $response);
  208.     }
  209.     // Note: If $passageSeparator is null (e.g. due to being unspecified) then the template file will use <p></p> tags to separate passages
  210.     public function excerptAction($excerptIdRequest $request$translationUrl null$textUnitSeparator "\n"$passageSeparator null$userSelected false)
  211.     {
  212.         $excerpt $this->expositionData('Excerpt')->findOneById($excerptId);
  213.         if($excerpt === null) {
  214.             $response = new Response();
  215.             $response->setStatusCode(404);
  216.             return $this->renderView('no_work_content', array(), $response);
  217.         }
  218.         
  219.         if($translationUrl === null) {
  220.             $translation $excerpt->getStartArea()->getTranslation();
  221.         } else {
  222.             $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  223.         }
  224.         if($userSelected) {
  225.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  226.         }
  227.         $translationId $translation->getId();
  228.         $excerptPassages = array();
  229.         $startTextArea $excerpt->getStartArea();
  230.         $endTextArea $excerpt->getEndArea();
  231.         if($startTextArea->getId() === $endTextArea->getId()) {
  232.             // Entire excerpt is in a single text unit
  233.             if($excerpt->getStartChar() > $excerpt->getEndChar()) {
  234.                 // Error! Invalid Excerpt: Start character comes after end character
  235.             }
  236.             $excerptPassages[] = substr($startTextArea->getText(), $excerpt->getStartChar(), 1+$excerpt->getEndChar()-$excerpt->getStartChar());
  237.         } else {
  238.             $startTextUnit $startTextArea->getPlacement();
  239.             $startPassage $startTextUnit->getPassage();
  240.             $endTextUnit $endTextArea->getPlacement();
  241.             $endPassage $endTextUnit->getPassage();
  242.             if($startPassage->getId() == $endPassage->getId()) {
  243.                 // Entire excerpt is in a single passage
  244.                 $startTextOrdering $startTextUnit->getOrdering();
  245.                 $endTextOrdering $endTextArea->getOrdering();
  246.                 if($startTextOrdering $endTextOrdering) {
  247.                     // Error! Invalid Excerpt: Start text unit comes after end text unit
  248.                 }
  249.                 $text substr($startTextArea->getText(), $excerpt->getStartChar());
  250.                 foreach($startPassage->getTextUnits() as $textUnit) {
  251.                     if($textUnit->getOrdering() > $startTextOrdering && $textUnit->getOrdering() < $endTextOrdering) {
  252.                         $text .= $textUnitSeparator.$textUnit->findTranslatedVersion($translationId)->getText();
  253.                     }
  254.                 }
  255.                 $text .= $textUnitSeparator.substr($endTextArea->getText(), 0$excerpt->getEndChar() + 1);
  256.                 $excerptPassages[] = $text;
  257.             } else {
  258.                 $startText substr($startTextArea->getText(), $excerpt->getStartChar());
  259.                 foreach($startPassage->getTextUnits() as $textUnit) {
  260.                     if($textUnit->getOrdering() > $startTextUnit->getOrdering()) {
  261.                         $startText .= $textUnitSeparator.$textUnit->findTranslatedVersion($translationId)->getText();
  262.                     }
  263.                 }
  264.                 $excerptPassages[] = $startText;
  265.                 // Add text for intermediate passages
  266.                 for($currentPassage $startPassage->findNextPassage(); $currentPassage != null && $currentPassage->getId() != $endPassage->getId(); $currentPassage $currentPassage->findNextPassage()) {
  267.                     $excerptPassages[] = $currentPassage->textInTranslation($translationId);
  268.                 }
  269.                 if($currentPassage == null) {
  270.                     // Error! Invalid Excerpt: End passage can't be reached by moving forward from start passage
  271.                 }
  272.                 // Build text for end of passage
  273.                 $endText "";
  274.                 foreach($endPassage->getTextUnits() as $textUnit) {
  275.                     if($textUnit->getOrdering() < $endTextUnit->getOrdering()) {
  276.                         $endText .= $textUnit->findTranslatedVersion($translationId)->getText().$textUnitSeparator;
  277.                     }
  278.                 }
  279.                 $endText .= substr($endTextArea->getText(), 0$excerpt->getEndChar() + 1);
  280.                 $excerptPassages[] = $endText;
  281.             }
  282.         }
  283.         $excerptData = array(
  284.             'excerpt' => $excerpt,
  285.             'excerpt_passages' => $excerptPassages,
  286.             'passage_separator' => $passageSeparator,
  287.             'nav_mode' => 'translation'
  288.         );
  289.         if($translation->getWork()->getSwedenborgType() !== null) {
  290.             $excerptData['selector_data'] = $this->buildSwedenborgSelectorList($translation->getLanguage()->getName(), $translation);
  291.         }
  292.         $this->setCurrentUrl($request); 
  293.         $this->onloadPage($request);
  294.         return $this->renderView('excerpt'$excerptData);
  295.     } // end function excerptAction
  296.     public function workIndexAction($workUrlRequest $request)
  297.     {
  298.         $this->onloadPage($request);
  299.         $work $this->expositionData('Work')->findOneBy(array('url' => $workUrl'isPublic' => true));
  300.         
  301.         $translation = ($work === null) ? null $work->selectTranslation();
  302.         if($translation === null) {
  303.             $response = new Response();
  304.             $response->setStatusCode(404);
  305.             return $this->renderView('no_work_content', array(), $response);
  306.         }
  307.         else 
  308.         {      
  309.             $this->setCurrentUrl($request);            
  310.             $translationUrl $translation->getUrl(); 
  311.             return $this->redirect($this->get('router')->generate('exposition_translation_index', array(
  312.                     'translationUrl' => $translationUrl
  313.                 )), 301);            
  314.         }
  315.     }
  316.    
  317.     public function workPassageAction($workUrlRequest $request$passageId null)
  318.     {
  319.         $this->onloadPage($request);
  320.         $work $this->expositionData('Work')->findOneBy(array('url' => $workUrl'isPublic' => true));
  321.         if($work === null) {
  322.             $response = new Response();
  323.             $response->setStatusCode(404);
  324.             return $this->renderView('no_work_content', array(), $response);
  325.         }
  326.         
  327.         $redir $this->checkRedirect($work);
  328.         if($redir !== null) {
  329.             return $this->redirect($redir301);
  330.         }
  331.                      
  332.          $locale $request->getLocale();
  333.          $aTranslation $this->getTranslationInfo($workUrl,$locale,$passageId);         
  334.         if(empty($aTranslation)) {
  335.             $response = new Response();
  336.             $response->setStatusCode(404);
  337.             return $this->renderView('no_work_content', array(), $response);
  338.         }
  339.         else 
  340.         {       
  341.             $this->setCurrentUrl($request);             
  342.             $translationUrl $aTranslation['translation_url'];
  343.             $divisionUrl $aTranslation['division_url'];
  344.             $passageNum $aTranslation['passage_order'];
  345.             return $this->redirect($this->get('router')->generate('exposition_translation_division_passage', array(
  346.                     'translationUrl' => $translationUrl,
  347.                     'divisionUrls' => $divisionUrl,
  348.                     'passageNumber' => $passageNum
  349.                 )), 301);        
  350.         }    
  351.     }
  352.     public function workDivisionPassageAction($workUrl$divisionUrlsRequest $request$passageNumber null)
  353.     {
  354.         $this->onloadPage($request);
  355.         $work $this->expositionData('Work')->findOneBy(array('url' => $workUrl'isPublic' => true));
  356.         $redir $this->checkRedirect($work);
  357.         if($redir !== null) {
  358.             return $this->redirect($redir301);
  359.         }
  360.         // Google seems to still be indexing results from /contents/<ordering> in Arcana Coelestia, so we'll redirect those to the URLs that are used for it now
  361.  /*       if($work !== null && $work->getUrl() === 'arcana-coelestia' && $divisionUrls === 'contents' && $passageNumber !== null && substr($passageNumber, -1) === '0') {
  362.             $passage = $this->expositionData('Passage')->findSwedenborgSection($work, substr($passageNumber, 0, -1));
  363.             return $this->passageCanonicalRedirect($passage);
  364.         } */
  365.         $passage $this->findPassageByWorkAndDivisions($work$divisionUrls$passageNumber);        
  366.         $translation = ($work === null) ? null $work->selectTranslation();
  367.         if($translation === null) {
  368.             $response = new Response();
  369.             $response->setStatusCode(404);
  370.             return $this->renderView('no_work_content', array(), $response);
  371.         }
  372.         else 
  373.         {      
  374.             $this->setCurrentUrl($request);            
  375.             $translationUrl $translation->getUrl(); 
  376.             if($passageNumber != null)
  377.             {
  378.                 return $this->redirect($this->get('router')->generate('exposition_translation_division_passage', array(
  379.                     'translationUrl' => $translationUrl,
  380.                     'divisionUrls' => $divisionUrls,
  381.                     'passageNumber' => $passageNumber
  382.                 )), 301);
  383.                 //return $this->redirect('/exposition/translation/'.$translationUrl.'/'.$divisionUrls.'/'.$passageNumber);
  384.             }
  385.             else
  386.             {
  387.                 return $this->redirect($this->get('router')->generate('exposition_translation_division', array(
  388.                     'translationUrl' => $translationUrl,
  389.                     'divisionUrls' => $divisionUrls
  390.                 )), 301);
  391.                 //return $this->redirect('/exposition/translation/'.$translationUrl.'/'.$divisionUrls);
  392.             }    
  393.         }                
  394.     }
  395.     protected function workPassageView($passage$work null$request)
  396.     {
  397.         $this->onloadPage($request);
  398.         if($work === null && $passage !== null) {
  399.             $work $passage->findWork();
  400.         }
  401.         // Once we have user preferences implemented, we should use the user's preferred translation (or the default for the user's preferred language) instead of the original, where applicable
  402.         $translation = ($work === null) ? null $work->selectTranslation();
  403.         
  404.         $sUrlCompareTo $request->query->get('compareTo');
  405.         $aCompare explode(";;"$sUrlCompareTo);
  406.         $nCompareLen count($aCompare);
  407.         $compareTo null;
  408.         $compareTo2 null;        
  409.         if($nCompareLen && $aCompare[0] != '')
  410.             $compareTo $this->expositionData('Translation')->findOneByUrl($aCompare[0]);        
  411.         
  412.         if($nCompareLen == && $aCompare[1] != '')            
  413.             $compareTo2 $this->expositionData('Translation')->findOneByUrl($aCompare[1]);
  414.                
  415.         $data = array(
  416.             'work' => $work,
  417.             'passage' => $passage,
  418.             'translation' => $translation,
  419.             'compare_to' => $compareTo,
  420.             'compare_to2' => $compareTo2,
  421.             'nav_mode' => 'work',
  422.             'text_style_override' => $this->getTextStyleOverride($translation->getLanguage()->getId())
  423.         );
  424.    /*     $selectorData = $this->selectSelectorList($work);
  425.         if($selectorData !== null) {
  426.             $data['selector_data'] = $selectorData;
  427.         } */
  428.         $this->setCurrentUrl($request);         
  429.         return $this->createPassageView($data'work'$work$request);
  430.     }
  431.     public function workDivisionAction($workUrl$divisionUrls)
  432.     {
  433.         $this->onloadPage($request);
  434.         $work $this->expositionData('Work')->findOneBy(array('url' => $workUrl'isPublic' => true));
  435.         $translation = ($work === null) ? null $work->selectTranslation();
  436.         if($translation === null) {
  437.             $response = new Response();
  438.             $response->setStatusCode(404);
  439.             return $this->renderView('no_work_content', array(), $response);
  440.         }
  441.         else 
  442.         {      
  443.             $this->setCurrentUrl($request);             
  444.             $translationUrl $translation->getUrl(); 
  445.             return $this->redirect($this->get('router')->generate('exposition_translation_division', array(
  446.                     'translationUrl' => $translationUrl,
  447.                     'divisionUrls' => $divisionUrls
  448.                 )), 301);
  449.             //return $this->redirect('/exposition/translation/'.$translationUrl.'/'.$divisionUrls);
  450.         
  451.     }
  452.     public function collectionIndexAction($collectionUrlRequest $request)
  453.     {
  454.         $this->onloadPage($request);
  455.         $collection $this->expositionData('Collection')->findOneByUrl($collectionUrl);
  456.         $response null;
  457.         if($collection === null) {
  458.             $response = new Response();
  459.             $response->setStatusCode(404);
  460.             return $this->renderView('no_work_content', array(), $response);
  461.         }
  462.         $this->setCurrentUrl($request);         
  463.         return $this->renderView('collection_index', array('collection' => $collection), $response);
  464.     }
  465.     public function translationIndexAction($translationUrlRequest $request$userSelected true)
  466.     {
  467.         $this->onloadPage($request);
  468.         $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  469.         $response null;
  470.         if($translation === null) {
  471.             $response = new Response();
  472.             $response->setStatusCode(404);
  473.             return $this->renderView('no_work_content', array(), $response);
  474.         }
  475.             
  476.         if($userSelected && $translation !== null) {
  477.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  478.         }
  479.         $data = array('translation' => $translation'nav_mode' => 'translation');
  480.         
  481.         $type_id $translation->getTypeId();
  482.         
  483.         if($type_id == $this->TRANSLATION_TYPE_ID_FILE
  484.         {
  485.             $file $translation->getFile();
  486.             if($file !== null) {
  487.                 $data['file'] = $file;
  488.             }
  489.         }
  490.         if($type_id == $this->TRANSLATION_TYPE_ID_LINK// link
  491.         {
  492.             $doc_link $translation->getDocLink();
  493.             if($doc_link !== null) {
  494.                 $data['doc_link'] = $doc_link;
  495.             }
  496.         }
  497.         
  498.         $data['type_id'] = $type_id;
  499.         
  500.         $nTransID $translation->getId();
  501.         $data['biblio'] = $this->getBiblio($nTransID$translation->getIsOriginal());
  502.         $data['work_biblio_orig'] = null;
  503.         if(!$translation->getIsOriginal())
  504.             $data['work_biblio_orig'] = $this->getBiblioOriginal($nTransID);
  505.             
  506.         $data['translation_index'] = '1';    
  507.         
  508.         $this->setCurrentUrl($request);         
  509.         return $this->renderView('translation_index'$data$response);
  510.     }
  511.     
  512.     public function translationPassageAction($translationUrlRequest $request$passageId null$userSelected true$inFrame false)
  513.     {
  514.         $this->onloadPage($request);
  515.         $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  516.          if($translation == null) {
  517.             $response = new Response();
  518.             $response->setStatusCode(404);
  519.             return $this->renderView('no_work_content', array(), $response);
  520.         }
  521.         
  522.         if($userSelected && $translation !== null) {
  523.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  524.         }
  525.         $redir $this->checkRedirect($translation);
  526.         if($redir !== null) {
  527.             return $this->redirect($redir301);
  528.         }
  529.         $passage = ($passageId !== null)
  530.             ? $this->expositionData('Passage')->findOneById($passageId)
  531.             : (($translation !== null) ? $translation->getWork()->findFirstNonEmptyPassage($translation) : null);
  532.  /*       if($passage !== null && $passage->findWork() === $translation->getWork()) {
  533.             return $this->passageCanonicalRedirect($passage, $translation);
  534.         } */
  535.         
  536.         if(!$inFrame)
  537.             $this->setCurrentUrl($request); 
  538.                         
  539.         return $this->translationPassageView($passage$translation$request$inFrame);
  540.     }
  541.     public function translationDivisionPassageAction($translationUrl$divisionUrlsRequest $request$passageNumber null$userSelected true$inFrame false)
  542.     {
  543.         $this->onloadPage($request);
  544.         $response null;
  545.         if(strlen($passageNumber) > 8) {
  546.             $response = new Response();
  547.             $response->setStatusCode(404);
  548.             return $this->renderView('no_work_content', array(), $response);
  549.         }
  550.         
  551.         if(!$this->IsSwedenborgWork($translationUrl))
  552.         {
  553.             return $this->redirect($this->get('router')->generate('exposition_translation', array(
  554.                     'translationUrl' => $translationUrl
  555.                 )), 301);
  556.         }
  557.     
  558.         $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  559.         if($translation == null) {
  560.             $response = new Response();
  561.             $response->setStatusCode(404);
  562.             return $this->renderView('no_work_content', array(), $response);
  563.         }
  564.         
  565.         if($userSelected && $translation !== null) {
  566.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  567.         }
  568.         $redir $this->checkRedirect($translation);
  569.         if($redir !== null) {
  570.             return $this->redirect($redir301);
  571.         }
  572.         $work = ($translation === null) ? null $translation->getWork();
  573.         
  574.         if(!$work->getIsPublic()) {
  575.             $response = new Response();
  576.             $response->setStatusCode(404);
  577.             return $this->renderView('no_work_content', array(), $response);
  578.         }
  579.         // Google seems to still be indexing results from /contents/<ordering> in Arcana Coelestia, so we'll redirect those to the URLs that are used for it now
  580.         if($work !== null && $work->getUrl() === 'arcana-coelestia' && $divisionUrls === 'contents' && $passageNumber !== null && substr($passageNumber, -1) === '0') {
  581.             $passage $this->expositionData('Passage')->findSwedenborgSection($worksubstr($passageNumber0, -1));
  582.             return $this->passageCanonicalRedirect($passage$translation);
  583.         }
  584.         $passage $this->findPassageByWorkAndDivisions($work$divisionUrls$passageNumber);
  585.         
  586.         if(!$inFrame)
  587.             $this->setCurrentUrl($request); 
  588.             
  589.         return $this->translationPassageView($passage$translation$request$inFrame);
  590.     }
  591.     protected function translationPassageView($passage$translation$request$inFrame false)
  592.     {    
  593.         $this->checkIfOnMobile($request);        
  594.         $locale $request->getLocale();
  595.         $nTranslationID $translation->getId();
  596.         $sUrlCompareTo $request->query->get('compareTo');
  597.         $aCompare explode(";;"$sUrlCompareTo);
  598.         $nCompareLen count($aCompare);
  599.         $compareTo null;
  600.         $compareTo2 null;    
  601.         $text_to_speech2 null;
  602.         $text_to_speech3 null;
  603.         $text_style_override_compare_to null;   
  604.         $text_style_override_compare_to2 null
  605.         $translation_shortname2 null;
  606.         $translation_shortname3 null;
  607.         if($nCompareLen && $aCompare[0] != '')
  608.         {
  609.             $compareTo $this->expositionData('Translation')->findOneBy(array('url' => $aCompare[0], 'isPublic' => true));   
  610.             if($compareTo != null)    
  611.             {
  612.                 $nLanguageID2 $compareTo->getLanguage()->getId();
  613.                 $text_style_override_compare_to $this->getTextStyleOverride($nLanguageID2);
  614.                 $text_to_speech2 $this->getTextToSpeech($nLanguageID2);
  615.                 
  616.                 $translation_shortname2 $this->getWorkTranslationShortName($compareTo->getId());                
  617.             }    
  618.         }         
  619.         
  620.         if($nCompareLen == && $aCompare[1] != ''
  621.         {           
  622.             $compareTo2 $this->expositionData('Translation')->findOneBy(array('url' => $aCompare[1], 'isPublic' => true)); 
  623.             if($compareTo2 != null)    
  624.             {
  625.                 $nLanguageID3 $compareTo2->getLanguage()->getId();
  626.                 $text_style_override_compare_to2 $this->getTextStyleOverride($nLanguageID3);
  627.                 $text_to_speech3 $this->getTextToSpeech($nLanguageID3);
  628.                 $translation_shortname3 $this->getWorkTranslationShortName($compareTo2->getId());
  629.             }    
  630.         }    
  631.         
  632.         $bSwedenborg $this->isSwedenborg($nTranslationID);
  633.         $chapterExplanations null;
  634.         $chapterExplanationsForCombo null;
  635.         $prev_chapter_explanation = array();
  636.         $next_chapter_explanation = array();
  637.         $explained_cbook_id null;
  638.         if(!$bSwedenborg)
  639.         {    
  640.             $chapterExplanations $this->getChapterExplanationsForNav($translation);       
  641.             $chapterExplanationsForCombo $this->getChapterExplanationsForTextForCombo($translation); 
  642.             
  643.             if(!empty($chapterExplanations))
  644.             {
  645.                 $bHasPass false;
  646.                 foreach($chapterExplanations as $ce)
  647.                 {
  648.                     if($ce['translation_id'] == $nTranslationID)
  649.                         $bHasPass true;
  650.                     else
  651.                     {    
  652.                         if(!$bHasPass)
  653.                         {
  654.                             $prev_chapter_explanation['url'] = $ce['translation_url'];
  655.                             $prev_chapter_explanation['title'] = $ce['explanationtitle'];
  656.                         }    
  657.                         else
  658.                         {
  659.                             $next_chapter_explanation['url'] = $ce['translation_url'];
  660.                             $next_chapter_explanation['title'] = $ce['explanationtitle'];
  661.                             break;
  662.                         }        
  663.                     }                            
  664.                 }
  665.                 
  666.                 $explained_cbook_id $chapterExplanations[0]['book_id'];
  667.             }
  668.         }
  669.         $ref_column_spec '';
  670.         if($bSwedenborg)
  671.             $ref_column_spec $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK;    
  672.         else
  673.             $ref_column_spec $this->MULTI_URL_INDICATOR_EXPLANATION;    
  674.         
  675.         $ref_column_spec .= '_' $translation->getUrl();
  676.         if($passage != null && $bSwedenborg)
  677.             $ref_column_spec .= '_' $passage->getSwedenborgSection();
  678.             
  679.         $nPassageID null;    
  680.         if($passage != null)
  681.             $nPassageID $passage->getId();
  682.             
  683.         $nLanguageID $translation->getLanguage()->getId();      
  684.         $data = array(
  685.             'translation' => $translation,
  686.             'passage' => $passage,
  687.             'compare_to' => $compareTo,
  688.             'compare_to2' => $compareTo2,
  689.             'nav_mode' => 'translation',            
  690.           //  'chapter_explanations' => $chapterExplanations,
  691.             'chapter_explanations_for_combo' => $chapterExplanationsForCombo,
  692.             'prev_chapter_explanation' => $prev_chapter_explanation,
  693.             'next_chapter_explanation' => $next_chapter_explanation,
  694.             'explained_cbook_id' => $explained_cbook_id,
  695.             'ref_column_spec' => $ref_column_spec,
  696.             'text_style_override' => $this->getTextStyleOverride($nLanguageID),
  697.             'text_style_override_compare_to' => $text_style_override_compare_to,
  698.             'text_style_override_compare_to2' => $text_style_override_compare_to2,
  699.             'text_to_speech1' => $this->getTextToSpeech($nLanguageID),
  700.             'text_to_speech2' => $text_to_speech2,
  701.             'text_to_speech3' => $text_to_speech3,            
  702.             'translation_shortname2' => $translation_shortname2,
  703.             'translation_shortname3' => $translation_shortname3            
  704.         );
  705.         
  706.         $data['is_ipad'] = $this->isIPad();
  707.         
  708.         if($translation !== null) {
  709.        /*     $selectorData = $this->selectSelectorList($translation->getWork(), $translation->getLanguage()->getName(), $translation);
  710.             if($selectorData !== null) {
  711.                 $data['selector_data'] = $selectorData;
  712.             } */
  713.             $work $translation->getWork();
  714.             
  715.             $bSwedenborgWork = ($work->getSwedenborgType() !== null);
  716.             $data['is_swedenborg'] = $bSwedenborgWork;
  717.             if($bSwedenborgWork)
  718.             {
  719.                 $data['linktype_id'] = $this->LINK_TYPE_ID_SWEDENBORG;
  720.             }
  721.             else
  722.             {
  723.                 $data['linktype_id'] = $this->LINK_TYPE_ID_OTHER;
  724.             }
  725.             if($bSwedenborgWork && $nLanguageID == $request->getSession()->get('work_search_language_id'))
  726.             {
  727.                 $data['work_searchterm'] = $request->getSession()->get('work_searchterm');
  728.                 $data['work_search_phrase'] = $request->getSession()->get('work_search_phrase');
  729.                 if($nLanguageID == $this->LANGUAGE_ID_LATIN)
  730.                 {
  731.                     $data['work_search_internal_amb'] = $request->getSession()->get('work_search_internal_amb');                    
  732.                     $data['work_search_external_amb'] = $request->getSession()->get('work_search_external_amb');
  733.                     $data['work_search_int_ext_amb'] = $request->getSession()->get('work_search_int_ext_amb');
  734.                 }
  735.                 else
  736.                 {
  737.                     $data['work_search_internal_amb'] = null;
  738.                     $data['work_search_external_amb'] = null;
  739.                     $data['work_search_int_ext_amb'] = null;
  740.                 }
  741.             }
  742.             else
  743.             {
  744.                 $data['work_searchterm'] = null;
  745.                 $data['work_search_phrase'] = null;
  746.                 $data['work_search_internal_amb'] = null;
  747.                 $data['work_search_external_amb'] = null;
  748.                 $data['work_search_int_ext_amb'] = null;
  749.             }
  750.             
  751.             $bConsider false;
  752.             $bBibleStudy false;
  753.             $bConcept false;
  754.             $bQA false;
  755.             $bConcordance false;
  756.             if(!$bSwedenborgWork)
  757.             {
  758.                 foreach($work->getCategories() as $category) {
  759.                     if($category->getId() == $this->CATEGORY_ID_SPIRITUAL_TOPIC) {
  760.                         $bConsider true;
  761.                     }
  762.                     elseif($category->getId() == $this->CATEGORY_ID_BIBLE_STUDY) {
  763.                         $bBibleStudy true;
  764.                     }
  765.                     elseif($category->getId() == $this->CATEGORY_ID_CONCEPT) {
  766.                         $bConcept true;
  767.                         $data['category_concept'] = 1;
  768.                     }
  769.                     elseif($category->getId() == $this->CATEGORY_ID_QA) {
  770.                         $bQA true;
  771.                     }
  772.                     elseif($category->getId() == $this->CATEGORY_ID_CONCORDANCE) {
  773.                         $bConcordance true;
  774.                     }
  775.                 }
  776.             }
  777.             
  778.             $nLanguageID $translation->getLanguage()->getId();
  779.             if($bQA)
  780.             {                
  781.                 $data['prev_next'] = $this->getPrevNextLink($translation->getId(), $this->CATEGORY_ID_QA$request);
  782.             }
  783.             else
  784.             {
  785.                 if($bConsider)
  786.                 {                
  787.                     $aAllTopic = array();
  788.                     $sTranslationUrl $translation->getUrl();
  789.                     $aSearchedTopic $request->getSession()->get('searched_topic_list');
  790.                     if(!empty($aSearchedTopic))
  791.                     {                
  792.                         foreach($aSearchedTopic as $s)
  793.                         {                
  794.                             if($s['translation_url'] == $sTranslationUrl)
  795.                             {
  796.                                 $aAllTopic $aSearchedTopic;
  797.                                 break;
  798.                             }
  799.                         }
  800.                     }
  801.                     
  802.                     if(empty($aAllTopic))
  803.                     {                    
  804.                         $aAllTopic $this->getCategoryList($nLanguageID$this->CATEGORY_ID_SPIRITUAL_TOPIC$locale);
  805.                     }                
  806.                 
  807.                     $data['consider_data'] = $aAllTopic;
  808.                     $data['prev_next'] = $this->getPrevNextLinkFromList($translation->getId(), $data['consider_data']);                    
  809.                 }
  810.                 
  811.                 if($bBibleStudy)
  812.                 {
  813.                     $data['biblestudy_data'] = $this->getCategoryList($nLanguageID$this->CATEGORY_ID_BIBLE_STUDY$locale);
  814.                     $data['prev_next'] = $this->getPrevNextLinkFromList($translation->getId(), $data['biblestudy_data']);                    
  815.                 }
  816.                 
  817.                 if($bConcordance)
  818.                 {            
  819.                     $aAllConcordance = array();
  820.                     $sTranslationUrl $translation->getUrl();
  821.                     $aSearchedConcordance $request->getSession()->get('searched_concordance_list');
  822.                     if(!empty($aSearchedConcordance))
  823.                     {                
  824.                         foreach($aSearchedConcordance as $s)
  825.                         {                
  826.                             if($s['translation_url'] == $sTranslationUrl)
  827.                             {
  828.                                 $aAllConcordance $aSearchedConcordance;
  829.                                 break;
  830.                             }
  831.                         }
  832.                         $data['prev_next'] = $this->getPrevNextLinkFromList($translation->getId(), $aAllConcordance);
  833.                     }
  834.                     if(empty($aAllConcordance))
  835.                     {                    
  836.                         $data['prev_next'] = $this->getNextPrevCategoryUrl($translation->getId(), $nLanguageID$this->CATEGORY_ID_CONCORDANCE$locale);
  837.                     }                
  838.                 }
  839.                 
  840.                 if($bConcept)
  841.                 {                
  842.                     $data['concept_prev_next'] = $this->getNextPrevConceptUrl($translation->getId(), $nLanguageID$locale);
  843.                 }                
  844.             }
  845.                         
  846.             if(!$bSwedenborgWork)                
  847.                 $data['authors'] = $this->getAuthorInfo($request$translation->getId());
  848.             else
  849.                 $data['IsSwedenborgWork'] = 1;    
  850.                 
  851.             $type_id $translation->getTypeId();
  852.         
  853.             if($type_id == $this->TRANSLATION_TYPE_ID_FILE
  854.             {
  855.                 $file $translation->getFile();
  856.                 if($file !== null) {
  857.                     $data['file'] = $file;
  858.                 }
  859.             }
  860.             if($type_id == $this->TRANSLATION_TYPE_ID_LINK
  861.             {
  862.                 $doc_link $translation->getDocLink();
  863.                 if($doc_link !== null) {
  864.                     $data['doc_link'] = $doc_link;
  865.                 }
  866.             }
  867.             
  868.             $data['type_id'] = $type_id;
  869.             
  870.             $data['in_frame'] = $inFrame;
  871.             
  872.             if($passage != null)
  873.             {            
  874.                 $nTranslationID $translation->getId();
  875.                 
  876.                 if(!$bSwedenborgWork)
  877.                     $data['passage_ref'] = $this->getWorkPassageRefs($nPassageID,$nTranslationID$request);
  878.                 
  879.                 if($bSwedenborgWork)
  880.                     $data['related_bible_ref'] = $this->getRelatedBibleRefForWork($nPassageID,$nTranslationID$request);
  881.                 $data['passage_footnote'] = $this->getPassageFootnotes($nPassageID,$nTranslationID);
  882.                 $data['passage_multilink'] = $this->getWorkPassageMultiLink($nPassageID,$nTranslationID$request);
  883.                 if($translation->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN || ($compareTo != null && $compareTo->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN) || ($compareTo2 != null && $compareTo2->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN))
  884.                 {                
  885.                     $data['passage_scanimage'] = $this->getWorkPassageScanImageFileName($nPassageID);
  886.                     $data['define_latin_icon'] = 1;
  887.                 }
  888.                 
  889.            //     $data['work_references'] = $this->getWorkRefForWork($nPassageID, $nLanguageID);
  890.            //     $data['explanation_references'] = $this->getExplanationRefForWork($nPassageID, $nLanguageID);
  891.            //     $data['gced_ref'] = $this->getGCEDRefForWork($nPassageID);
  892.            //     $data['otle_ref'] = $this->getOTLERefForWork($nPassageID);
  893.            //     $data['related_passages'] = $this->getRelatedPassages($nPassageID, $nLanguageID);
  894.                 
  895.                 $request->getSession()->set('current_explanation_cchapter_id''');                
  896.                 $nExplainChapterID $this->getExplainChapterID($nTranslationID$this->getCurrUserID($request)); 
  897.                   if(!empty($nExplainChapterID))
  898.                   {                  
  899.                       $data['cchapter_id'] = $nExplainChapterID;
  900.                     $request->getSession()->set('current_explanation_cchapter_id'$nExplainChapterID); 
  901.                       $request->getSession()->set('current_explanation_translation_id'$nTranslationID);
  902.                   }
  903.                                     
  904.                   if(!$bSwedenborgWork)
  905.                   {
  906.                       if ($this->canEditExplanation($request))                  
  907.                           $data['explanation_translation_id_to_edit'] = $nTranslationID;
  908.                   }    
  909.                   else if ($this->canEditWork($request))
  910.                   {
  911.                       $data['work_translation_id_to_edit'] = $nTranslationID;    
  912.                       $data['work_passage_num_to_edit'] = $passage->getSwedenborgSection();        
  913.                       //$data['has_slider_item_for_work'] = $this->hasSliderItemForWork($nPassageID, $nTranslationID, $request, $nLanguageID);
  914.         
  915.                     $data['slider_url'] = $this->get('router')->generate('exposition_slider', array(
  916.                             'translationId' => $nTranslationID,
  917.                             'passageId' => $nPassageID
  918.                         ));
  919.                   }    
  920.                   
  921.                   if($bSwedenborgWork)
  922.                   {                              
  923.                       $data['has_slider_item_for_work'] = $this->hasSliderItemForWork($nPassageID$nTranslationID$request$nLanguageID);
  924.         
  925.                     $data['slider_url'] = $this->get('router')->generate('exposition_slider', array(
  926.                             'translationId' => $nTranslationID,
  927.                             'passageId' => $nPassageID
  928.                         ));
  929.                     
  930.                     if($passage->emptyInTranslation($translation))
  931.                     {    
  932.                         $data['last_passage_num'] = $this->getLastAvailablePassageNum($nTranslationID);
  933.                     }   
  934.                   }    
  935.                   
  936.                   // check table of contents
  937.                   $aTOC $this->getWorkTranslationTOC($nTranslationIDtrue); 
  938.                   if(!empty($aTOC))
  939.                   {                  
  940.                       $data['has_work_toc'] = true;
  941.                   }              
  942.             }
  943.             $data['text_to_speech'] = $this->getTextToSpeech($translation->getLanguage()->getId());    
  944.             
  945.             if($bSwedenborgWork)   
  946.             {     
  947.                 $data['biblio_info'] = $this->getBiblioForTranslation($translation->getId());
  948.             //    $data['swedenborg_works'] = $this->getCategorizedSwedenborgWorksForTranslation($request, $translation->getId(), $translation->getLanguage()->getId());
  949.             }
  950.             else
  951.             {
  952.                 // check concept image
  953.                 if($compareTo == null)
  954.                 {
  955.                     $conceptUrl $this->getConceptUrl($translation->getWork()->getId());                    
  956.                     if(!empty($conceptUrl))
  957.                     {
  958.                         $concept $this->getRepository('Concepts\Concept')->findOneByUrl($conceptUrl);
  959.                         $illustrations $concept->getIllustrations();
  960.                         $data['image'] = ($illustrations->isEmpty()) ? null $illustrations[0]->getImage();
  961.                     }
  962.                 }
  963.             }    
  964.         } else {
  965.             $work null;
  966.         }
  967.         return $this->createPassageView($data'translation'$work$request);
  968.     }
  969.     public function translationDivisionAction($translationUrl$divisionUrls$userSelected trueRequest $request)
  970.     {
  971.         $this->onloadPage($request);
  972.         $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  973.         if($userSelected) {
  974.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  975.         }
  976.         $redir $this->checkRedirect($translation);
  977.         if($redir !== null) {
  978.             return $this->redirect($redir301);
  979.         }
  980.         $work = ($translation === null) ? null $translation->getWork();
  981.         $division $this->findDivisionByWorkAndUrls($work$divisionUrls);
  982.         $data = array('translation' => $translation'division' => $division'nav_mode' => 'translation');
  983.   /*      $selectorData = $this->selectSelectorList($translation->getWork(), $translation->getLanguage()->getName(), $translation);
  984.         if($selectorData !== null) {
  985.             $data['selector_data'] = $selectorData;
  986.         } */
  987.         $response null;
  988.         if($division === null) {
  989.             $response = new Response();
  990.             $response->setStatusCode(404);
  991.             return $this->renderView('no_work_content', array(), $response);
  992.         }
  993.         $this->setCurrentUrl($request);         
  994.         return $this->renderView('translation_division'$data$response);
  995.     }
  996.     // Final tasks to be performed when rendering a passage, whether accessed via work or via translation
  997.     protected function createPassageView($data$mode$work$request)
  998.     {
  999.         $locale $request->getLocale();
  1000.         $response null;
  1001.         if($work === null || $data['translation'] === null || $data['passage'] === null || $data['passage']->findWork() !== $work) {
  1002.             $response = new Response();
  1003.             $response->setStatusCode(404);
  1004.             return $this->renderView('no_work_content', array(), $response);
  1005.         }
  1006.         
  1007.         $nPassageID $data['passage']->getId();
  1008.         $nTranslationID $data['translation']->getId();
  1009.         $nLanguageID $data['translation']->getLanguage()->getId();
  1010.         $data['translation_shortname'] = $this->getWorkTranslationShortName($nTranslationID);
  1011.         
  1012.         $nBibleBookIDForSummary $this->getBibleBookIDForSummary($nTranslationID);
  1013.         $bBibleBookSummary = ($nBibleBookIDForSummary != '');
  1014.         if($bBibleBookSummary)
  1015.             $data['is_book_summary'] = '1';
  1016.         
  1017.         if($work !== null) {              
  1018.                $nLevelID '';
  1019.                $aStory $this->getStoryInfo($nTranslationID);
  1020.             if(!empty($aStory))
  1021.             {                   
  1022.                 $nStoryID $aStory['story_id'];
  1023.                 $nLevelID $aStory['level_id'];               
  1024.                 if($nLevelID == $this->STORY_LEVEL_ID_BIBLE)
  1025.                 {  
  1026.                     $aAllStory = array();
  1027.             /*        $aSearchedStory = $request->getSession()->get('searched_bible_story_list');
  1028.                     if(!empty($aSearchedStory))
  1029.                     {
  1030.                         $sTranslationUrl = $data['translation']->getUrl();
  1031.                         foreach($aSearchedStory as $s)
  1032.                         {                
  1033.                             if($s['commentary_url'] == $sTranslationUrl)
  1034.                             {
  1035.                                 $aAllStory = $aSearchedStory;
  1036.                                 break;
  1037.                             }
  1038.                         }
  1039.                     }
  1040.                     
  1041.                     if(empty($aAllStory))
  1042.                     {
  1043.                         $aAllStory = $this->getExplainedStoryList($locale);
  1044.                     }
  1045.             //        print_r($aAllStory); */
  1046.                     $data['all_stories'] = $aAllStory;
  1047.                     
  1048.                     $data['story_explanations'] = $this->getWorkListForStory($locale$nStoryID);
  1049.                     $data['commentary_type'] = 'storyexplanation';                                            
  1050.                 }
  1051.                 elseif($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
  1052.                     $data['is_chapter_explanation'] = '1';
  1053.                 elseif($nLevelID == $this->STORY_LEVEL_ID_VERSE)
  1054.                     $data['is_verse_explanation'] = '1';    
  1055.                                
  1056.                 $data['story_id'] = $nStoryID;
  1057.             }  
  1058.             // We can override the 'storyexplanation' commentary type because some "story" explanations are really verse explanations.
  1059.             // There shouldn't be any similar situation with concept explanations, so if we have an associated concept, then we'll skip the category check below.
  1060.             // The reason for not using just the category check and nothing else is in case a work or translation doesn't get put in the appropriate category.
  1061.             if($this->getConceptID($data['translation']->getId()) !== null) {
  1062.                 $data['commentary_type'] = 'conceptexplanation';
  1063.             } else {
  1064.                 $containingCategories $work->getCategories()->toArray();
  1065.                 if($data['translation'] !== null) {
  1066.                     $containingCategories array_merge($containingCategories$data['translation']->getCategories()->toArray());
  1067.                 }
  1068.                 $categoryUrlToCommentaryTypeMap = array(
  1069.                     'doctrinal-topic-explanations' => 'doctrinaltopic',
  1070.                     'verse-explanations' => 'verseexplanation',
  1071.                     // The story-explanation category doesn't exist at the time of writing this as far as I know, but if it gets added later then we'll want this
  1072.                     'story-explanations' => 'storyexplanation'
  1073.                 );
  1074.                 // If the content doesn't belong to the Category for any major commentary type, then $data['commentary_type'] can just remain unset.
  1075.                 foreach($containingCategories as $cat) {
  1076.                     if(array_key_exists($cat->getUrl(), $categoryUrlToCommentaryTypeMap)) {
  1077.                         $data['commentary_type'] = $categoryUrlToCommentaryTypeMap[$cat->getUrl()];
  1078.                         // At the time of coding this, there shouldn't be anything which belongs to more than one major commentary type.
  1079.                         break;
  1080.                     }
  1081.                 }
  1082.             }
  1083.         }
  1084.                 
  1085.         if($work->getSwedenborgType() !== null)
  1086.         {              
  1087.             $data['previous_passage'] = $this->getPreviousPassageWithContent($data['passage'], $data['translation']);
  1088.             $data['next_passage'] = $this->getNextPassageWithContent($data['passage'], $data['translation']); 
  1089.             
  1090.             // Get meta description
  1091.             $nTextLength 140;            
  1092.             $sPassageText $this->getWorkPassageContents($nPassageID,$nTranslationID); 
  1093.             $sMetaDesc $this->fixWorkText($sPassageText);
  1094.               $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength"...");          
  1095.               $data['work_meta_desc'] = $sMetaDesc;
  1096.         } 
  1097.         else
  1098.         {
  1099.             // Get meta description
  1100.             $nTextLength 140;
  1101.             $sPassageText '';
  1102.             if($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
  1103.             {            
  1104.                 $sPassageText $this->getWorkPassageContents($nPassageID,$nTranslationID);
  1105.             }
  1106.             else
  1107.             {
  1108.                 $sPassageText $this->getWorkTranslationDesc($nTranslationID); 
  1109.                 if(empty($sPassageText))
  1110.                 {
  1111.                     $sPassageText $this->getWorkPassageContents($nPassageID,$nTranslationID); 
  1112.                 }
  1113.             }
  1114.             $sMetaDesc $this->fixWorkText($sPassageText);
  1115.               $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength"...");          
  1116.               $data['work_meta_desc'] = $sMetaDesc;
  1117.         }      
  1118.         
  1119.         $data['work'] = $work;
  1120.                      
  1121.         return $this->renderView($mode.'_passage'$data$response);
  1122.     }
  1123.     protected function findDivisionByWorkAndUrls($work$divisionUrls)
  1124.     {
  1125.         if($work === null) {
  1126.             return null;
  1127.         }
  1128.         $divisionUrlList explode('/'$divisionUrls);
  1129.         $divisionData $this->expositionData('Division');
  1130.         $division $divisionData->findOneBy(array(
  1131.             'work' => $work->getId(), 'url' => array_shift($divisionUrlList)));
  1132.         foreach($divisionUrlList as $url) {
  1133.             if($division === null) {
  1134.                 return null;
  1135.             }
  1136.             $division $divisionData->findOneBy(array('superdivision' => $division->getId(), 'url' => $url));
  1137.         }
  1138.         return $division;
  1139.     }
  1140.     protected function findPassageByWorkAndDivisions($work$divisionUrls$passageNumber null)
  1141.     {
  1142.         $division $this->findDivisionByWorkAndUrls($work$divisionUrls);
  1143.         if($division === null) {
  1144.             return null;
  1145.         }
  1146.         return ($passageNumber === null)
  1147.             ? $division->findFirstPassage()
  1148.             : $this->expositionData('Passage')->findOneBy(array(
  1149.                 'division' => $division->getId(),
  1150.                 'ordering' => $passageNumber
  1151.             ));
  1152.     }
  1153.     public function conceptAction($conceptUrlRequest $request$languageCode ''$asOverlay false)
  1154.     {
  1155.       // $memcache = $this->get('cache');  // it's actually apccache, but behaves the same way
  1156.       // $apccache = $this->get('cache');    
  1157.       
  1158.           // The client requested to use translation url instead of concept url (3/16/2020)
  1159.           
  1160.           $this->onloadPage($request);          
  1161.         if(!$asOverlay)
  1162.         {
  1163.             $sTranslationUrl $this->getConceptTranslationUrl($conceptUrl$languageCode);
  1164.             if(!empty($sTranslationUrl))
  1165.             {
  1166.                 return $this->redirect($this->get('router')->generate('exposition_translation', array(
  1167.                         'translationUrl' => $sTranslationUrl
  1168.                     )), 301);
  1169.             }        
  1170.         }
  1171.       
  1172.           $locale $request->getLocale();
  1173.         $displayInfo = array('nav_mode' => 'translation''commentary_type' => 'conceptexplanation');
  1174.         $concept $this->getRepository('Concepts\Concept')->findOneByUrl($conceptUrl);
  1175.         
  1176.         if(!empty($languageCode))
  1177.         {
  1178.             $language $this->getLanguageByBibliographicCode($languageCode);
  1179.             $nLanguageID $language['id'];
  1180.         }
  1181.         else
  1182.         {
  1183.             $nLanguageID $this->getLanguageIDByShortCode($locale);            
  1184.         }
  1185.         
  1186.         $sTranslationUrl $this->getConceptTranslationUrl($conceptUrl$languageCode);
  1187.                  
  1188.         if(!empty($sTranslationUrl)) 
  1189.         {     
  1190.             $translation =  $this->expositionData('Translation')->findOneByUrl($sTranslationUrl); 
  1191.             $displayInfo['translation'] = $translation;               
  1192.             $displayInfo['title'] = $translation->getNameOrTitle();
  1193.             $illustrations $concept->getIllustrations();
  1194.             $displayInfo['image'] = ($illustrations->isEmpty()) ? null $illustrations[0]->getImage();
  1195.             
  1196.             $displayInfo['passage'] = $translation->getWork()->findFirstPassage();
  1197.             $displayInfo['text_style_override'] = $this->getTextStyleOverride($translation->getLanguage()->getId());
  1198.             
  1199.             $displayInfo['passage_ref'] = $this->getWorkPassageRefs($displayInfo['passage']->getId(),$translation->getId(), $request); 
  1200.             $displayInfo['ref_column_spec'] = $this->getExplanationUrl($translation->getId());
  1201.             $displayInfo['passage_footnote'] = $this->getPassageFootnotes($displayInfo['passage']->getId(),$translation->getId());
  1202.             $displayInfo['passage_multilink'] = $this->getWorkPassageMultiLink($displayInfo['passage']->getId(),$translation->getId(), $request);
  1203.         } elseif($concept !== null) {
  1204.             // If the concept exists but not in this language, then we probably want a 404 with a list of languages that do have this concept
  1205.         } else {
  1206.             $displayInfo['translation'] = null;
  1207.             $displayInfo['passage'] = null;
  1208.         }
  1209.         $response null;
  1210.         if(empty($sTranslationUrl) || $displayInfo['translation'] === null) {
  1211.             $response = new Response();
  1212.             $response->setStatusCode(404);
  1213.             return $this->renderView('no_work_content', array(), $response);
  1214.         }
  1215.     
  1216.         $templateName $asOverlay 'overlay/passage' 'translation_passage';
  1217.         
  1218.         if(!$asOverlay)
  1219.         {
  1220.             $this->setCurrentUrl($request);
  1221.             $displayInfo['concept_prev_next'] = $this->getNextPrevConcept($concept->getId());
  1222.         }     
  1223.                         
  1224.         return $this->renderView($templateName$displayInfo$response);
  1225.     }
  1226.     protected function passageCanonicalRedirect($passage$translation$code 301)
  1227.     {    
  1228.           $redirectUrl $this->get('router')->generate('exposition_translation_division_passage', array(
  1229.                     'translationUrl' => $translation->getUrl(),
  1230.                     'divisionUrls' => $passage->getDivision()->getUrl(),
  1231.                     'passageNumber' => $passage->getOrdering()
  1232.                 )); 
  1233.               
  1234.         $args = @$_SERVER['QUERY_STRING'];
  1235.         if(!empty($args)) 
  1236.         {                
  1237.             $redirectUrl .= '?'.$args;                   
  1238.         }
  1239.         return $this->redirect($redirectUrl$code);
  1240.     }
  1241.     public function swedenborgGotoAction(Request $request)
  1242.     {
  1243.         $this->onloadPage($request);
  1244.         $statusCode 200;
  1245.         $query $request->query;
  1246.         if(!$query->has('translation') && !$query->has('work')) {
  1247.             // If we aren't told what book to show, then we'll redirect to the list of all Swedenborg books
  1248.             return $this->redirect($this->get('router')->generate('swedenborg'));
  1249.         }
  1250.         
  1251.         $translation $this->expositionData('Translation')->findOneByUrl($query->get('translation'));
  1252.         if($translation !== null) {
  1253.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  1254.             $work $translation->getWork();
  1255.             $params = array('translation' => $translation'nav_mode' => 'translation');
  1256.      /*       if($work->getSwedenborgType() !== null) {
  1257.                 $params['selector_data'] = $this->buildSwedenborgSelectorList($translation->getLanguage()->getName(), $translation); 
  1258.             }*/
  1259.         } else {
  1260.             $work $this->expositionData('Work')->findOneByUrl($query->get('work'));
  1261.             $params = array('work' => $work'nav_mode' => 'work');
  1262.             $translation $work->selectTranslation();
  1263.     /*        if($work->getSwedenborgType() !== null) {
  1264.                 $params['selector_data'] = $this->buildSwedenborgSelectorList();
  1265.             } */
  1266.         }
  1267.         if($query->has('section')) {
  1268.             $targetSectionNumber $query->get('section');
  1269.             $targetSection $this->expositionData('Passage')->findSwedenborgSection($work$targetSectionNumber);
  1270.             
  1271.             $inframe $query->get('inframe');
  1272.             if($inframe == 1)
  1273.             {
  1274.                 return $this->redirect($this->get('router')->generate('exposition_frame_passage', array(
  1275.                         'translationUrl' => $translation->getUrl(),
  1276.                         'divisionUrls' => $targetSection->getDivision()->getUrl(),
  1277.                         'passageNumber' => $targetSection->getOrdering()
  1278.                     )), 301);                
  1279.             } 
  1280.         } else {
  1281.             $targetSection $work->findFirstPassage();
  1282.         }
  1283.         if($targetSection !== null) {
  1284.             return $this->passageCanonicalRedirect($targetSection$translation);
  1285.         } else {
  1286.             $fromSection $query->get('fromSection');
  1287.             if($fromSection !== null) {
  1288.                 $params['passage'] = $this->expositionData('Passage')->findSwedenborgSection($work$fromSection);
  1289.                 $template $params['nav_mode'].'_passage';
  1290.             } else {
  1291.                 $template $params['nav_mode'].'_index';
  1292.             }
  1293.             $title = ($translation !== null) ? $translation->getTranslatedTitle() : $work->selectTranslation()->getTranslatedTitle();
  1294.             // "%title% does not contain a section numbered _2000_"
  1295.      /*       $params['error_message'] = $this->get('translator')->trans($request->getSession()->get('ui_str')["exposition.passage.outofrange"], array(
  1296.                 '_1000_' => $title,
  1297.                 '_2000_' => $targetSectionNumber
  1298.             )); // $title." does not contain a section numbered ".$targetSectionNumber;
  1299.             */
  1300.             
  1301.             $aReplace = array(
  1302.                 '_1000_' => $title,
  1303.                 '_2000_' => $targetSectionNumber
  1304.             );
  1305.             $params['error_message'] = $this->ui_string_replace($request->getSession()->get('ui_str')["bible.chapternav.bookchapterrange"], $aReplace);
  1306.             
  1307.             $statusCode 404;
  1308.         }
  1309.         
  1310.         $sUrlCompareTo $request->query->get('compareTo');
  1311.         $aCompare explode(";;"$sUrlCompareTo);
  1312.         $nCompareLen count($aCompare);
  1313.         $compareTo null;
  1314.         $compareTo2 null;        
  1315.         if($nCompareLen && $aCompare[0] != '')
  1316.             $compareTo $this->expositionData('Translation')->findOneByUrl($aCompare[0]);        
  1317.         
  1318.         if($nCompareLen == && $aCompare[1] != '')            
  1319.             $compareTo2 $this->expositionData('Translation')->findOneByUrl($aCompare[1]);
  1320.             
  1321.         $params['compare_to'] = $compareTo;
  1322.         $params['compare_to2'] = $compareTo2;
  1323.         $response null;
  1324.         if($statusCode !== 200) {
  1325.             $response = new Response();
  1326.             $response->setStatusCode($statusCode);
  1327.         }
  1328.         $this->setCurrentUrl($request);         
  1329.         return $this->renderView($template$params$response);
  1330.     }
  1331.     public function quickviewTranslationPassageAction($passageId$translationIdRequest $request)
  1332.     {
  1333.         $translation $this->expositionData('Translation')->findOneById($translationId);
  1334.         $nTranslationID $translation->getId();
  1335.         $work $translation->getWork();
  1336.         $nLanguageID $translation->getLanguage()->getId();
  1337.   /*      $sUrlCompareTo = $request->query->get('compareTo');
  1338.         $aCompare = explode(";;", $sUrlCompareTo);
  1339.         $nCompareLen = count($aCompare);
  1340.         $compareTo = null;
  1341.         $compareTo2 = null;        
  1342.         if($nCompareLen > 0 && $aCompare[0] != '')        
  1343.             $compareTo = $this->expositionData('Translation')->findOneByUrl($aCompare[0]);        
  1344.         
  1345.         if($nCompareLen == 2 && $aCompare[1] != '')             
  1346.             $compareTo2 = $this->expositionData('Translation')->findOneByUrl($aCompare[1]);
  1347.       */  
  1348.         $passage $this->expositionData('Passage')->findOneById($passageId);    
  1349.         $quickviewData = array(
  1350.             'translation' => $translation,
  1351.        //     'compare_to' => $compareTo,
  1352.        //     'compare_to2' => $compareTo2,
  1353.             'passage' => $passage,
  1354.             'text_style_override' => $this->getTextStyleOverride($nLanguageID)
  1355.         );
  1356.         
  1357.         if($passage != null && $translation != null)
  1358.         {           
  1359.             $quickviewData['passage_footnote'] = $this->getPassageFootnotes($passage->getId(),$nTranslationID);
  1360.             $quickviewData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTranslationID$request);
  1361.             $quickviewData['previous_passage'] = $this->getPreviousPassageWithContent($passage,$translation);     
  1362.             $quickviewData['next_passage'] = $this->getNextPassageWithContent($passage,$translation);     
  1363.             
  1364.             $nWorkID $work->getId();
  1365.             
  1366.             if($nLanguageID != $this->LANGUAGE_ID_LATIN)
  1367.             {
  1368.                 $request->getSession()->set('last_quickview_language_id'$nLanguageID); 
  1369.             }
  1370.             
  1371.             $sLanguages "";
  1372.             $nLastLangID $request->getSession()->get('last_quickview_language_id');
  1373.             if($nLanguageID == $this->LANGUAGE_ID_LATIN)
  1374.             {          
  1375.                 if(empty($nLastLangID))
  1376.                     $sLanguages $nLanguageID;
  1377.                 else
  1378.                     $sLanguages $nLanguageID "," $request->getSession()->get('last_quickview_language_id');     
  1379.             }          
  1380.             else
  1381.                 $sLanguages $nLanguageID ", " $this->LANGUAGE_ID_LATIN;
  1382.                 
  1383.             $quickviewData['translations_by_language'] = $this->getWorkTranslationsByLanguage($nWorkID$sLanguages);  
  1384.             
  1385.             $quickviewData['shortname'] = $this->getWorkTranslationShortName($nTranslationID);  
  1386.             $quickviewData['translation_id'] = $nTranslationID;
  1387.             $quickviewData['passage_id'] = $passage->getId(); 
  1388.             
  1389.             $bSwedenborgWork = ($work->getSwedenborgType() !== null);
  1390.             if(!$bSwedenborgWork)                
  1391.                 $quickviewData['authors'] = $this->getAuthorInfo($request$translation->getId());
  1392.             else
  1393.                 $quickviewData['IsSwedenborgWork'] = 1;      
  1394.         }
  1395.         
  1396.         return $this->renderView('quickview/passage'$quickviewData);
  1397.     }
  1398.     public function quickviewSwedenborgTranslationGotoAction(Request $request)
  1399.     {
  1400.         $query $request->query;
  1401.         if(!$query->has('translation')) {
  1402.             // We haven't been told what book to show; maybe someone tried to access this directly rather than via AJAX from the search page?
  1403.             // We'll redirect to the search page
  1404.             return $this->redirect($this->get('router')->generate('advanced_search'));
  1405.         }
  1406.         $translation $this->expositionData('Translation')->findOneByUrl($query->get('translation'));
  1407.         if($query->has('section')) {
  1408.             $targetSection $this->expositionData('Passage')->findSwedenborgSection($translation->getWork(), $query->get('section'));
  1409.         } else {
  1410.             $targetSection $translation->getWork()->findFirstPassage();
  1411.         }
  1412.         return $this->quickviewTranslationPassageAction($targetSection->getId(), $translation->getId(), $request);
  1413.     }
  1414.     public function expositionSearchPostAction(Request $request)
  1415.     {
  1416.         // $query = $this->getRequest()->query;
  1417.         // $searchTerm = $query['searchTerm'];
  1418.         $params $request->request->all();
  1419.         if ( array_key_exists'searchTerm'$params ) ) {
  1420.             $searchTerm $params['searchTerm'];
  1421.         } else {
  1422.             $searchTerm '';
  1423.         }
  1424.         return $this->expositionSearchAction($searchTerm);
  1425.     }
  1426.     public function expositionSearchAction($searchTerm$start=1) {
  1427.         // $templateName = 'explanation_search';
  1428.         // return $this->sharedSearchAction( $searchTerm, 'is', $templateName, $start );
  1429.         return $this->renderView('search/exposition_search', array('searchTerm' => $searchTerm'content_class' => 'explanation''start' => $start));
  1430.     }
  1431.     public function expositionSearchResultsAction($searchTerm$pageNum 1)
  1432.     {
  1433.         return $this->renderView('search/search_results'$this->expositionSearchResults($searchTermfalse'locale'$pageNum));
  1434.     }
  1435.     public function swedenborgSearchPostAction(Request $request)
  1436.     {
  1437.         // $query = $this->getRequest()->query;
  1438.         // $searchTerm = $query['searchTerm'];
  1439.         $params $request->request->all();
  1440.         if ( array_key_exists'searchTerm'$params ) ) {
  1441.             $searchTerm $params['searchTerm'];
  1442.         } else {
  1443.             $searchTerm '';
  1444.         }
  1445.         return $this->swedenborgSearchAction($searchTerm);
  1446.     }
  1447.     public function swedenborgSearchAction($searchTerm$start=1)
  1448.     {
  1449.         // $templateName = 'swedenborg_search';
  1450.         // return $this->sharedSearchAction( $searchTerm, 'is not', $templateName, $start );
  1451.         return $this->renderView('search/exposition_search', array('searchTerm' => $searchTerm'content_class' => 'swedenborg''start' => $start));
  1452.     }
  1453.     public function swedenborgSearchResultsAction($searchTerm$pageNum 1)
  1454.     {
  1455.         // $templateName = 'swedenborg_search';
  1456.         // return $this->sharedSearchAction( $searchTerm, 'is not', $templateName, $start );
  1457.         return $this->renderView('search/search_results'$this->expositionSearchResults($searchTermtrue'locale'$pageNum));
  1458.     }
  1459.     public function expositionSearchResults(Request $request$searchTerm$isSwedenborg$forceLanguage null$start 1)
  1460.     {
  1461.         $search = new PostgresSearch();
  1462.         $em $this->getDoctrine()->getManager();
  1463.         $search->setManager($em);
  1464.         return $search->getExpositionSearchResults($request$searchTerm$isSwedenborg, array('language' => $forceLanguage'page' => $start));
  1465.     }         
  1466.             
  1467.     public function topicalPathIndexAction(Request $request)
  1468.     {
  1469.         $this->onloadPage($request);
  1470.         $locale $request->getLocale();
  1471.         $topicData $this->getTopPathList($locale);
  1472.         $data = array(
  1473.             'topic_data' => $topicData        
  1474.         );
  1475.         $this->setCurrentUrl($request);         
  1476.         return $this->renderView('index/topical_paths'$data);
  1477.     }
  1478.     
  1479.     public function topPathAction($TopPathUrlRequest $request)
  1480.     {
  1481.         $this->onloadPage($request);
  1482.         $locale $request->getLocale();
  1483.         $topPath $this->getTopPathInfo($TopPathUrl,$locale);
  1484.         $subPathList $this->getSubPathList($TopPathUrl,$locale);
  1485.         $data = array(
  1486.             'sub_path_list' => $subPathList,
  1487.             'top_path' => $topPath,
  1488.             'top_path_url' => $TopPathUrl       
  1489.         );
  1490.         $this->setCurrentUrl($request);         
  1491.         return $this->renderView('top_path'$data);
  1492.     }
  1493.     
  1494.     public function subPathAction($TopPathUrl$SubPathUrlRequest $request)
  1495.     {
  1496.         $this->onloadPage($request);
  1497.         $locale $request->getLocale();
  1498.         $bibleTranslationUrl $this->DEFAULT_BIBLE_VERSION;
  1499.         $nBibleTransID $request->getSession()->get('current_bible_translation_id');
  1500.         if($nBibleTransID != '')
  1501.         {   
  1502.                $bibleTranslation $this->getBibleTranslationByID($nBibleTransID);
  1503.                $bibleTranslationUrl $bibleTranslation['url'];
  1504.         }
  1505.         $topPath $this->getTopPathInfo($TopPathUrl,$locale);
  1506.         $subPath $this->getSubPathInfo($SubPathUrl,$locale);
  1507.         $explanationList $this->getExplanationListForTopAndSubPath($TopPathUrl$SubPathUrl,$locale);
  1508.         $data = array(
  1509.             'explanation_list' => $explanationList,
  1510.             'top_path' => $topPath,
  1511.             'sub_path' => $subPath,
  1512.             'sub_path_url' => $SubPathUrl,
  1513.             'top_path_url' => $TopPathUrl,
  1514.             'bible_translation_url' => $bibleTranslationUrl       
  1515.         );
  1516.         $this->setCurrentUrl($request);         
  1517.         return $this->renderView('sub_path'$data);
  1518.     }
  1519.     
  1520.     public function topicIndexAction(Request $request)
  1521.     {
  1522.         $locale $request->getLocale();
  1523.         $topicData $this->getTopicList($locale);
  1524.         $data = array(
  1525.             'topic_data' => $topicData        
  1526.         );
  1527.       
  1528.            $this->setCurrentUrl($request); 
  1529.            $this->onloadPage($request);
  1530.         return $this->renderView('index/topics'$data);
  1531.     }
  1532.     
  1533.     public function topicAction($TopicUrl,Request $request)
  1534.     {        
  1535.         $this->onloadPage($request);
  1536.         $locale $request->getLocale(); 
  1537.         $bibleTranslationUrl $this->DEFAULT_BIBLE_VERSION;
  1538.         $nBibleTransID $request->getSession()->get('current_bible_translation_id');
  1539.         if($nBibleTransID != '')
  1540.         {   
  1541.                $bibleTranslation $this->getBibleTranslationByID($nBibleTransID);
  1542.                $bibleTranslationUrl $bibleTranslation['url'];
  1543.         }   
  1544.         $topic $this->getSubPathInfo($TopicUrl,$locale);
  1545.         $explanationList $this->getExplanationListForTopic($TopicUrl,$locale);
  1546.         $data = array(
  1547.             'explanation_list' => $explanationList,            
  1548.             'topic' => $topic,
  1549.             'topic_url' => $TopicUrl,
  1550.             'bible_translation_url' => $bibleTranslationUrl        
  1551.         );
  1552.         $this->setCurrentUrl($request);         
  1553.         return $this->renderView('topic'$data);
  1554.     }
  1555.     
  1556.     public function viewscanimagesAction($PassageIDRequest $request)
  1557.     {             
  1558.         $this->onloadPage($request);
  1559.         $aImage = array(
  1560.             'scanimage' => $this->getWorkPassageScanImageFileName($PassageID),
  1561.             'translation_info' => $this->getCurrentPassageForLatin($PassageID),
  1562.             'next_passage' => $this->getNextPassageWithScan($PassageID),
  1563.             'previous_passage' => $this->getPreviousPassageWithScan($PassageID)       
  1564.         );
  1565.         return $this->renderView('view_scanimages'$aImage);
  1566.     }
  1567.     
  1568.     public function popoverconceptAction($explanationID$conceptIDRequest $request)
  1569.     {         
  1570.           $locale $request->getLocale();        
  1571.         $sPopupText $this->getBibleWordPopupText($explanationID$conceptID);
  1572.         $aConceptInfo $this->getBibleWordPopupConceptInfo($explanationID$conceptID);
  1573.         $data = array(
  1574.             'popup_text' => $sPopupText,
  1575.             'title' => $aConceptInfo['title'],
  1576.             'concept_url' => $aConceptInfo['concept_url']
  1577.         );
  1578.          
  1579.         return $this->renderView('word_popup'$data);
  1580.     }
  1581.     
  1582.     /**
  1583.      * Show chapter summary list on a popup for multi page
  1584.      */
  1585.     public function selectchaptersummaryAction($explanationID$bibleBookIDRequest $request)
  1586.     {             
  1587.       $data['chapter_summary_list'] = $this->getChapterSummaryList($explanationID$bibleBookID);
  1588.                        
  1589.       return $this->renderView('selectchaptersummary'$data);
  1590.     }
  1591.     
  1592.     /**
  1593.      * Show chapter summary list on a popup for single chapter summary page
  1594.      */
  1595.     public function selectchaptersummarysinglepageAction($explanationID$cBibleBookIDRequest $request)
  1596.     {             
  1597.       $data['chapter_summary_list'] = $this->getChapterSummaryListForSinglePage($explanationID$cBibleBookID);
  1598.                        
  1599.       return $this->renderView('selectchaptersummarysinglepage'$data);
  1600.     }
  1601.     
  1602.     public function featured_spiritual_topicsAction(Request $request)
  1603.     {                       
  1604.     //    $this->setCurrentUrl($request); 
  1605.         $this->onloadPage($request);
  1606.         $locale $request->getLocale();
  1607.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale9);
  1608.         if(empty($featuredList))
  1609.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale9true);
  1610.         $request->getSession()->set('searched_topic_list', array());
  1611.         return $this->renderView('index/spiritual_topics_featured', array(     
  1612.             'featured_topic' => $featuredList            
  1613.         ));
  1614.     }
  1615.     
  1616.     public function searched_spiritual_topicsAction(Request $request)
  1617.     {                       
  1618.     //    $this->setCurrentUrl($request); 
  1619.         $this->onloadPage($request);
  1620.         $locale $request->getLocale();
  1621.         $sSearchTerm $request->query->get('searchTerm');
  1622.         $searchedResults null;   
  1623.         if($sSearchTerm != '')
  1624.         {
  1625.             $searchedResults $this->getSearchedListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale$request);
  1626.         }        
  1627.         else
  1628.         {
  1629.             $nPathwayID $request->query->get('pathwayid');
  1630.             if(!empty($nPathwayID))
  1631.             {
  1632.                 $searchedResults $this->getSearchedListByCategoryAndPathway($locale$request$this->CATEGORY_ID_SPIRITUAL_TOPIC$nPathwayID);
  1633.             }
  1634.             else
  1635.             {
  1636.                 $nAll $request->query->get('all');
  1637.                 if($nAll == '1')
  1638.                 {
  1639.                     $searchedResults $this->getAllListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale$request);
  1640.                 }
  1641.             }
  1642.         }
  1643.         return $this->renderView('index/spiritual_topics_searched', array(     
  1644.             'searched_topic' => $searchedResults            
  1645.         ));
  1646.     }
  1647.     
  1648.     public function getSearchedListByCategory($vCategoryId$locale$request)
  1649.     {
  1650.         $search = new PostgresSearch();
  1651.         $em $this->getDoctrine()->getManager();
  1652.         $search->setManager($em);
  1653.         return $search->getCategorySearchResults($vCategoryId$locale$request);
  1654.     }
  1655.     
  1656.     public function getSearchedOTLEVideos($locale$request)
  1657.     {
  1658.         $search = new PostgresSearch();
  1659.         $em $this->getDoctrine()->getManager();
  1660.         $search->setManager($em);
  1661.         return $search->getOTLESearchResults($locale$request);
  1662.     }
  1663.     
  1664.     public function expositionSliderAction($translationIdRequest $request$passageId$userSelected true$inFrame false)
  1665.     {
  1666.   /*      $translation = $this->expositionData('Translation')->findOneBy(array('id' => $translationId, 'isPublic' => true));
  1667.          if($translation == null) {
  1668.             $response = new Response();
  1669.             $response->setStatusCode(404);
  1670.             return $this->renderView('no_work_content', array(), $response);
  1671.         }
  1672.         
  1673.         $passage = ($passageId !== null)
  1674.             ? $this->expositionData('Passage')->findOneById($passageId)
  1675.             : (($translation !== null) ? $translation->getWork()->findFirstNonEmptyPassage($translation) : null); */
  1676.             
  1677.         $aTranslation $this->getTranslationData($translationId);    
  1678.         $aPassage $this->getPassageData($passageId);  
  1679.              
  1680.         $this->checkIfOnMobile($request);
  1681.     //    $locale = $request->getLocale();
  1682.              
  1683.         $ref_column_spec '';
  1684.      //   $work = $translation->getWork();
  1685.         $bSwedenborgWork = ($aTranslation['swedenborgtype'] != null);
  1686.         if($bSwedenborgWork)
  1687.             $ref_column_spec $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK;    
  1688.         else
  1689.             $ref_column_spec $this->MULTI_URL_INDICATOR_EXPLANATION;    
  1690.         
  1691.         $ref_column_spec .= '_' $aTranslation['url'];
  1692.         if($bSwedenborgWork)
  1693.             $ref_column_spec .= '_' $aPassage['swedenborgsection'];
  1694.                     
  1695.         $nLanguageID $aTranslation['language_id'];      
  1696.         $data = array(
  1697.            // 'translation' => $translation,
  1698.            // 'passage' => $passage,  
  1699.             'ref_column_spec' => $ref_column_spec,  
  1700.             'passage_order' => $aPassage['ordering'],  
  1701.             'passage_id' => $passageId,                     
  1702.         );
  1703.      //   $data['passage_ref'] = $this->getWorkPassageRefs($passageId,$translationId, $request);
  1704.         
  1705.     //    if($bSwedenborgWork)
  1706.     //        $data['related_bible_ref'] = $this->getRelatedBibleRefForWork($passageId,$translationId, $request);
  1707.     //    $data['passage_footnote'] = $this->getPassageFootnotes($passageId,$translationId);
  1708.     //    $data['passage_multilink'] = $this->getWorkPassageMultiLink($passageId,$translationId, $request);
  1709.                     
  1710.         $data['work_references'] = $this->getWorkRefForWork($passageId$translationId$nLanguageID);
  1711.       
  1712.         $data['explanation_references'] = $this->getExplanationRefForWork($passageId$nLanguageID);
  1713.         $data['gced_ref'] = $this->getGCEDRefForWork($passageId);
  1714.         $data['otle_ref'] = $this->getOTLERefForWork($passageId);
  1715.         $data['related_passages'] = $this->getRelatedPassages($passageId$nLanguageID);                                        
  1716.           // get table of contents
  1717.           $aTOC $this->getWorkTranslationTOC($translationId); 
  1718.           if(!empty($aTOC))
  1719.           {                  
  1720.               $data['work_toc'] = $aTOC;
  1721.           }
  1722.                    
  1723.         return $this->renderView('refsidrw'$data);
  1724.     }
  1725.     public function selecttopicAction(Request $request)
  1726.     {       
  1727.       $locale $request->getLocale();  
  1728.       $sSearchText $request->query->get('st');
  1729.                        
  1730.       $data['consider_data'] = $this->getConsiderList($locale$sSearchText); 
  1731.                     
  1732.       return $this->renderView('selecttopic'$data);
  1733.     } 
  1734.     
  1735.     public function otlevideosAction(Request $request)
  1736.     {            
  1737.         $this->onloadPage($request);
  1738.         $locale $request->getLocale();
  1739.         $aBrand $this->getBrandList();
  1740.         $aShowTopic $this->getShowTopicList();
  1741.         $aShowType $this->getShowTypeList();   
  1742.         $data = array(
  1743.               'brand_list' => $aBrand,
  1744.               'topic_list' => $aShowTopic,
  1745.                'type_list' => $aShowType            
  1746.         );
  1747.         $this->setCurrentUrl($request);         
  1748.         return $this->renderView('otle_videos'$data);
  1749.     }
  1750.     
  1751.     public function searched_otle_videosAction(Request $request)
  1752.     {            
  1753.         $locale $request->getLocale();
  1754.         $searchedResults = array();
  1755.         $sSearchTerm $request->query->get('searchTerm');
  1756.         $nBrandID $request->query->get('brandid');
  1757.         if($sSearchTerm != '')
  1758.         {
  1759.             $searchedResults $this->getSearchedOTLEVideos($locale$request);
  1760.         }        
  1761.         else
  1762.         {
  1763.             $nStartNum $request->query->get('startnum');            
  1764.             $searchedResults $this->getOTLEVideos($nStartNum$request);            
  1765.         }            
  1766.         
  1767.         return $this->renderView('otle_videos_searched', array(     
  1768.             'searched_video' => $searchedResults['results'],
  1769.             'total_record' => $searchedResults['total_record'],
  1770.             'has_more' => $searchedResults['has_more'],
  1771.             'start_num' => $searchedResults['start_num']            
  1772.         ));
  1773.     }
  1774.     
  1775.     public function otlevideopageAction($showIDRequest $request)
  1776.     {            
  1777.         //$locale = $request->getLocale();        
  1778.         $aShow $this->getShowInfo($showID);
  1779.         $aShowRef $this->getShowRefs($showID$request);    
  1780.         
  1781.         $nTextLength 150;
  1782.         $sDesc $aShow['description'];
  1783.         $sMetaDesc $this->fixWorkText($sDesc);
  1784.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength"...");          
  1785.               
  1786.         return $this->renderView('otle_video_page', array(  
  1787.             'show_id' => $showID,   
  1788.             'show_info' => $aShow,
  1789.             'show_ref' => $aShowRef,
  1790.             'meta_desc' => $sMetaDesc           
  1791.         ));
  1792.     }
  1793.     
  1794.     public function audiohubAction(Request $request)
  1795.     {            
  1796.         $this->onloadPage($request);
  1797.         $locale $request->getLocale();        
  1798.         $aLanguage $this->getLanguageListForAudioHub(); 
  1799.         $aCategory $this->getCategoryListForAudioHub();   
  1800.         $data = array(
  1801.                'language_list' => $aLanguage,
  1802.                'category_list' => $aCategory            
  1803.         );
  1804.         $this->setCurrentUrl($request);        
  1805.         return $this->renderView('audiohub'$data);
  1806.     }
  1807.     
  1808.     public function search_audioAction(Request $request)
  1809.     {            
  1810.         $locale $request->getLocale();
  1811.         $searchedResults = array();
  1812.         $sSearchTerm $request->query->get('searchTerm');  
  1813.         $nStartNum $request->query->get('startnum');      
  1814.         if($sSearchTerm != '')
  1815.         {
  1816.             $searchedResults $this->getSearchedAudio($locale$request);
  1817.         }    
  1818.         else
  1819.         {
  1820.             $nFormatID $this->PRIMARY_FORMAT_ID_AUDIO;
  1821.             $searchedResults $this->getExplanationList($nStartNum$locale$request$nFormatID);            
  1822.         }            
  1823.         
  1824.         return $this->renderView('audio_searched', array(     
  1825.             'searched_audio' => $searchedResults,
  1826.             'start_num' => $nStartNum           
  1827.         ));
  1828.     }
  1829.         
  1830.     public function getSearchedAudio($locale$request)
  1831.     {        
  1832.         $search = new PostgresSearch();
  1833.         $em $this->getDoctrine()->getManager();
  1834.         $search->setManager($em);
  1835.         $sCategoryId 'any';
  1836.         return $search->getCategorySearchResults($sCategoryId$locale$request);
  1837.     } 
  1838.     
  1839.     public function qahubAction(Request $request)
  1840.     {            
  1841.         $locale $request->getLocale(); 
  1842.         $data = array(                         
  1843.         );
  1844.         $this->setCurrentUrl($request); 
  1845.         $this->onloadPage($request);
  1846.         return $this->renderView('qahub'$data);
  1847.     }
  1848.     
  1849.     public function search_qaAction(Request $request)
  1850.     {            
  1851.         $locale $request->getLocale();
  1852.         $searchedResults = array();
  1853.         $sSearchTerm $request->query->get('searchTerm');  
  1854.         $nStartNum $request->query->get('startnum');      
  1855.         if($sSearchTerm != '')
  1856.         {
  1857.             $searchedResults $this->getSearchedQA($locale$request);
  1858.         }    
  1859.         else
  1860.         {            
  1861.             $searchedResults $this->getExplanationList($nStartNum$locale$request);
  1862.         }            
  1863.         
  1864.         return $this->renderView('qa_searched', array(     
  1865.             'searched_qa' => $searchedResults,
  1866.             'start_num' => $nStartNum           
  1867.         ));
  1868.     }
  1869.         
  1870.     public function getSearchedQA($locale$request)
  1871.     {        
  1872.         $search = new PostgresSearch();
  1873.         $em $this->getDoctrine()->getManager();
  1874.         $search->setManager($em);
  1875.         $sCategoryId 47;
  1876.         return $search->getCategorySearchResults($sCategoryId$locale$request);
  1877.     } 
  1878.     
  1879.     public function search_classAction(Request $request)
  1880.     {            
  1881.         $locale $request->getLocale();
  1882.         $searchedResults = array();
  1883.         $sSearchTerm $request->query->get('searchTerm');  
  1884.         $nStartNum $request->query->get('startnum');      
  1885.         if($sSearchTerm != '')
  1886.         {
  1887.             $searchedResults $this->getSearchedClass($locale$request);
  1888.         }    
  1889.         else
  1890.         {            
  1891.             $searchedResults $this->getClassList($nStartNum$request);            
  1892.         }            
  1893.         
  1894.         return $this->renderView('class_searched', array(     
  1895.             'searched_class' => $searchedResults['results'],
  1896.             'total_record' => $searchedResults['total_record'],
  1897.             'has_filter' => $searchedResults['has_filter'],
  1898.             'has_more' => $searchedResults['has_more'],
  1899.             'start_num' => $nStartNum           
  1900.         ));
  1901.     }
  1902.     
  1903.     public function getSearchedClass($locale$request)
  1904.     {
  1905.         $search = new PostgresSearch();
  1906.         $em $this->getDoctrine()->getManager();
  1907.         $search->setManager($em);
  1908.         return $search->getClassSearchResults($locale$request);
  1909.     }
  1910.     
  1911.     public function coursepageAction($courseIDRequest $request)
  1912.     {        
  1913.         $aCourse $this->getCourseInfo($courseID);         
  1914.         if(empty($aCourse))
  1915.         {
  1916.             $response = new Response();
  1917.             $response->setStatusCode(404);
  1918.             return $this->renderView('no_work_content', array(), $response);
  1919.         }
  1920.         $aLeader $this->getLeadersForCourse($courseID);
  1921.         $aAudience $this->getAudienceForCourse($courseID);    
  1922.         
  1923.         $nTextLength 150;
  1924.         $sDesc $aCourse['full_description'];
  1925.         $sMetaDesc $this->fixWorkText($sDesc);
  1926.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength"..."); 
  1927.                               
  1928.         return $this->renderView('course_page', array(     
  1929.             'course_info' => $aCourse,
  1930.             'leader_list' => $aLeader,
  1931.             'audience_list' => $aAudience,
  1932.             'meta_desc' => $sMetaDesc          
  1933.         ));
  1934.     }
  1935.     
  1936.     public function search_sermonAction(Request $request)
  1937.     {            
  1938.         $locale $request->getLocale();
  1939.         $searchedResults = array();
  1940.         $sSearchTerm $request->query->get('searchTerm');  
  1941.         $nStartNum $request->query->get('startnum'); 
  1942.         $nStorehouse $request->query->get('storehouse');     
  1943.         if($sSearchTerm != '')
  1944.         {
  1945.             $searchedResults $this->getSearchedSermon($locale$request);
  1946.         }    
  1947.         else
  1948.         {            
  1949.             $searchedResults $this->getSermonList($nStartNum$request);            
  1950.         }            
  1951.         
  1952.         return $this->renderView('sermon_searched', array(     
  1953.             'searched_sermon' => $searchedResults['results'],
  1954.             'total_record' => $searchedResults['total_record'],
  1955.             'has_more' => $searchedResults['has_more'],
  1956.             'has_filter' => $searchedResults['has_filter'],
  1957.             'start_num' => $nStartNum,
  1958.             'is_storehouse' => $nStorehouse          
  1959.         ));
  1960.     }
  1961.     
  1962.     public function getSearchedSermon($locale$request)
  1963.     {
  1964.         $search = new PostgresSearch();
  1965.         $em $this->getDoctrine()->getManager();
  1966.         $search->setManager($em);
  1967.         return $search->getSermonSearchResults($locale$request);
  1968.     }
  1969.     
  1970.     public function sermonpageAction($sermonIDRequest $request)
  1971.     {        
  1972.         if(!$this->userCanSeeAllSermons($request))
  1973.         {
  1974.             $nTypeID $this->getSermonTypeID($sermonID);
  1975.             if($nTypeID != $this->LNCSERMON_TYPE_ID_PUBLIC)
  1976.             {
  1977.                 $bCanView false;
  1978.                 if($this->userCanSeeLNCSermons($request) && $nTypeID == $this->LNCSERMON_TYPE_ID_LNC_MEMBER)
  1979.                 {
  1980.                     $bCanView true;
  1981.                 }
  1982.                 
  1983.                 if(!$bCanView)
  1984.                 {
  1985.                     return $this->redirect($this->get('router')->generate('sermons', array()), 301);
  1986.                 }
  1987.             }        
  1988.         }
  1989.     
  1990.         $aSermon $this->getSermonInfo($sermonID);
  1991.         $aAuthor $this->getAuthorsForSermon($sermonID);
  1992.         $aTopic $this->getTopicsForSermon($sermonID);
  1993.         $aSermonRef $this->getSermonRefs($sermonID$request);
  1994.         
  1995.         $nTextLength 150;
  1996.         $sDesc $aSermon['searchsummary'];
  1997.         $sMetaDesc $this->fixWorkText($sDesc);
  1998.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength"...");
  1999.        
  2000.         return $this->renderView('sermon_page', array(   
  2001.             'sermon_id' => $sermonID,  
  2002.             'sermon_info' => $aSermon,
  2003.             'author_list' => $aAuthor,
  2004.             'topic_list' => $aTopic,
  2005.             'sermon_ref' => $aSermonRef,
  2006.             'meta_desc' => $sMetaDesc        
  2007.         ));
  2008.     }
  2009.     
  2010.     public function sermonstorehousepageAction($sermonIDRequest $request)
  2011.     {   
  2012.         $nTypeID $this->getSermonTypeID($sermonID);
  2013.         if($nTypeID != $this->LNCSERMON_TYPE_ID_PUBLIC)
  2014.         {            
  2015.             return $this->redirect($this->get('router')->generate('sermon_storehouse', array()), 301);
  2016.         }   
  2017.     
  2018.         $aSermon $this->getSermonInfo($sermonID);
  2019.         $aAuthor $this->getAuthorsForSermon($sermonID);
  2020.         $aTopic $this->getTopicsForSermon($sermonID);
  2021.         $aSermonRef $this->getSermonRefs($sermonID$request);
  2022.         
  2023.         $nTextLength 150;
  2024.         $sDesc $aSermon['searchsummary'];
  2025.         $sMetaDesc $this->fixWorkText($sDesc);
  2026.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength"...");
  2027.        
  2028.         return $this->renderView('sermon_storehouse_page', array(   
  2029.             'sermon_id' => $sermonID,  
  2030.             'sermon_info' => $aSermon,
  2031.             'author_list' => $aAuthor,
  2032.             'topic_list' => $aTopic,
  2033.             'sermon_ref' => $aSermonRef,
  2034.             'meta_desc' => $sMetaDesc        
  2035.         ));
  2036.     }
  2037.     
  2038.     /**
  2039.      * Show chapter list on a popup
  2040.      */
  2041.     public function selectworkcompareAction($workID$translationUrl$translationUrl2$divisionUrl$passageNumberRequest $request)
  2042.     {         
  2043.       $data['translation_url'] = $translationUrl;
  2044.       $data['translation_url2'] = $translationUrl2
  2045.       $data['division_url'] = $divisionUrl
  2046.       $data['passage_number'] = $passageNumber;      
  2047.       $data['work_id'] = $workID;   
  2048.                    
  2049.       $data['translations_by_language'] = $this->getWorkTranslationsByLanguage($workID);    
  2050.                                    
  2051.       return $this->renderView('selectworkcompare'$data);
  2052.     }
  2053.     
  2054.     /**
  2055.      * Show translation list on a popup
  2056.      */
  2057.     public function selectworktranslationAction($workID$translationUrl$passageNumber$passageOrderRequest $request)
  2058.     {    
  2059.           $data['translation_url'] = $translationUrl;          
  2060.           $data['passage_number'] = $passageNumber;  
  2061.           $data['passage_order'] = $passageOrder;    
  2062.           $data['work_id'] = $workID;   
  2063.                        
  2064.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguageAllType($workID);
  2065.                    
  2066.           return $this->renderView('selectworktranslation'$data);
  2067.     }
  2068.     
  2069.     /**
  2070.      * Show translation list on a popup
  2071.      */
  2072.     public function selectworkpassageAction($workID$translationUrlRequest $request)
  2073.     {    
  2074.           $data['translation_url'] = $translationUrl;                       
  2075.           $data['passage_list'] = $this->getWorkPassages($workID);
  2076.           $data['work_id'] = $workID;
  2077.                    
  2078.           return $this->renderView('selectpassage'$data);
  2079.     }
  2080.     
  2081.     /**
  2082.      * Show work list on a popup
  2083.      */
  2084.     public function selectworkAction($workID$translationID$languageIDRequest $request)
  2085.     {    
  2086.           $data['translation_id'] = $translationID;          
  2087.           $data['language_id'] = $languageID;      
  2088.           $data['work_id'] = $workID;   
  2089.                        
  2090.           $data['swedenborg_works'] = $this->getCategorizedSwedenborgWorksForTranslation($request$translationID$languageID);
  2091.                    
  2092.           return $this->renderView('selectwork'$data);
  2093.     }
  2094.     
  2095.     /**
  2096.      * Show translation list on a popup
  2097.      */
  2098.     public function selectsearchtranslationAction($workID$translationID$passageIDRequest $request)
  2099.     {    
  2100.           $data['translation_id'] = $translationID;          
  2101.           $data['passage_id'] = $passageID;      
  2102.           $data['work_id'] = $workID;   
  2103.            
  2104.           $nLanguageID $this->getLanguageIDByTranslation($translationID); 
  2105.           if($nLanguageID != $this->LANGUAGE_ID_LATIN)          
  2106.             $request->getSession()->set('last_quickview_language_id'$nLanguageID); 
  2107.                   
  2108.           $sLanguages "";
  2109.           if($nLanguageID == $this->LANGUAGE_ID_LATIN)            
  2110.             $sLanguages $nLanguageID ", " $request->getSession()->get('last_quickview_language_id');           
  2111.           else
  2112.             $sLanguages $nLanguageID ", " $this->LANGUAGE_ID_LATIN;
  2113.                                  
  2114.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguage($workID$sLanguages);
  2115.                    
  2116.           return $this->renderView('selectsearchtranslation'$data);
  2117.     }
  2118.     
  2119.     /**
  2120.      * Show translation list on a popup
  2121.      */
  2122.     public function selectstorytranslationforworkAction($workID$storyID$translationIDRequest $request)
  2123.     {    
  2124.       $locale $request->getLocale();
  2125.       $data['work_id'] = $workID;  
  2126.       $data['translation_id'] = $translationID;       
  2127.       $data['story_id'] = $storyID;   
  2128.                            
  2129.       $data['story_explanations'] = $this->getWorkListForStory($locale$storyID);
  2130.                
  2131.       return $this->renderView('selectstorytranslationforwork'$data);
  2132.     }
  2133.     
  2134.     public function search_conceptAction(Request $request)
  2135.     {            
  2136.         $locale $request->getLocale();
  2137.         $searchedResults = array();
  2138.         $sSearchTerm $request->query->get('searchTerm');  
  2139.         $nStartNum $request->query->get('startnum');      
  2140.         if($sSearchTerm != '')
  2141.         {
  2142.             //$searchedResults = $this->getSearchedConcept($locale, $request);
  2143.             $searchedResults $this->getSearchedListByCategory($this->CATEGORY_ID_CONCEPT$locale$request);
  2144.         }    
  2145.         else
  2146.         {            
  2147.             //$searchedResults = $this->getConceptList($nStartNum, $request);
  2148.             $searchedResults $this->getAllListByCategory($this->CATEGORY_ID_CONCEPT$locale$request);            
  2149.         }            
  2150.         
  2151.         return $this->renderView('concept_searched', array(     
  2152.             'searched_results' => $searchedResults           
  2153.         ));
  2154.     }    
  2155.     
  2156.     public function featured_conceptsAction(Request $request)
  2157.     {                   
  2158.         $this->onloadPage($request);
  2159.         $locale $request->getLocale();
  2160.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCEPT$locale9false);
  2161.         if(empty($featuredList))
  2162.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCEPT$locale9true);
  2163.         return $this->renderView('concepts_featured', array(     
  2164.             'featured_records' => $featuredList            
  2165.         ));
  2166.     }    
  2167.     
  2168.     /**
  2169.      * Show translation list on a popup
  2170.      */
  2171.     public function selectbiblebooksummaryAction($translationID$BibleBookIDForSummaryRequest $request)
  2172.     {           
  2173.       $data['translation_id'] = $translationID;                               
  2174.       $data['book_summaries'] = $this->getBibleBookSummaryList($BibleBookIDForSummary);
  2175.                
  2176.       return $this->renderView('selectbiblebooksummary'$data);
  2177.     }
  2178.     
  2179.     /**
  2180.      * Show translation list on a popup
  2181.      */
  2182.     public function selectbiblechaptersummarytranslationAction($translationIDRequest $request)
  2183.     {           
  2184.       $data['translation_id'] = $translationID;                               
  2185.       $data['chapter_summary_translations'] = $this->getChapterExplanationsForPopup($translationID);
  2186.                
  2187.       return $this->renderView('selectbiblechaptersummarytranslation'$data);
  2188.     }
  2189.     
  2190.     public function selectbiblestudyAction(Request $request)
  2191.     {       
  2192.       $locale $request->getLocale();  
  2193.       //$sSearchText = $request->query->get('st');
  2194.                        
  2195.       $data['biblestudy_data'] = $this->getBibleStudyList($locale); 
  2196.                     
  2197.       return $this->renderView('selectbiblestudy'$data);
  2198.     } 
  2199.     
  2200.     /**
  2201.      * Show translation list on a popup
  2202.      */
  2203.     public function selectbibleversesummaryAction($workID$chapterID$languageIDRequest $request)
  2204.     {                  
  2205.           $data['work_id'] = $workID;     
  2206.           $data['verse_explanations'] = $this->getVerseExplanations($chapterID$languageID$request);
  2207.                    
  2208.           return $this->renderView('selectbibleversesummary'$data);
  2209.     }
  2210.     
  2211.     /**
  2212.      * Show work list on a popup for search
  2213.      */
  2214.     public function selectworksforsearchAction(Request $request)
  2215.     {    
  2216.           $nLanguageID $request->query->get('lang');    
  2217.                        
  2218.           $data['swedenborg_works'] = $this->getCategorizedSwedenborgWorksForTranslation($requestnull$nLanguageID);
  2219.                    
  2220.           return $this->renderView('selectworksforsearch'$data);
  2221.     }
  2222.     
  2223.     /**
  2224.      * Show work translation list on a popup for search
  2225.      */
  2226.     public function selectworktranslationsforsearchAction(Request $request)
  2227.     {    
  2228.           $nLanguageID $request->query->get('lang'); 
  2229.           $sSelectedWorkIDs $request->query->get('selectedworkids');  
  2230.           $sWorkType $request->query->get('worktype'); 
  2231.                        
  2232.           $data['work_translations'] = $this->getSWWorkTranslations($sSelectedWorkIDs$nLanguageID$sWorkType);
  2233.                    
  2234.           return $this->renderView('selectworktranslationsforsearch'$data);
  2235.     }
  2236.     
  2237.     /**
  2238.      * Show work translation list on a popup for reading plan step
  2239.      */
  2240.     public function selectworktranslationforreadingplanAction(Request $request)
  2241.     {    
  2242.           $nWorkID $request->query->get('wid'); 
  2243.           $sTranslationUrl $request->query->get('turl');
  2244.           $sReadingPlanUrl $request->query->get('rpurl'); 
  2245.           $nStepOrder $request->query->get('step'); 
  2246.           $nSW $request->query->get('sw');  
  2247.           
  2248.           $data['work_id'] = $nWorkID;
  2249.           $data['translation_url'] = $sTranslationUrl;          
  2250.           $data['readingplan_url'] = $sReadingPlanUrl;  
  2251.           $data['step_order'] = $nStepOrder
  2252.                                  
  2253.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguageAllType($nWorkID);
  2254.                    
  2255.           return $this->renderView('selectworktranslationforreadingplan'$data);
  2256.     }
  2257.     
  2258.     /**
  2259.      * Show work translation list on a popup for reading plan step
  2260.      */
  2261.     public function selectexplanationtranslationforreadingplanAction(Request $request)
  2262.     {    
  2263.           $nWorkID $request->query->get('wid'); 
  2264.           $sTranslationUrl $request->query->get('turl');
  2265.           $sReadingPlanUrl $request->query->get('rpurl'); 
  2266.           $nStepOrder $request->query->get('step');   
  2267.           
  2268.           $data['work_id'] = $nWorkID;
  2269.           $data['translation_url'] = $sTranslationUrl;          
  2270.           $data['readingplan_url'] = $sReadingPlanUrl;  
  2271.           $data['step_order'] = $nStepOrder
  2272.                                  
  2273.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguageAllType($nWorkID);
  2274.                    
  2275.           return $this->renderView('selectexplanationtranslationforreadingplan'$data);
  2276.     }
  2277.     
  2278.     /**
  2279.      * Show work list on a popup
  2280.      */
  2281.     public function selectbiblechaptersummaryworkAction($translationIDRequest $request)
  2282.     {           
  2283.       $aTrans $this->getWorkTranslationData($translationID);        
  2284.       $nWorkID $aTrans['work_id'];
  2285.       $data['translation_id'] = $translationID;     
  2286.       $data['work_id'] = $nWorkID;                              
  2287.       $data['chapter_summary_works'] = $this->getChapterExplanationWorksForPopup($translationID);
  2288.                
  2289.       return $this->renderView('selectbiblechaptersummarywork'$data);
  2290.     }
  2291.     
  2292.     public function fullviewTranslationPassageAction($passageId$translationIdRequest $request)
  2293.     {        
  2294.            $sSql "select url FROM expositiontranslation where id = " $translationId;
  2295.            
  2296.  //   echo $sSql."<br>";   
  2297.        $sUrl $this->getSingleData($sSql);
  2298.        
  2299.        $sLink $this->get('router')->generate('exposition_translation_passage', array(
  2300.                         'translationUrl' => $sUrl,
  2301.                         'passageId' => $passageId                      
  2302.                     ));
  2303.             
  2304.        if(!empty($sLink))
  2305.                return $this->redirect($sLink301);            
  2306.        else
  2307.             return $this->redirect("/"301);
  2308.     }
  2309.     
  2310.     public function projecthubAction(Request $request)
  2311.     {            
  2312.         $locale $request->getLocale(); 
  2313.         $data = array(                         
  2314.         );
  2315.         $this->setCurrentUrl($request); 
  2316.         $this->onloadPage($request);
  2317.         return $this->renderView('projecthub'$data);
  2318.     }
  2319.     
  2320.     public function search_projectAction(Request $request)
  2321.     {            
  2322.         $locale $request->getLocale();
  2323.         $searchedResults = array();
  2324.         $sSearchTerm $request->query->get('searchTerm');  
  2325.         $nStartNum $request->query->get('startnum');      
  2326.         if($sSearchTerm != '')
  2327.         {
  2328.             $searchedResults $this->getSearchedProject($locale$request);
  2329.         }    
  2330.         else
  2331.         {            
  2332.             $searchedResults $this->getExplanationList($nStartNum$locale$request);
  2333.         }            
  2334.         
  2335.         return $this->renderView('project_searched', array(     
  2336.             'searched_project' => $searchedResults,
  2337.             'start_num' => $nStartNum           
  2338.         ));
  2339.     }
  2340.         
  2341.     public function getSearchedProject($locale$request)
  2342.     {        
  2343.         $search = new PostgresSearch();
  2344.         $em $this->getDoctrine()->getManager();
  2345.         $search->setManager($em);
  2346.         $sCategoryId 52;
  2347.         return $search->getCategorySearchResults($sCategoryId$locale$request);
  2348.     }
  2349.     
  2350.     public function featured_projectsAction(Request $request)
  2351.     {                   
  2352.         $this->onloadPage($request);
  2353.         $locale $request->getLocale();
  2354.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_PROJECT$locale9false);
  2355.         if(empty($featuredList))
  2356.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_PROJECT$locale9true);
  2357.         return $this->renderView('projects_featured', array(     
  2358.             'featured_records' => $featuredList            
  2359.         ));
  2360.     }
  2361.     
  2362.     public function search_concordanceAction(Request $request)
  2363.     {            
  2364.         $locale $request->getLocale();
  2365.         $searchedResults = array();
  2366.         $sSearchTerm $request->query->get('searchTerm');  
  2367.         //$nStartNum = $request->query->get('startnum');      
  2368.         if($sSearchTerm != '')
  2369.         {            
  2370.             //$searchedResults = $this->getSearchedListByCategory($this->CATEGORY_ID_CONCORDANCE, $locale, $request);
  2371.             $searchedResults $this->getListByCategoryWithSearchTerm($request$locale$this->CATEGORY_ID_CONCORDANCE$sSearchTerm);
  2372.         }    
  2373.         else
  2374.         {
  2375.             $searchedResults $this->getAllListByCategory($this->CATEGORY_ID_CONCORDANCE$locale$request);
  2376.         }            
  2377.         
  2378.         return $this->renderView('concordance_searched', array(     
  2379.             'searched_results' => $searchedResults           
  2380.         ));
  2381.     }
  2382.     
  2383.     public function featured_concordanceAction(Request $request)
  2384.     {                       
  2385.     //    $this->setCurrentUrl($request); 
  2386.         $this->onloadPage($request);
  2387.         $locale $request->getLocale();        
  2388.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCORDANCE$locale9);
  2389.         if(empty($featuredList))
  2390.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCORDANCE$locale9true);
  2391.         $request->getSession()->set('searched_concordance_list', array());
  2392.         return $this->renderView('concordance_featured', array(     
  2393.             'featured_concordance' => $featuredList            
  2394.         ));
  2395.     }
  2396. }