<?php
namespace NCBS\WebsiteBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use NCBS\WebsiteBundle\Entity\Bible\Book as BibleBook;
use NCBS\WebsiteBundle\Entity\Bible\Canonical\Book as CanonicalBook;
use NCBS\WebsiteBundle\Tools\DataAssembly;
use Skymark\UtilitiesBundle\Tools\TextFormatter;
use Symfony\Component\HttpFoundation\Request;
class BibleController extends NCBSWController
{
protected $prefix = 'Bible';
public function indexAction(Request $request)
{
return $this->firstbookAction($request, false);
}
/**
* Produces the index page for the Bible section of the website.
*/
public function translationListAction(Request $request, $languageCode = null)
{
$this->onloadPage($request);
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$translation_list = null;
$sLanguageName = "";
if(!empty($languageCode))
{
$aLanguage = $this->getLanguageByBibliographicCode($languageCode);
if(!empty($aLanguage))
{
$sLanguageName = $aLanguage['name'];
$translation_list = $this->getBibleTranslationListForLanguage($aLanguage['id']);
}
}
if(empty($translation_list))
{
$translation_list = $this->getBibleTranslationListByLanguage($nUILanguageID);
}
// $language = $this->getRepository('Language')->findOneByBibliographicCode($languageCode);
// $translations = $this->getRepository('Bible\Translation')->getByLanguageOrAll($language);
return $this->renderView('index', array(
'translation_list' => $translation_list,
'language_name' => $sLanguageName
// 'illustration' => $this->getRepository('Media\Image')->findOneByFile('Still_life_with_Bible.jpg')
));
}
function getManager() {
return $this->getDoctrine()->getManager();
}
protected function getTranslationByUrl($translationUrl, $request, $setCurrentLanguage = false)
{
//s33: cleanup
//error_log("2200 gTBU - this is a " . ClassName::class );
$em = $this->getDoctrine()->getManager();
// $em = $this->getContainer()->get('doctrine.orm.entity_manager');
$bt = $em->getRepository('NCBSWBundle:Bible\\Translation');
if ( 0 ) {
// old
$translation = $this->bibleData('Translation')->findOneBy(array('url' => $translationUrl, 'enabled' => true));
} else {
$translation = $bt->findOneBy(array('url' => $translationUrl, 'enabled' => true));
}
if($translation !== null && $setCurrentLanguage) {
$request->getSession()->set('current_language', $translation->getLanguage()->getBibliographicCode());
}
return $translation;
}
protected function getTranslationByUrlNoOption($translationUrl)
{
$translation = $this->bibleData('Translation')->findOneBy(array('url' => $translationUrl, 'enabled' => true));
return $translation;
}
protected function getTranslationByID($translationID, $setCurrentLanguage = false, $request)
{
$translation = $this->bibleData('Translation')->findOneBy(array('id' => $translationID, 'enabled' => true));
if($translation !== null && $setCurrentLanguage) {
$request->getSession()->set('current_language', $translation->getLanguage()->getBibliographicCode());
}
return $translation;
}
/**
* Produces the main page for a given Bible translation.
* $userSelected is true if the user specifically chose to view this translation, false if it was chosen for the user (e.g. as a site default)
*/
public function translationAction($translationUrl, Request $request, $userSelected = true)
{
$this->onloadPage($request);
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$translation = $this->getTranslationByUrl($translationUrl, $request, $userSelected);
$response = null;
if(empty($translation)) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$nTranslationID = $translation->getId();
$book_list = $this->getBibleBookList($request, $nTranslationID);
// Don't show stories now (6/17/2022)
$suggested = array();
// $suggested = $this->getStoriesForTranslation($translation->getId(), 4);
$renderView = $this->renderView('translation', array(
'book_list' => $book_list,
'suggested_stories' => $suggested,
// 'translations_by_language' => $this->getBibleTranslationsByLanguage(),
'translation' => $translation
), $response);
// $this->logtime(" T:translationAction generated rendering");
// lastly, we cache for next time
// $memcache->save($cacheKey, $renderView, $this->getCacheTime());
// }
return $renderView;
}
function getCacheTime()
{
$cd = 1800;
try {
$cd = $this->container->getParameter('cache_duration'); // see this is not actually catchable ?
// $this->logtime(" T:from params, got: $cd cache_duration");
} catch (Symfony\Component\DependencyInjection\Exception\InvalidArgumentException $e) {
$this->logtime(" T: getParameter FAIL! default $cd cache_duration");
}
return $cd;
}
/**
* Show the first bible book page.
* $userSelected is true if the user specifically chose to view this translation, false if it was chosen for the user (e.g. as a site default)
*/
public function firstbookAction(Request $request, $userSelected = true)
{
// $translation = $this->getTranslationByID($translationID, $userSelected, $request);
$translation = $this->getFirstBibleTranslation($request);
$response = null;
if(empty($translation)) {
$response = new Response();
$response->setStatusCode(404);
}
return $this->redirect($this->get('router')->generate('bible_book', array(
'translationUrl' => $translation['url'],
'bookUrl' => $translation['book_url'],
// 'sp' => true // show popup
)), 301);
/* return $this->renderView('firstbook', array(
'translation' => $translation
), $response); */
}
/**
* Produces the page for a given Bible translation's information.
* $userSelected is true if the user specifically chose to view this translation, false if it was chosen for the user (e.g. as a site default)
*/
public function infoAction($translationUrl, Request $request, $userSelected = true)
{
$this->onloadPage($request);
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$translation = $this->getTranslationByUrl($translationUrl, $request, $userSelected);
$response = null;
if($translation === null) {
$response = new Response();
$response->setStatusCode(404);
}
return $this->renderView('info', array(
'translation' => $translation,
// 'translations_by_language' => $this->getBibleTranslationsByLanguage(),
'translation_info' => '1'
), $response);
}
protected function getBookByUrl($translationUrl, $bookUrl, $request, $setCurrentLanguage = false)
{
$translation = $this->getTranslationByUrl(TextFormatter::urlify($translationUrl), $request, $setCurrentLanguage);
if($translation === null) {
return null;
}
return $this->bibleData('Book')->getOneByUrlFromTranslation(TextFormatter::urlify($bookUrl), $translation);
}
/**
* Produces the chapter list for a particular book.
* $userSelected is true if the user specifically chose to view this translation, false if the translation was chosen for the user (e.g. as a site default)
*/
public function bookAction($translationUrl, $bookUrl, Request $request, $userSelected = true)
{
$this->onloadPage($request);
$book = $this->getBookByUrl($translationUrl, $bookUrl, $request, $userSelected);
$response = null;
if($book === null) {
$response = new Response();
$response->setStatusCode(404);
}
return $this->renderView('book', array(
'book' => $book,
'chapters' => $this->bibleData('Chapter')->getByBook($book),
'translations_by_language' => $this->getBibleTranslationsByLanguage($book->getCanonicalization()->getId()),
'left_to_right' => $this->isRightToLeft($translationUrl)
), $response);
}
/**
* $userSelected is true if the user specifically chose to view this translation, false if the translation was chosen for the user (e.g. as a site default)
*/
public function chapterRangeAction($translationUrl, $bookUrl, $chapterStartIndex, $chapterEndIndex, Request $request, $verseStartIndex = null, $verseEndIndex = null, $userSelected = true)
{
$this->onloadPage($request);
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
if($chapterStartIndex == $chapterEndIndex) {
if($verseStartIndex === null || $verseEndIndex === null) {
return $this->chapterAction($translationUrl, $bookUrl, $request, $chapterStartIndex);
} else {
return $this->verseRangeAction($translationUrl, $bookUrl, $chapterStartIndex, $request, $verseStartIndex, $verseEndIndex);
}
}
$right_to_left = $this->isRightToLeft($translationUrl);
$chapterRangeData = array(
'book' => $this->getBookByUrl($translationUrl, $bookUrl, $request, $userSelected),
'right_to_left' => $right_to_left
);
if($verseStartIndex === null) {
$chapterRangeData['content_class'] = 'chapter';
$chapterRangeData['range_name'] = $this->get('translator')->trans("bible.chapternav.bookchapterrange", array(
'%bookname%' => $chapterRangeData['book']->getName(),
'%chapterstart%' => $chapterStartIndex,
'%chapterend%' => $chapterEndIndex
));
$chapterRangeData['slider_url'] = $this->get('router')->generate('bible_slider_chapter_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterStartIndex' => $chapterStartIndex,
'chapterEndIndex' => $chapterEndIndex
));
} else {
$chapterRangeData['content_class'] = 'verse';
$chapterRangeData['range_name'] = $this->get('translator')->trans("bible.chapternav.bookchapterrangeverserange", array(
'%bookname%' => $chapterRangeData['book']->getName(),
'%chapterstart%' => $chapterStartIndex,
'%chapterend%' => $chapterEndIndex,
'%versestart%' => $verseStartIndex,
'%verseend%' => $verseEndIndex
));
$chapterRangeData['slider_url'] = $this->get('router')->generate('bible_slider_chapter_verse_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterStartIndex' => $chapterStartIndex,
'chapterEndIndex' => $chapterEndIndex,
'verseStartIndex' => $verseStartIndex,
'verseEndIndex' => $verseEndIndex
));
}
// if range from start to end is >= 2, redirect to something shorter.
// We don't need to redirect now as the speed of the pages has been improved (5/15/2018)
// We decided to limit the range to 3 chapters maximum to avoid some errors. (7/19/2019).
// Changed to allow up to 8 chapters (6/21/2024)
$nMaxChapter = 4;
if ( $chapterEndIndex - $chapterStartIndex >= $nMaxChapter ) {
$oldEnd = $chapterEndIndex;
$chapterEndIndex = $chapterStartIndex+$nMaxChapter-1;
//$verseEndIndex = null;
// error_log("chapterRangeAction: //$chapterStartIndex-$oldEnd/ too large a range, redirecting to /$translationUrl/$bookUrl/$chapterStartIndex-$chapterEndIndex/");
return $this->redirect($this->get('router')->generate('bible_chapter_range',
array( 'translationUrl' => $translationUrl, 'bookUrl' => $bookUrl, 'chapterStartIndex' => $chapterStartIndex,
'chapterEndIndex' => $chapterEndIndex,
// 'verseStartIndex' => $verseStartIndex, 'verseEndIndex' => $verseEndIndex -- _verse
)), 301);
}
$chapterRangeData['contents'] = DataAssembly::getVerseRangeFromBook($chapterRangeData['book'], $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$chapterRangeData['translation_url'] = $translationUrl;
$chapterRangeData['bible_column_spec'] = $this->getMultiColumnSpecForChapterRange($translationUrl, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
return $this->createChaptersView($chapterRangeData, $request);
}
// Creates multi-chapter view for access via both canonical and translation-specific numbering
protected function createChaptersView($chapterRangeData, $request)
{
$this->checkIfOnMobile($request);
$response = null;
if(empty($chapterRangeData['contents'])) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$allVerses = array_reduce($chapterRangeData['contents'], 'array_merge', array());
$aVerseInfo = $this->getVerseInfo($allVerses);
if($chapterRangeData['content_class'] !== 'storytext') {
// $chapterRangeData['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
}
$bInframe = (isset($versesData['in_frame']) && $versesData['in_frame']);
$chapterRangeData['has_slider_item'] = $this->hasSliderItem($aVerseInfo, $bInframe, $request, ($chapterRangeData['content_class'] == 'chapter'));
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array(), true);
// $chapterRangeData['otle_ref'] = $aOTLE['otle_nonmusic'];
$chapterRangeData['otle_ref_music'] = $aOTLE['otle_music'];
$chapterRangeData['explained_verse'] = $this->getFirstExplainedVerse($aVerseInfo, $request);
$nCBookID = $chapterRangeData['book']->getCanonicalization()->getId();
$nChapterStartOrder = $allVerses[0]->getChapter()->getOrdering();
$nChapterEndOrder = end($allVerses)->getChapter()->getOrdering();
$nVerseStartOrder = $allVerses[0]->getIndexDisplay();
$nVerseEndOrder = end($allVerses)->getIndexDisplay();
$chapterRangeData['cbook_id'] = $nCBookID;
$chapterRangeData['chapter_start_order'] = $nChapterStartOrder;
$chapterRangeData['chapter_end_order'] = $nChapterEndOrder;
$chapterRangeData['verse_start_order'] = $nVerseStartOrder;
$chapterRangeData['verse_end_order'] = $nVerseEndOrder;
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$chapterRangeData['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($nCBookID, $nChapterStartOrder, $nVerseStartOrder, $nChapterEndOrder, $nVerseEndOrder, $nUILanguageID);
if(!array_key_exists('canonical_chapter_start', $chapterRangeData)) {
$canonicalRangeData = DataAssembly::getVerseNumberRange(DataAssembly::canonicalize($chapterRangeData['contents']));
if($canonicalRangeData !== null) {
$chapterRangeData['canonical_chapter_start'] = $canonicalRangeData['chapter_start'];
$chapterRangeData['canonical_chapter_end'] = $canonicalRangeData['chapter_end'];
$chapterRangeData['canonical_verse_start'] = $canonicalRangeData['verse_start'];
$chapterRangeData['canonical_verse_end'] = $canonicalRangeData['verse_end'];
}
}
$chapterRangeData['text_style_override'] = $this->getTextStyleOverrideForBible($chapterRangeData['book']->getId());
// $chapterRangeData['book_list'] = $this->getBibleBookList($chapterRangeData['book']->getTranslation()->getId());
$chapterRangeData['verses_concept'] = $this->getVerseContentWithConceptLinks($request, $allVerses, $chapterRangeData['bible_column_spec']);
$chapterRangeData['book_url'] = $chapterRangeData['book']->getUrl();
$chapterRangeData['chapter_index'] = $aVerseInfo['FirstChapterIndex'];
return $this->renderView('chapter_range', $chapterRangeData, $response);
}
/**
* $userSelected is true if the user specifically chose to view this translation, false if the translation was chosen for the user (e.g. as a site default)
*/
public function chapterAction($translationUrl, $bookUrl, Request $request, $chapterIndex = 1, $userSelected = true, $inFrame = false)
{
$this->onloadPage($request);
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$language_id = $this->getLanguageIDByBibleTrans($translationUrl);
$chapterData = $this->getChapterPath($translationUrl, $bookUrl, $chapterIndex, $request, $userSelected);
$response = null;
if($chapterData['chapter'] === null) {
$nFirstChapterOrder = $this->getFirstBibleChapterOrder($translationUrl, $bookUrl);
if($nFirstChapterOrder != null)
{
return $this->redirect($this->get('router')->generate('bible_chapter', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => 1
)), 301);
}
}
if($chapterData['chapter'] === null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$chapterData['verses'] = $this->bibleData('Verse')->getByChapter($chapterData['chapter']);
$chapterData['content_class'] = 'chapter';
$chapterData['chapter_index'] = $chapterIndex;
$chapterData['right_to_left'] = $this->isRightToLeft($translationUrl);
$chapterData['content_type'] = 'verseRange';
$chapterData['translation_url'] = $translationUrl;
$chapterExplanations = null;
$nCChapterID = null;
$request->getSession()->set('current_explanation_cchapter_id', '');
if($this->showBibleChapterSummary($language_id) && $chapterData['chapter']->getCanonicalization() != null)
{
$nCChapterID = $chapterData['chapter']->getCanonicalization()->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl, $request);
$nExplainChapterTranslationID = $this->getExplainChapterTranslation($nCChapterID, $this->getCurrUserID($request), $translationUrl);
if($nExplainChapterTranslationID > -1)
{
$chapterData['cchapter_id'] = $nCChapterID;
$request->getSession()->set('current_explanation_cchapter_id', $nCChapterID);
$request->getSession()->set('current_explanation_translation_id', $nExplainChapterTranslationID);
}
}
$chapterData['chapter_explanation'] = $chapterExplanations;
$chapterData['chapter_order'] = $chapterIndex;
$chapterData['book_url'] = $bookUrl;
if(!empty($chapterExplanations))
{
$chapter_explanations_for_combo = $this->getChapterExplanationForCombo($nCChapterID);
$chapterData['chapter_explanations_for_combo'] = $chapter_explanations_for_combo;
$nSelectedExplTransID = $request->query->get('et');
if($nSelectedExplTransID == '')
{
$nTransID = current($chapterExplanations)['translation_id'];
$bIsModern = current($chapterExplanations)['is_modern'];
}
else
{
foreach($chapter_explanations_for_combo as $e)
{
if($e['translation_id'] == $nSelectedExplTransID)
{
$nTransID = $e['translation_id'];
$bIsModern = $e['is_modern'];
break;
}
}
}
// Load chapter summary in text after loading the main page
if($bIsModern && !empty($nTransID) && $this->showBibleChapterSummary($language_id))
{
$sChapterSumUrl = $this->get('router')->generate('bible_chapter_summary', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex,
'summaryTranslationID' => $nTransID
));
$sBookName = $chapterData['book']->getName();
$chapterData['chapter_summary_url'] = $sChapterSumUrl."?bookname=".urlencode($sBookName);
}
}
$bookList = $this->getBibleBookList($request, $chapterData['book']->getTranslation()->getId());
// $chapterData['book_list'] = $bookList;
$nNextBookID = $this->getNextBookID($chapterData['book']->getId(), $bookList);
$nPreviousBookID = $this->getPreviousBookID($chapterData['book']->getId(), $bookList);
$chapterData['next_chapter'] = $this->getNextChapter($chapterData['chapter']->getId(), $nNextBookID);
$chapterData['prev_chapter'] = $this->getPreviousChapter($chapterData['chapter']->getId(), $nPreviousBookID);
$chapterData['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $bookUrl, $chapterIndex);
$chapterData['bible_credit'] = $this->getBibleTranslationCredit($translationUrl);
$chapterData['in_frame'] = $inFrame;
$chapterData['slider_url'] = $this->get('router')->generate('bible_slider_chapter', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex
));
$versesView = $this->createVersesView($chapterData, $request);
if(!$inFrame)
{
$this->setCurrentUrl($request);
}
return $versesView ;
}
/**
* $userSelected is true if the user specifically chose to view this translation, false if the translation was chosen for the user (e.g. as a site default)
*/
public function verseRangeAction($translationUrl, $bookUrl, $chapterIndex, Request $request, $verseStartIndex = null, $verseEndIndex = null, $userSelected = true)
{
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
if($verseStartIndex != null && $verseStartIndex == $verseEndIndex)
{
return $this->redirect($this->get('router')->generate('bible_verse', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex,
'verseIndex' => $verseStartIndex
)), 301);
}
$this->onloadPage($request);
$verseRangeData = $this->getChapterPath($translationUrl, $bookUrl, $chapterIndex, $request, $userSelected);
if($verseRangeData['book'] == null)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$verseRangeData['verses'] = ($verseRangeData['chapter'] === null) ? array() : $this->bibleData('Verse')->getByIndexRangeFromChapter(
$verseStartIndex,
$verseEndIndex,
$verseRangeData['chapter']
);
if($verseEndIndex !== null) {
$verseRangeData['verses_last_index'] = $verseEndIndex;
}
$chapter = $verseRangeData['chapter'];
if($chapter == null)
{
$verseRangeData['content_class'] = 'verse';
}
else
{
$chapterVerses = $verseRangeData['chapter']->getVerses();
if($verseStartIndex != null && $verseStartIndex == $chapterVerses->first()->getOrdering() && $verseEndIndex == $chapterVerses->last()->getOrdering() )
{
$verseRangeData['content_class'] = 'chapter';
}
else
{
$verseRangeData['content_class'] = 'verse';
}
}
// $verseRangeData['content_class'] = 'verse';
$verseRangeData['right_to_left'] = $this->isRightToLeft($translationUrl);
$verseRangeData['content_type'] = 'verseRange';
$verseRangeData['text_style_override'] = $this->getTextStyleOverrideForBible($verseRangeData['book']->getId());
$verseRangeData['translation_url'] = $translationUrl;
$verseRangeData['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $bookUrl, $chapterIndex, $verseStartIndex, $verseEndIndex);
$verseRangeData['bible_credit'] = $this->getBibleTranslationCredit($translationUrl);
$chapterExplanations = null;
$nCChapterID = null;
$request->getSession()->set('current_explanation_cchapter_id', '');
$CChapter = $verseRangeData['chapter']->getCanonicalization();
if($CChapter != null)
{
$nCChapterID = $CChapter->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl, $request);
$nExplainChapterTranslationID = $this->getExplainChapterTranslation($nCChapterID, $this->getCurrUserID($request), $translationUrl);
if($nExplainChapterTranslationID > -1)
{
$verseRangeData['cchapter_id'] = $nCChapterID;
$request->getSession()->set('current_explanation_cchapter_id', $nCChapterID);
$request->getSession()->set('current_explanation_translation_id', $nExplainChapterTranslationID);
}
}
$verseRangeData['chapter_explanation'] = $chapterExplanations;
$verseRangeData['chapter_order'] = $chapterIndex;
$verseRangeData['book_url'] = $bookUrl;
if(!empty($chapterExplanations))
{
$nTransID = current($chapterExplanations)['translation_id'];
$bIsModern = current($chapterExplanations)['is_modern'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$verseRangeData['is_modern_chapter_summary'] = $bIsModern;
$verseRangeData['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$verseRangeData['explanation_translation'] = $explanation_translation;
$verseRangeData['explanation_passage'] = $passage;
$verseRangeData['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$verseRangeData['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$verseRangeData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$verseRangeData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$verseRangeData['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl . "_" . $bookUrl . "_" . $chapterIndex;
$verseRangeData['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$verseRangeData['explanation_cchapter_id'] = $nCChapterID;
$verseRangeData['explanation_translation_id'] = $nTransID;
}
}
}
}
$verseRangeData['slider_url'] = $this->get('router')->generate('bible_slider_verserange', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex,
'verseStartIndex' => $verseStartIndex,
'verseEndIndex' => $verseEndIndex
));
$this->setCurrentUrl($request);
return $this->createVersesView($verseRangeData, $request);
}
/**
* Handles much of the code that is common to the full-chapter and verse-range views
*/
protected function createVersesView($versesData, $request)
{
//$this->logtime(' T:createVersesView enter'); $cc = 1;
$this->checkIfOnMobile($request);
$aVerseInfo = $this->getVerseInfo($versesData['verses']);
if(empty($aVerseInfo)) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$bInframe = (isset($versesData['in_frame']) && $versesData['in_frame']);
$versesData['has_slider_item'] = $this->hasSliderItem($aVerseInfo, $bInframe, $request, ($versesData['content_class'] == 'chapter'));
$aOTLE = $this->getOTLERefForBible($aVerseInfo, ($versesData['content_class'] == 'chapter') ? array($versesData['chapter']) : array(), true);
// $versesData['otle_ref'] = $aOTLE['otle_nonmusic'];
$versesData['otle_ref_music'] = $aOTLE['otle_music'];
$nCBookID = $versesData['book']->getCanonicalization()->getId();
$nChapterStartOrder = reset($versesData['verses'])->getChapter()->getOrdering();
$nVerseStartOrder = reset($versesData['verses'])->getIndexDisplay();
$nChapterEndOrder = end($versesData['verses'])->getChapter()->getOrdering();
$nVerseEndOrder = end($versesData['verses'])->getIndexDisplay();
$versesData['cbook_id'] = $nCBookID;
$versesData['chapter_start_order'] = $nChapterStartOrder;
$versesData['chapter_end_order'] = $nChapterEndOrder;
$versesData['verse_start_order'] = $nVerseStartOrder;
$versesData['verse_end_order'] = $nVerseEndOrder;
$bible_column_spec = '';
if(array_key_exists('bible_column_spec', $versesData))
$bible_column_spec = $versesData['bible_column_spec'];
$versesData['verses_concept'] = $this->getVerseContentWithConceptLinks($request, $versesData['verses'], $bible_column_spec);
//$this->logtime(" T:createVersesView got translations_by_language $cc"); $cc++;
if(!array_key_exists('canonical_chapter_start', $versesData)) {
// Need to pass array($versesData['verses']) rather than just $verseData['verses'] so it will sort by ordering rather than by database ID
$canonicalRangeData = DataAssembly::getVerseNumberRange(DataAssembly::canonicalize(array($versesData['verses'])));
if($canonicalRangeData !== null) {
if(array_key_exists('chapter_index', $versesData) && $versesData['chapter_index'] != null)
{
$versesData['canonical_chapter_start'] = $versesData['chapter_index'];
$versesData['canonical_chapter_end'] = null;
$versesData['canonical_verse_start'] = null;
$versesData['canonical_verse_end'] = null;
}
else
{
$versesData['canonical_chapter_start'] = $canonicalRangeData['chapter_start'];
$versesData['canonical_chapter_end'] = $canonicalRangeData['chapter_end'];
$versesData['canonical_verse_start'] = $canonicalRangeData['verse_start'];
$versesData['canonical_verse_end'] = $canonicalRangeData['verse_end'];
}
}
}
$response = null;
if($versesData['book'] === null || $versesData['chapter'] === null || empty($versesData['verses'])) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$translation = $versesData['book']->getTranslation();
$nTranslationID = $translation->getId();
$nLanguageID = $translation->getLanguage()->getId();
$versesData['hide_highlights'] = !$this->showBibleHighlights($nLanguageID);
// $versesData['lang_str_for_meta'] = $this->getLanguageStrForMeta($nLanguageID);
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$versesData['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($nCBookID, $nChapterStartOrder, $nVerseStartOrder, $nChapterEndOrder, $nVerseEndOrder, $nUILanguageID);
$versesData['book_url'] = $versesData['book']->getUrl();
$versesData['chapter_index'] = $aVerseInfo['FirstChapterIndex'];
// if(!isset($versesData['book_list']) || $versesData['book_list'] == null)
// $versesData['book_list'] = $this->getBibleBookList($nTranslationID);
// get qBible data
$versesData['qbible_link'] = $this->getQBibleLink($versesData['book'], $versesData['chapter'], $versesData['verses']);
// get commentary with file (pdf)
$versesData['commentary_with_doc'] = $this->getCommentaryWithDocForBible($versesData['book'], current($versesData['verses'])->getChapter()->getOrdering());
$versesData['text_style_override'] = $this->getTextStyleOverrideForBible($versesData['book']->getId());
$versesData['text_to_speech'] = $this->getTextToSpeech($nLanguageID);
if($versesData['content_type'] == 'single_verse')
{
$nSelectedExplTransID = $request->query->get('et');
$nTextLength = 140;
$sVerseContent = $versesData['verse']->getContent();
$sMetaDesc = $this->fixVerseText($sVerseContent);
$sMetaDesc = $this->getTextWithinLength($sMetaDesc, $nTextLength, "...");
$versesData['verse_meta_desc'] = $sMetaDesc;
$stories = DataAssembly::findVerseStories($versesData['verse'], $this->getManager(), true);
if(!empty($stories)) {
$illustrations = array();
$explanations = array();
foreach($stories as $story) {
$illustrations = array_merge($illustrations, $story->getIllustrations()->toArray());
$explanations = array_merge($explanations, $story->getExplanations()->toArray());
}
$versesData['verse_illustrations'] = $illustrations;
if(count($explanations) > 0 && $explanations[0]->selectTranslation() != null && $explanations[0]->findFirstPassage() != null)
{
// get the explanation with the same language of the verse if there is
$versesData['verse_explanations'] = $explanations;
$verseexplanation = $this->getVerseExplanationInText($request, $explanations, $nLanguageID);
if(!empty($verseexplanation))
{
$versesData['verse_explanations_for_combo'] = $this->getVerseExplanationsForVerse($versesData['verse']->getId());
$versesData['verse_explanation'] = $verseexplanation;
$versesData['passage_multilink'] = $this->getWorkPassageMultiLink($verseexplanation->findFirstNonEmptyPassage()->getId(),$verseexplanation->getId(), $request);
$versesData['authors'] = $this->getAuthorInfo($request, $verseexplanation->getId());
}
}
}
}
else
{
// Full chapter
$nTextLength = 150;
$sVerseText = "";
foreach($versesData['verses'] as $v) {
if($sVerseText != "")
$sVerseText .= " ";
$sVerseContent = $v->getContent();
$sVerseText .= $this->fixVerseText($sVerseContent);
if(strlen($sVerseText) > $nTextLength)
break;
}
$sMetaDesc = $this->getTextWithinLength($sVerseText, $nTextLength, "...");
$versesData['chapter_meta_desc'] = $sMetaDesc;
}
$versesData['linktype_id'] = $this->LINK_TYPE_ID_BIBLE;
return $this->renderView('verses', $versesData, $response);
}
// TODO: should take more args besides just key .. or body could be more generic
// expands the function
function cacheBibleTranslationDropdown( $cacheKey, $twigVars, $dropdown_target )
{
$memcache = $this->get('cache'); // really apccache, but behaves the same way
$this->logtime(" ===== ");
if ( $memcache->contains($cacheKey) ) {
$this->logtime(" T::returning cache value for: $cacheKey");
$dropdown = $memcache->fetch($cacheKey) . "\n<!-- from cache -->";
} else {
$this->logtime(" T::generating cache value for: $cacheKey");
// not found -
//$subTemplate = 'Bible:interface/translation_dropdown/dropdown.html.twig';
// full path (include bundle) to the template that is include'd
$subTemplate = 'NCBSWBundle:Bible:interface/translation_dropdown/dropdown.html.twig';
$templateVariables = $twigVars;
// add these because of the 'with' it gets called with
// Bible:interface/translation_dropdown/dropdown.html.twig' with {'dropdown_target': 'index'}
// NOT SURE --
$templateVariables[ 'dropdown_target' ] = $dropdown_target; // 'index';
// first we render the template, to get the content as html
$engine = $this->container->get('templating');
$this->logtime(" T:context! $templateVariables[dropdown_target]");
$content = $engine->render($subTemplate, $templateVariables);
$dropdown_html = $content;
// now we cache it, so it gets used next time
$value_to_cache = "<!-- start cache $cacheKey: " . strlen($dropdown_html) . " chars, at " . `date` . "-->\n"
. $dropdown_html . "<!-- end cached $cacheKey -->\n";
// for demonstration, keep for one minute
$memcache->save($cacheKey, $value_to_cache, 60 * 2 ); //3600);
$dropdown = $value_to_cache;
}
$this->logtime(" ===== ");
return $dropdown;
}
/**
* $userSelected is true if the user specifically chose to view this translation, false if the translation was chosen for the user (e.g. as a site default)
*/
public function verseAction($translationUrl, $bookUrl, $chapterIndex, $verseIndex, Request $request, $subverseIndex = null, $userSelected = true)
{
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$this->onloadPage($request);
$cacheKey = "verse:$translationUrl:$bookUrl:$chapterIndex:$verseIndex:$subverseIndex:$userSelected:" . $request->getLocale();
$this->logtime(" T:verseAction enter $cacheKey");
$content = $this->verseAction_nonCached($translationUrl, $bookUrl, $chapterIndex, $verseIndex, $request, $subverseIndex, $userSelected);
$this->logtime(" T:verseAction generated content for cache entry $cacheKey");
return $content;
}
public function verseAction_nonCached($translationUrl, $bookUrl, $chapterIndex, $verseIndex, Request $request, $subverseIndex = null, $userSelected = true)
{
if(!is_numeric($verseIndex))
{
return $this->redirect($this->get('router')->generate('bible_chapter', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex
)), 301);
}
$verseData = $this->getChapterPath($translationUrl, $bookUrl, $chapterIndex, $request, $userSelected);
// $verseData['verse'] = $this->bibleData('Verse')->getByIndexFromChapter($verseIndex, $verseData['chapter']);
// as verse range
$verseStartIndex = $verseIndex;
$verseEndIndex = $verseIndex;
$verseData['verses'] = ($verseData['chapter'] === null) ? array() : $this->bibleData('Verse')->getByIndexRangeFromChapter(
$verseStartIndex,
$verseEndIndex,
$verseData['chapter']
);
if(empty($verseData['verses']))
{
return $this->redirect($this->get('router')->generate('bible_chapter', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex
)), 301);
}
$verseData['verse'] = current($verseData['verses']);
$verseData['translation_url'] = $translationUrl;
// Don't show subverse view. Always show the main verse view
/* if($subverseIndex !== null) {
$verseData['subverse'] = ($verseData['verse'] === null) ? null : $this->bibleData('Verse')->getSubverseByIndexFromVerse($subverseIndex, $verseData['verse']);
if($verseData['verse'] !== null) {
$canonicalRangeData = DataAssembly::getVerseNumberRange($verseData['verse']->getCanonicalization()->toArray());
if($canonicalRangeData !== null) {
$verseData['canonical_chapter_start'] = $canonicalRangeData['chapter_start'];
$verseData['canonical_chapter_end'] = $canonicalRangeData['chapter_end'];
$verseData['canonical_verse_start'] = $canonicalRangeData['verse_start'];
$verseData['canonical_verse_end'] = $canonicalRangeData['verse_end'];
}
}
$verseData['right_to_left'] = $this->isRightToLeft($translationUrl);
$verseData['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $bookUrl, $chapterIndex, $subverseIndex);
$verseData['bible_credit'] = $this->getBibleTranslationCredit($translationUrl);
$sSubVerseIndexDisplay = $verseData['subverse']->getIndexDisplay();
$nVerseID = null;
if(strpos($sSubVerseIndexDisplay, '-') !== false)
$nVerseID = $verseData['verse']->getId();
else
$nVerseID = $verseData['subverse']->getId();
if($nVerseId != null && $nVerseId != '')
{
$verseData['next_verse'] = $this->getNextVerse($nVerseID);
$verseData['prev_verse'] = $this->getPreviousVerse($nVerseID);
}
return $this->createVerseView($verseData, $request);
}
else
{ */
if($verseEndIndex !== null) {
$verseData['verses_last_index'] = $verseEndIndex;
}
$nVerseID = $verseData['verse']->getId();
$verseData['content_class'] = 'verse';
$verseData['content_type'] = 'single_verse';
// $verseData['verse'] = $this->bibleData('Verse')->getByIndexFromChapter($verseIndex, $verseData['chapter']);
$verseData['right_to_left'] = $this->isRightToLeft($translationUrl);
$verseData['translation_url'] = $translationUrl;
$verseData['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $bookUrl, $chapterIndex, $verseIndex);
$verseData['bible_credit'] = $this->getBibleTranslationCredit($translationUrl);
$verseData['next_verse'] = $this->getNextVerse($nVerseID);
$verseData['prev_verse'] = $this->getPreviousVerse($nVerseID);
$verseData['book_url'] = $bookUrl;
$verseData['chapter_index'] = $chapterIndex;
$verseData['verse_index'] = $verseIndex;
$verseData['verse_id_for_verse_of_day'] = $nVerseID;
// show chapter summary on verse level
$cchapter = $verseData['chapter']->getCanonicalization();
if($cchapter != null)
{
$nCChapterID = $cchapter->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl, $request);
$verseData['chapter_explanation'] = $chapterExplanations;
$verseData['chapter_order'] = $chapterIndex;
if(!empty($chapterExplanations))
{
$nTransID = current($chapterExplanations)['translation_id'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$verseData['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$verseData['explanation_translation'] = $explanation_translation;
$verseData['explanation_passage'] = $passage;
$verseData['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$verseData['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$verseData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$verseData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$verseData['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl . "_" . $bookUrl . "_" . $chapterIndex;
$verseData['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$verseData['explanation_cchapter_id'] = $nCChapterID;
$verseData['explanation_translation_id'] = $nTransID;
}
}
}
}
}
$verseData['slider_url'] = $this->get('router')->generate('bible_slider_verse', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex,
'verseStartIndex' => $verseIndex
));
$versesView = $this->createVersesView($verseData, $request);
$this->setCurrentUrl($request);
return $versesView;
// }
}
// Creates multi-chapter view for access via both canonical and translation-specific numbering
public function createVerseView($verseData, $request)
{
$this->checkIfOnMobile($request);
$stories = DataAssembly::findVerseStories($verseData['verse'], $this->getManager(), true);
$aVerse = array();
if(!array_key_exists('subverse', $verseData))
$aVerse = array($verseData['verse']);
else
{
$aVerse = array(
$verseData['verse'],
$verseData['subverse']
);
}
$aVerseInfo = $this->getVerseInfo($aVerse);
$bInframe = (isset($verseData['in_frame']) && $verseData['in_frame']);
$verseData['has_slider_item'] = $this->hasSliderItem($aVerseInfo, $bInframe, $request);
if(!empty($stories)) {
$illustrations = array();
$explanations = array();
foreach($stories as $story) {
$illustrations = array_merge($illustrations, $story->getIllustrations()->toArray());
$explanations = array_merge($explanations, $story->getExplanations()->toArray());
}
$verseData['verse_illustrations'] = $illustrations;
if(count($explanations) > 0 && $explanations[0]->selectTranslation() != null && $explanations[0]->findFirstPassage() != null)
{
$verseData['verse_explanations'] = $explanations;
$verseexplanation = $this->getVerseExplanationInText($request, $explanations, $nLanguageID);
if(!empty($verseexplanation))
{
$versesData['verse_explanation'] = $verseexplanation;
$versesData['passage_multilink'] = $this->getWorkPassageMultiLink($verseexplanation->findFirstNonEmptyPassage()->getId(),$verseexplanation->getId(), $request);
$versesData['authors'] = $this->getAuthorInfo($request, $verseexplanation->getId());
}
}
}
$verseData['translations_by_language'] = $this->getBibleTranslationsByLanguage($verseData['book']->getCanonicalization()->getId());
$verseData['verses_concept'] = $this->getVerseContentWithConceptLinks($request, $verseData['verse'], $verseData['bible_column_spec']);
$verseData['text_style_override'] = $this->getTextStyleOverrideForBible($verseData['book']->getId());
$response = null;
if($verseData['verse'] === null) {
$response = new Response();
$response->setStatusCode(404);
}
// $verseData['book_list'] = $this->getBibleBookList($verseData['book']->getTranslation()->getId());
return $this->renderView('verse', $verseData, $response);
}
public function canonicalNumberedContentAction($translationUrl, $bookUrl, $chapterStartIndex, Request $request, $chapterEndIndex = null, $verseStartIndex = null, $verseEndIndex = null)
{
$msgData = $this->checkBibleTranslationMsg($translationUrl);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$translation = $this->bibleData('Translation')->findOneBy(array('url' => TextFormatter::urlify($translationUrl), 'enabled' => true));
$canonicalBook = $this->bibleData('Canonical\Book')->findOneByUrl(TextFormatter::urlify($bookUrl));
if($canonicalBook == null)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
if($chapterStartIndex != null)
{
$book = $this->getBookByUrl($translationUrl, $bookUrl, $request, false);
if($book != null)
{
$lastChapterNum = $book->getChapters()->last()->getOrdering();
if($lastChapterNum < $chapterStartIndex)
{
$chapterStartIndex = $lastChapterNum;
$verseStartIndex = null;
$verseEndIndex = null;
}
if($chapterEndIndex != null && $lastChapterNum < $chapterEndIndex)
{
$chapterEndIndex = $lastChapterNum;
$verseStartIndex = null;
$verseEndIndex = null;
}
}
else
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$chapter = $this->bibleData('Chapter')->findOneBy(array('book' => $book->getId(), 'ordering' => $chapterStartIndex));
if($chapter != null)
{
if($verseStartIndex != null)
{
$verses = $chapter->getVerses();
$nOrder = 0;
foreach($verses as $verse) {
$sIndexDisplay = $verse->getIndexDisplay();
if(is_numeric ($sIndexDisplay))
{
$nTempOrder = (int)$sIndexDisplay;
if($nTempOrder > $verseStartIndex)
break;
else
$nOrder = $nTempOrder;
}
}
if($nOrder != $verseStartIndex)
{
//$verseStartIndex = $nOrder;
$verseStartIndex = null; // go to chapter level
$verseEndIndex = null;
}
}
if($verseEndIndex != null)
{
$verses = $chapter->getVerses();
$nOrder = 0;
foreach($verses as $verse) {
$sIndexDisplay = $verse->getIndexDisplay();
if(is_numeric ($sIndexDisplay))
{
$nTempOrder = (int)$sIndexDisplay;
if($nTempOrder > $verseEndIndex)
break;
else
$nOrder = $nTempOrder;
}
}
if($nOrder != $verseEndIndex)
{
//$verseEndIndex = $nOrder;
$verseStartIndex = null; // go to chapter level
$verseEndIndex = null;
}
}
}
}
$canonicalVerseData = DataAssembly::getVerseRangeFromBook($canonicalBook, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$translatedVerseData = DataAssembly::decanonicalizeSpan($this->getManager(), $translation->getId(), $canonicalVerseData);
$contentData = array(
'canonical_chapter_start' => $chapterStartIndex,
'canonical_chapter_end' => $chapterEndIndex,
'canonical_verse_start' => $verseStartIndex,
'canonical_verse_end' => $verseEndIndex
);
$contentData['bible_column_spec'] = $this->getMultiColumnSpecForChapterRange($translationUrl, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
if(count($translatedVerseData) === 1) {
// Single chapter
$verseList = reset($translatedVerseData);
$v1 = reset($verseList)->findMainVerse();
$vn = end($verseList)->findMainVerse();
$contentData['chapter'] = $v1->getChapter();
$contentData['book'] = $contentData['chapter']->getBook();
if(count($verseList) === 1) {
$listedVerse = reset($verseList);
// return $this->redirect($this->getUriDiscovery()->discoverUri($listedVerse), 301);
$redirectUrl = $this->get('router')->generate('bible_verse', array(
'translationUrl' => $contentData['book']->getTranslation()->getUrl(),
'bookUrl' => $contentData['book']->getUrl(),
'chapterIndex' => $contentData['chapter']->getOrdering(),
'verseIndex' => $listedVerse->getIndexDisplay()
));
return $this->redirect($redirectUrl, 301);
/* To build this page immediately rather than redirecting:
if($listedVerse->getVerse() === null) {
$contentData['verse'] = $listedVerse;
} else {
$contentData['subverse'] = $listedVerse;
$contentData['verse'] = $listedVerse->getVerse();
}
return $this->createVerseView($contentData, $request);
*/
}
$contentData['verses'] = $verseList;
// Check whether we're showing an entire chapter or just part of a chapter
$chapterVerses = $contentData['chapter']->getVerses();
if( $v1->getId() == $chapterVerses->first()->getId() && $vn->getId() == $chapterVerses->last()->getId() ) {
// return $this->redirect($this->getUriDiscovery()->discoverUri($contentData['chapter']), 301);
return $this->redirect($this->get('router')->generate('bible_chapter', array(
'translationUrl' => $translationUrl,
'bookUrl' => $contentData['book']->getUrl(),
'chapterIndex' => $contentData['chapter']->getOrdering()
)), 301);
} else {
return $this->redirect($this->get('router')->generate('bible_verse_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $contentData['book']->getUrl(),
'chapterIndex' => $contentData['chapter']->getOrdering(),
'verseStartIndex' => $v1->getIndexDisplay(),
'verseEndIndex' => $vn->getIndexDisplay()
)), 301);
}
/* To build this page immediately rather than redirecting:
if( $v1->getId() == $chapterVerses->first()->getId() && $vn->getId() == $chapterVerses->last()->getId() ) {
$contentData['content_class'] = 'chapter';
} else {
$contentData['content_class'] = 'verses';
$contentData['verses_last_index'] = $vn->getIndexDisplay();
}
return $this->createVersesView($contentData, $request);
*/
} elseif(count($translatedVerseData) === 0) {
// Zero chapters -- this translation doesn't have this book/chapter(s)/verse(s)
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
} else {
// Multiple chapters
$firstChapterContent = reset($translatedVerseData);
$v1 = reset($firstChapterContent)->findMainVerse();
$lastChapterContent = end($translatedVerseData);
$vn = end($lastChapterContent)->findMainVerse();
$c1 = $v1->getChapter();
$cn = $vn->getChapter();
$contentData['contents'] = $translatedVerseData;
$contentData['book'] = $c1->getBook();
if( $v1->getId() == $c1->getVerses()->first()->getId() && $vn->getId() == $cn->getVerses()->last()->getId() ) {
return $this->redirect($this->get('router')->generate('bible_chapter_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $contentData['book']->getUrl(),
'chapterStartIndex' => $c1->getOrdering(),
'chapterEndIndex' => $cn->getOrdering()
)), 301);
} else {
return $this->redirect($this->get('router')->generate('bible_chapter_verse_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $contentData['book']->getUrl(),
'chapterStartIndex' => $c1->getOrdering(),
'chapterEndIndex' => $cn->getOrdering(),
'verseStartIndex' => $v1->getIndexDisplay(),
'verseEndIndex' => $vn->getIndexDisplay()
)), 301);
}
/* To build this page immediately rather than redirecting:
if( $v1->getId() == $c1->getVerses()->first()->getId() && $vn->getId() == $cn->getVerses()->last()->getId() ) {
$contentData['content_class'] = 'chapter';
$contentData['range_name'] = $contentData['book']->getName().' '.$c1->getOrdering().'-'.$cn->getOrdering();
} else {
$contentData['content_class'] = 'verse';
$contentData['range_name'] = $contentData['book']->getName().' '.$c1->getOrdering().':'.$v1->getIndexDisplay().' - '.$cn->getOrdering().':'.$vn->getIndexDisplay();
}
return $this->createChaptersView($contentData);
*/
}
}
public function storyTextAction($storyUrl, Request $request, $bibleTranslationUrl = null)
{
$locale = $request->getLocale();
if($bibleTranslationUrl === null) {
// For SEO purposes, we'll send the visitor to the route for the story with the default translation
$defaultLanguage = $this->getRepository('Language')->findOneBySiteDefault(true);
$defaultTranslation = $this->bibleData('Translation')->findOneBy(array('language' => $defaultLanguage->getId(), 'languageDefault' => true, 'enabled' => true));
return $this->redirect($this->get('router')->generate('bible_translated_story_text', array(
'storyUrl' => $storyUrl,
'bibleTranslationUrl' => $defaultTranslation->getUrl()
)), 301);
}
$story = $this->bibleData('Stories\Story')->findOneBy(array('url' => $storyUrl, 'level_id' => $this->STORY_LEVEL_ID_BIBLE, 'isPublic' => true));
$response = null;
if($story == null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$translation = $this->bibleData('Translation')->findOneBy(array('url' => $bibleTranslationUrl, 'enabled' => true));
$response = null;
if($translation === null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
if($locale != 'en')
{
$sStoryName = $this->getBibleStoryName($story->getId(), $locale);
if(!empty($sStoryName))
$story->setName($sStoryName);
}
$aPublicStoryExplanation = $this->getExplainedStoryList($locale, $story->getId());
$bHasPublicStoryExplanation = !empty($aPublicStoryExplanation);
$right_to_left = $translation->getLanguage()->getRightToLeft();
$canonicalStartVerse = $story->getStartVerse();
$canonicalEndVerse = $story->getEndVerse();
$canonicalStartChapter = $canonicalStartVerse->getChapter();
$canonicalEndChapter = $canonicalEndVerse->getChapter();
$canonicalBook = $canonicalStartChapter->getBook();
$contentsCanonical = DataAssembly::getVerseRangeFromBook($canonicalBook, $canonicalStartChapter->getOrdering(), $canonicalEndChapter->getOrdering(), $canonicalStartVerse->getOrdering(), $canonicalEndVerse->getOrdering());
$contents = DataAssembly::decanonicalizeSpan($this->getManager(), $translation->getId(), $contentsCanonical);
$this->onloadPage($request);
if(count($contents) === 0) {
// Content does not exist in this translation
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
} else {
$this->setCurrentUrl($request);
$firstChapterContents = reset($contents);
$firstVerse = reset($firstChapterContents);
$firstChapter = $firstVerse->findMainVerse()->getChapter();
$lastChapterContents = end($contents);
$lastVerse = end($lastChapterContents);
$lastChapter = $lastVerse->findMainVerse()->getChapter();
$completeChapters = $firstVerse === $firstChapter->getVerses()->first() && $lastVerse === $lastChapter->getVerses()->last();
$storyData = array(
'story' => $story,
'has_public_explanation' => $bHasPublicStoryExplanation,
'translation' => $translation,
'book' => $firstVerse->findMainVerse()->getChapter()->getBook(),
'content_class' => 'storytext',
'right_to_left' => $right_to_left
);
// $storyData['next_chapter'] = $this->getNextChapter($firstChapter->getId());
// $storyData['prev_chapter'] = $this->getPreviousChapter($firstChapter->getId());
$storyData['translation_url'] = $translation->getUrl();
$storyData['book_url'] = $canonicalBook->getUrl();
$storyData['bible_column_spec'] = $this->getBibleMultiColumnSpec($storyData['translation_url'], $storyData['book_url'], $canonicalStartChapter->getOrdering(), $canonicalStartVerse->getOrdering(), $canonicalEndVerse->getOrdering());
if(count($contents) === 1) {
// Story is entirely within a single chapter
$storyData['chapter'] = $firstChapter;
$storyData['verses'] = $firstChapterContents;
if(!$completeChapters) {
$storyData['verses_last_index'] = $lastVerse->getFullIndexDisplay();
}
$storyData['content_type'] = 'verseRange';
$storyData['slider_url'] = $this->get('router')->generate('bible_slider_verserange', array(
'translationUrl' => $storyData['translation_url'],
'bookUrl' => $storyData['book_url'],
'chapterIndex' => $firstChapter->getOrdering(),
'verseStartIndex' => $canonicalStartVerse->getOrdering(),
'verseEndIndex' => $canonicalEndVerse->getOrdering()
));
return $this->createVersesView($storyData, $request);
} else {
// Story contains text from more than one chapter
$storyData['contents'] = $contents;
if($completeChapters) {
$storyData['range_name'] = $this->get('translator')->trans("bible.chapternav.bookchapterrange", array(
'%bookname%' => $storyData['book']->getName(),
'%chapterstart%' => $firstChapter->getOrdering(),
'%chapterend%' => $lastChapter->getOrdering()
));
$storyData['slider_url'] = $this->get('router')->generate('bible_slider_chapter_range', array(
'translationUrl' => $storyData['translation_url'],
'bookUrl' => $storyData['book_url'],
'chapterStartIndex' => $firstChapter->getOrdering(),
'chapterEndIndex' => $lastChapter->getOrdering()
));
} else {
$storyData['range_name'] = $this->get('translator')->trans("bible.chapternav.bookchapterrangeverserange", array(
'%bookname%' => $storyData['book']->getName(),
'%chapterstart%' => $firstChapter->getOrdering(),
'%chapterend%' => $lastChapter->getOrdering(),
'%versestart%' => $firstVerse->getFullIndexDisplay(),
'%verseend%' => $lastVerse->getFullIndexDisplay()
));
$storyData['slider_url'] = $this->get('router')->generate('bible_slider_chapter_verse_range', array(
'translationUrl' => $storyData['translation_url'],
'bookUrl' => $storyData['book_url'],
'chapterStartIndex' => $firstChapter->getOrdering(),
'chapterEndIndex' => $lastChapter->getOrdering(),
'verseStartIndex' => $canonicalStartVerse->getOrdering(),
'verseEndIndex' => $canonicalEndVerse->getOrdering()
));
}
// echo $storyData['slider_url'];
return $this->createChaptersView($storyData, $request);
}
}
}
public function compareVersesAction($translationUrl1, $translationUrl2, $bookUrl, $chapterStartIndex, Request $request, $chapterEndIndex = null, $verseStartIndex = null, $verseEndIndex = null)
{
$this->checkIfOnMobile($request);
$msgData = $this->checkBibleTranslationMsg($translationUrl1);
if(empty($msgData))
$msgData = $this->checkBibleTranslationMsg($translationUrl2);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$this->onloadPage($request);
$response = null;
$translation1 = $this->getBibleTranslationInfo($translationUrl1, $bookUrl);
$translation2 = $this->getBibleTranslationInfo($translationUrl2, $bookUrl);
if(empty($translation1) || empty($translation2))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
$right_to_left1 = $translation1['righttoleft'];
$right_to_left2 = $translation2['righttoleft'];
$canonicalBook = $this->bibleData('Canonical\Book')->findOneByUrl($bookUrl);
if($chapterStartIndex != null)
{
$lastChapterNumBook1 = $translation1['last_chapter_order'];
if($lastChapterNumBook1 < $chapterStartIndex)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_chapter_back', array(), $response);
}
$lastChapterNumBook2 = $translation2['last_chapter_order'];
if($lastChapterNumBook2 < $chapterStartIndex)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_chapter_back', array(), $response);
}
}
$bVerseLevel = false;
$bible_column_spec = $this->getMultiColumnSpecForChapterRange($translationUrl1, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$canonicalVerseData = DataAssembly::getVerseRangeFromBook($canonicalBook, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$verses1 = DataAssembly::decanonicalizeSpan($this->getManager(), $translation1['id'], $canonicalVerseData);
if(count($verses1) < 1)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_chapter_back', array(), $response);
}
$verses2 = DataAssembly::decanonicalizeSpan($this->getManager(), $translation2['id'], $canonicalVerseData);
$aVerse = array_reduce($verses1, 'array_merge', array());
$aVerse2 = array_reduce($verses2, 'array_merge', array());
$nCBookID = $canonicalBook->getId();
$nChapterStartOrder = reset($aVerse)->getChapter()->getOrdering();
$nVerseStartOrder = reset($aVerse)->getIndexDisplay();
$nChapterID = reset($aVerse)->getChapter()->getId();
$nChapterEndOrder = end($aVerse)->getChapter()->getOrdering();
$nVerseEndOrder = end($aVerse)->getIndexDisplay();
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$templateData = array(
'translation1' => $translation1,
'contents1' => $verses1,
'translation2' => $translation2,
'contents2' => $verses2,
'translations_by_language' => $this->getBibleTranslationsByLanguageForVerses($nCBookID, $nChapterStartOrder, $nVerseStartOrder, $nChapterEndOrder, $nVerseEndOrder, $nUILanguageID),
'verses_concept1' => $this->getVerseContentWithConceptLinks($request, $aVerse, $bible_column_spec),
'verses_concept2' => $this->getVerseContentWithConceptLinks($request, $aVerse2, $bible_column_spec, 2),
'canonical_book' => $canonicalBook,
'contents_canonical' => $canonicalVerseData,
'canonical_chapter_start' => $chapterStartIndex,
'canonical_chapter_end' => $chapterEndIndex,
'canonical_verse_start' => $verseStartIndex,
'canonical_verse_end' => $verseEndIndex,
'right_to_left1' => $right_to_left1,
'right_to_left2' => $right_to_left2,
'text_style_override1' => $this->getTextStyleOverrideForBible($translation1['book_id']),
'text_style_override2' => $this->getTextStyleOverrideForBible($translation2['book_id']),
'text_to_speech1' => $this->getTextToSpeech($translation1['language_id']),
'text_to_speech2' => $this->getTextToSpeech($translation2['language_id'])
);
$templateData['cbook_id'] = $nCBookID;
$templateData['chapter_start_order'] = $nChapterStartOrder;
$templateData['chapter_end_order'] = $nChapterEndOrder;
$templateData['verse_start_order'] = $nVerseStartOrder;
$templateData['verse_end_order'] = $nVerseEndOrder;
if($verseStartIndex == null && $chapterEndIndex == null)
$templateData['content_class'] = "chapter";
$templateData['bible_column_spec1'] = $this->getMultiColumnSpecForChapterRange($translationUrl1, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$templateData['bible_column_spec2'] = $this->getMultiColumnSpecForChapterRange($translationUrl2, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$bEmptyContent2 = empty($templateData['contents2']);
if($bEmptyContent2)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
else
{
$aVerseInfo = $this->getVerseInfo($aVerse);
$aVerseInfo2 = $this->getVerseInfo($aVerse2);
// $templateData['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
// If we have a single (canonical) verse, we'll check if it has an explanation; otherwise, we'll look for verses that have explanations
if($chapterEndIndex === null && $verseStartIndex !== null && ($verseEndIndex === null || $verseEndIndex <= $verseStartIndex)) {
$bVerseLevel = true;
$chapterList = reset($canonicalVerseData);
$verse = reset($chapterList);
$verseId = $verse->getId();
$verseStory = $this->bibleData('Stories\Story')->findOneBy(array('startVerse' => $verseId, 'level_id' => $this->STORY_LEVEL_ID_VERSE, 'isPublic' => true));
$illustrations = array();
$explanations = array();
if($verseStory != null)
{
$illustrations = $verseStory->getIllustrations();
$explanations = $verseStory->getExplanations();
}
$templateData['verse_illustrations'] = $illustrations;
if(count($explanations) > 0 && $explanations[0]->selectTranslation() != null && $explanations[0]->findFirstPassage() != null)
{
$templateData['verse_explanations'] = $explanations;
$nTempLanguageID = $translation1['language_id'];
$verseexplanation = $this->getVerseExplanationInText($request, $explanations, $nTempLanguageID);
if(!empty($verseexplanation))
{
$templateData['verse_explanation'] = $verseexplanation;
$templateData['passage_multilink'] = $this->getWorkPassageMultiLink($verseexplanation->findFirstNonEmptyPassage()->getId(),$verseexplanation->getId(), $request);
$templateData['authors'] = $this->getAuthorInfo($request, $verseexplanation->getId());
}
}
} else {
$templateData['explained_verse'] = $this->getFirstExplainedVerse($aVerseInfo, $request);
}
$bInframe = (isset($templateData['in_frame']) && $templateData['in_frame']);
$templateData['has_slider_item'] = $this->hasSliderItem($aVerseInfo, $bInframe, $request);
$sSliderUrl = "";
// echo $verseStartIndex . ";;". $verseEndIndex;
$sTranslationUrl = $translation1['url'];
$sBookUrl = $canonicalBook->getUrl();
if(empty($verseStartIndex) && empty($verseEndIndex))
{
$sSliderUrl = $this->get('router')->generate('bible_slider_chapter', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex
));
}
elseif($bVerseLevel || empty($verseEndIndex))
{
$sSliderUrl = $this->get('router')->generate('bible_slider_verse', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex,
'verseStartIndex' => $verseStartIndex
));
}
else
{
$sSliderUrl = $this->get('router')->generate('bible_slider_verserange', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex,
'verseStartIndex' => $verseStartIndex,
'verseEndIndex' => $verseEndIndex
));
}
$templateData['slider_url'] = $sSliderUrl;
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array(), true);
// $templateData['otle_ref'] = $aOTLE['otle_nonmusic'];
$templateData['otle_ref_music'] = $aOTLE['otle_music'];
$templateData['word_explanations'] = $this->getBibleWordExplanations($aVerseInfo, $request);
$templateData['word_explanations2'] = $this->getBibleWordExplanations($aVerseInfo2, $request);
$templateData['book_display_name'] = ($translation1['book_name'] !== null) ? $translation1['book_name'] : $translation2['book_name'];
$templateData['book_url'] = $bookUrl;
$templateData['translation_url'] = $translationUrl1;
$bookList = $this->getBibleBookList($request, $translation1['id'], $translation2['id']);
// $templateData['book_list'] = $bookList;
$nNextBookID = $this->getNextBookID($translation1['book_id'], $bookList);
$nPreviousBookID = $this->getPreviousBookID($translation1['book_id'], $bookList);
$templateData['next_chapter'] = $this->getNextChapter($nChapterID, $nNextBookID);
$templateData['prev_chapter'] = $this->getPreviousChapter($nChapterID, $nPreviousBookID);
$templateData['qbible_link'] = $this->getQBibleLink2($canonicalBook, $chapterStartIndex, $verses1);
// if($chapterEndIndex == null && $verseStartIndex == null && $verseEndIndex == null)
// {
$chapter = current(current($canonicalVerseData))->getChapter();
$nCChapterID = $chapter->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl1, $request);
$templateData['chapter_explanation'] = $chapterExplanations;
$templateData['chapter_order'] = $chapter->getOrdering();
if(!empty($chapterExplanations))
{
$nTransID = current($chapterExplanations)['translation_id'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$templateData['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$templateData['explanation_translation'] = $explanation_translation;
$templateData['explanation_passage'] = $passage;
$templateData['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$templateData['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$templateData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$templateData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$templateData['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl1 . "_" . $bookUrl . "_" . $templateData['chapter_order'];
$templateData['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$templateData['explanation_cchapter_id'] = $nCChapterID;
$templateData['explanation_translation_id'] = $nTransID;
}
}
}
}
// }
$this->setCurrentUrl($request);
$templateData['linktype_id'] = $this->LINK_TYPE_ID_BIBLE;
return $this->renderView('comparison/span', $templateData, $response);
}
}
public function quickviewVerseAction($verseId, Request $request)
{
$this->onloadPage($request);
$verse = $this->bibleData('Verse')->findOneById($verseId);
return $this->chapterQuickview($verse->getChapter());
}
public function quickviewChapterAction($chapterId, Request $request)
{
$this->onloadPage($request);
return $this->chapterQuickview($this->bibleData('Chapter')->findOneById($chapterId));
}
public function quickviewTranslationChapterAction($translationId, $chapterId, Request $request)
{
$this->onloadPage($request);
$new_chapterId = $this->getChapterIDForTranslation($translationId, $chapterId);
return $this->chapterQuickview($this->bibleData('Chapter')->findOneById($new_chapterId));
}
protected function chapterQuickview($chapter)
{
$response = null;
if($chapter === null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$book = $chapter->getBook();
$verses = $chapter->getVerses();
$quickviewData = array(
'book' => ($chapter === null) ? null : $book,
'contents' => ($chapter === null) ? array() : array($chapter->getOrdering() => $verses),
'chapter_id' => ($chapter === null) ? null : $chapter->getId(),
'prev_chapter' => ($chapter === null) ? null : $this->getPreviousChapter($chapter->getId()),
'next_chapter' => ($chapter === null) ? null : $this->getNextChapter($chapter->getId())
);
$sFirstVerseIndex = "";
$sLastVerseIndex = "";
foreach($verses as $v)
{
if($sFirstVerseIndex == "")
$sFirstVerseIndex = $v->getIndexDisplay();
$sLastVerseIndex = $v->getIndexDisplay();
}
$quickviewData['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($book->getCanonicalization()->getId(), $chapter->getOrdering(), $sFirstVerseIndex, $chapter->getOrdering(), $sLastVerseIndex);
return $this->renderView('quickview/verse_range', $quickviewData, $response);
}
protected function getChapterPath($translationUrl, $bookUrl, $chapterIndex, $request, $setCurrentLanguage = false)
{
// $this->logtime(' T:getChapterPath: enter');
$rval['book'] = $this->getBookByUrl($translationUrl, $bookUrl, $request, $setCurrentLanguage);
if($rval['book'] === null) {
$rval['chapter'] = null;
$rval['translation'] = $this->bibleData('Translation')->findOneBy(array('url' => $translationUrl, 'enabled' => true));
} else {
$rval['chapter'] = $this->bibleData('Chapter')->findOneBy(array('book' => $rval['book']->getId(), 'ordering' => $chapterIndex));
}
$rval['canonical_book'] = $this->bibleData('Canonical\Book')->findOneByUrl(TextFormatter::urlify($bookUrl));
//$this->logtime(' T:getChapterPath: exit');
return $rval;
}
/**
* $userSelected is true if the user specifically wanted to view this translation, false if the translation was chosen for the user
* (which is usually the case with an excerpt, since the excerpt is from a specific translation)
*/
public function excerptAction($excerptId, Request $request, $userSelected = false)
{
$this->checkIfOnMobile($request);
$excerpt = $this->bibleData('Excerpt')->findOneById($excerptId);
if($excerpt !== null) {
$startVerse = $excerpt->getStartVerse();
$endVerse = $excerpt->getEndVerse();
$book = $startVerse->findMainVerse()->getChapter()->getBook();
$excerptContents = $book->getVerseList($startVerse, $endVerse);
if($userSelected) {
$request->getSession()->set('current_language', $book->getTranslation()->getLanguage()->getBibliographicCode());
}
$aVerse = array_reduce($excerptContents, 'array_merge', array());
$aVerseInfo = $this->getVerseInfo($aVerse);
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array(), true);
// $otle_ref = $aOTLE['otle_nonmusic'];
$otle_ref_music = $aOTLE['otle_music'];
$bHasSliderItem = $this->hasSliderItem($aVerseInfo, false, $request);
$response = null;
} else {
$startVerse = null;
$endVerse = null;
$book = null;
$excerptContents = array();
// $referringPassages = array();
// $corePassages = array();
$response = new Response();
$response->setStatusCode(404);
}
if($startVerse->getId() == $endVerse->getId()) {
return $this->renderView('excerpt_verse', array(
'verse' => $startVerse,
'excerpt_text' => substr($startVerse->getContent(), $excerpt->getStartChar(), $excerpt->getEndChar()-$excerpt->getStartChar()+1),
'has_slider_item' => $bHasSliderItem,
'otle_ref_music' => $otle_ref_music
), $response);
}
return $this->renderView('excerpt_book', array(
'book' => $book,
'excerpt_contents' => $excerptContents,
'begin_text' => substr($startVerse->getContent(), $excerpt->getStartChar()),
'end_text' => substr($endVerse->getContent(), 0, $excerpt->getEndChar()+1),
'has_slider_item' => $bHasSliderItem
), $response);
}
protected function isRightToLeft($translationUrl) {
$translation = $this->getTranslationByUrlNoOption($translationUrl);
$bRightToLeft = false;
if($translation != null)
{
$language = $translation->getLanguage();
$bRightToLeft = $language->getRightToLeft();
}
return $bRightToLeft;
}
public function compareVerses3colAction($translationUrl1, $translationUrl2, $translationUrl3, $bookUrl, $chapterStartIndex, Request $request, $chapterEndIndex = null, $verseStartIndex = null, $verseEndIndex = null)
{
$this->checkIfOnMobile($request);
$msgData = $this->checkBibleTranslationMsg($translationUrl1);
if(empty($msgData))
$msgData = $this->checkBibleTranslationMsg($translationUrl2);
if(empty($msgData))
$msgData = $this->checkBibleTranslationMsg($translationUrl3);
if(!empty($msgData))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', $msgData, $response);
}
$this->onloadPage($request);
$translation1 = $this->getBibleTranslationInfo($translationUrl1, $bookUrl);
$translation2 = $this->getBibleTranslationInfo($translationUrl2, $bookUrl);
$translation3 = $this->getBibleTranslationInfo($translationUrl3, $bookUrl);
if(empty($translation1) || empty($translation2) || empty($translation3))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
if($chapterStartIndex != null)
{
$lastChapterNumBook1 = $translation1['last_chapter_order'];
if($lastChapterNumBook1 < $chapterStartIndex)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_chapter_back', array(), $response);
}
$lastChapterNumBook2 = $translation2['last_chapter_order'];
if($lastChapterNumBook2 < $chapterStartIndex)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_chapter_back', array(), $response);
}
$lastChapterNumBook3 = $translation3['last_chapter_order'];
if($lastChapterNumBook3 < $chapterStartIndex)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_chapter_back', array(), $response);
}
}
$bVerseLevel = false;
$locale = $request->getLocale();
$nLanguageID = $this->getLanguageIDByShortCode($locale);
$bible_column_spec = $this->getMultiColumnSpecForChapterRange($translationUrl1, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$right_to_left1 = $translation1['righttoleft'];
$right_to_left2 = $translation2['righttoleft'];
$right_to_left3 = $translation3['righttoleft'];
$canonicalBook = $this->bibleData('Canonical\Book')->findOneByUrl($bookUrl);
$canonicalVerseData = DataAssembly::getVerseRangeFromBook($canonicalBook, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$verses1 = DataAssembly::decanonicalizeSpan($this->getManager(), $translation1['id'], $canonicalVerseData);
$verses2 = DataAssembly::decanonicalizeSpan($this->getManager(), $translation2['id'], $canonicalVerseData);
$verses3 = DataAssembly::decanonicalizeSpan($this->getManager(), $translation3['id'], $canonicalVerseData);
$aVerse = array_reduce($verses1, 'array_merge', array());
$aVerse2 = array_reduce($verses2, 'array_merge', array());
$aVerse3 = array_reduce($verses3, 'array_merge', array());
$templateData = array(
'translation1' => $translation1,
'contents1' => $verses1,
'translation2' => $translation2,
'contents2' => $verses2,
'translation3' => $translation3,
'contents3' => $verses3,
'translations_by_language' => $this->getBibleTranslationsByLanguage($canonicalBook->getId(), $nLanguageID),
'verses_concept1' => $this->getVerseContentWithConceptLinks($request, $aVerse, $bible_column_spec),
'verses_concept2' => $this->getVerseContentWithConceptLinks($request, $aVerse2, $bible_column_spec, 2),
'verses_concept3' => $this->getVerseContentWithConceptLinks($request, $aVerse3, $bible_column_spec, 3),
'canonical_book' => $canonicalBook,
'contents_canonical' => $canonicalVerseData,
'canonical_chapter_start' => $chapterStartIndex,
'canonical_chapter_end' => $chapterEndIndex,
'canonical_verse_start' => $verseStartIndex,
'canonical_verse_end' => $verseEndIndex,
'right_to_left1' => $right_to_left1,
'right_to_left2' => $right_to_left2,
'right_to_left3' => $right_to_left3,
'text_style_override1' => $this->getTextStyleOverrideForBible($translation1['book_id']),
'text_style_override2' => $this->getTextStyleOverrideForBible($translation2['book_id']),
'text_style_override3' => $this->getTextStyleOverrideForBible($translation3['book_id']),
'text_to_speech1' => $this->getTextToSpeech($translation1['language_id']),
'text_to_speech2' => $this->getTextToSpeech($translation2['language_id']),
'text_to_speech3' => $this->getTextToSpeech($translation3['language_id'])
);
$templateData['bible_column_spec1'] = $this->getMultiColumnSpecForChapterRange($translationUrl1, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$templateData['bible_column_spec2'] = $this->getMultiColumnSpecForChapterRange($translationUrl2, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$templateData['bible_column_spec3'] = $this->getMultiColumnSpecForChapterRange($translationUrl3, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$bEmptyContent1 = empty($templateData['contents1']);
$bEmptyContent2 = empty($templateData['contents2']);
$bEmptyContent3 = empty($templateData['contents3']);
$response = null;
if($bEmptyContent1 || $bEmptyContent2 || $bEmptyContent3)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
else
{
$aVerseInfo = $this->getVerseInfo($aVerse);
$aVerseInfo2 = $this->getVerseInfo($aVerse2);
$aVerseInfo3 = $this->getVerseInfo($aVerse3);
$nChapterID = $aVerseInfo['FirstChapterID'];
// $templateData['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
// If we have a single (canonical) verse, we'll check if it has an explanation; otherwise, we'll look for verses that have explanations
if($chapterEndIndex === null && $verseStartIndex !== null && ($verseEndIndex === null || $verseEndIndex <= $verseStartIndex)) {
$bVerseLevel = true;
$chapterList = reset($canonicalVerseData);
$verse = reset($chapterList);
$verseId = $verse->getId();
$verseStory = $this->bibleData('Stories\Story')->findOneBy(array('startVerse' => $verseId, 'level_id' => $this->STORY_LEVEL_ID_VERSE, 'isPublic' => true));
$illustrations = array();
$explanations = array();
if($verseStory != null)
{
$illustrations = $verseStory->getIllustrations();
$explanations = $verseStory->getExplanations();
}
$templateData['verse_illustrations'] = $illustrations;
if(count($explanations) > 0 && $explanations[0]->selectTranslation() != null && $explanations[0]->findFirstPassage() != null)
{
$templateData['verse_explanations'] = $explanations;
$nTempLanguageID = $translation1['language_id'];
$verseexplanation = $this->getVerseExplanationInText($request, $explanations, $nTempLanguageID);
if(!empty($verseexplanation))
{
$templateData['verse_explanation'] = $verseexplanation;
$templateData['passage_multilink'] = $this->getWorkPassageMultiLink($verseexplanation->findFirstNonEmptyPassage()->getId(),$verseexplanation->getId(), $request);
$templateData['authors'] = $this->getAuthorInfo($request, $verseexplanation->getId());
}
}
} else {
$templateData['explained_verse'] = $this->getFirstExplainedVerse($aVerseInfo, $request);
}
$bInframe = (isset($templateData['in_frame']) && $templateData['in_frame']);
$templateData['has_slider_item'] = $this->hasSliderItem($aVerseInfo, $bInframe, $request);
$sSliderUrl = "";
// echo $verseStartIndex . ";;". $verseEndIndex;
$sTranslationUrl = $translation1['url'];
$sBookUrl = $canonicalBook->getUrl();
if(empty($verseStartIndex) && empty($verseEndIndex))
{
$sSliderUrl = $this->get('router')->generate('bible_slider_chapter', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex
));
}
elseif($bVerseLevel || empty($verseEndIndex))
{
$sSliderUrl = $this->get('router')->generate('bible_slider_verse', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex,
'verseStartIndex' => $verseStartIndex
));
}
else
{
$sSliderUrl = $this->get('router')->generate('bible_slider_verserange', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex,
'verseStartIndex' => $verseStartIndex,
'verseEndIndex' => $verseEndIndex
));
}
$templateData['slider_url'] = $sSliderUrl;
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array(), true);
// $templateData['otle_ref'] = $aOTLE['otle_nonmusic'];
$templateData['otle_ref_music'] = $aOTLE['otle_music'];
$templateData['word_explanations'] = $this->getBibleWordExplanations($aVerseInfo, $request);
$templateData['word_explanations2'] = $this->getBibleWordExplanations($aVerseInfo2, $request);
$templateData['word_explanations3'] = $this->getBibleWordExplanations($aVerseInfo3, $request);
$templateData['book_display_name'] = ($translation1['book_name'] !== null) ? $translation1['book_name'] : $translation2['book_name'];
$templateData['book_url'] = $bookUrl;
$templateData['translation_url'] = $translationUrl1;
$bookList = $this->getBibleBookList($request, $translation1['id'], $translation2['id'], $translation3['id']);
// $templateData['book_list'] = $bookList;
$nNextBookID = $this->getNextBookID($translation1['book_id'], $bookList);
$nPreviousBookID = $this->getPreviousBookID($translation1['book_id'], $bookList);
$templateData['next_chapter'] = $this->getNextChapter($nChapterID, $nNextBookID);
$templateData['prev_chapter'] = $this->getPreviousChapter($nChapterID, $nPreviousBookID);
$templateData['qbible_link'] = $this->getQBibleLink2($canonicalBook, $chapterStartIndex, $verses1);
// if($chapterEndIndex == null && $verseStartIndex == null && $verseEndIndex == null)
// {
$chapter = current(current($canonicalVerseData))->getChapter();
$nCChapterID = $chapter->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl1, $request);
$templateData['chapter_explanation'] = $chapterExplanations;
$templateData['chapter_order'] = $chapter->getOrdering();
if(!empty($chapterExplanations))
{
$nTransID = current($chapterExplanations)['translation_id'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$templateData['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$templateData['explanation_translation'] = $explanation_translation;
$templateData['explanation_passage'] = $passage;
$templateData['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$templateData['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$templateData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$templateData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$templateData['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl1 . "_" . $bookUrl . "_" . $templateData['chapter_order'];
$templateData['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$templateData['explanation_cchapter_id'] = $nCChapterID;
$templateData['explanation_translation_id'] = $nTransID;
}
}
}
}
// }
$this->setCurrentUrl($request);
return $this->renderView('comparison/span3col', $templateData, $response);
}
}
private function logtime($msg)
{
$tparts = explode(' ',microtime());
$s = ($tparts[1] % 10) + $tparts[0];
$logger = $this->get('logger');
// TODO: test if env is prod..
// don't run in prod
if ( $this->get('kernel')->getEnvironment() == 'dev' ) {
$logger->info( sprintf( '%2.5f %s', $s, $msg) );
}
//error_log( sprintf( '%2.5f %s', $s, $msg) );
// or only log for time > threshold
}
function getQBibleLink($book, $chapter, $verses)
{
$cbook = $book->getCanonicalization();
$nCBookId = $cbook->getId();
$nChapterOrder = $chapter->getOrdering();
$nVerseOrder = 1;
foreach($verses as $key => $val) {
if(!is_array($val)) {
$nVerseOrder = $val->getIndexDisplay();
break;
}
}
$nTestmentId = $cbook->getTestament()->getId();
$sLinkStart = '';
if($nTestmentId == 1) // old testament
$sLinkStart = 'http://qbible.com/hebrew-old-testament/';
else
$sLinkStart = 'http://qbible.com/greek-new-testament/';
return $this->getNativeQueryResults("SELECT '" . $sLinkStart . "' || qbible_url || '/' || '" . $nChapterOrder . "' || '.html#' || '" . $nVerseOrder . "' as url from canonicalbiblebook"
." WHERE id = " . $nCBookId . " and qbible_url is not null and qbible_url <> ''");
}
function getQBibleLink2($cbook, $nChapterOrder, $verses)
{
$nCBookId = $cbook->getId();
$nVerseOrder = 1;
foreach($verses as $key => $val) {
if(!is_array($val)) {
$nVerseOrder = $val->getIndexDisplay();
break;
}
}
$nTestmentId = $cbook->getTestament()->getId();
$sLinkStart = '';
if($nTestmentId == 1) // old testament
$sLinkStart = 'http://qbible.com/hebrew-old-testament/';
else
$sLinkStart = 'http://qbible.com/greek-new-testament/';
return $this->getNativeQueryResults("SELECT '" . $sLinkStart . "' || qbible_url || '/' || '" . $nChapterOrder . "' || '.html#' || '" . $nVerseOrder . "' as url from canonicalbiblebook"
." WHERE id = " . $nCBookId . " and qbible_url is not null and qbible_url <> ''");
}
function getMultiColumnSpecForChapterRange($translationUrl, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex=null, $verseEndIndex = null)
{
$bible_multi_spec = $this->MULTI_URL_INDICATOR_BIBLE . '_' . $translationUrl . '_' . $bookUrl;
if($chapterStartIndex != null)
{
$bible_multi_spec .= '_' . $chapterStartIndex;
if($chapterEndIndex != null)
$bible_multi_spec .= '-' . $chapterEndIndex;
if($verseStartIndex != null)
{
$bible_multi_spec .= '_' . $verseStartIndex;
if($verseEndIndex != null)
$bible_multi_spec .= '-' . $verseEndIndex;
}
}
return $bible_multi_spec;
}
public function readingPlanIndexAction(Request $request)
{
$this->setCurrentUrl($request);
$this->onloadPage($request);
$locale = $request->getLocale();
$nUserID = $request->getSession()->get("user_id");
$list = $this->getReadingPlanList($nUserID, $locale);
$data = array(
'plan_data' => $list
);
return $this->renderView('reading_plan_index', $data);
}
public function readingPlanAction($readingPlanUrl, Request $request)
{
$this->onloadPage($request);
$this->setCurrentUrl($request);
$locale = $request->getLocale();
$info = $this->getReadingPlanInfo($readingPlanUrl,$locale);
$nUserID = $request->getSession()->get("user_id");
$user_plan = null;
$nTextLength = 150;
$sMetaDesc = $this->getTextWithinLength($info['description'], $nTextLength, "...");
$aReminderOption = array();
if(!empty($nUserID))
{
$aReminderOption = $this->getReminderOptionList($request);
}
$data = array(
'reading_plan' => $info,
'meta_desc' => $sMetaDesc,
'reminder_options' => $aReminderOption
);
$data['user_plan'] = $this->getUserReadingPlanInfo($readingPlanUrl,$nUserID, $request);
return $this->renderView('reading_plan', $data);
}
public function readingPlanStepsAction($readingPlanUrl, Request $request)
{
$this->onloadPage($request);
$nUserID = $request->getSession()->get("user_id");
if($nUserID == '')
{
}
else
{
$user_plan = $this->getUserReadingPlanInfo($readingPlanUrl,$nUserID, $request);
$step_order = $user_plan['step_order'];
}
return $this->redirect($this->get('router')->generate('reading_plan_step', array(
'readingPlanUrl' => $readingPlanUrl,
'stepOrder' => $step_order
)), 301);
}
public function readingPlanStepAction($readingPlanUrl, $stepOrder, Request $request, $translationUrl = null)
{
$rps = $this->getReadingPlanStepBasicInfo($readingPlanUrl, $stepOrder, $request);
if(empty($rps)) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$this->onloadPage($request);
$this->setCurrentUrl($request);
$nUserID = $request->getSession()->get("user_id");
$nStart = null;
if($nUserID == '')
{
}
else
{
$nStart = $request->query->get('s');
if(!empty($nStart))
$request->getSession()->set("reading_plan_started", $nStart);
}
$nTypeID = $rps['type_id'];
if($nTypeID == $this->READINGPLAN_STEP_TYPE_ID_ADHOC)
{
$plan_step = $rps;
return $this->readingplanStepForAdhoc($readingPlanUrl, $plan_step, $request);
}
else if($nTypeID != $this->READINGPLAN_STEP_TYPE_ID_BIBLE)
{
$work_id = "";
if($nTypeID == $this->READINGPLAN_STEP_TYPE_ID_SWEDENBORG_WORK)
$work_id = $rps['work_id'];
else
$work_id = $rps['explanation_id'];
if($translationUrl === null) {
$sTranslationUrl = "";
if($work_id == $request->getSession()->get("current_reading_plan_work_id"))
{
$sTranslationUrl = $request->getSession()->get("current_reading_plan_work_translation_url");
}
if($sTranslationUrl == '')
{
$trans = $this->getDefaultWorkTranslation($work_id, $request);
$sTranslationUrl = $trans['url'];
}
return $this->redirect($this->get('router')->generate('reading_plan_step_translated', array(
'readingPlanUrl' => $readingPlanUrl,
'stepOrder' => $stepOrder,
'translationUrl' => $sTranslationUrl
)), 301);
}
$passage_id = $rps['passage_id'];
$plan_step = $rps;
return $this->readingplanStepForWork($translationUrl, $work_id, $passage_id, $readingPlanUrl, $plan_step, $request);
}
else
{
$readingPlanStep = $this->getReadingPlanStepInfoForBible($readingPlanUrl, $stepOrder, $request);
if($translationUrl === null) {
// For SEO purposes, we'll send the visitor to the route for the Plan step with the default translation
$sTranslationUrl = "";
if($request->getSession()->get("current_reading_plan_bible_translation_url") != '')
{
$sTranslationUrl = $request->getSession()->get("current_reading_plan_bible_translation_url");
}
if($sTranslationUrl == '')
{
$bibletrans = $this->getDefaultBibleTranslation($readingPlanStep['book_id'], $request);
$sTranslationUrl = $bibletrans['url'];
}
return $this->redirect($this->get('router')->generate('reading_plan_step_translated', array(
'readingPlanUrl' => $readingPlanUrl,
'stepOrder' => $stepOrder,
'translationUrl' => $sTranslationUrl
)), 301);
}
$translation = $this->bibleData('Translation')->findOneBy(array('url' => $translationUrl, 'enabled' => true));
if($translation === null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
if($translationUrl != null)
{
$request->getSession()->set("current_reading_plan_bible_translation_url", $translationUrl);
}
$right_to_left = $translation->getLanguage()->getRightToLeft();
$canonicalStartVerseOrder = $readingPlanStep['start_verse_order'];
$canonicalEndVerseOrder = $readingPlanStep['end_verse_order'];
$canonicalStartChapterOrder = $readingPlanStep['start_chapter_order'];
$canonicalEndChapterOrder = $readingPlanStep['end_chapter_order'];
$canonicalBook = $this->bibleData('Canonical\Book')->findOneBy(array('id' => $readingPlanStep['book_id']));
$contentsCanonical = DataAssembly::getVerseRangeFromBook($canonicalBook, $canonicalStartChapterOrder, $canonicalEndChapterOrder, $canonicalStartVerseOrder, $canonicalEndVerseOrder);
$contents = DataAssembly::decanonicalizeSpan($this->getManager(), $translation->getId(), $contentsCanonical);
if(count($contents) === 0) {
// Content does not exist in this translation
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
} else {
$firstChapterContents = reset($contents);
$firstVerse = reset($firstChapterContents);
$firstChapter = $firstVerse->findMainVerse()->getChapter();
$lastChapterContents = end($contents);
$lastVerse = end($lastChapterContents);
$lastChapter = $lastVerse->findMainVerse()->getChapter();
$completeChapters = $firstVerse === $firstChapter->getVerses()->first() && $lastVerse === $lastChapter->getVerses()->last();
$planStepData = array(
'plan_step' => $readingPlanStep,
'translation' => $translation,
'book' => $firstVerse->findMainVerse()->getChapter()->getBook(),
'content_class' => 'planstep',
'right_to_left' => $right_to_left
);
// $planStepData['next_chapter'] = $this->getNextChapter($firstChapter->getId());
// $planStepData['prev_chapter'] = $this->getPreviousChapter($firstChapter->getId());
$bSingleVerse = ($firstVerse == $lastVerse);
if($bSingleVerse)
$planStepData['content_type'] = 'single_verse';
else
$planStepData['content_type'] = 'verseRange';
$nContentNum = 0;
foreach($contents as $c)
{
$nContentNum += count($c);
}
$bShowBottomNav = ($nContentNum >= 6);
$bSingleChapter = false;
if(count($contents) === 1) {
// Plan step is entirely within a single chapter
$bSingleChapter = true;
$planStepData['chapter'] = $firstChapter;
if($bSingleVerse)
{
$planStepData['verse'] = $firstVerse;
$planStepData['verse_index'] = $canonicalStartVerseOrder;
}
$planStepData['verses'] = $firstChapterContents;
if(!$completeChapters) {
$planStepData['verses_last_index'] = $lastVerse->getFullIndexDisplay();
}
// $planStepData['content_type'] = 'verseRange';
$planStepData['slider_url'] = $this->get('router')->generate('bible_slider_verserange', array(
'translationUrl' => $translationUrl,
'bookUrl' => $planStepData['book']->getUrl(),
'chapterIndex' => $firstChapter->getOrdering(),
'verseStartIndex' => $firstVerse->getFullIndexDisplay(),
'verseEndIndex' => $lastVerse->getFullIndexDisplay()
));
} else {
// Plan step contains text from more than one chapter
$planStepData['contents'] = $contents;
if($completeChapters) {
/* $planStepData['range_name'] = $this->get('translator')->trans("bible.chapternav.bookchapterrange", array(
'%bookname%' => $planStepData['book']->getName(),
'%chapterstart%' => $firstChapter->getOrdering(),
'%chapterend%' => $lastChapter->getOrdering()
)); */
$planStepData['slider_url'] = $this->get('router')->generate('bible_slider_chapter_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $planStepData['book']->getUrl(),
'chapterStartIndex' => $firstChapter->getOrdering(),
'chapterEndIndex' => $lastChapter->getOrdering()
));
} else {
/* $planStepData['range_name'] = $this->get('translator')->trans("bible.chapternav.bookchapterrangeverserange", array(
'%bookname%' => $planStepData['book']->getName(),
'%chapterstart%' => $firstChapter->getOrdering(),
'%chapterend%' => $lastChapter->getOrdering(),
'%versestart%' => $firstVerse->getFullIndexDisplay(),
'%verseend%' => $lastVerse->getFullIndexDisplay()
));*/
$planStepData['slider_url'] = $this->get('router')->generate('bible_slider_chapter_verse_range', array(
'translationUrl' => $translationUrl,
'bookUrl' => $planStepData['book']->getUrl(),
'chapterStartIndex' => $firstChapter->getOrdering(),
'chapterEndIndex' => $lastChapter->getOrdering(),
'verseStartIndex' => $firstVerse->getFullIndexDisplay(),
'verseEndIndex' => $lastVerse->getFullIndexDisplay()
));
}
}
$planStepData['linktype_id'] = $this->LINK_TYPE_ID_BIBLE;
$planStepData['text_style_override'] = $this->getTextStyleOverrideForBible($planStepData['book']->getId());
$planStepData['translation_url'] = $translationUrl;
$planStepData['show_bottom_nav'] = $bShowBottomNav;
$planStepData['next_reading_plan_step'] = $this->getNextReadingPlanStep($readingPlanUrl, $stepOrder, $request);
$planStepData['prev_reading_plan_step'] = $this->getPreviousReadingPlanStep($readingPlanUrl, $stepOrder);
if($nUserID != '')
$planStepData['reading_plan_completed_info'] = $this->getUserStepInfo($readingPlanUrl, $nUserID);
$nCompletedStepOrder = null;
if(isset($planStepData['reading_plan_completed_info']['completed_step_order']))
$nCompletedStepOrder = $planStepData['reading_plan_completed_info']['completed_step_order'];
$planStepData['completed_percentage'] = $this->getStepCompletedPercentage($readingPlanUrl, $request);
// $planStepData['reading_plan_step_list'] = $this->getReadingPlanStepList($readingPlanUrl, $translationUrl);
$planStepData['reading_plan_order_info'] = $this->getReadingPlanOrderInfo($readingPlanUrl);
$planStepData['reading_plan_url'] = $readingPlanUrl;
$planStepData['step_order'] = $stepOrder;
$planStepData['current_step_id'] = $readingPlanStep['id'];
$bPlanStarted = ($request->getSession()->get("reading_plan_started") == 1 || $this->hasReadingPlanStarted($readingPlanUrl,$nUserID));
$planStepData['plan_started'] = $bPlanStarted;
/* $bCompleted = false;
if($stepOrder <= $nCompletedStepOrder)
$bCompleted = true; */
$nStepID = $readingPlanStep['id'];
$bCompleted = $this->IsReadingPlanStepCompleted($nStepID, $request);
$planStepData['step_completed'] = $bCompleted;
$bLastUncompleted = false;
if(!$bCompleted)
$bLastUncompleted = $this->IsLastReadingPlanStepUncompleted($nStepID, $request);
$planStepData['last_step_uncompleted'] = $bLastUncompleted;
$bLastStep = $this->IsLastReadingPlanStep($nStepID, $request);
$planStepData['is_last_step'] = $bLastStep;
$planStepData['chapter_order'] = $firstChapter->getOrdering();
$chapterExplanations = null;
$nCChapterID = null;
$request->getSession()->set('current_explanation_cchapter_id', '');
$CChapter = $firstChapter->getCanonicalization();
if($CChapter != null)
{
$nCChapterID = $CChapter->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl, $request);
$nExplainChapterTranslationID = $this->getExplainChapterTranslation($nCChapterID, $this->getCurrUserID($request), $translationUrl);
if($nExplainChapterTranslationID > -1)
{
$planStepData['cchapter_id'] = $nCChapterID;
$request->getSession()->set('current_explanation_cchapter_id', $nCChapterID);
$request->getSession()->set('current_explanation_translation_id', $nExplainChapterTranslationID);
}
}
$planStepData['chapter_explanation'] = $chapterExplanations;
if(!empty($chapterExplanations))
{
$nTransID = current($chapterExplanations)['translation_id'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$planStepData['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$planStepData['explanation_translation'] = $explanation_translation;
$planStepData['explanation_passage'] = $passage;
$planStepData['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$planStepData['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$planStepData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$planStepData['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$planStepData['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl . "_" . $canonicalBook->getUrl() . "_" . $firstChapter->getOrdering();
$planStepData['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$planStepData['explanation_cchapter_id'] = $nCChapterID;
$planStepData['explanation_translation_id'] = $nTransID;
}
}
}
}
if($bSingleChapter)
{
$planStepData['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $planStepData['book']->getUrl(), $canonicalStartChapterOrder, $canonicalStartVerseOrder, $canonicalEndVerseOrder);
return $this->createVersesView($planStepData, $request);
}
else
{
$planStepData['bible_column_spec'] = $this->getMultiColumnSpecForChapterRange($translationUrl, $planStepData['book']->getUrl(), $canonicalStartChapterOrder, $canonicalEndChapterOrder, $canonicalStartVerseOrder, $canonicalEndVerseOrder);
return $this->createChaptersView($planStepData, $request);
}
}
}
}
public function versealltranslationsAction($bookUrl, $chapterIndex, $verseIndex, Request $request, $userSelected = true)
{
$this->onloadPage($request);
$nTranslationID = $this->DEFAULT_BIBLE_TRANSLATION_ID;
$nUserTranslationID = $request->getSession()->get('current_bible_translation_id');
if(!empty($nUserTranslationID))
{
$nTranslationID = $nUserTranslationID;
}
$aTransInfo = $this->getAvailableTranslantion($bookUrl, $nTranslationID);
if(!empty($aTransInfo))
{
$nTranslationID = $aTransInfo['id'];
$translationUrl = $aTransInfo['url'];
}
$verseData = $this->getChapterPath($translationUrl, $bookUrl, $chapterIndex, $request, $userSelected);
$verseData['verses'] = ($verseData['chapter'] === null) ? array() : $this->bibleData('Verse')->getByIndexRangeFromChapter(
$verseIndex,
$verseIndex,
$verseData['chapter']
);
if(empty($verseData['verses']))
{
return $this->redirect($this->get('router')->generate('bible_chapter', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex
)), 301);
}
if($verseIndex !== null) {
$verseData['verses_last_index'] = $verseIndex;
}
$verseData['verse'] = current($verseData['verses']);
$verseData['all_translations'] = true;
$verseData['content_class'] = 'verse_all_translations';
$verseData['content_type'] = 'single_verse';
$verseData['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $bookUrl, $chapterIndex, $verseIndex);
$nCurrVerseID = current($verseData['verses'])->getId();
$verseData['next_verse'] = $this->getNextVerse($nCurrVerseID);
$verseData['prev_verse'] = $this->getPreviousVerse($nCurrVerseID);
$verseData['book_url'] = $bookUrl;
$verseData['chapter_index'] = $chapterIndex;
$verseData['verse_index'] = $verseIndex;
$verseData['translation_url'] = $translationUrl;
$verseData['slider_url'] = $this->get('router')->generate('bible_slider_verse', array(
'translationUrl' => $translationUrl,
'bookUrl' => $bookUrl,
'chapterIndex' => $chapterIndex,
'verseStartIndex' => $verseIndex
));
$versesView = $this->createVersesAllTransView($verseData, $nTranslationID, $request);
$this->setCurrentUrl($request);
return $versesView;
}
/**
* Handles much of the code that is a verse with all translations views
*/
protected function createVersesAllTransView($verseData, $nTranslationID, $request)
{
$this->checkIfOnMobile($request);
$aVerseInfo = $this->getVerseInfo($verseData['verses']);
$bInframe = (isset($verseData['in_frame']) && $verseData['in_frame']);
$verseData['has_slider_item'] = $this->hasSliderItem($aVerseInfo, $bInframe, $request);
$aOTLE = $this->getOTLERefForBible($aVerseInfo, ($verseData['content_class'] == 'chapter') ? array($verseData['chapter']) : array(), true);
// $verseData['otle_ref'] = $aOTLE['otle_nonmusic'];
$verseData['otle_ref_music'] = $aOTLE['otle_music'];
$currVerse = current($verseData['verses']);
$nBookId = $verseData['book']->getCanonicalization()->getId();
$verseData['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($nBookId, $verseData['chapter_index'], $verseData['verse_index'], $verseData['chapter_index'], $verseData['verse_index']);
$verseData['verse_content'] = $this->getAllBibleTranslationsForVerse($nBookId, $verseData['chapter_index'], $verseData['verse_index']);
// $verseData['verses_concept_all_trans'] = $this->getVerseContentWithConceptLinksForAllTrans($aVerseInfo['CVerseIDs']);
if(!array_key_exists('canonical_chapter_start', $verseData)) {
// Need to pass array($verseData['verses']) rather than just $verseData['verses'] so it will sort by ordering rather than by database ID
$canonicalRangeData = DataAssembly::getVerseNumberRange(DataAssembly::canonicalize(array($verseData['verses'])));
if($canonicalRangeData !== null) {
if(array_key_exists('chapter_index', $verseData) && $verseData['chapter_index'] != null)
{
$verseData['canonical_chapter_start'] = $verseData['chapter_index'];
$verseData['canonical_chapter_end'] = null;
$verseData['canonical_verse_start'] = null;
$verseData['canonical_verse_end'] = null;
}
else
{
$verseData['canonical_chapter_start'] = $canonicalRangeData['chapter_start'];
$verseData['canonical_chapter_end'] = $canonicalRangeData['chapter_end'];
$verseData['canonical_verse_start'] = $canonicalRangeData['verse_start'];
$verseData['canonical_verse_end'] = $canonicalRangeData['verse_end'];
}
}
}
// $verseData['book_list'] = $this->getBibleBookList($nTranslationID);
// get qBible data
$verseData['qbible_link'] = $this->getQBibleLink($verseData['book'], $verseData['chapter'], $verseData['verses']);
// get commentary with file (pdf)
$verseData['commentary_with_doc'] = $this->getCommentaryWithDocForBible($verseData['book'], current($verseData['verses'])->getChapter()->getOrdering());
$verseData['text_style_override'] = $this->getTextStyleOverrideForBible($verseData['book']->getId());
// $verseData['text_to_speech'] = $this->getTextToSpeech($nLanguageID);
/* if($verseData['content_type'] == 'single_verse')
{
$stories = DataAssembly::findVerseStories($verseData['verses'], $this->getManager(), true);
if(!empty($stories)) {
$illustrations = array();
$explanations = array();
foreach($stories as $story) {
$illustrations = array_merge($illustrations, $story->getIllustrations()->toArray());
$explanations = array_merge($explanations, $story->getExplanations()->toArray());
}
$verseData['verse_illustrations'] = $illustrations;
if(count($explanations) > 0 && $explanations[0]->selectTranslation() != null && $explanations[0]->findFirstPassage() != null)
{
$verseData['verse_explanations'] = $explanations;
$trans = $explanations[0]->selectTranslation();
$verseData['passage_multilink'] = $this->getWorkPassageMultiLink($explanations[0]->findFirstPassage()->getId(),$trans->getId(), $request);
$verseData['authors'] = $this->getAuthorInfo($request, $trans->getId());
}
}
} */
return $this->renderView('versealltrans', $verseData);
}
/**
* Show book list on a popup
*/
public function selectbookAction($translationUrl, $translationUrl2, $translationUrl3, Request $request)
{
$nTranslationID = $this->getBibleTranslationID($translationUrl);
if($translationUrl == '-none-' || empty($nTranslationID))
{
$translation = $this->getFirstBibleTranslation($request);
$translationUrl = $translation['url'];
$nTranslationID = $translation['id'];
$data['translation_name'] = $translation['name'];
}
$data['translation_url'] = $translationUrl;
/* if($bookUrl == '-none-')
$bookUrl = $this->DEFAULT_BIBLE_VERSION;
$data['book_url'] = $bookUrl; */
// echo 'tid:'.$nTranslationID;
if(empty($nTranslationID))
$nTranslationID = $this->DEFAULT_BIBLE_TRANSLATION_ID;
$nTranslationID2 = null;
$nTranslationID3 = null;
if(!empty($translationUrl2) && $translationUrl2 != "-none-")
{
$nTranslationID2 = $this->getBibleTranslationID($translationUrl2);
}
if(!empty($translationUrl3) && $translationUrl3 != "-none-")
{
$nTranslationID3 = $this->getBibleTranslationID($translationUrl3);
}
$data['book_list'] = $this->getBibleBookList($request, $nTranslationID, $nTranslationID2, $nTranslationID3);
return $this->renderView('selectbook', $data);
}
/**
* Show chapter list on a popup
*/
public function selectchapterAction($translationUrl, $translationUrl2, $translationUrl3, $bookUrl, Request $request, $inFrame = false )
{
$data['translation_url'] = $translationUrl;
$data['book_url'] = $bookUrl;
$data['in_frame'] = $inFrame;
if(empty($translationUrl))
$translationUrl = $this->DEFAULT_BIBLE_VERSION;
$aTrans = $this->getBibleTransInfo($translationUrl);
$data['translation_name'] = $aTrans['name'];
$data['chapter_list'] = $this->getBibleChapterList($translationUrl, $translationUrl2, $translationUrl3, $bookUrl);
$data['book_summary_url'] = $this->getBibleBookSummary($translationUrl, $bookUrl);
return $this->renderView('selectchapter', $data);
}
/**
* Show translation list on a popup
*/
public function selecttranslationAction(Request $request)
{
$data = array();
return $this->renderView('selecttranslation', $data);
}
/**
* Show translation list on a popup with translation data
*/
public function selecttranslationfrombookAction(Request $request)
{
$data['translation_list'] = $this->getBibleTranslationsByLanguage();
return $this->renderView('selecttranslationfrombook', $data);
}
public function biblenewAction($translationUrl, $bookUrl, Request $request, $chapterIndex = 1)
{
if($this->getCurrUserID($request) == '')
{
return $this->redirect($this->get('router')->generate('login', array()), 301);
}
else
{
$this->onloadPage($request);
$aBookInfo = $this->getBibleTranslationInfo($translationUrl, $bookUrl);
if(empty($aBookInfo))
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
else
{
$data['translation_url'] = $translationUrl;
$data['book_url'] = $bookUrl;
$data['chapter_index'] = $chapterIndex;
$data['book_name'] = $aBookInfo['book_name'];
$data['translation_name'] = $aBookInfo['name'];
$data['bible_new'] = true;
}
$this->setCurrentUrl($request);
return $this->renderView('biblenew', $data);
}
}
// The middle frame for chapters
public function bibleframeexplanationchapterAction($translationUrl, $bookUrl, $chapterIndex, Request $request)
{
$this->onloadPage($request);
$bInframe = true;
$aVerseInfo = $this->getVerseInfoForFrame($translationUrl, $bookUrl, $chapterIndex);
$data['referring_passages'] = $this->getBibleCrossRef($aVerseInfo, true, false);
// $data['core_passages'] = $this->getBibleRefPassage($aVerseInfo, false, true);
$bookInfo = $this->getBibleBookInfo($translationUrl, $bookUrl);
$data['book_name'] = $bookInfo['name'];
$data['chapter_index'] = $chapterIndex;
$data['bFullChapter'] = true;
$data['in_frame'] = $bInframe;
return $this->renderView('biblerefinframe', $data);
}
// The middle frame for verses
public function bibleframeexplanationverseAction($translationUrl, $bookUrl, $chapterIndex, $verseIndex, Request $request)
{
$this->onloadPage($request);
$bInframe = true;
$aVerseInfo = $this->getVerseInfoForFrame($translationUrl, $bookUrl, $chapterIndex, $verseIndex);
$data['referring_passages'] = $this->getBibleCrossRef($aVerseInfo, false, false);
// $data['core_passages'] = $this->getBibleRefPassage($aVerseInfo, false, true);
$bookInfo = $this->getBibleBookInfo($translationUrl, $bookUrl);
$data['book_name'] = $bookInfo['name'];
$data['chapter_index'] = $chapterIndex;
$data['verse_index'] = $verseIndex;
$data['in_frame'] = true;
$data['translation_url'] = $translationUrl;
$data['book_url'] = $bookUrl;
return $this->renderView('biblerefinframe', $data);
}
/**
* Show slider contents
*/
public function bibleSliderAction($translationUrl, $bookUrl, $chapterIndex, Request $request, $verseStartIndex = null, $verseEndIndex = null, $userSelected = true)
{
$data = $this->getChapterPath($translationUrl, $bookUrl, $chapterIndex, $request, $userSelected);
// print_r($data);
if($verseStartIndex == null)
{
$data['verses'] = $this->bibleData('Verse')->getByChapter($data['chapter']);
$data['content_type'] = 'verseRange';
}
else
{
$data['verses'] = ($data['chapter'] === null) ? array() : $this->bibleData('Verse')->getByIndexRangeFromChapter(
$verseStartIndex,
$verseEndIndex,
$data['chapter']
);
if($verseEndIndex == null)
$data['content_type'] = 'single_verse';
else
$data['content_type'] = 'verseRange';
}
if($verseEndIndex !== null) {
$data['verses_last_index'] = $verseEndIndex;
}
$nInFrame = $request->query->get('if');
$data['in_frame'] = ($nInFrame == 1);
$chapter = $data['chapter'];
if($chapter == null)
{
$data['content_class'] = 'verse';
}
else
{
$chapterVerses = $data['chapter']->getVerses();
if($verseStartIndex == null || ($verseStartIndex != null && $verseStartIndex == $chapterVerses->first()->getOrdering() && $verseEndIndex == $chapterVerses->last()->getOrdering()) )
{
$data['content_class'] = 'chapter';
}
else
{
$data['content_class'] = 'verse';
}
}
$data['translation_url'] = $translationUrl;
$data['bible_column_spec'] = $this->getBibleMultiColumnSpec($translationUrl, $bookUrl, $chapterIndex, $verseStartIndex, $verseEndIndex);
$chapterExplanations = null;
$nCChapterID = null;
$request->getSession()->set('current_explanation_cchapter_id', '');
$CChapter = $data['chapter']->getCanonicalization();
if($CChapter != null)
{
$nCChapterID = $CChapter->getId();
$chapterExplanations = $this->getChapterExplanation($nCChapterID, $translationUrl, $request, true);
$nExplainChapterTranslationID = $this->getExplainChapterTranslation($nCChapterID, $this->getCurrUserID($request), $translationUrl);
if($nExplainChapterTranslationID > -1)
{
$data['cchapter_id'] = $nCChapterID;
$request->getSession()->set('current_explanation_cchapter_id', $nCChapterID);
$request->getSession()->set('current_explanation_translation_id', $nExplainChapterTranslationID);
}
}
$data['chapter_explanation'] = $chapterExplanations;
$data['chapter_order'] = $chapterIndex;
$data['book_url'] = $bookUrl;
if(!empty($chapterExplanations))
{
$nTransID = current($chapterExplanations)['translation_id'];
$bIsModern = current($chapterExplanations)['is_modern'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$data['is_modern_chapter_summary'] = $bIsModern;
$data['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$data['explanation_translation'] = $explanation_translation;
$data['explanation_passage'] = $passage;
$data['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$data['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$data['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$data['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$data['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl . "_" . $bookUrl . "_" . $chapterIndex;
$data['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$data['explanation_cchapter_id'] = $nCChapterID;
$data['explanation_translation_id'] = $nTransID;
}
}
}
}
return $this->createSliderView($data, $request);
}
/**
* Create slider view
*/
protected function createSliderView($data, $request)
{
$this->checkIfOnMobile($request);
$aVerseInfo = $this->getVerseInfo($data['verses']);
if(!isset($data['in_frame']) || !$data['in_frame'])
{
// Show chapter level refs for verse pages too.
// $bChapter = ($data['content_class'] == 'chapter');
$bChapter = true;
$data['referring_passages'] = $this->getBibleRefPassageNew($aVerseInfo, $bChapter, false);
$data['core_passages'] = $this->getBibleRefPassageNew($aVerseInfo, $bChapter, true);
}
$data['explanation_ref'] = $this->getExplanationRefForBible($aVerseInfo, $request);
$data['gced_ref'] = $this->getGCEDRefForBible($aVerseInfo, ($data['content_class'] == 'chapter') ? array($data['chapter']) : array());
$aOTLE = $this->getOTLERefForBible($aVerseInfo, ($data['content_class'] == 'chapter') ? array($data['chapter']) : array());
$data['otle_ref'] = $aOTLE['otle_nonmusic'];
$data['otle_ref_music'] = $aOTLE['otle_music'];
$data['verse_cross'] = $this->getVerseCrossRefs($aVerseInfo, $request);
$data['word_explanations'] = $this->getBibleWordExplanations($aVerseInfo, $request);
$data['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
$data['explained_verse'] = $this->getFirstExplainedVerse($aVerseInfo, $request);
$bible_column_spec = '';
if(array_key_exists('bible_column_spec', $data))
$bible_column_spec = $data['bible_column_spec'];
$translation = $data['book']->getTranslation();
$nTranslationID = $translation->getId();
$nLanguageID = $translation->getLanguage()->getId();
$data['book_url'] = $data['book']->getUrl();
$data['chapter_index'] = $aVerseInfo['FirstChapterIndex'];
// get qBible data
$data['qbible_link'] = $this->getQBibleLink($data['book'], $data['chapter'], $data['verses']);
// get commentary with file (pdf)
$data['commentary_with_doc'] = $this->getCommentaryWithDocForBible($data['book'], current($data['verses'])->getChapter()->getOrdering());
/* if($data['content_type'] == 'single_verse')
{
$nSelectedExplTransID = $request->query->get('et');
$stories = DataAssembly::findVerseStories($data['verse'], $this->getManager(), true);
if(!empty($stories)) {
$illustrations = array();
$explanations = array();
foreach($stories as $story) {
$illustrations = array_merge($illustrations, $story->getIllustrations()->toArray());
$explanations = array_merge($explanations, $story->getExplanations()->toArray());
}
$data['verse_illustrations'] = $illustrations;
if(count($explanations) > 0 && $explanations[0]->selectTranslation() != null && $explanations[0]->findFirstPassage() != null)
{
// get the explanation with the same language of the verse if there is
$data['verse_explanations'] = $explanations;
$verseexplanation = $this->getVerseExplanationInText($request, $explanations, $nLanguageID);
if(!empty($verseexplanation))
{
$data['verse_explanations_for_combo'] = $this->getVerseExplanationsForVerse($data['verse']->getId());
$data['verse_explanation'] = $verseexplanation;
$data['passage_multilink'] = $this->getWorkPassageMultiLink($verseexplanation->findFirstNonEmptyPassage()->getId(),$verseexplanation->getId(), $request);
$data['authors'] = $this->getAuthorInfo($request, $verseexplanation->getId());
}
}
}
} */
return $this->renderView('refsidr', $data);
}
public function bibleChapterRangeSliderAction($translationUrl, $bookUrl, $chapterStartIndex, $chapterEndIndex, Request $request, $verseStartIndex = null, $verseEndIndex = null, $userSelected = true)
{
$chapterRangeData = array(
'book' => $this->getBookByUrl($translationUrl, $bookUrl, $request, $userSelected)
);
if($verseStartIndex === null) {
$chapterRangeData['content_class'] = 'chapter';
} else {
$chapterRangeData['content_class'] = 'verse';
}
$chapterRangeData['contents'] = DataAssembly::getVerseRangeFromBook($chapterRangeData['book'], $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
$chapterRangeData['translation_url'] = $translationUrl;
$chapterRangeData['bible_column_spec'] = $this->getMultiColumnSpecForChapterRange($translationUrl, $bookUrl, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
return $this->createChaptersSliderView($chapterRangeData, $request);
}
protected function createChaptersSliderView($chapterRangeData, $request)
{
$allVerses = array_reduce($chapterRangeData['contents'], 'array_merge', array());
$aVerseInfo = $this->getVerseInfo($allVerses);
if($chapterRangeData['content_class'] !== 'storytext') {
// $chapterRangeData['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
}
// echo 'aaa';
$bChapter = false;
$chapterRangeData['referring_passages'] = $this->getBibleRefPassageNew($aVerseInfo, $bChapter, false);
$chapterRangeData['core_passages'] = $this->getBibleRefPassageNew($aVerseInfo, $bChapter, true);
$chapterRangeData['explanation_ref'] = $this->getExplanationRefForBible($aVerseInfo, $request);
$chapterRangeData['gced_ref'] = $this->getGCEDRefForBible($aVerseInfo, array());
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array());
$chapterRangeData['otle_ref'] = $aOTLE['otle_nonmusic'];
$chapterRangeData['otle_ref_music'] = $aOTLE['otle_music'];
$chapterRangeData['verse_cross'] = $this->getVerseCrossRefs($aVerseInfo, $request);
$chapterRangeData['word_explanations'] = $this->getBibleWordExplanations($aVerseInfo, $request);
$chapterRangeData['explained_verse'] = $this->getFirstExplainedVerse($aVerseInfo, $request);
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$chapterRangeData['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($chapterRangeData['book']->getCanonicalization()->getId(), current($allVerses)->getChapter()->getOrdering(), current($allVerses)->getIndexDisplay(), end($allVerses)->getChapter()->getOrdering(), end($allVerses)->getIndexDisplay(), $nUILanguageID);
$chapterRangeData['verses_concept'] = $this->getVerseContentWithConceptLinks($request, $allVerses, $chapterRangeData['bible_column_spec']);
$chapterRangeData['book_url'] = $chapterRangeData['book']->getUrl();
$chapterRangeData['chapter_index'] = $aVerseInfo['FirstChapterIndex'];
return $this->renderView('refsidr', $chapterRangeData);
}
public function selectbiblestoryAction(Request $request)
{
$locale = $request->getLocale();
$sSearchText = $request->query->get('st');
if(empty($sSearchText))
$data['stories'] = $this->getExplainedStoryList($locale);
else
$data['stories'] = $this->getExplainedStoryListForSearch($locale, $sSearchText);
return $this->renderView('selectbiblestory', $data);
}
/**
* load chapter summary after loading the main chpater page
*/
public function chaptersummaryAction($translationUrl, $bookUrl, $chapterIndex, $summaryTranslationID, Request $request)
{
$response = null;
$data['chapter_order'] = $chapterIndex;
// $data['translation_url'] = $translationUrl;
// $data['book_url'] = $bookUrl;
if(!empty($summaryTranslationID))
{
$nTransID = $summaryTranslationID;
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$data['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$data['explanation_translation'] = $explanation_translation;
$data['explanation_passage'] = $passage;
$data['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$data['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$data['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$data['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$data['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translationUrl . "_" . $bookUrl . "_" . $chapterIndex;
$data['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$nCChapterID = $this->getCChapterID($bookUrl, $chapterIndex);
$data['explanation_cchapter_id'] = $nCChapterID;
$data['explanation_translation_id'] = $nTransID;
}
}
}
}
// Set this b/c footnote popup issue
$data['bible_chapter_summary'] = true;
return $this->renderView('chaptersummaryintext', $data, $response);
}
/**
* Show translation list on a popup
*/
public function selectcompareAction($translationUrl, $translationUrl2, $bookUrl, $cbookID, $chapterStartOrder, $chapterEndOrder, $verseStartOrder, $verseEndOrder, Request $request)
{
$data['translation_url'] = $translationUrl;
$data['translation_url2'] = $translationUrl2;
$data['book_url'] = $bookUrl;
if(empty($translationUrl))
$translationUrl = $this->DEFAULT_BIBLE_VERSION;
// $aTrans = $this->getBibleTransInfo($translationUrl);
// $data['translation_name'] = $aTrans['name'];
$data['single_verse'] = ($chapterStartOrder == $chapterEndOrder && $verseStartOrder == $verseEndOrder);
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$data['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($cbookID, $chapterStartOrder, $verseStartOrder, $chapterEndOrder, $verseEndOrder, $nUILanguageID);
if($chapterEndOrder == $chapterStartOrder)
$chapterEndOrder = null;
if($verseEndOrder == $verseStartOrder)
$verseEndOrder = null;
$data['chapter_start_order'] = $chapterStartOrder;
$data['chapter_end_order'] = $chapterEndOrder;
$data['verse_start_order'] = $verseStartOrder;
$data['verse_end_order'] = $verseEndOrder;
return $this->renderView('selectcompare', $data);
}
public function selectstorytranslationAction(Request $request)
{
$locale = $request->getLocale();
$data['story_url'] = $request->query->get('storyurl');
$data['bible_translation_url'] = $request->query->get('bturl');
$data['commentary_url'] = $request->query->get('commentaryurl');
$nCBookID = $request->query->get('cbookid');
$nChapterStartOrder = $request->query->get('chapterstartorder');
$nVerseStartIndex = $request->query->get('versestartindex');
$nChapterEndOrder = $request->query->get('chapterendorder');
$nVerseEndIndex = $request->query->get('verseendindex');
$locale = $request->getLocale();
$nUILanguageID = $this->getLanguageIDByShortCode($locale);
$data['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($nCBookID, $nChapterStartOrder, $nVerseStartIndex, $nChapterEndOrder, $nVerseEndIndex, $nUILanguageID);
return $this->renderView('selectstorytranslation', $data);
}
/**
* Show translation list on a popup
*/
public function selecttranslationindexAction(Request $request, $translationUrl)
{
$locale = $request->getLocale();
$nLanguageID = $this->getLanguageIDByShortCode($locale);
// $nLanguageID = $this->getLanguageIDByBibleTrans($translationUrl);
$data['translation_list'] = $this->getBibleTranslationListByLanguage($nLanguageID);
$data['translation_url'] = $translationUrl;
return $this->renderView('selecttranslationindex', $data);
}
/**
* Show book list on a popup for advanced search
*/
public function selectbiblebooksforsearchAction(Request $request)
{
$nTranslationID = $request->query->get('trans');
// $nLanguageID = $request->query->get('lang');
$sSelectedBookIDs = $request->query->get('selectedids');
$data['book_list'] = $this->getBibleBookList($request, $nTranslationID);
$data['selected_ids'] = $sSelectedBookIDs;
return $this->renderView('selectbiblebooksforsearch', $data);
}
// For reading plan - work
protected function readingplanStepForWork($translationUrl, $work_id, $passageId, $readingPlanUrl, $planstep, $request)
{
$translation = $this->expositionData('Translation')->findOneBy(array('url' => $translationUrl, 'isPublic' => true));
if($translation == null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
if($passageId != "")
{
$request->getSession()->set("current_reading_plan_work_id", $work_id);
$request->getSession()->set("current_reading_plan_work_translation_url", $translationUrl);
}
$passage = ($passageId !== null)
? $this->expositionData('Passage')->findOneById($passageId)
: (($translation !== null) ? $translation->getWork()->findFirstNonEmptyPassage($translation) : null);
$this->checkIfOnMobile($request);
$locale = $request->getLocale();
$sUrlCompareTo = $request->query->get('compareTo');
$aCompare = explode(";;", $sUrlCompareTo);
$nCompareLen = count($aCompare);
$compareTo = null;
$compareTo2 = null;
$text_to_speech2 = null;
$text_to_speech3 = null;
$text_style_override_compare_to = null;
$text_style_override_compare_to2 = null;
$translation_shortname2 = null;
$translation_shortname3 = null;
if($nCompareLen > 0 && $aCompare[0] != '')
{
$compareTo = $this->expositionData('Translation')->findOneBy(array('url' => $aCompare[0], 'isPublic' => true));
if($compareTo != null)
{
$nLanguageID2 = $compareTo->getLanguage()->getId();
$text_style_override_compare_to = $this->getTextStyleOverride($nLanguageID2);
$text_to_speech2 = $this->getTextToSpeech($nLanguageID2);
$translation_shortname2 = $this->getWorkTranslationShortName($compareTo->getId());
}
}
if($nCompareLen == 2 && $aCompare[1] != '')
{
$compareTo2 = $this->expositionData('Translation')->findOneBy(array('url' => $aCompare[1], 'isPublic' => true));
if($compareTo2 != null)
{
$nLanguageID3 = $compareTo2->getLanguage()->getId();
$text_style_override_compare_to2 = $this->getTextStyleOverride($nLanguageID3);
$text_to_speech3 = $this->getTextToSpeech($nLanguageID3);
$translation_shortname3 = $this->getWorkTranslationShortName($compareTo2->getId());
}
}
$chapterExplanations = $this->getChapterExplanationsForText($translation);
$chapterExplanationsForCombo = $this->getChapterExplanationsForTextForCombo($translation);
$ref_column_spec = '';
$bSwedenborg = $this->isSwedenborg($translation->getId());
if($bSwedenborg)
$ref_column_spec = $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK;
else
$ref_column_spec = $this->MULTI_URL_INDICATOR_EXPLANATION;
$ref_column_spec .= '_' . $translation->getUrl();
if($passage != null && $bSwedenborg)
$ref_column_spec .= '_' . $passage->getSwedenborgSection();
$nPassageID = null;
if($passage != null)
$nPassageID = $passage->getId();
$nLanguageID = $translation->getLanguage()->getId();
$data = array(
'translation' => $translation,
'passage' => $passage,
'compare_to' => $compareTo,
'compare_to2' => $compareTo2,
'nav_mode' => 'translation',
'chapter_explanations' => $chapterExplanations,
'chapter_explanations_for_combo' => $chapterExplanationsForCombo,
'ref_column_spec' => $ref_column_spec,
'text_style_override' => $this->getTextStyleOverride($nLanguageID),
'text_style_override_compare_to' => $text_style_override_compare_to,
'text_style_override_compare_to2' => $text_style_override_compare_to2,
'text_to_speech1' => $this->getTextToSpeech($nLanguageID),
'text_to_speech2' => $text_to_speech2,
'text_to_speech3' => $text_to_speech3,
'translation_shortname2' => $translation_shortname2,
'translation_shortname3' => $translation_shortname3,
'plan_step' => $planstep
);
$stepOrder = $planstep['step_order'];
$data['next_reading_plan_step'] = $this->getNextReadingPlanStep($readingPlanUrl, $stepOrder, $request);
$data['prev_reading_plan_step'] = $this->getPreviousReadingPlanStep($readingPlanUrl, $stepOrder);
$nUserID = $request->getSession()->get("user_id");
if($nUserID != '')
$data['reading_plan_completed_info'] = $this->getUserStepInfo($readingPlanUrl, $nUserID);
$nCompletedStepOrder = null;
if(isset($data['reading_plan_completed_info']['completed_step_order']))
$nCompletedStepOrder = $data['reading_plan_completed_info']['completed_step_order'];
$data['completed_percentage'] = $this->getStepCompletedPercentage($readingPlanUrl, $request);
$data['reading_plan_order_info'] = $this->getReadingPlanOrderInfo($readingPlanUrl);
$data['reading_plan_url'] = $readingPlanUrl;
$data['step_order'] = $stepOrder;
$data['current_step_id'] = $planstep['id'];
$bPlanStarted = ($request->getSession()->get("reading_plan_started") == 1 || $this->hasReadingPlanStarted($readingPlanUrl,$nUserID));
$data['plan_started'] = $bPlanStarted;
/* $bCompleted = false;
if($stepOrder <= $nCompletedStepOrder)
$bCompleted = true; */
$nStepID = $planstep['id'];
$bCompleted = $this->IsReadingPlanStepCompleted($nStepID, $request);
$data['step_completed'] = $bCompleted;
$bLastUncompleted = false;
if(!$bCompleted)
$bLastUncompleted = $this->IsLastReadingPlanStepUncompleted($nStepID, $request);
$data['last_step_uncompleted'] = $bLastUncompleted;
$bLastStep = $this->IsLastReadingPlanStep($nStepID, $request);
$data['is_last_step'] = $bLastStep;
if($translation !== null) {
$work = $translation->getWork();
$bSwedenborgWork = ($work->getSwedenborgType() !== null);
$data['is_swedenborg'] = $bSwedenborgWork;
$bConsider = false;
$bBibleStudy = false;
$bConcept = false;
$bQA = false;
if(!$bSwedenborgWork)
{
foreach($work->getCategories() as $category) {
if($category->getId() == $this->CATEGORY_ID_SPIRITUAL_TOPIC) {
$bConsider = true;
}
elseif($category->getId() == $this->CATEGORY_ID_BIBLE_STUDY) {
$bBibleStudy = true;
}
elseif($category->getId() == $this->CATEGORY_ID_CONCEPT) {
$bConcept = true;
$data['category_concept'] = 1;
}
elseif($category->getId() == $this->CATEGORY_ID_QA) {
$bQA = true;
}
}
}
$nLanguageID = $translation->getLanguage()->getId();
if(!$bSwedenborgWork)
$data['authors'] = $this->getAuthorInfo($request, $translation->getId());
else
$data['IsSwedenborgWork'] = 1;
$type_id = $translation->getTypeId();
if($type_id == $this->TRANSLATION_TYPE_ID_FILE)
{
$file = $translation->getFile();
if($file !== null) {
$data['file'] = $file;
}
}
if($type_id == $this->TRANSLATION_TYPE_ID_LINK)
{
$doc_link = $translation->getDocLink();
if($doc_link !== null) {
$data['doc_link'] = $doc_link;
}
}
$data['type_id'] = $type_id;
$data['in_frame'] = false;
if($passage != null)
{
$nTranslationID = $translation->getId();
if(!$bSwedenborgWork)
$data['passage_ref'] = $this->getWorkPassageRefs($nPassageID,$nTranslationID, $request);
if($bSwedenborgWork)
$data['related_bible_ref'] = $this->getRelatedBibleRefForWork($nPassageID,$nTranslationID, $request);
$data['passage_footnote'] = $this->getPassageFootnotes($nPassageID,$nTranslationID);
$data['passage_multilink'] = $this->getWorkPassageMultiLink($nPassageID,$nTranslationID, $request);
$request->getSession()->set('current_explanation_cchapter_id', '');
$nExplainChapterID = $this->getExplainChapterID($nTranslationID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$data['cchapter_id'] = $nExplainChapterID;
$request->getSession()->set('current_explanation_cchapter_id', $nExplainChapterID);
$request->getSession()->set('current_explanation_translation_id', $nTranslationID);
}
if($bSwedenborgWork)
{
$data['has_slider_item_for_work'] = $this->hasSliderItemForWork($nPassageID, $nTranslationID, $request, $nLanguageID);
$data['slider_url'] = $this->get('router')->generate('exposition_slider', array(
'translationId' => $nTranslationID,
'passageId' => $nPassageID
));
}
}
$data['text_to_speech'] = $this->getTextToSpeech($translation->getLanguage()->getId());
if($bSwedenborgWork)
{
$data['biblio_info'] = $this->getBiblioForTranslation($translation->getId());
}
else
{
// check concept image
if($compareTo == null)
{
$conceptUrl = $this->getConceptUrl($translation->getWork()->getId());
if(!empty($conceptUrl))
{
$concept = $this->getRepository('Concepts\Concept')->findOneByUrl($conceptUrl);
$illustrations = $concept->getIllustrations();
$data['image'] = ($illustrations->isEmpty()) ? null : $illustrations[0]->getImage();
}
}
}
} else {
$work = null;
}
return $this->createWorkPassageView($data, $work, $request);
}
protected function createWorkPassageView($data, $work, $request)
{
$locale = $request->getLocale();
$response = null;
if($work === null || $data['translation'] === null || $data['passage'] === null) {
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content', array(), $response);
}
$nPassageID = $data['passage']->getId();
$nTranslationID = $data['translation']->getId();
$nLanguageID = $data['translation']->getLanguage()->getId();
$data['translation_shortname'] = $this->getWorkTranslationShortName($nTranslationID);
$nBibleBookIDForSummary = $this->getBibleBookIDForSummary($nTranslationID);
$bBibleBookSummary = ($nBibleBookIDForSummary != '');
if($bBibleBookSummary)
$data['is_book_summary'] = '1';
if($work !== null) {
$nLevelID = '';
$aStory = $this->getStoryInfo($nTranslationID);
if(!empty($aStory))
{
$nStoryID = $aStory['story_id'];
$nLevelID = $aStory['level_id'];
if($nLevelID == $this->STORY_LEVEL_ID_BIBLE)
{
// $data['all_stories'] = $this->getExplainedStoryList($locale);
// $data['story_explanations'] = $this->getWorkListForStory($locale, $nStoryID);
$data['commentary_type'] = 'storyexplanation';
}
elseif($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
$data['is_chapter_explanation'] = '1';
elseif($nLevelID == $this->STORY_LEVEL_ID_VERSE)
$data['is_verse_explanation'] = '1';
$data['story_id'] = $nStoryID;
}
// We can override the 'storyexplanation' commentary type because some "story" explanations are really verse explanations.
// 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.
// 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.
if($this->getConceptID($data['translation']->getId()) != null) {
$data['commentary_type'] = 'conceptexplanation';
} else {
$containingCategories = $work->getCategories()->toArray();
if($data['translation'] !== null) {
$containingCategories = array_merge($containingCategories, $data['translation']->getCategories()->toArray());
}
$categoryUrlToCommentaryTypeMap = array(
'doctrinal-topic-explanations' => 'doctrinaltopic',
'verse-explanations' => 'verseexplanation',
// 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
'story-explanations' => 'storyexplanation'
);
// If the content doesn't belong to the Category for any major commentary type, then $data['commentary_type'] can just remain unset.
foreach($containingCategories as $cat) {
if(array_key_exists($cat->getUrl(), $categoryUrlToCommentaryTypeMap)) {
$data['commentary_type'] = $categoryUrlToCommentaryTypeMap[$cat->getUrl()];
// At the time of coding this, there shouldn't be anything which belongs to more than one major commentary type.
break;
}
}
}
}
if($work->getSwedenborgType() !== null)
{
// $data['previous_passage'] = $this->getPreviousPassageWithContent($data['passage'], $data['translation']);
// $data['next_passage'] = $this->getNextPassageWithContent($data['passage'], $data['translation']);
// Get meta description
$nTextLength = 140;
$sPassageText = $this->getWorkPassageContents($nPassageID,$nTranslationID);
$sMetaDesc = $this->fixWorkText($sPassageText);
$sMetaDesc = $this->getTextWithinLength($sMetaDesc, $nTextLength, "...");
$data['work_meta_desc'] = $sMetaDesc;
}
else
{
// Get meta description
$nTextLength = 140;
$sPassageText = '';
if($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
{
$sPassageText = $this->getWorkPassageContents($nPassageID,$nTranslationID);
}
else
{
$sPassageText = $this->getWorkTranslationDesc($nTranslationID);
if(empty($sPassageText))
{
$sPassageText = $this->getWorkPassageContents($nPassageID,$nTranslationID);
}
}
$sMetaDesc = $this->fixWorkText($sPassageText);
$sMetaDesc = $this->getTextWithinLength($sMetaDesc, $nTextLength, "...");
$data['work_meta_desc'] = $sMetaDesc;
}
$data['work'] = $work;
return $this->renderView('work_passage', $data, $response);
}
/* public function fullviewVerseAction($verseId, Request $request)
{
// Go to the chapter view of the verse
$sSql = "select t.url as trans_url, cb.url as book_url, c.ordering FROM canonicalbiblechapter cc, biblebook b, biblechapter c, bibleverse v, bibletranslation t, canonicalbiblebook cb where v.id = " . $verseId . " and v.chapter_id = c.id and c.book_id = b.id and b.canonicalization_id = cc.book_id and cc.book_id = cb.id and b.translation_id = t.id and cc.ordering = c.ordering limit 1";
// echo $sSql."<br>";
$aData = $this->getRowData($sSql);
$sBookUrl = trim($aData['book_url']);
$sTransUrl = trim($aData['trans_url']);
$nOrder = trim($aData['ordering']);
$sLink = $this->get('router')->generate('bible_chapter', array(
'translationUrl' => $sTransUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $nOrder
));
if(!empty($sLink))
return $this->redirect($sLink, 301);
else
return $this->redirect("/", 301);
}
*/
public function fullviewChapterAction($chapterId, Request $request)
{
// Go to the chapter view
$sSql = "select t.url as trans_url, cb.url as book_url, c.ordering FROM canonicalbiblechapter cc, biblebook b, biblechapter c, bibletranslation t, canonicalbiblebook cb where c.id = " . $chapterId . " and c.book_id = b.id and b.canonicalization_id = cc.book_id and cc.book_id = cb.id and b.translation_id = t.id and cc.ordering = c.ordering limit 1";
// echo $sSql."<br>";
$aData = $this->getRowData($sSql);
$sBookUrl = trim($aData['book_url']);
$sTransUrl = trim($aData['trans_url']);
$nOrder = trim($aData['ordering']);
$sLink = $this->get('router')->generate('bible_chapter', array(
'translationUrl' => $sTransUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $nOrder
));
if(!empty($sLink))
return $this->redirect($sLink, 301);
else
return $this->redirect("/", 301);
}
// For reading plan - ad-hoc
protected function readingplanStepForAdHoc($readingPlanUrl, $planstep, $request)
{
$this->checkIfOnMobile($request);
$locale = $request->getLocale();
$nStepID = $planstep['id'];
$nLanguageID = $this->getLanguageIDByShortCode($locale);
$data = array(
'nav_mode' => 'ad-hoc',
'text_style_override' => $this->getTextStyleOverride($nLanguageID),
'text_to_speech1' => $this->getTextToSpeech($nLanguageID),
'plan_step' => $planstep
);
$stepOrder = $planstep['step_order'];
$data['next_reading_plan_step'] = $this->getNextReadingPlanStep($readingPlanUrl, $stepOrder, $request);
$data['prev_reading_plan_step'] = $this->getPreviousReadingPlanStep($readingPlanUrl, $stepOrder);
$nUserID = $request->getSession()->get("user_id");
if($nUserID != '')
$data['reading_plan_completed_info'] = $this->getUserStepInfo($readingPlanUrl, $nUserID);
$nCompletedStepOrder = null;
if(isset($data['reading_plan_completed_info']['completed_step_order']))
$nCompletedStepOrder = $data['reading_plan_completed_info']['completed_step_order'];
$data['completed_percentage'] = $this->getStepCompletedPercentage($readingPlanUrl, $request);
$data['reading_plan_order_info'] = $this->getReadingPlanOrderInfo($readingPlanUrl);
$data['reading_plan_url'] = $readingPlanUrl;
$data['step_order'] = $stepOrder;
$data['current_step_id'] = $nStepID;
$bPlanStarted = ($request->getSession()->get("reading_plan_started") == 1 || $this->hasReadingPlanStarted($readingPlanUrl,$nUserID));
$data['plan_started'] = $bPlanStarted;
/* $bCompleted = false;
if($stepOrder <= $nCompletedStepOrder)
$bCompleted = true; */
$bCompleted = $this->IsReadingPlanStepCompleted($nStepID, $request);
$data['step_completed'] = $bCompleted;
$bLastUncompleted = false;
if(!$bCompleted)
$bLastUncompleted = $this->IsLastReadingPlanStepUncompleted($nStepID, $request);
$data['last_step_uncompleted'] = $bLastUncompleted;
$bLastStep = $this->IsLastReadingPlanStep($nStepID, $request);
$data['is_last_step'] = $bLastStep;
return $this->createAdHocReadingPlanStepView($data, $request);
}
protected function createAdHocReadingPlanStepView($data, $request)
{
$locale = $request->getLocale();
$response = null;
$nLanguageID = $this->getLanguageIDByShortCode($locale);
return $this->renderView('readingplan_adhoc', $data, $response);
}
public function readingPlanOutlineAction($readingPlanUrl, Request $request)
{
$this->onloadPage($request);
$locale = $request->getLocale();
$info = $this->getReadingPlanInfo($readingPlanUrl,$locale);
$nUserID = $request->getSession()->get("user_id");
$user_plan = null;
$nTextLength = 150;
$sMetaDesc = $this->getTextWithinLength($info['description'], $nTextLength, "...");
$data = array(
'reading_plan' => $info,
'meta_desc' => $sMetaDesc
);
// $data['user_plan'] = $this->getUserReadingPlanInfo($readingPlanUrl,$nUserID, $request);
$data['plan_step_list'] = $this->getReadingPlanStepsForOutline($readingPlanUrl,$nUserID, $request);
$bPlanStarted = $this->hasReadingPlanStarted($readingPlanUrl,$nUserID);
$data['plan_started'] = $bPlanStarted;
return $this->renderView('reading_plan_outline', $data);
}
} // End of class