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

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($request$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.         $msgData $this->checkWorkTranslationMsg($request$translationUrl); 
  546.         if(!empty($msgData))
  547.         {
  548.               $response = new Response();
  549.             $response->setStatusCode(404);
  550.               return $this->renderView('no_content'$msgData$response);
  551.         }    
  552.         
  553.         if(strlen($passageNumber) > 8) {
  554.             $response = new Response();
  555.             $response->setStatusCode(404);
  556.             return $this->renderView('no_work_content', array(), $response);
  557.         }
  558.         
  559.         if(!$this->IsSwedenborgWork($translationUrl))
  560.         {
  561.             return $this->redirect($this->get('router')->generate('exposition_translation', array(
  562.                     'translationUrl' => $translationUrl
  563.                 )), 301);
  564.         }
  565.     
  566.         $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  567.         if($translation == null) {
  568.             $response = new Response();
  569.             $response->setStatusCode(404);
  570.             return $this->renderView('no_work_content', array(), $response);
  571.         }
  572.         
  573.         if($userSelected && $translation !== null) {
  574.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  575.         }
  576.         $redir $this->checkRedirect($translation);
  577.         if($redir !== null) {
  578.             return $this->redirect($redir301);
  579.         }
  580.         $work = ($translation === null) ? null $translation->getWork();
  581.         
  582.         if(!$work->getIsPublic()) {
  583.             $response = new Response();
  584.             $response->setStatusCode(404);
  585.             return $this->renderView('no_work_content', array(), $response);
  586.         }
  587.         // 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
  588.         if($work !== null && $work->getUrl() === 'arcana-coelestia' && $divisionUrls === 'contents' && $passageNumber !== null && substr($passageNumber, -1) === '0') {
  589.             $passage $this->expositionData('Passage')->findSwedenborgSection($worksubstr($passageNumber0, -1));
  590.             return $this->passageCanonicalRedirect($passage$translation);
  591.         }
  592.         $passage $this->findPassageByWorkAndDivisions($work$divisionUrls$passageNumber);
  593.         
  594.         if(!$inFrame)
  595.             $this->setCurrentUrl($request); 
  596.             
  597.         return $this->translationPassageView($passage$translation$request$inFrame);
  598.     }
  599.     protected function translationPassageView($passage$translation$request$inFrame false)
  600.     {    
  601.         $this->checkIfOnMobile($request);        
  602.         $locale $request->getLocale();
  603.         $nTranslationID $translation->getId();
  604.         $sUrlCompareTo $request->query->get('compareTo');
  605.         $aCompare explode(";;"$sUrlCompareTo);
  606.         $nCompareLen count($aCompare);
  607.         $compareTo null;
  608.         $compareTo2 null;    
  609.         $text_to_speech2 null;
  610.         $text_to_speech3 null;
  611.         $text_style_override_compare_to null;   
  612.         $text_style_override_compare_to2 null
  613.         $translation_shortname2 null;
  614.         $translation_shortname3 null;
  615.         if($nCompareLen && $aCompare[0] != '')
  616.         {
  617.             $compareTo $this->expositionData('Translation')->findOneBy(array('url' => $aCompare[0], 'isPublic' => true));   
  618.             if($compareTo != null)    
  619.             {
  620.                 $nLanguageID2 $compareTo->getLanguage()->getId();
  621.                 $text_style_override_compare_to $this->getTextStyleOverride($nLanguageID2);
  622.                 $text_to_speech2 $this->getTextToSpeech($request$nLanguageID2);
  623.                 
  624.                 $translation_shortname2 $this->getWorkTranslationShortName($compareTo->getId());                
  625.             }    
  626.         }         
  627.         
  628.         if($nCompareLen == && $aCompare[1] != ''
  629.         {           
  630.             $compareTo2 $this->expositionData('Translation')->findOneBy(array('url' => $aCompare[1], 'isPublic' => true)); 
  631.             if($compareTo2 != null)    
  632.             {
  633.                 $nLanguageID3 $compareTo2->getLanguage()->getId();
  634.                 $text_style_override_compare_to2 $this->getTextStyleOverride($nLanguageID3);
  635.                 $text_to_speech3 $this->getTextToSpeech($request$nLanguageID3);
  636.                 $translation_shortname3 $this->getWorkTranslationShortName($compareTo2->getId());
  637.             }    
  638.         }    
  639.         
  640.         $bSwedenborg $this->isSwedenborg($nTranslationID);
  641.         $chapterExplanations null;
  642.         $chapterExplanationsForCombo null;
  643.         $prev_chapter_explanation = array();
  644.         $next_chapter_explanation = array();
  645.         $explained_cbook_id null;
  646.         if(!$bSwedenborg)
  647.         {    
  648.             $chapterExplanations $this->getChapterExplanationsForNav($translation);       
  649.             $chapterExplanationsForCombo $this->getChapterExplanationsForTextForCombo($translation); 
  650.             
  651.             if(!empty($chapterExplanations))
  652.             {
  653.                 $bHasPass false;
  654.                 foreach($chapterExplanations as $ce)
  655.                 {
  656.                     if($ce['translation_id'] == $nTranslationID)
  657.                         $bHasPass true;
  658.                     else
  659.                     {    
  660.                         if(!$bHasPass)
  661.                         {
  662.                             $prev_chapter_explanation['url'] = $ce['translation_url'];
  663.                             $prev_chapter_explanation['title'] = $ce['explanationtitle'];
  664.                         }    
  665.                         else
  666.                         {
  667.                             $next_chapter_explanation['url'] = $ce['translation_url'];
  668.                             $next_chapter_explanation['title'] = $ce['explanationtitle'];
  669.                             break;
  670.                         }        
  671.                     }                            
  672.                 }
  673.                 
  674.                 $explained_cbook_id $chapterExplanations[0]['book_id'];
  675.             }
  676.         }
  677.         $ref_column_spec '';
  678.         if($bSwedenborg)
  679.             $ref_column_spec $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK;    
  680.         else
  681.             $ref_column_spec $this->MULTI_URL_INDICATOR_EXPLANATION;    
  682.         
  683.         $ref_column_spec .= '_' $translation->getUrl();
  684.         if($passage != null && $bSwedenborg)
  685.             $ref_column_spec .= '_' $passage->getSwedenborgSection();
  686.             
  687.         $nPassageID null;    
  688.         if($passage != null)
  689.             $nPassageID $passage->getId();
  690.             
  691.         $nLanguageID $translation->getLanguage()->getId();      
  692.         $data = array(
  693.             'translation' => $translation,
  694.             'passage' => $passage,
  695.             'compare_to' => $compareTo,
  696.             'compare_to2' => $compareTo2,
  697.             'nav_mode' => 'translation',            
  698.           //  'chapter_explanations' => $chapterExplanations,
  699.             'chapter_explanations_for_combo' => $chapterExplanationsForCombo,
  700.             'prev_chapter_explanation' => $prev_chapter_explanation,
  701.             'next_chapter_explanation' => $next_chapter_explanation,
  702.             'explained_cbook_id' => $explained_cbook_id,
  703.             'ref_column_spec' => $ref_column_spec,
  704.             'text_style_override' => $this->getTextStyleOverride($nLanguageID),
  705.             'text_style_override_compare_to' => $text_style_override_compare_to,
  706.             'text_style_override_compare_to2' => $text_style_override_compare_to2,
  707.             'text_to_speech1' => $this->getTextToSpeech($request$nLanguageID),
  708.             'text_to_speech2' => $text_to_speech2,
  709.             'text_to_speech3' => $text_to_speech3,            
  710.             'translation_shortname2' => $translation_shortname2,
  711.             'translation_shortname3' => $translation_shortname3            
  712.         );
  713.         
  714.         $data['is_ipad'] = $this->isIPad();
  715.         
  716.         if($translation !== null) {
  717.        /*     $selectorData = $this->selectSelectorList($translation->getWork(), $translation->getLanguage()->getName(), $translation);
  718.             if($selectorData !== null) {
  719.                 $data['selector_data'] = $selectorData;
  720.             } */
  721.             $work $translation->getWork();
  722.             
  723.             $bSwedenborgWork = ($work->getSwedenborgType() !== null);
  724.             $data['is_swedenborg'] = $bSwedenborgWork;
  725.             if($bSwedenborgWork)
  726.             {
  727.                 $data['linktype_id'] = $this->LINK_TYPE_ID_SWEDENBORG;
  728.             }
  729.             else
  730.             {
  731.                 $data['linktype_id'] = $this->LINK_TYPE_ID_OTHER;
  732.             }
  733.             if($bSwedenborgWork && $nLanguageID == $request->getSession()->get('work_search_language_id'))
  734.             {
  735.                 $data['work_searchterm'] = $request->getSession()->get('work_searchterm');
  736.                 $data['work_search_phrase'] = $request->getSession()->get('work_search_phrase');
  737.                 if($nLanguageID == $this->LANGUAGE_ID_LATIN)
  738.                 {
  739.                     $data['work_search_internal_amb'] = $request->getSession()->get('work_search_internal_amb');                    
  740.                     $data['work_search_external_amb'] = $request->getSession()->get('work_search_external_amb');
  741.                     $data['work_search_int_ext_amb'] = $request->getSession()->get('work_search_int_ext_amb');
  742.                 }
  743.                 else
  744.                 {
  745.                     $data['work_search_internal_amb'] = null;
  746.                     $data['work_search_external_amb'] = null;
  747.                     $data['work_search_int_ext_amb'] = null;
  748.                 }
  749.             }
  750.             else
  751.             {
  752.                 $data['work_searchterm'] = null;
  753.                 $data['work_search_phrase'] = null;
  754.                 $data['work_search_internal_amb'] = null;
  755.                 $data['work_search_external_amb'] = null;
  756.                 $data['work_search_int_ext_amb'] = null;
  757.             }
  758.             
  759.             $bConsider false;
  760.             $bBibleStudy false;
  761.             $bConcept false;
  762.             $bQA false;
  763.             $bConcordance false;
  764.             if(!$bSwedenborgWork)
  765.             {
  766.                 foreach($work->getCategories() as $category) {
  767.                     if($category->getId() == $this->CATEGORY_ID_SPIRITUAL_TOPIC) {
  768.                         $bConsider true;
  769.                     }
  770.                     elseif($category->getId() == $this->CATEGORY_ID_BIBLE_STUDY) {
  771.                         $bBibleStudy true;
  772.                     }
  773.                     elseif($category->getId() == $this->CATEGORY_ID_CONCEPT) {
  774.                         $bConcept true;
  775.                         $data['category_concept'] = 1;
  776.                     }
  777.                     elseif($category->getId() == $this->CATEGORY_ID_QA) {
  778.                         $bQA true;
  779.                     }
  780.                     elseif($category->getId() == $this->CATEGORY_ID_CONCORDANCE) {
  781.                         $bConcordance true;
  782.                     }
  783.                 }
  784.             }
  785.             
  786.             $nLanguageID $translation->getLanguage()->getId();
  787.             if($bQA)
  788.             {                
  789.                 $data['prev_next'] = $this->getPrevNextLink($translation->getId(), $this->CATEGORY_ID_QA$request);
  790.             }
  791.             else
  792.             {
  793.                 if($bConsider)
  794.                 {                
  795.                     $aAllTopic = array();
  796.                     $sTranslationUrl $translation->getUrl();
  797.                     $aSearchedTopic $request->getSession()->get('searched_topic_list');
  798.                     if(!empty($aSearchedTopic))
  799.                     {                
  800.                         foreach($aSearchedTopic as $s)
  801.                         {                
  802.                             if($s['translation_url'] == $sTranslationUrl)
  803.                             {
  804.                                 $aAllTopic $aSearchedTopic;
  805.                                 break;
  806.                             }
  807.                         }
  808.                     }
  809.                     
  810.                     if(empty($aAllTopic))
  811.                     {                    
  812.                         $aAllTopic $this->getCategoryList($nLanguageID$this->CATEGORY_ID_SPIRITUAL_TOPIC$locale);
  813.                     }                
  814.                 
  815.                     $data['consider_data'] = $aAllTopic;
  816.                     $data['prev_next'] = $this->getPrevNextLinkFromList($translation->getId(), $data['consider_data']);                    
  817.                 }
  818.                 
  819.                 if($bBibleStudy)
  820.                 {
  821.                     $data['biblestudy_data'] = $this->getCategoryList($nLanguageID$this->CATEGORY_ID_BIBLE_STUDY$locale);
  822.                     $data['prev_next'] = $this->getPrevNextLinkFromList($translation->getId(), $data['biblestudy_data']);                    
  823.                 }
  824.                 
  825.                 if($bConcordance)
  826.                 {            
  827.                     $aAllConcordance = array();
  828.                     $sTranslationUrl $translation->getUrl();
  829.                     $aSearchedConcordance $request->getSession()->get('searched_concordance_list');
  830.                     if(!empty($aSearchedConcordance))
  831.                     {                
  832.                         foreach($aSearchedConcordance as $s)
  833.                         {                
  834.                             if($s['translation_url'] == $sTranslationUrl)
  835.                             {
  836.                                 $aAllConcordance $aSearchedConcordance;
  837.                                 break;
  838.                             }
  839.                         }
  840.                     }
  841.                     if(empty($aAllConcordance))
  842.                     {                    
  843.                         $data['prev_next'] = $this->getNextPrevCategoryUrl($translation->getId(), $nLanguageID$this->CATEGORY_ID_CONCORDANCE$locale);
  844.                     }
  845.                     else
  846.                     {
  847.                         $data['prev_next'] = $this->getPrevNextLinkFromList($translation->getId(), $aAllConcordance);
  848.                         $data['concordance_has_searched_list'] = true;
  849.                         $data['work_searchterm'] = $request->getSession()->get('searched_concordance_term');        
  850.                         $data['work_search_phrase'] = $request->getSession()->get('searched_concordance_phrase');
  851.                     }                
  852.                 }
  853.                 
  854.                 if($bConcept)
  855.                 {                
  856.                     $data['concept_prev_next'] = $this->getNextPrevConceptUrl($translation->getId(), $nLanguageID$locale);
  857.                     $data['related_concept_list'] = $this->getRelatedConceptList($translation->getId());
  858.                     $data['concept_url'] = $this->getConceptUrlFromTranslation($translation->getId());
  859.                 }                
  860.             }
  861.                         
  862.             if(!$bSwedenborgWork)                
  863.                 $data['authors'] = $this->getAuthorInfo($request$translation->getId());
  864.             else
  865.                 $data['IsSwedenborgWork'] = 1;    
  866.                 
  867.             $type_id $translation->getTypeId();
  868.         
  869.             if($type_id == $this->TRANSLATION_TYPE_ID_FILE
  870.             {
  871.                 $file $translation->getFile();
  872.                 if($file !== null) {
  873.                     $data['file'] = $file;
  874.                 }
  875.             }
  876.             if($type_id == $this->TRANSLATION_TYPE_ID_LINK
  877.             {
  878.                 $doc_link $translation->getDocLink();
  879.                 if($doc_link !== null) {
  880.                     $data['doc_link'] = $doc_link;
  881.                 }
  882.             }
  883.             
  884.             $data['type_id'] = $type_id;
  885.             
  886.             $data['in_frame'] = $inFrame;
  887.             
  888.             if($passage != null)
  889.             {            
  890.                 $nTranslationID $translation->getId();
  891.                 
  892.                 if(!$bSwedenborgWork)
  893.                     $data['passage_ref'] = $this->getWorkPassageRefs($nPassageID,$nTranslationID$request);
  894.                 
  895.                 if($bSwedenborgWork)
  896.                     $data['related_bible_ref'] = $this->getRelatedBibleRefForWork($nPassageID,$nTranslationID$request);
  897.                 $data['passage_footnote'] = $this->getPassageFootnotes($nPassageID,$nTranslationID);
  898.                 $data['passage_multilink'] = $this->getWorkPassageMultiLink($nPassageID,$nTranslationID$request);
  899.                 if($bSwedenborgWork && ($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)))
  900.                 {                
  901.                     $data['passage_scanimage'] = $this->getWorkPassageScanImageFileName($nPassageID);
  902.                     $data['define_latin_icon'] = 1;    
  903.                     
  904.                     if($this->userCanSeeHdpf($request))
  905.                     {
  906.                         $nLatinTransID null;
  907.                         if($translation->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN)
  908.                             $nLatinTransID $translation->getId();
  909.                         else if($compareTo != null && $compareTo->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN)
  910.                             $nLatinTransID $compareTo->getId();
  911.                         else if($compareTo2 != null && $compareTo2->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN)
  912.                             $nLatinTransID $compareTo2->getId();
  913.                         if(!empty($nLatinTransID))
  914.                         {
  915.                             $data['passage_hdpf_info'] = $this->getHDPFInfo($nLatinTransID$passage->getSwedenborgSection());
  916.                         }                        
  917.                     }
  918.                 }
  919.                                           
  920.                 $request->getSession()->set('current_explanation_cchapter_id''');                
  921.                 $nExplainChapterID $this->getExplainChapterID($nTranslationID$this->getCurrUserID($request)); 
  922.                   if(!empty($nExplainChapterID))
  923.                   {                  
  924.                       $data['cchapter_id'] = $nExplainChapterID;
  925.                     $request->getSession()->set('current_explanation_cchapter_id'$nExplainChapterID); 
  926.                       $request->getSession()->set('current_explanation_translation_id'$nTranslationID);
  927.                   }
  928.                                     
  929.                   if(!$bSwedenborgWork)
  930.                   {
  931.                       if ($this->canEditExplanation($request))                  
  932.                           $data['explanation_translation_id_to_edit'] = $nTranslationID;
  933.                   }    
  934.                   else if ($this->canEditWork($request))
  935.                   {
  936.                       $data['work_translation_id_to_edit'] = $nTranslationID;    
  937.                       $data['work_passage_num_to_edit'] = $passage->getSwedenborgSection();        
  938.                       //$data['has_slider_item_for_work'] = $this->hasSliderItemForWork($nPassageID, $nTranslationID, $request, $nLanguageID);
  939.         
  940.                     $data['slider_url'] = $this->get('router')->generate('exposition_slider', array(
  941.                             'translationId' => $nTranslationID,
  942.                             'passageId' => $nPassageID
  943.                         ));
  944.                   }    
  945.                   
  946.                   if($bSwedenborgWork)
  947.                   {                              
  948.                       $data['has_slider_item_for_work'] = $this->hasSliderItemForWork($nPassageID$nTranslationID$request$nLanguageID);
  949.         
  950.                     $data['slider_url'] = $this->get('router')->generate('exposition_slider', array(
  951.                             'translationId' => $nTranslationID,
  952.                             'passageId' => $nPassageID
  953.                         ));
  954.                     
  955.                     if($passage->emptyInTranslation($translation))
  956.                     {    
  957.                         $data['last_passage_num'] = $this->getLastAvailablePassageNum($nTranslationID);
  958.                     }   
  959.                   }    
  960.                   
  961.                   // check table of contents
  962.                   $aTOC $this->getWorkTranslationTOC($nTranslationIDtrue); 
  963.                   if(!empty($aTOC))
  964.                   {                  
  965.                       $data['has_work_toc'] = true;
  966.                   }              
  967.             }
  968.             $data['text_to_speech'] = $this->getTextToSpeech($request$nLanguageID);
  969.             $data['language_for_speech'] = $this->getLanguageForSpeech($request$nLanguageID);
  970.             
  971.             if($bSwedenborgWork)   
  972.             {     
  973.                 $data['biblio_info'] = $this->getBiblioForTranslation($translation->getId());
  974.             //    $data['swedenborg_works'] = $this->getCategorizedSwedenborgWorksForTranslation($request, $translation->getId(), $translation->getLanguage()->getId());
  975.             }
  976.             else
  977.             {
  978.                 // check concept image
  979.                 if($compareTo == null)
  980.                 {
  981.                     $conceptUrl $this->getConceptUrl($translation->getWork()->getId());                    
  982.                     if(!empty($conceptUrl))
  983.                     {
  984.                         $concept $this->getRepository('Concepts\Concept')->findOneByUrl($conceptUrl);
  985.                         $illustrations $concept->getIllustrations();
  986.                         $data['image'] = ($illustrations->isEmpty()) ? null $illustrations[0]->getImage();
  987.                     }
  988.                 }
  989.             }    
  990.         } else {
  991.             $work null;
  992.         }
  993.         return $this->createPassageView($data'translation'$work$request);
  994.     }
  995.     public function translationDivisionAction($translationUrl$divisionUrls$userSelected trueRequest $request)
  996.     {
  997.         $this->onloadPage($request);
  998.         $translation $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl'isPublic' => true));
  999.         if($userSelected) {
  1000.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  1001.         }
  1002.         $redir $this->checkRedirect($translation);
  1003.         if($redir !== null) {
  1004.             return $this->redirect($redir301);
  1005.         }
  1006.         $work = ($translation === null) ? null $translation->getWork();
  1007.         $division $this->findDivisionByWorkAndUrls($work$divisionUrls);
  1008.         $data = array('translation' => $translation'division' => $division'nav_mode' => 'translation');
  1009.   /*      $selectorData = $this->selectSelectorList($translation->getWork(), $translation->getLanguage()->getName(), $translation);
  1010.         if($selectorData !== null) {
  1011.             $data['selector_data'] = $selectorData;
  1012.         } */
  1013.         $response null;
  1014.         if($division === null) {
  1015.             $response = new Response();
  1016.             $response->setStatusCode(404);
  1017.             return $this->renderView('no_work_content', array(), $response);
  1018.         }
  1019.         $this->setCurrentUrl($request);         
  1020.         return $this->renderView('translation_division'$data$response);
  1021.     }
  1022.     // Final tasks to be performed when rendering a passage, whether accessed via work or via translation
  1023.     protected function createPassageView($data$mode$work$request)
  1024.     {
  1025.         $locale $request->getLocale();
  1026.         $response null;
  1027.         if($work === null || $data['translation'] === null || $data['passage'] === null || $data['passage']->findWork() !== $work) {
  1028.             $response = new Response();
  1029.             $response->setStatusCode(404);
  1030.             return $this->renderView('no_work_content', array(), $response);
  1031.         }
  1032.         
  1033.         $nPassageID $data['passage']->getId();
  1034.         $nTranslationID $data['translation']->getId();
  1035.         $nLanguageID $data['translation']->getLanguage()->getId();
  1036.         $data['translation_shortname'] = $this->getWorkTranslationShortName($nTranslationID);
  1037.         
  1038.         $nBibleBookIDForSummary $this->getBibleBookIDForSummary($nTranslationID);
  1039.         $bBibleBookSummary = ($nBibleBookIDForSummary != '');
  1040.         if($bBibleBookSummary)
  1041.             $data['is_book_summary'] = '1';
  1042.         
  1043.         if($work !== null) {              
  1044.                $nLevelID '';
  1045.                $aStory $this->getStoryInfo($nTranslationID);
  1046.             if(!empty($aStory))
  1047.             {                   
  1048.                 $nStoryID $aStory['story_id'];
  1049.                 $nLevelID $aStory['level_id'];               
  1050.                 if($nLevelID == $this->STORY_LEVEL_ID_BIBLE)
  1051.                 {  
  1052.                     $aAllStory = array();
  1053.             /*        $aSearchedStory = $request->getSession()->get('searched_bible_story_list');
  1054.                     if(!empty($aSearchedStory))
  1055.                     {
  1056.                         $sTranslationUrl = $data['translation']->getUrl();
  1057.                         foreach($aSearchedStory as $s)
  1058.                         {                
  1059.                             if($s['commentary_url'] == $sTranslationUrl)
  1060.                             {
  1061.                                 $aAllStory = $aSearchedStory;
  1062.                                 break;
  1063.                             }
  1064.                         }
  1065.                     }
  1066.                     
  1067.                     if(empty($aAllStory))
  1068.                     {
  1069.                         $aAllStory = $this->getExplainedStoryList($locale);
  1070.                     }
  1071.             //        print_r($aAllStory); */
  1072.                     $data['all_stories'] = $aAllStory;
  1073.                     
  1074.                     $data['story_explanations'] = $this->getWorkListForStory($locale$nStoryID);
  1075.                     $data['commentary_type'] = 'storyexplanation';                                            
  1076.                 }
  1077.                 elseif($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
  1078.                     $data['is_chapter_explanation'] = '1';
  1079.                 elseif($nLevelID == $this->STORY_LEVEL_ID_VERSE)
  1080.                     $data['is_verse_explanation'] = '1';    
  1081.                                
  1082.                 $data['story_id'] = $nStoryID;
  1083.             }  
  1084.             // We can override the 'storyexplanation' commentary type because some "story" explanations are really verse explanations.
  1085.             // 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.
  1086.             // 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.
  1087.             if($this->getConceptID($data['translation']->getId()) !== null) {
  1088.                 $data['commentary_type'] = 'conceptexplanation';
  1089.             } else {
  1090.                 $containingCategories $work->getCategories()->toArray();
  1091.                 if($data['translation'] !== null) {
  1092.                     $containingCategories array_merge($containingCategories$data['translation']->getCategories()->toArray());
  1093.                 }
  1094.                 $categoryUrlToCommentaryTypeMap = array(
  1095.                     'doctrinal-topic-explanations' => 'doctrinaltopic',
  1096.                     'verse-explanations' => 'verseexplanation',
  1097.                     // 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
  1098.                     'story-explanations' => 'storyexplanation'
  1099.                 );
  1100.                 // If the content doesn't belong to the Category for any major commentary type, then $data['commentary_type'] can just remain unset.
  1101.                 foreach($containingCategories as $cat) {
  1102.                     if(array_key_exists($cat->getUrl(), $categoryUrlToCommentaryTypeMap)) {
  1103.                         $data['commentary_type'] = $categoryUrlToCommentaryTypeMap[$cat->getUrl()];
  1104.                         // At the time of coding this, there shouldn't be anything which belongs to more than one major commentary type.
  1105.                         break;
  1106.                     }
  1107.                 }
  1108.             }
  1109.         }
  1110.                 
  1111.         if($work->getSwedenborgType() !== null)
  1112.         {              
  1113.             $data['previous_passage'] = $this->getPreviousPassageWithContent($data['passage'], $data['translation']);
  1114.             $data['next_passage'] = $this->getNextPassageWithContent($data['passage'], $data['translation']); 
  1115.                         
  1116.             $nTextLength 140;            
  1117.             $sPassageText $this->getWorkPassageContents($nPassageID,$nTranslationID);
  1118.             $sPassageNum $data['passage']->getSwedenborgSection();
  1119.             if(intval($sPassageNum) == && strlen($sPassageText) < 160)
  1120.             {                
  1121.                 $aTOC $this->getWorkTranslationTOC($nTranslationID);        
  1122.                   if(!empty($aTOC))
  1123.                   {          
  1124.                       $data['work_toc'] = $aTOC;
  1125.                   }
  1126.             }
  1127.             
  1128.             $sMetaDesc $this->fixWorkText($sPassageText);
  1129.               $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength);          
  1130.               $data['work_meta_desc'] = $sMetaDesc;
  1131.         }
  1132.         else
  1133.         {
  1134.             $nTextLength 140;
  1135.             $sPassageText '';
  1136.             if($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
  1137.             {
  1138.                 $sPassageText $this->getWorkPassageContents($nPassageID,$nTranslationID);
  1139.             }
  1140.             else
  1141.             {
  1142.                 $sPassageText $this->getWorkTranslationDesc($nTranslationID); 
  1143.                 if(empty($sPassageText))
  1144.                 {
  1145.                     $sPassageText $this->getWorkPassageContents($nPassageID,$nTranslationID); 
  1146.                 }
  1147.             }
  1148.             $sMetaDesc $this->fixWorkText($sPassageText);
  1149.               $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength);          
  1150.               $data['work_meta_desc'] = $sMetaDesc;
  1151.         }      
  1152.         
  1153.         $data['work'] = $work;
  1154.                      
  1155.         return $this->renderView($mode.'_passage'$data$response);
  1156.     }
  1157.     protected function findDivisionByWorkAndUrls($work$divisionUrls)
  1158.     {
  1159.         if($work === null) {
  1160.             return null;
  1161.         }
  1162.         $divisionUrlList explode('/'$divisionUrls);
  1163.         $divisionData $this->expositionData('Division');
  1164.         $division $divisionData->findOneBy(array(
  1165.             'work' => $work->getId(), 'url' => array_shift($divisionUrlList)));
  1166.         foreach($divisionUrlList as $url) {
  1167.             if($division === null) {
  1168.                 return null;
  1169.             }
  1170.             $division $divisionData->findOneBy(array('superdivision' => $division->getId(), 'url' => $url));
  1171.         }
  1172.         return $division;
  1173.     }
  1174.     protected function findPassageByWorkAndDivisions($work$divisionUrls$passageNumber null)
  1175.     {
  1176.         $division $this->findDivisionByWorkAndUrls($work$divisionUrls);
  1177.         if($division === null) {
  1178.             return null;
  1179.         }
  1180.         return ($passageNumber === null)
  1181.             ? $division->findFirstPassage()
  1182.             : $this->expositionData('Passage')->findOneBy(array(
  1183.                 'division' => $division->getId(),
  1184.                 'ordering' => $passageNumber
  1185.             ));
  1186.     }
  1187.     public function conceptAction($conceptUrlRequest $request$languageCode ''$asOverlay false)
  1188.     {      
  1189.           // The client requested to use translation url instead of concept url if not overlay (3/16/2020)
  1190.           
  1191.           $this->onloadPage($request);          
  1192.         if(!$asOverlay)
  1193.         {
  1194.             $sTranslationUrl $this->getConceptTranslationUrl($conceptUrl$languageCode);
  1195.             if(!empty($sTranslationUrl))
  1196.             {
  1197.                 return $this->redirect($this->get('router')->generate('exposition_translation', array(
  1198.                         'translationUrl' => $sTranslationUrl
  1199.                     )), 301);
  1200.             }        
  1201.         }
  1202.       
  1203.           $locale $request->getLocale();
  1204.         $displayInfo = array('nav_mode' => 'translation''commentary_type' => 'conceptexplanation');
  1205.         $concept $this->getRepository('Concepts\Concept')->findOneByUrl($conceptUrl);
  1206.         
  1207.         if(!empty($languageCode))
  1208.         {
  1209.             $language $this->getLanguageByBibliographicCode($languageCode);
  1210.             $nLanguageID $language['id'];
  1211.         }
  1212.         else
  1213.         {
  1214.             $nLanguageID $this->getLanguageIDByShortCode($locale);            
  1215.         }
  1216.         
  1217.         $sTranslationUrl $this->getConceptTranslationUrl($conceptUrl$languageCode);
  1218.                  
  1219.         if(!empty($sTranslationUrl)) 
  1220.         {     
  1221.             $translation =  $this->expositionData('Translation')->findOneByUrl($sTranslationUrl); 
  1222.             $displayInfo['translation'] = $translation;               
  1223.             $displayInfo['title'] = $translation->getNameOrTitle();
  1224.             $illustrations $concept->getIllustrations();
  1225.             $displayInfo['image'] = ($illustrations->isEmpty()) ? null $illustrations[0]->getImage();
  1226.             
  1227.             $displayInfo['passage'] = $translation->getWork()->findFirstPassage();
  1228.             $displayInfo['text_style_override'] = $this->getTextStyleOverride($translation->getLanguage()->getId());
  1229.             
  1230.             $displayInfo['passage_ref'] = $this->getWorkPassageRefs($displayInfo['passage']->getId(),$translation->getId(), $request); 
  1231.             $displayInfo['ref_column_spec'] = $this->getExplanationUrl($translation->getId());
  1232.             $displayInfo['passage_footnote'] = $this->getPassageFootnotes($displayInfo['passage']->getId(),$translation->getId());
  1233.             $displayInfo['passage_multilink'] = $this->getWorkPassageMultiLink($displayInfo['passage']->getId(),$translation->getId(), $request);
  1234.             $displayInfo['concept_url'] = $conceptUrl;
  1235.         } elseif($concept !== null) {
  1236.             // 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
  1237.         } else {
  1238.             $displayInfo['translation'] = null;
  1239.             $displayInfo['passage'] = null;
  1240.         }
  1241.         $response null;
  1242.         if(empty($sTranslationUrl) || $displayInfo['translation'] === null) {
  1243.             $response = new Response();
  1244.             $response->setStatusCode(404);
  1245.             return $this->renderView('no_work_content', array(), $response);
  1246.         }
  1247.     
  1248.         $templateName $asOverlay 'overlay/passage' 'translation_passage';
  1249.         
  1250.     /*    if(!$asOverlay)
  1251.         {
  1252.             $this->setCurrentUrl($request);
  1253.             $displayInfo['concept_prev_next'] = $this->getNextPrevConcept($concept->getId());
  1254.         }    */ 
  1255.                         
  1256.         return $this->renderView($templateName$displayInfo$response);
  1257.     }
  1258.     protected function passageCanonicalRedirect($passage$translation$code 301)
  1259.     {    
  1260.           $redirectUrl $this->get('router')->generate('exposition_translation_division_passage', array(
  1261.                     'translationUrl' => $translation->getUrl(),
  1262.                     'divisionUrls' => $passage->getDivision()->getUrl(),
  1263.                     'passageNumber' => $passage->getOrdering()
  1264.                 )); 
  1265.               
  1266.         $args = @$_SERVER['QUERY_STRING'];
  1267.         if(!empty($args)) 
  1268.         {                
  1269.             $redirectUrl .= '?'.$args;                   
  1270.         }
  1271.         return $this->redirect($redirectUrl$code);
  1272.     }
  1273.     public function swedenborgGotoAction(Request $request)
  1274.     {
  1275.         $this->onloadPage($request);
  1276.         $statusCode 200;
  1277.         $query $request->query;
  1278.         if(!$query->has('translation') && !$query->has('work')) {
  1279.             // If we aren't told what book to show, then we'll redirect to the list of all Swedenborg books
  1280.             return $this->redirect($this->get('router')->generate('swedenborg'));
  1281.         }
  1282.         
  1283.         $translation $this->expositionData('Translation')->findOneByUrl($query->get('translation'));
  1284.         if($translation !== null) {
  1285.             $request->getSession()->set('current_language'$translation->getLanguage()->getBibliographicCode());
  1286.             $work $translation->getWork();
  1287.             $params = array('translation' => $translation'nav_mode' => 'translation');
  1288.      /*       if($work->getSwedenborgType() !== null) {
  1289.                 $params['selector_data'] = $this->buildSwedenborgSelectorList($translation->getLanguage()->getName(), $translation); 
  1290.             }*/
  1291.         } else {
  1292.             $work $this->expositionData('Work')->findOneByUrl($query->get('work'));
  1293.             $params = array('work' => $work'nav_mode' => 'work');
  1294.             $translation $work->selectTranslation();
  1295.     /*        if($work->getSwedenborgType() !== null) {
  1296.                 $params['selector_data'] = $this->buildSwedenborgSelectorList();
  1297.             } */
  1298.         }
  1299.         if($query->has('section')) {
  1300.             $targetSectionNumber $query->get('section');
  1301.             $targetSection $this->expositionData('Passage')->findSwedenborgSection($work$targetSectionNumber);
  1302.             
  1303.             $inframe $query->get('inframe');
  1304.             if($inframe == 1)
  1305.             {
  1306.                 return $this->redirect($this->get('router')->generate('exposition_frame_passage', array(
  1307.                         'translationUrl' => $translation->getUrl(),
  1308.                         'divisionUrls' => $targetSection->getDivision()->getUrl(),
  1309.                         'passageNumber' => $targetSection->getOrdering()
  1310.                     )), 301);                
  1311.             } 
  1312.         } else {
  1313.             $targetSection $work->findFirstPassage();
  1314.         }
  1315.         if($targetSection !== null) {
  1316.             return $this->passageCanonicalRedirect($targetSection$translation);
  1317.         } else {
  1318.             $fromSection $query->get('fromSection');
  1319.             if($fromSection !== null) {
  1320.                 $params['passage'] = $this->expositionData('Passage')->findSwedenborgSection($work$fromSection);
  1321.                 $template $params['nav_mode'].'_passage';
  1322.             } else {
  1323.                 $template $params['nav_mode'].'_index';
  1324.             }
  1325.             $title = ($translation !== null) ? $translation->getTranslatedTitle() : $work->selectTranslation()->getTranslatedTitle();
  1326.             // "%title% does not contain a section numbered _2000_"
  1327.      /*       $params['error_message'] = $this->get('translator')->trans($request->getSession()->get('ui_str')["exposition.passage.outofrange"], array(
  1328.                 '_1000_' => $title,
  1329.                 '_2000_' => $targetSectionNumber
  1330.             )); // $title." does not contain a section numbered ".$targetSectionNumber;
  1331.             */
  1332.             
  1333.             $aReplace = array(
  1334.                 '_1000_' => $title,
  1335.                 '_2000_' => $targetSectionNumber
  1336.             );
  1337.             $params['error_message'] = $this->ui_string_replace($request->getSession()->get('ui_str')["bible.chapternav.bookchapterrange"], $aReplace);
  1338.             
  1339.             $statusCode 404;
  1340.         }
  1341.         
  1342.         $sUrlCompareTo $request->query->get('compareTo');
  1343.         $aCompare explode(";;"$sUrlCompareTo);
  1344.         $nCompareLen count($aCompare);
  1345.         $compareTo null;
  1346.         $compareTo2 null;        
  1347.         if($nCompareLen && $aCompare[0] != '')
  1348.             $compareTo $this->expositionData('Translation')->findOneByUrl($aCompare[0]);        
  1349.         
  1350.         if($nCompareLen == && $aCompare[1] != '')            
  1351.             $compareTo2 $this->expositionData('Translation')->findOneByUrl($aCompare[1]);
  1352.             
  1353.         $params['compare_to'] = $compareTo;
  1354.         $params['compare_to2'] = $compareTo2;
  1355.         $response null;
  1356.         if($statusCode !== 200) {
  1357.             $response = new Response();
  1358.             $response->setStatusCode($statusCode);
  1359.         }
  1360.         $this->setCurrentUrl($request);         
  1361.         return $this->renderView($template$params$response);
  1362.     }
  1363.     public function quickviewTranslationPassageAction($passageId$translationIdRequest $request)
  1364.     {
  1365.         $translation $this->expositionData('Translation')->findOneById($translationId);
  1366.         $nTranslationID $translation->getId();
  1367.         $work $translation->getWork();
  1368.         $nLanguageID $translation->getLanguage()->getId();
  1369.   /*      $sUrlCompareTo = $request->query->get('compareTo');
  1370.         $aCompare = explode(";;", $sUrlCompareTo);
  1371.         $nCompareLen = count($aCompare);
  1372.         $compareTo = null;
  1373.         $compareTo2 = null;        
  1374.         if($nCompareLen > 0 && $aCompare[0] != '')        
  1375.             $compareTo = $this->expositionData('Translation')->findOneByUrl($aCompare[0]);        
  1376.         
  1377.         if($nCompareLen == 2 && $aCompare[1] != '')             
  1378.             $compareTo2 = $this->expositionData('Translation')->findOneByUrl($aCompare[1]);
  1379.       */  
  1380.         $passage $this->expositionData('Passage')->findOneById($passageId);    
  1381.         $quickviewData = array(
  1382.             'translation' => $translation,
  1383.        //     'compare_to' => $compareTo,
  1384.        //     'compare_to2' => $compareTo2,
  1385.             'passage' => $passage,
  1386.             'text_style_override' => $this->getTextStyleOverride($nLanguageID)
  1387.         );
  1388.         
  1389.         if($passage != null && $translation != null)
  1390.         {           
  1391.             $quickviewData['passage_footnote'] = $this->getPassageFootnotes($passage->getId(),$nTranslationID);
  1392.             $quickviewData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTranslationID$request);
  1393.             $quickviewData['previous_passage'] = $this->getPreviousPassageWithContent($passage,$translation);     
  1394.             $quickviewData['next_passage'] = $this->getNextPassageWithContent($passage,$translation);     
  1395.             
  1396.             $nWorkID $work->getId();
  1397.             
  1398.             if($nLanguageID != $this->LANGUAGE_ID_LATIN)
  1399.             {
  1400.                 $request->getSession()->set('last_quickview_language_id'$nLanguageID); 
  1401.             }
  1402.             
  1403.             $sLanguages "";
  1404.             $nLastLangID $request->getSession()->get('last_quickview_language_id');
  1405.             if($nLanguageID == $this->LANGUAGE_ID_LATIN)
  1406.             {          
  1407.                 if(empty($nLastLangID))
  1408.                     $sLanguages $nLanguageID;
  1409.                 else
  1410.                     $sLanguages $nLanguageID "," $request->getSession()->get('last_quickview_language_id');     
  1411.             }          
  1412.             else
  1413.                 $sLanguages $nLanguageID ", " $this->LANGUAGE_ID_LATIN;
  1414.                 
  1415.             $quickviewData['translations_by_language'] = $this->getWorkTranslationsByLanguage($request$nWorkID$sLanguages);  
  1416.             
  1417.             $quickviewData['shortname'] = $this->getWorkTranslationShortName($nTranslationID);  
  1418.             $quickviewData['translation_id'] = $nTranslationID;
  1419.             $quickviewData['passage_id'] = $passage->getId(); 
  1420.             
  1421.             $bSwedenborgWork = ($work->getSwedenborgType() !== null);
  1422.             if(!$bSwedenborgWork)                
  1423.                 $quickviewData['authors'] = $this->getAuthorInfo($request$translation->getId());
  1424.             else
  1425.                 $quickviewData['IsSwedenborgWork'] = 1;      
  1426.         }
  1427.         
  1428.         return $this->renderView('quickview/passage'$quickviewData);
  1429.     }
  1430.     public function quickviewSwedenborgTranslationGotoAction(Request $request)
  1431.     {
  1432.         $query $request->query;
  1433.         if(!$query->has('translation')) {
  1434.             // We haven't been told what book to show; maybe someone tried to access this directly rather than via AJAX from the search page?
  1435.             // We'll redirect to the search page
  1436.             return $this->redirect($this->get('router')->generate('advanced_search'));
  1437.         }
  1438.         $translation $this->expositionData('Translation')->findOneByUrl($query->get('translation'));
  1439.         if($query->has('section')) {
  1440.             $targetSection $this->expositionData('Passage')->findSwedenborgSection($translation->getWork(), $query->get('section'));
  1441.         } else {
  1442.             $targetSection $translation->getWork()->findFirstPassage();
  1443.         }
  1444.         return $this->quickviewTranslationPassageAction($targetSection->getId(), $translation->getId(), $request);
  1445.     }
  1446.     public function expositionSearchPostAction(Request $request)
  1447.     {
  1448.         // $query = $this->getRequest()->query;
  1449.         // $searchTerm = $query['searchTerm'];
  1450.         $params $request->request->all();
  1451.         if ( array_key_exists'searchTerm'$params ) ) {
  1452.             $searchTerm $params['searchTerm'];
  1453.         } else {
  1454.             $searchTerm '';
  1455.         }
  1456.         return $this->expositionSearchAction($searchTerm);
  1457.     }
  1458.     public function expositionSearchAction($searchTerm$start=1) {
  1459.         // $templateName = 'explanation_search';
  1460.         // return $this->sharedSearchAction( $searchTerm, 'is', $templateName, $start );
  1461.         return $this->renderView('search/exposition_search', array('searchTerm' => $searchTerm'content_class' => 'explanation''start' => $start));
  1462.     }
  1463.     public function expositionSearchResultsAction($searchTerm$pageNum 1)
  1464.     {
  1465.         return $this->renderView('search/search_results'$this->expositionSearchResults($searchTermfalse'locale'$pageNum));
  1466.     }
  1467.     public function swedenborgSearchPostAction(Request $request)
  1468.     {
  1469.         // $query = $this->getRequest()->query;
  1470.         // $searchTerm = $query['searchTerm'];
  1471.         $params $request->request->all();
  1472.         if ( array_key_exists'searchTerm'$params ) ) {
  1473.             $searchTerm $params['searchTerm'];
  1474.         } else {
  1475.             $searchTerm '';
  1476.         }
  1477.         return $this->swedenborgSearchAction($searchTerm);
  1478.     }
  1479.     public function swedenborgSearchAction($searchTerm$start=1)
  1480.     {
  1481.         // $templateName = 'swedenborg_search';
  1482.         // return $this->sharedSearchAction( $searchTerm, 'is not', $templateName, $start );
  1483.         return $this->renderView('search/exposition_search', array('searchTerm' => $searchTerm'content_class' => 'swedenborg''start' => $start));
  1484.     }
  1485.     public function swedenborgSearchResultsAction($searchTerm$pageNum 1)
  1486.     {
  1487.         // $templateName = 'swedenborg_search';
  1488.         // return $this->sharedSearchAction( $searchTerm, 'is not', $templateName, $start );
  1489.         return $this->renderView('search/search_results'$this->expositionSearchResults($searchTermtrue'locale'$pageNum));
  1490.     }
  1491.     public function expositionSearchResults(Request $request$searchTerm$isSwedenborg$forceLanguage null$start 1)
  1492.     {
  1493.         $search = new PostgresSearch();
  1494.         $em $this->getDoctrine()->getManager();
  1495.         $search->setManager($em);
  1496.         return $search->getExpositionSearchResults($request$searchTerm$isSwedenborg, array('language' => $forceLanguage'page' => $start));
  1497.     }         
  1498.             
  1499.     public function topicalPathIndexAction(Request $request)
  1500.     {
  1501.         $this->onloadPage($request);
  1502.         $locale $request->getLocale();
  1503.         $topicData $this->getTopPathList($locale);
  1504.         $data = array(
  1505.             'topic_data' => $topicData        
  1506.         );
  1507.         $this->setCurrentUrl($request);         
  1508.         return $this->renderView('index/topical_paths'$data);
  1509.     }
  1510.     
  1511.     public function topPathAction($TopPathUrlRequest $request)
  1512.     {
  1513.         $this->onloadPage($request);
  1514.         $locale $request->getLocale();
  1515.         $topPath $this->getTopPathInfo($TopPathUrl,$locale);
  1516.         $subPathList $this->getSubPathList($TopPathUrl,$locale);
  1517.         $data = array(
  1518.             'sub_path_list' => $subPathList,
  1519.             'top_path' => $topPath,
  1520.             'top_path_url' => $TopPathUrl       
  1521.         );
  1522.         $this->setCurrentUrl($request);         
  1523.         return $this->renderView('top_path'$data);
  1524.     }
  1525.     
  1526.     public function subPathAction($TopPathUrl$SubPathUrlRequest $request)
  1527.     {
  1528.         $this->onloadPage($request);
  1529.         $locale $request->getLocale();
  1530.         $bibleTranslationUrl $this->DEFAULT_BIBLE_VERSION;
  1531.         $nBibleTransID $request->getSession()->get('current_bible_translation_id');
  1532.         if($nBibleTransID != '')
  1533.         {   
  1534.                $bibleTranslation $this->getBibleTranslationByID($request$nBibleTransID);
  1535.                $bibleTranslationUrl $bibleTranslation['url'];
  1536.         }
  1537.         $topPath $this->getTopPathInfo($TopPathUrl,$locale);
  1538.         $subPath $this->getSubPathInfo($SubPathUrl,$locale);
  1539.         $explanationList $this->getExplanationListForTopAndSubPath($TopPathUrl$SubPathUrl,$locale);
  1540.         $data = array(
  1541.             'explanation_list' => $explanationList,
  1542.             'top_path' => $topPath,
  1543.             'sub_path' => $subPath,
  1544.             'sub_path_url' => $SubPathUrl,
  1545.             'top_path_url' => $TopPathUrl,
  1546.             'bible_translation_url' => $bibleTranslationUrl       
  1547.         );
  1548.         $this->setCurrentUrl($request);         
  1549.         return $this->renderView('sub_path'$data);
  1550.     }
  1551.     
  1552.     public function topicIndexAction(Request $request)
  1553.     {
  1554.         $locale $request->getLocale();
  1555.         $topicData $this->getTopicList($locale);
  1556.         $data = array(
  1557.             'topic_data' => $topicData        
  1558.         );
  1559.       
  1560.            $this->setCurrentUrl($request); 
  1561.            $this->onloadPage($request);
  1562.         return $this->renderView('index/topics'$data);
  1563.     }
  1564.     
  1565.     public function topicAction($TopicUrl,Request $request)
  1566.     {        
  1567.         $this->onloadPage($request);
  1568.         $locale $request->getLocale(); 
  1569.         $bibleTranslationUrl $this->DEFAULT_BIBLE_VERSION;
  1570.         $nBibleTransID $request->getSession()->get('current_bible_translation_id');
  1571.         if($nBibleTransID != '')
  1572.         {   
  1573.                $bibleTranslation $this->getBibleTranslationByID($request$nBibleTransID);
  1574.                $bibleTranslationUrl $bibleTranslation['url'];
  1575.         }   
  1576.         $topic $this->getSubPathInfo($TopicUrl,$locale);
  1577.         $explanationList $this->getExplanationListForTopic($TopicUrl,$locale);
  1578.         $data = array(
  1579.             'explanation_list' => $explanationList,            
  1580.             'topic' => $topic,
  1581.             'topic_url' => $TopicUrl,
  1582.             'bible_translation_url' => $bibleTranslationUrl        
  1583.         );
  1584.         $this->setCurrentUrl($request);         
  1585.         return $this->renderView('topic'$data);
  1586.     }
  1587.     
  1588.     public function viewscanimagesAction($PassageIDRequest $request)
  1589.     {             
  1590.         $this->onloadPage($request);
  1591.         $aImage = array(
  1592.             'scanimage' => $this->getWorkPassageScanImageFileName($PassageID),
  1593.             'translation_info' => $this->getCurrentPassageForLatin($PassageID),
  1594.             'next_passage' => $this->getNextPassageWithScan($PassageID),
  1595.             'previous_passage' => $this->getPreviousPassageWithScan($PassageID)       
  1596.         );
  1597.         return $this->renderView('view_scanimages'$aImage);
  1598.     }
  1599.     
  1600.     public function popoverconceptAction($explanationID$conceptIDRequest $request)
  1601.     {         
  1602.           $locale $request->getLocale();        
  1603.         $sPopupText $this->getBibleWordPopupText($explanationID$conceptID);
  1604.         $aConceptInfo $this->getBibleWordPopupConceptInfo($explanationID$conceptID);
  1605.         $data = array(
  1606.             'popup_text' => $sPopupText,
  1607.             'title' => $aConceptInfo['title'],
  1608.             'concept_url' => $aConceptInfo['concept_url']
  1609.         );
  1610.          
  1611.         return $this->renderView('word_popup'$data);
  1612.     }
  1613.     
  1614.     /**
  1615.      * Show chapter summary list on a popup for multi page
  1616.      */
  1617.     public function selectchaptersummaryAction($explanationID$bibleBookIDRequest $request)
  1618.     {             
  1619.       $data['chapter_summary_list'] = $this->getChapterSummaryList($explanationID$bibleBookID);
  1620.                        
  1621.       return $this->renderView('selectchaptersummary'$data);
  1622.     }
  1623.     
  1624.     /**
  1625.      * Show chapter summary list on a popup for single chapter summary page
  1626.      */
  1627.     public function selectchaptersummarysinglepageAction($explanationID$cBibleBookIDRequest $request)
  1628.     {             
  1629.       $data['chapter_summary_list'] = $this->getChapterSummaryListForSinglePage($explanationID$cBibleBookID);
  1630.                        
  1631.       return $this->renderView('selectchaptersummarysinglepage'$data);
  1632.     }
  1633.     
  1634.     public function featured_spiritual_topicsAction(Request $request)
  1635.     {                       
  1636.     //    $this->setCurrentUrl($request); 
  1637.         $this->onloadPage($request);
  1638.         $locale $request->getLocale();
  1639.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale9);
  1640.         if(empty($featuredList))
  1641.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale9true);
  1642.         $request->getSession()->set('searched_topic_list', array());
  1643.         return $this->renderView('index/spiritual_topics_featured', array(     
  1644.             'featured_topic' => $featuredList            
  1645.         ));
  1646.     }
  1647.     
  1648.     public function searched_spiritual_topicsAction(Request $request)
  1649.     {                       
  1650.     //    $this->setCurrentUrl($request); 
  1651.         $this->onloadPage($request);
  1652.         $locale $request->getLocale();
  1653.         $sSearchTerm $request->query->get('searchTerm');
  1654.         $searchedResults null;   
  1655.         if($sSearchTerm != '')
  1656.         {
  1657.             $searchedResults $this->getSearchedListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPICtruefalse$locale$request);
  1658.         }        
  1659.         else
  1660.         {
  1661.             $nPathwayID $request->query->get('pathwayid');
  1662.             if(!empty($nPathwayID))
  1663.             {
  1664.                 $searchedResults $this->getSearchedListByCategoryAndPathway($locale$request$this->CATEGORY_ID_SPIRITUAL_TOPIC$nPathwayID);
  1665.             }
  1666.             else
  1667.             {
  1668.                 $nAll $request->query->get('all');
  1669.                 if($nAll == '1')
  1670.                 {
  1671.                     $searchedResults $this->getAllListByCategory($this->CATEGORY_ID_SPIRITUAL_TOPIC$locale$request);
  1672.                 }
  1673.             }
  1674.         }
  1675.         return $this->renderView('index/spiritual_topics_searched', array(     
  1676.             'searched_topic' => $searchedResults            
  1677.         ));
  1678.     }
  1679.     
  1680.     public function getSearchedListByCategory($vCategoryId$vWholeWordOnly$vTitleOnly$locale$request)
  1681.     {
  1682.         $search = new PostgresSearch();
  1683.         $em $this->getDoctrine()->getManager();
  1684.         $search->setManager($em);
  1685.         return $search->getCategorySearchResults($vCategoryId$vWholeWordOnly$vTitleOnly$locale$request);
  1686.     }
  1687.     
  1688.     public function getSearchedOTLEVideos($locale$request)
  1689.     {
  1690.         $search = new PostgresSearch();
  1691.         $em $this->getDoctrine()->getManager();
  1692.         $search->setManager($em);
  1693.         return $search->getOTLESearchResults($locale$request);
  1694.     }
  1695.     
  1696.     public function expositionSliderAction($translationIdRequest $request$passageId$userSelected true$inFrame false)
  1697.     {
  1698.   /*      $translation = $this->expositionData('Translation')->findOneBy(array('id' => $translationId, 'isPublic' => true));
  1699.          if($translation == null) {
  1700.             $response = new Response();
  1701.             $response->setStatusCode(404);
  1702.             return $this->renderView('no_work_content', array(), $response);
  1703.         }
  1704.         
  1705.         $passage = ($passageId !== null)
  1706.             ? $this->expositionData('Passage')->findOneById($passageId)
  1707.             : (($translation !== null) ? $translation->getWork()->findFirstNonEmptyPassage($translation) : null); */
  1708.             
  1709.         $aTranslation $this->getTranslationData($translationId);    
  1710.         $aPassage $this->getPassageData($passageId);  
  1711.              
  1712.         $this->checkIfOnMobile($request);
  1713.     //    $locale = $request->getLocale();
  1714.              
  1715.         $ref_column_spec '';
  1716.      //   $work = $translation->getWork();
  1717.         $bSwedenborgWork = ($aTranslation['swedenborgtype'] != null);
  1718.         if($bSwedenborgWork)
  1719.             $ref_column_spec $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK;    
  1720.         else
  1721.             $ref_column_spec $this->MULTI_URL_INDICATOR_EXPLANATION;    
  1722.         
  1723.         $ref_column_spec .= '_' $aTranslation['url'];
  1724.         if($bSwedenborgWork)
  1725.             $ref_column_spec .= '_' $aPassage['swedenborgsection'];
  1726.                     
  1727.         $nLanguageID $aTranslation['language_id'];      
  1728.         $data = array(
  1729.            // 'translation' => $translation,
  1730.            // 'passage' => $passage,  
  1731.             'ref_column_spec' => $ref_column_spec,  
  1732.             'passage_order' => $aPassage['ordering'],  
  1733.             'passage_id' => $passageId,                     
  1734.         );
  1735.                          
  1736.         $data['work_references'] = $this->getWorkRefForWork($request$passageId$translationId$nLanguageID);
  1737.         $data['explanation_references'] = $this->getExplanationRefForWork($request$passageId$nLanguageID);
  1738.         $data['gced_ref'] = $this->getGCEDRefForWork($passageId);
  1739.         $data['otle_ref'] = $this->getOTLERefForWork($passageId);
  1740.         $data['related_passages'] = $this->getRelatedPassages($request$passageId$nLanguageID);                                        
  1741.           // get table of contents
  1742.           $aTOC $this->getWorkTranslationTOC($translationId); 
  1743.           if(!empty($aTOC))
  1744.           {                  
  1745.               $data['work_toc'] = $aTOC;
  1746.           }
  1747.                    
  1748.         return $this->renderView('refsidrw'$data);
  1749.     }
  1750.     public function selecttopicAction(Request $request)
  1751.     {       
  1752.       $locale $request->getLocale();  
  1753.       $sSearchText $request->query->get('st');
  1754.                        
  1755.       $data['consider_data'] = $this->getConsiderList($locale$sSearchText); 
  1756.                     
  1757.       return $this->renderView('selecttopic'$data);
  1758.     } 
  1759.     
  1760.     public function otlevideosAction(Request $request)
  1761.     {            
  1762.         $this->onloadPage($request);
  1763.         $locale $request->getLocale();
  1764.         $aBrand $this->getBrandList();
  1765.         $aShowTopic $this->getShowTopicList();
  1766.         $aShowType $this->getShowTypeList();   
  1767.         $data = array(
  1768.               'brand_list' => $aBrand,
  1769.               'topic_list' => $aShowTopic,
  1770.                'type_list' => $aShowType            
  1771.         );
  1772.         $this->setCurrentUrl($request);         
  1773.         return $this->renderView('otle_videos'$data);
  1774.     }
  1775.     
  1776.     public function searched_otle_videosAction(Request $request)
  1777.     {            
  1778.         $locale $request->getLocale();
  1779.         $searchedResults = array();
  1780.         $sSearchTerm $request->query->get('searchTerm');
  1781.         $nBrandID $request->query->get('brandid');
  1782.         if($sSearchTerm != '')
  1783.         {
  1784.             $searchedResults $this->getSearchedOTLEVideos($locale$request);
  1785.         }        
  1786.         else
  1787.         {
  1788.             $nStartNum $request->query->get('startnum');            
  1789.             $searchedResults $this->getOTLEVideos($nStartNum$request);            
  1790.         }            
  1791.         
  1792.         return $this->renderView('otle_videos_searched', array(     
  1793.             'searched_video' => $searchedResults['results'],
  1794.             'total_record' => $searchedResults['total_record'],
  1795.             'has_more' => $searchedResults['has_more'],
  1796.             'start_num' => $searchedResults['start_num']            
  1797.         ));
  1798.     }
  1799.     
  1800.     public function otlevideopageAction($showIDRequest $request)
  1801.     {            
  1802.         //$locale = $request->getLocale();        
  1803.         $aShow $this->getShowInfo($showID);
  1804.         if(empty($aShow))
  1805.            {
  1806.                $response = new Response();
  1807.             $response->setStatusCode(404);
  1808.               return $this->renderView('no_content', array(), $response);
  1809.            }
  1810.         
  1811.         $aShowRef $this->getShowRefs($request$showID);    
  1812.         
  1813.         $nTextLength 150;
  1814.         $sDesc $aShow['description'];
  1815.         $sMetaDesc $this->fixWorkText($sDesc);
  1816.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength);          
  1817.               
  1818.         return $this->renderView('otle_video_page', array(  
  1819.             'show_id' => $showID,   
  1820.             'show_info' => $aShow,
  1821.             'show_ref' => $aShowRef,
  1822.             'meta_desc' => $sMetaDesc           
  1823.         ));
  1824.     }
  1825.     
  1826.     public function audiohubAction(Request $request)
  1827.     {            
  1828.         $this->onloadPage($request);
  1829.         $locale $request->getLocale();        
  1830.         $aLanguage $this->getLanguageListForAudioHub(); 
  1831.         $aCategory $this->getCategoryListForAudioHub();   
  1832.         $data = array(
  1833.                'language_list' => $aLanguage,
  1834.                'category_list' => $aCategory            
  1835.         );
  1836.         $this->setCurrentUrl($request);        
  1837.         return $this->renderView('audiohub'$data);
  1838.     }
  1839.     
  1840.     public function search_audioAction(Request $request)
  1841.     {            
  1842.         $locale $request->getLocale();
  1843.         $searchedResults = array();
  1844.         $sSearchTerm $request->query->get('searchTerm');  
  1845.         $nStartNum $request->query->get('startnum');      
  1846.         if($sSearchTerm != '')
  1847.         {
  1848.             $searchedResults $this->getSearchedAudio($locale$request);
  1849.         }    
  1850.         else
  1851.         {
  1852.             $nFormatID $this->PRIMARY_FORMAT_ID_AUDIO;
  1853.             $searchedResults $this->getExplanationList($nStartNum$locale$request$nFormatID);            
  1854.         }            
  1855.         
  1856.         return $this->renderView('audio_searched', array(     
  1857.             'searched_audio' => $searchedResults,
  1858.             'start_num' => $nStartNum           
  1859.         ));
  1860.     }
  1861.         
  1862.     public function getSearchedAudio($locale$request)
  1863.     {        
  1864.         $search = new PostgresSearch();
  1865.         $em $this->getDoctrine()->getManager();
  1866.         $search->setManager($em);
  1867.         $sCategoryId 'any';
  1868.         return $search->getCategorySearchResults($sCategoryIdtruefalse$locale$request);
  1869.     } 
  1870.     
  1871.     public function qahubAction(Request $request)
  1872.     {            
  1873.         $locale $request->getLocale(); 
  1874.         $data = array(                         
  1875.         );
  1876.         $this->setCurrentUrl($request); 
  1877.         $this->onloadPage($request);
  1878.         return $this->renderView('qahub'$data);
  1879.     }
  1880.     
  1881.     public function search_qaAction(Request $request)
  1882.     {            
  1883.         $locale $request->getLocale();
  1884.         $searchedResults = array();
  1885.         $sSearchTerm $request->query->get('searchTerm');  
  1886.         $nStartNum $request->query->get('startnum');      
  1887.         if($sSearchTerm != '')
  1888.         {
  1889.             $searchedResults $this->getSearchedQA($locale$request);
  1890.         }    
  1891.         else
  1892.         {            
  1893.             $searchedResults $this->getExplanationList($nStartNum$locale$request);
  1894.         }            
  1895.         
  1896.         return $this->renderView('qa_searched', array(     
  1897.             'searched_qa' => $searchedResults,
  1898.             'start_num' => $nStartNum           
  1899.         ));
  1900.     }
  1901.         
  1902.     public function getSearchedQA($locale$request)
  1903.     {        
  1904.         $search = new PostgresSearch();
  1905.         $em $this->getDoctrine()->getManager();
  1906.         $search->setManager($em);
  1907.         $sCategoryId 47;
  1908.         return $search->getCategorySearchResults($sCategoryIdtruefalse$locale$request);
  1909.     } 
  1910.     
  1911.     public function search_classAction(Request $request)
  1912.     {            
  1913.         $locale $request->getLocale();
  1914.         $searchedResults = array();
  1915.         $sSearchTerm $request->query->get('searchTerm');  
  1916.         $nStartNum $request->query->get('startnum');      
  1917.         if($sSearchTerm != '')
  1918.         {
  1919.             $searchedResults $this->getSearchedClass($locale$request);
  1920.         }    
  1921.         else
  1922.         {            
  1923.             $searchedResults $this->getClassList($nStartNum$request);            
  1924.         }            
  1925.         
  1926.         return $this->renderView('class_searched', array(     
  1927.             'searched_class' => $searchedResults['results'],
  1928.             'total_record' => $searchedResults['total_record'],
  1929.             'has_filter' => $searchedResults['has_filter'],
  1930.             'has_more' => $searchedResults['has_more'],
  1931.             'start_num' => $nStartNum           
  1932.         ));
  1933.     }
  1934.     
  1935.     public function getSearchedClass($locale$request)
  1936.     {
  1937.         $search = new PostgresSearch();
  1938.         $em $this->getDoctrine()->getManager();
  1939.         $search->setManager($em);
  1940.         return $search->getClassSearchResults($locale$request);
  1941.     }
  1942.     
  1943.     public function coursepageAction($courseIDRequest $request)
  1944.     {        
  1945.         $aCourse $this->getCourseInfo($courseID);         
  1946.         if(empty($aCourse))
  1947.         {
  1948.             $response = new Response();
  1949.             $response->setStatusCode(404);
  1950.             return $this->renderView('no_work_content', array(), $response);
  1951.         }
  1952.         $aLeader $this->getLeadersForCourse($courseID);
  1953.         $aAudience $this->getAudienceForCourse($courseID);    
  1954.         
  1955.         $nTextLength 150;
  1956.         $sDesc $aCourse['full_description'];
  1957.         $sMetaDesc $this->fixWorkText($sDesc);
  1958.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength); 
  1959.                               
  1960.         return $this->renderView('course_page', array(     
  1961.             'course_info' => $aCourse,
  1962.             'leader_list' => $aLeader,
  1963.             'audience_list' => $aAudience,
  1964.             'meta_desc' => $sMetaDesc          
  1965.         ));
  1966.     }
  1967.     
  1968.     public function search_sermonAction(Request $request)
  1969.     {            
  1970.         $locale $request->getLocale();
  1971.         $searchedResults = array();
  1972.         $sSearchTerm $request->query->get('searchTerm');  
  1973.         $nStartNum $request->query->get('startnum'); 
  1974.         $nStorehouse $request->query->get('storehouse');     
  1975.         if($sSearchTerm != '')
  1976.         {
  1977.             $searchedResults $this->getSearchedSermon($locale$request);
  1978.         }    
  1979.         else
  1980.         {            
  1981.             $searchedResults $this->getSermonList($nStartNum$request);            
  1982.         }            
  1983.         
  1984.         return $this->renderView('sermon_searched', array(     
  1985.             'searched_sermon' => $searchedResults['results'],
  1986.             'total_record' => $searchedResults['total_record'],
  1987.             'has_more' => $searchedResults['has_more'],
  1988.             'has_filter' => $searchedResults['has_filter'],
  1989.             'start_num' => $nStartNum,
  1990.             'is_storehouse' => $nStorehouse          
  1991.         ));
  1992.     }
  1993.     
  1994.     public function getSearchedSermon($locale$request)
  1995.     {
  1996.         $search = new PostgresSearch();
  1997.         $em $this->getDoctrine()->getManager();
  1998.         $search->setManager($em);
  1999.         return $search->getSermonSearchResults($locale$request);
  2000.     }
  2001.     
  2002.     public function sermonpageAction($sermonIDRequest $request)
  2003.     {        
  2004.         if(!$this->userCanSeeAllSermons($request))
  2005.         {
  2006.             $nTypeID $this->getSermonTypeID($sermonID);
  2007.             if($nTypeID != $this->LNCSERMON_TYPE_ID_PUBLIC)
  2008.             {
  2009.                 $bCanView false;
  2010.                 if($this->userCanSeeLNCSermons($request) && $nTypeID == $this->LNCSERMON_TYPE_ID_LNC_MEMBER)
  2011.                 {
  2012.                     $bCanView true;
  2013.                 }
  2014.                 
  2015.                 if(!$bCanView)
  2016.                 {
  2017.                     return $this->redirect($this->get('router')->generate('sermons', array()), 301);
  2018.                 }
  2019.             }        
  2020.         }
  2021.         $this->onloadPage($request);
  2022.         $aSermon $this->getSermonInfo($sermonID);
  2023.         $aAuthor $this->getAuthorsForSermon($sermonID);
  2024.         $aTopic $this->getTopicsForSermon($sermonID);
  2025.         $aSermonRef $this->getSermonRefs($sermonID$request);
  2026.         
  2027.         $nTextLength 150;
  2028.         $sDesc $aSermon['searchsummary'];
  2029.         $sMetaDesc $this->fixWorkText($sDesc);
  2030.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength);
  2031.        
  2032.         return $this->renderView('sermon_page', array(   
  2033.             'sermon_id' => $sermonID,  
  2034.             'sermon_info' => $aSermon,
  2035.             'author_list' => $aAuthor,
  2036.             'topic_list' => $aTopic,
  2037.             'sermon_ref' => $aSermonRef,
  2038.             'meta_desc' => $sMetaDesc        
  2039.         ));
  2040.     }
  2041.     
  2042.     public function sermonstorehousepageAction($sermonIDRequest $request)
  2043.     {   
  2044.         $nTypeID $this->getSermonTypeID($sermonID);
  2045.         if($nTypeID != $this->LNCSERMON_TYPE_ID_PUBLIC)
  2046.         {            
  2047.             return $this->redirect($this->get('router')->generate('sermon_storehouse', array()), 301);
  2048.         }   
  2049.     
  2050.         $aSermon $this->getSermonInfo($sermonID);
  2051.         $aAuthor $this->getAuthorsForSermon($sermonID);
  2052.         $aTopic $this->getTopicsForSermon($sermonID);
  2053.         $aSermonRef $this->getSermonRefs($sermonID$request);
  2054.         
  2055.         $nTextLength 150;
  2056.         $sDesc $aSermon['searchsummary'];
  2057.         $sMetaDesc $this->fixWorkText($sDesc);
  2058.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength);
  2059.        
  2060.         return $this->renderView('sermon_storehouse_page', array(   
  2061.             'sermon_id' => $sermonID,  
  2062.             'sermon_info' => $aSermon,
  2063.             'author_list' => $aAuthor,
  2064.             'topic_list' => $aTopic,
  2065.             'sermon_ref' => $aSermonRef,
  2066.             'meta_desc' => $sMetaDesc        
  2067.         ));
  2068.     }
  2069.     
  2070.     /**
  2071.      * Show chapter list on a popup
  2072.      */
  2073.     public function selectworkcompareAction($workID$translationUrl$translationUrl2$divisionUrl$passageNumberRequest $request)
  2074.     {         
  2075.       $data['translation_url'] = $translationUrl;
  2076.       $data['translation_url2'] = $translationUrl2
  2077.       $data['division_url'] = $divisionUrl
  2078.       $data['passage_number'] = $passageNumber;      
  2079.       $data['work_id'] = $workID;   
  2080.                    
  2081.       $data['translations_by_language'] = $this->getWorkTranslationsByLanguage($request$workID);    
  2082.                                    
  2083.       return $this->renderView('selectworkcompare'$data);
  2084.     }
  2085.     
  2086.     /**
  2087.      * Show translation list on a popup
  2088.      */
  2089.     public function selectworktranslationAction($workID$translationUrl$passageNumber$passageOrderRequest $request)
  2090.     {    
  2091.           $data['translation_url'] = $translationUrl;          
  2092.           $data['passage_number'] = $passageNumber;  
  2093.           $data['passage_order'] = $passageOrder;    
  2094.           $data['work_id'] = $workID;   
  2095.                        
  2096.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguageAllType($request$workID);
  2097.                    
  2098.           return $this->renderView('selectworktranslation'$data);
  2099.     }
  2100.     
  2101.     /**
  2102.      * Show translation list on a popup
  2103.      */
  2104.     public function selectworkpassageAction($workID$translationUrlRequest $request)
  2105.     {    
  2106.           $data['translation_url'] = $translationUrl;                       
  2107.           $data['passage_list'] = $this->getWorkPassages($workID);
  2108.           $data['work_id'] = $workID;
  2109.                    
  2110.           return $this->renderView('selectpassage'$data);
  2111.     }
  2112.     
  2113.     /**
  2114.      * Show work list on a popup
  2115.      */
  2116.     public function selectworkAction($workID$translationID$languageIDRequest $request)
  2117.     {    
  2118.           $data['translation_id'] = $translationID;          
  2119.           $data['language_id'] = $languageID;      
  2120.           $data['work_id'] = $workID;   
  2121.                        
  2122.           $data['swedenborg_works'] = $this->getCategorizedSwedenborgWorksForTranslation($request$translationID$languageID);
  2123.                    
  2124.           return $this->renderView('selectwork'$data);
  2125.     }
  2126.     
  2127.     /**
  2128.      * Show translation list on a popup
  2129.      */
  2130.     public function selectsearchtranslationAction($workID$translationID$passageIDRequest $request)
  2131.     {    
  2132.           $data['translation_id'] = $translationID;          
  2133.           $data['passage_id'] = $passageID;      
  2134.           $data['work_id'] = $workID;   
  2135.            
  2136.           $nLanguageID $this->getLanguageIDByTranslation($translationID); 
  2137.           if($nLanguageID != $this->LANGUAGE_ID_LATIN)          
  2138.             $request->getSession()->set('last_quickview_language_id'$nLanguageID); 
  2139.                   
  2140.           $sLanguages "";
  2141.           if($nLanguageID == $this->LANGUAGE_ID_LATIN)            
  2142.             $sLanguages $nLanguageID ", " $request->getSession()->get('last_quickview_language_id');           
  2143.           else
  2144.             $sLanguages $nLanguageID ", " $this->LANGUAGE_ID_LATIN;
  2145.                                  
  2146.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguage($request$workID$sLanguages);
  2147.                    
  2148.           return $this->renderView('selectsearchtranslation'$data);
  2149.     }
  2150.     
  2151.     /**
  2152.      * Show translation list on a popup
  2153.      */
  2154.     public function selectstorytranslationforworkAction($workID$storyID$translationIDRequest $request)
  2155.     {    
  2156.       $locale $request->getLocale();
  2157.       $data['work_id'] = $workID;  
  2158.       $data['translation_id'] = $translationID;       
  2159.       $data['story_id'] = $storyID;   
  2160.                            
  2161.       $data['story_explanations'] = $this->getWorkListForStory($locale$storyID);
  2162.                
  2163.       return $this->renderView('selectstorytranslationforwork'$data);
  2164.     }
  2165.     
  2166.     public function search_conceptAction(Request $request)
  2167.     {            
  2168.         $locale $request->getLocale();
  2169.         $searchedResults = array();
  2170.         $sSearchTerm $request->query->get('searchTerm');  
  2171.         $nStartNum $request->query->get('startnum');      
  2172.         if($sSearchTerm != '')
  2173.         {
  2174.             $nWholeWordOnly $request->query->get('wholewordonly'); 
  2175.             //$searchedResults = $this->getSearchedConcept($locale, $request);
  2176.             $searchedResults $this->getSearchedListByCategory($this->CATEGORY_ID_CONCEPT$nWholeWordOnlyfalse$locale$request);
  2177.         }    
  2178.         else
  2179.         {            
  2180.             //$searchedResults = $this->getConceptList($nStartNum, $request);
  2181.             $searchedResults $this->getAllListByCategory($this->CATEGORY_ID_CONCEPT$locale$request);            
  2182.         }            
  2183.         
  2184.         return $this->renderView('concept_searched', array(     
  2185.             'searched_results' => $searchedResults           
  2186.         ));
  2187.     }    
  2188.     
  2189.     public function featured_conceptsAction(Request $request)
  2190.     {                   
  2191.         $this->onloadPage($request);
  2192.         $locale $request->getLocale();
  2193.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCEPT$locale9false);
  2194.         if(empty($featuredList))
  2195.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCEPT$locale9true);
  2196.         return $this->renderView('concepts_featured', array(     
  2197.             'featured_records' => $featuredList            
  2198.         ));
  2199.     }    
  2200.     
  2201.     /**
  2202.      * Show translation list on a popup
  2203.      */
  2204.     public function selectbiblebooksummaryAction($translationID$BibleBookIDForSummaryRequest $request)
  2205.     {           
  2206.       $data['translation_id'] = $translationID;                               
  2207.       $data['book_summaries'] = $this->getBibleBookSummaryList($BibleBookIDForSummary);
  2208.                
  2209.       return $this->renderView('selectbiblebooksummary'$data);
  2210.     }
  2211.     
  2212.     /**
  2213.      * Show translation list on a popup
  2214.      */
  2215.     public function selectbiblechaptersummarytranslationAction($translationIDRequest $request)
  2216.     {           
  2217.       $data['translation_id'] = $translationID;                               
  2218.       $data['chapter_summary_translations'] = $this->getChapterExplanationsForPopup($translationID);
  2219.                
  2220.       return $this->renderView('selectbiblechaptersummarytranslation'$data);
  2221.     }
  2222.     
  2223.     public function selectbiblestudyAction(Request $request)
  2224.     {       
  2225.       $locale $request->getLocale();  
  2226.       //$sSearchText = $request->query->get('st');
  2227.                        
  2228.       $data['biblestudy_data'] = $this->getBibleStudyList($locale); 
  2229.                     
  2230.       return $this->renderView('selectbiblestudy'$data);
  2231.     } 
  2232.     
  2233.     /**
  2234.      * Show translation list on a popup
  2235.      */
  2236.     public function selectbibleversesummaryAction($workID$chapterID$languageIDRequest $request)
  2237.     {                  
  2238.           $data['work_id'] = $workID;     
  2239.           $data['verse_explanations'] = $this->getVerseExplanations($chapterID$languageID$request);
  2240.                    
  2241.           return $this->renderView('selectbibleversesummary'$data);
  2242.     }
  2243.     
  2244.     /**
  2245.      * Show work list on a popup for search
  2246.      */
  2247.     public function selectworksforsearchAction(Request $request)
  2248.     {    
  2249.           $nLanguageID $request->query->get('lang');    
  2250.                        
  2251.           $data['swedenborg_works'] = $this->getCategorizedSwedenborgWorksForTranslation($requestnull$nLanguageID);
  2252.                    
  2253.           return $this->renderView('selectworksforsearch'$data);
  2254.     }
  2255.     
  2256.     /**
  2257.      * Show work translation list on a popup for search
  2258.      */
  2259.     public function selectworktranslationsforsearchAction(Request $request)
  2260.     {    
  2261.           $nLanguageID $request->query->get('lang'); 
  2262.           $sSelectedWorkIDs $request->query->get('selectedworkids');  
  2263.           $sWorkType $request->query->get('worktype'); 
  2264.                        
  2265.           $data['work_translations'] = $this->getSWWorkTranslations($request$sSelectedWorkIDs$nLanguageID$sWorkType);
  2266.                    
  2267.           return $this->renderView('selectworktranslationsforsearch'$data);
  2268.     }
  2269.     
  2270.     /**
  2271.      * Show work translation list on a popup for reading plan step
  2272.      */
  2273.     public function selectworktranslationforreadingplanAction(Request $request)
  2274.     {    
  2275.           $nWorkID $request->query->get('wid'); 
  2276.           $sTranslationUrl $request->query->get('turl');
  2277.           $sReadingPlanUrl $request->query->get('rpurl'); 
  2278.           $nStepOrder $request->query->get('step'); 
  2279.           $nSW $request->query->get('sw');  
  2280.           
  2281.           $data['work_id'] = $nWorkID;
  2282.           $data['translation_url'] = $sTranslationUrl;          
  2283.           $data['readingplan_url'] = $sReadingPlanUrl;  
  2284.           $data['step_order'] = $nStepOrder
  2285.                                  
  2286.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguageAllType($request$nWorkID);
  2287.                    
  2288.           return $this->renderView('selectworktranslationforreadingplan'$data);
  2289.     }
  2290.     
  2291.     /**
  2292.      * Show work translation list on a popup for reading plan step
  2293.      */
  2294.     public function selectexplanationtranslationforreadingplanAction(Request $request)
  2295.     {    
  2296.           $nWorkID $request->query->get('wid'); 
  2297.           $sTranslationUrl $request->query->get('turl');
  2298.           $sReadingPlanUrl $request->query->get('rpurl'); 
  2299.           $nStepOrder $request->query->get('step');   
  2300.           
  2301.           $data['work_id'] = $nWorkID;
  2302.           $data['translation_url'] = $sTranslationUrl;          
  2303.           $data['readingplan_url'] = $sReadingPlanUrl;  
  2304.           $data['step_order'] = $nStepOrder
  2305.                                  
  2306.           $data['translations_by_language'] = $this->getWorkTranslationsByLanguageAllType($request$nWorkID);
  2307.                    
  2308.           return $this->renderView('selectexplanationtranslationforreadingplan'$data);
  2309.     }
  2310.     
  2311.     /**
  2312.      * Show work list on a popup
  2313.      */
  2314.     public function selectbiblechaptersummaryworkAction($translationIDRequest $request)
  2315.     {           
  2316.       $aTrans $this->getWorkTranslationData($translationID);        
  2317.       $nWorkID $aTrans['work_id'];
  2318.       $data['translation_id'] = $translationID;     
  2319.       $data['work_id'] = $nWorkID;                              
  2320.       $data['chapter_summary_works'] = $this->getChapterExplanationWorksForPopup($translationID);
  2321.                
  2322.       return $this->renderView('selectbiblechaptersummarywork'$data);
  2323.     }
  2324.     
  2325.     public function fullviewTranslationPassageAction($passageId$translationIdRequest $request)
  2326.     {        
  2327.            $sSql "select url FROM expositiontranslation where id = " $translationId;
  2328.            
  2329.  //   echo $sSql."<br>";   
  2330.        $sUrl $this->getSingleData($sSql);
  2331.        
  2332.        $sLink $this->get('router')->generate('exposition_translation_passage', array(
  2333.                         'translationUrl' => $sUrl,
  2334.                         'passageId' => $passageId                      
  2335.                     ));
  2336.             
  2337.        if(!empty($sLink))
  2338.                return $this->redirect($sLink301);            
  2339.        else
  2340.             return $this->redirect("/"301);
  2341.     }
  2342.     
  2343.     public function projecthubAction(Request $request)
  2344.     {            
  2345.         $locale $request->getLocale(); 
  2346.         $data = array(                         
  2347.         );
  2348.         $this->setCurrentUrl($request); 
  2349.         $this->onloadPage($request);
  2350.         return $this->renderView('projecthub'$data);
  2351.     }
  2352.     
  2353.     public function search_projectAction(Request $request)
  2354.     {            
  2355.         $locale $request->getLocale();
  2356.         $searchedResults = array();
  2357.         $sSearchTerm $request->query->get('searchTerm');  
  2358.         $nStartNum $request->query->get('startnum');      
  2359.         if($sSearchTerm != '')
  2360.         {
  2361.             $searchedResults $this->getSearchedProject($locale$request);
  2362.         }    
  2363.         else
  2364.         {            
  2365.             $searchedResults $this->getExplanationList($nStartNum$locale$request);
  2366.         }            
  2367.         
  2368.         return $this->renderView('project_searched', array(     
  2369.             'searched_project' => $searchedResults,
  2370.             'start_num' => $nStartNum           
  2371.         ));
  2372.     }
  2373.         
  2374.     public function getSearchedProject($locale$request)
  2375.     {        
  2376.         $search = new PostgresSearch();
  2377.         $em $this->getDoctrine()->getManager();
  2378.         $search->setManager($em);
  2379.         $sCategoryId 52;
  2380.         return $search->getCategorySearchResults($sCategoryIdtruefalse$locale$request);
  2381.     }
  2382.     
  2383.     public function featured_projectsAction(Request $request)
  2384.     {                   
  2385.         $this->onloadPage($request);
  2386.         $locale $request->getLocale();
  2387.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_PROJECT$locale9false);
  2388.         if(empty($featuredList))
  2389.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_PROJECT$locale9true);
  2390.         return $this->renderView('projects_featured', array(     
  2391.             'featured_records' => $featuredList            
  2392.         ));
  2393.     }
  2394.     
  2395.     public function search_concordanceAction(Request $request)
  2396.     {            
  2397.         $locale $request->getLocale();
  2398.         $searchedResults = array();
  2399.         $sSearchTerm $request->query->get('searchTerm');  
  2400.         $nWholeWordOnly $request->query->get('wholewordonly'); 
  2401.         $nTitleOnly $request->query->get('titleonly');
  2402.         $bWholeWordOnly = ($nWholeWordOnly == 1);
  2403.         $bTitleOnly = ($nTitleOnly == 1);
  2404.         if($sSearchTerm != '')
  2405.         {
  2406.             $searchedResults $this->getSearchedListByCategory($this->CATEGORY_ID_CONCORDANCE$bWholeWordOnly$bTitleOnly$locale$request);
  2407.             
  2408.             //$searchedResults = $this->getListByCategoryWithSearchTerm($request, $locale, $this->CATEGORY_ID_CONCORDANCE, $sSearchTerm);
  2409.         }    
  2410.         else
  2411.         {
  2412.             $searchedResults $this->getAllListByCategory($this->CATEGORY_ID_CONCORDANCE$locale$request);
  2413.         }
  2414.         
  2415.         $data['searched_results'] = $searchedResults;
  2416.         $data['searchterm'] = $request->getSession()->get('searched_concordance_term');        
  2417.         $data['search_phrase'] = $request->getSession()->get('searched_concordance_phrase');            
  2418.         
  2419.         return $this->renderView('concordance_searched'$data);
  2420.     }
  2421.     
  2422.     public function featured_concordanceAction(Request $request)
  2423.     {                       
  2424.     //    $this->setCurrentUrl($request); 
  2425.         $this->onloadPage($request);
  2426.         $locale $request->getLocale();        
  2427.         $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCORDANCE$locale9);
  2428.         if(empty($featuredList))
  2429.             $featuredList $this->getFeaturedListByCategory($this->CATEGORY_ID_CONCORDANCE$locale9true);
  2430.         $request->getSession()->set('searched_concordance_list', array());
  2431.         $request->getSession()->set('searched_concordance_term', array());
  2432.         $request->getSession()->set('searched_concordance_phrase', array());
  2433.         return $this->renderView('concordance_featured', array(     
  2434.             'featured_concordance' => $featuredList            
  2435.         ));
  2436.     }
  2437.     
  2438.     public function search_gcresourceAction(Request $request)
  2439.     {            
  2440.         $locale $request->getLocale();
  2441.         $searchedResults = array();
  2442.         $sSearchTerm $request->query->get('searchTerm');  
  2443.         $nStartNum $request->query->get('startnum');
  2444.         if($sSearchTerm != '')
  2445.         {
  2446.             $searchedResults $this->getSearchedGcresource($locale$request);
  2447.         }    
  2448.         else
  2449.         {            
  2450.             $searchedResults $this->getGcresourceList($nStartNum$request);            
  2451.         }   
  2452.         
  2453.         $aSearchedResult $searchedResults['results'];        
  2454.         return $this->renderView('gcresource_searched', array(     
  2455.             'searched_gcresource' => $aSearchedResult,
  2456.             'total_record' => $searchedResults['total_record'],
  2457.             'has_more' => $searchedResults['has_more'],
  2458.             'has_filter' => $searchedResults['has_filter'],
  2459.             'start_num' => $nStartNum          
  2460.         ));
  2461.     }
  2462.     
  2463.     public function getSearchedGcresource($locale$request)
  2464.     {
  2465.         $search = new PostgresSearch();
  2466.         $em $this->getDoctrine()->getManager();
  2467.         $search->setManager($em);
  2468.         return $search->getGcresourceSearchResults($locale$request);
  2469.     }
  2470.     
  2471.     public function gcresourcepageAction($gcresourceIDRequest $request)
  2472.     {        
  2473.         $this->onloadPage($request);
  2474.         $aGcresource $this->getGcresourceInfo($gcresourceID);        
  2475.         $aTopic $this->getTopicsForGcresource($gcresourceID);
  2476.         $aGcresourceRef $this->getGcresourceRefs($gcresourceID$request);
  2477.         
  2478.         $nTextLength 150;
  2479.         $sDesc $aGcresource['searchsummary'];
  2480.         $sMetaDesc $this->fixWorkText($sDesc);
  2481.           $sMetaDesc $this->getTextWithinLength($sMetaDesc$nTextLength);
  2482.                  
  2483.         return $this->renderView('gcresource_page', array(   
  2484.             'gcresource_id' => $gcresourceID,  
  2485.             'gcresource_info' => $aGcresource,            
  2486.             'topic_list' => $aTopic,
  2487.             'gcresource_ref' => $aGcresourceRef,
  2488.             'meta_desc' => $sMetaDesc      
  2489.         ));
  2490.     }
  2491.     public function showhdpfAction($editionRequest $request)
  2492.     {             
  2493.         $this->onloadPage($request);
  2494.         $book_code = @$_GET['b'];
  2495.         $passage_num = @$_GET['p'];
  2496.         $sEmail $this->getEmailRegisteredToHdpf($request);
  2497.         if(empty($sEmail))
  2498.         {    
  2499.            $request->getSession()->set("hdpf_book_code"$book_code);
  2500.            $request->getSession()->set("hdpf_passage_num"$passage_num); 
  2501.            $request->getSession()->set("hdpf_edition"$edition);        
  2502.            return $this->redirect($this->get('router')->generate('registerhdpfform', array()), 301);
  2503.         }
  2504.         else
  2505.         {    
  2506.             $sLink $this->getHdpfLink($request$sEmail$book_code$passage_num$edition);
  2507.             if(!empty($sLink))
  2508.             {
  2509.                 header('Location: '.$sLink);
  2510.                 exit;
  2511.             }
  2512.             else
  2513.             {
  2514.                 return $this->redirect($this->get('router')->generate('homepage', array()), 301);
  2515.             } 
  2516.         }
  2517.     }
  2518.     
  2519.     public function registerhdpfformAction(Request $request)
  2520.     {             
  2521.         $this->onloadPage($request);
  2522.         $sEmail $this->getCurrUserEmail($request);
  2523.         if(!empty($sEmail))
  2524.         {  
  2525.             $aData = array(               
  2526.                 'curremail' => $sEmail       
  2527.             );
  2528.             return $this->renderView('registerhdpfform'$aData);
  2529.         }
  2530.         else
  2531.         {    
  2532.             return $this->redirect($this->get('router')->generate('homepage', array()), 301);
  2533.         }
  2534.     }
  2535.     
  2536.     public function registerhdpfAction($email,Request $request)
  2537.     {             
  2538.         $this->onloadPage($request);
  2539.         if($this->registerToHdpf($request$email))
  2540.         {
  2541.             $book_code $request->getSession()->get('hdpf_book_code');
  2542.             $passage_num $request->getSession()->get('hdpf_passage_num');
  2543.             $edition $request->getSession()->get('hdpf_edition');
  2544.             if(!empty($book_code) && !empty($passage_num) && !empty($edition))
  2545.             {
  2546.                 $sLink $this->getHdpfLink($request$email$book_code$passage_num$edition);
  2547.                 if(!empty($sLink))
  2548.                 {
  2549.                     header('Location: '.$sLink);
  2550.                     exit;
  2551.                 }
  2552.                 else
  2553.                 {
  2554.                     return $this->redirect($this->get('router')->generate('homepage', array()), 301);
  2555.                 }
  2556.             }
  2557.         }
  2558.         else
  2559.         {    
  2560.             return $this->redirect($this->get('router')->generate('homepage', array()), 301);
  2561.         }
  2562.     }
  2563.     
  2564.     /**
  2565.      * load explanation text
  2566.      */
  2567.     public function explanationtextAction(Request $request)
  2568.     {        
  2569.       $response null
  2570.       $data = array();
  2571.       $translationID = @$_GET['t'];    
  2572.       if(!empty($translationID))
  2573.       {
  2574.               $nTransID $translationID;                  
  2575.               $explanation_translation $this->expositionData('Translation')->findOneById($nTransID);              
  2576.               if($explanation_translation != null)
  2577.               {
  2578.                   $title $explanation_translation->getTranslatedTitle();
  2579.                 $data['translated_title'] = $title;
  2580.                   $passage $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
  2581.                   if($passage != null)
  2582.                   {                          
  2583.                       $data['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
  2584.                       $data['explanation_translation'] = $explanation_translation;
  2585.                       $data['explanation_passage'] = $passage;
  2586.                       //$data['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
  2587.                       //$data['explanation_text_to_speech'] = $this->getTextToSpeech($request, $explanation_translation->getLanguage()->getId());
  2588.                       //$data['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
  2589.                       $data['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID$request);                                            
  2590.                   }
  2591.               }    
  2592.       }
  2593.             
  2594.       return $this->renderView('explanationtext'$data$response);
  2595.     }    
  2596. // end of php class