<?php
namespace NCBS\WebsiteBundle\Controller;
use NCBS\WebsiteBundle\Tools\DataAssembly;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\Request;
class GeneralController extends NCBSWController
{
protected $prefix = 'General';
// Simplify the code for determining whether Bible content is using canonical numbering or not
protected $bibleCategoryIsCanonical = array('c' => false, 'v' => false, 'cc' => true, 'cv' => true, 'st' => true);
protected $language1 = null;
protected $work1 = null;
public function spotlightFragmentAction($spot)
{
$method = $spot.'SpotlightAction';
if(method_exists($this, $method)) {
return $this->$method();
}
}
public function multicolumnAction($column1Details, $column2Details, Request $request, $column3Details = null, $renderingData = array())
{
$this->onloadPage($request);
$bStory = (isset($renderingData['content_class']) && $renderingData['content_class'] == 'story');
$this->language1 = null;
$this->work1 = null;
$request->getSession()->set('has_explanation_cchapter_id_temp_bible', '');
$request->getSession()->set('has_explanation_cchapter_id_temp_trans', '');
$request->getSession()->set('current_explanation_cchapter_id_temp_bible', '');
$request->getSession()->set('current_explanation_cchapter_id_temp_trans', '');
$request->getSession()->set('current_explanation_cchapter_id', '');
$renderingData['columns'] = array(
1 => $this->convertColumnData($column1Details, 1, $request),
2 => $this->convertColumnData($column2Details, 2, $request)
);
$nLastColNum = 2;
$sLastColNewUrl = "";
$renderingData['multicolumn_route_params'] = array(
'column1Details' => $column1Details,
'column2Details' => $column2Details
);
if(empty($column3Details)) {
$renderingData['multicolumn_path'] = 'arbitrary_two_column';
} else {
$nLastColNum = 3;
$renderingData['multicolumn_path'] = 'arbitrary_three_column';
$renderingData['columns'][3] = $this->convertColumnData($column3Details, 3, $request);
$renderingData['multicolumn_route_params']['column3Details'] = $column3Details;
}
$curr_book = null;
$story_translation_url = null;
$explained_verse = null;
$first_col_chapter_id = null;
$bExplainedChapter = false;
$first_col_verse_id = null;
$bExplainedVerse = false;
$bExplainedVersePage = false; // The explanation is for the verse on column 1
foreach($renderingData['columns'] as $columnNum => $columnDetails) {
if(empty($columnDetails)|| $columnDetails['column_type'] === 'unrecognized')
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
$columnDetails['column_number'] = $columnNum;
if($columnDetails['column_type'] === 'dependent') {
return $this->assembleMulticolumnWithDependencies($renderingData, $column1Details, $column2Details, $request, $column3Details);
}
if($columnDetails['column_type'] === 'bible') {
//$chapterExplanation = $columnDetails['chapter_explanations_for_commentary'];
$curr_book = null;
if(isset($columnDetails['curr_book']))
$curr_book = $columnDetails['curr_book'];
$story_translation_url = $columnDetails['story_translation_url'];
if($columnNum == 1)
{
$explained_verse = $columnDetails['explained_verse'];
if($columnDetails['content_category'] == 'c')
$first_col_chapter_id = $columnDetails['chapter_id'];
if($columnDetails['content_category'] == 'v')
$first_col_verse_id = $columnDetails['verse_id'];
}
if(empty($column3Details) && $columnNum == 1 && isset($columnDetails['verse_meta_desc']))
$renderingData['verse_meta_desc'] = $columnDetails['verse_meta_desc'];
}
elseif($columnDetails['column_type'] === 'exposition') {
//$renderingData['chapter_explanations'] = $chapterExplanation;
if(isset($columnDetails['translation']) && $columnDetails['translation'] != null) {
$translation_id = $columnDetails['translation']->getId();
if($columnNum == $nLastColNum && @$_GET["fs"] == 1)
{
$passage_id = $columnDetails['passage']->getId();
$sLastColNewUrl = $this->getNewWorkTranslationUrl($translation_id, $passage_id);
if(!empty($sLastColNewUrl))
{
break;
}
}
$nBibleBookIDForSummary = $this->getBibleBookIDForSummary($translation_id);
$bBibleBookSummary = ($nBibleBookIDForSummary != '');
$aBibleBookSummaryList = null;
if($bBibleBookSummary)
{
$aBibleBookSummaryList = $this->getBibleBookSummaryList($nBibleBookIDForSummary);
if(!empty($aBibleBookSummaryList))
$renderingData['book_id_for_summaries'] = $nBibleBookIDForSummary;
}
$renderingData['book_summaries'] = $aBibleBookSummaryList;
$tempchapterExplanation = null;
$tempchapterExplanationForCombo = null;
if(!$bBibleBookSummary)
{
if($curr_book != null)
{
$tempchapterExplanation = $this->getChapterExplanations($curr_book, $columnDetails['translation'], $request);
$tempchapterExplanationForCombo = $this->getChapterExplanationsForCombo($curr_book, $columnDetails['translation']);
$renderingData['explained_book'] = $curr_book;
}
else
{
$tempchapterExplanation = $this->getChapterExplanationsForText($columnDetails['translation']);
$tempchapterExplanationForCombo = $tempchapterExplanation;
}
if($tempchapterExplanation != null)
{
$renderingData['chapter_explanations'] = $tempchapterExplanation;
$columnDetails['chapter_explanations'] = $tempchapterExplanation;
$renderingData['chapter_explanations_for_combo'] = $tempchapterExplanationForCombo;
if($columnNum == 2 && $first_col_chapter_id != null && $curr_book != null)
{
foreach($tempchapterExplanation as $explanation)
{
if($explanation['chapter_id'] == $first_col_chapter_id)
{
$bExplainedChapter = true;
break;
}
}
}
}
if($columnNum > 1 && $explained_verse != null)
{
if($columnNum == 2 && !empty($first_col_verse_id))
$bExplainedVersePage = $this->isExplainedVerse($translation_id, $first_col_verse_id);
$tempVerse_explanations = $this->getVerseExplanations($explained_verse['chapter_id'], $explained_verse['language_id'], $request);
$renderingData['verse_explanations'] = $tempVerse_explanations;
$renderingData['chapter_id_for_verse_explanation'] = $explained_verse['chapter_id'];
$renderingData['language_id_for_verse_explanation'] = $explained_verse['language_id'];
foreach($tempVerse_explanations as $explanation)
{
if($explanation['verse_id'] == $first_col_verse_id)
{
$bExplainedVerse = true;
break;
}
}
}
}
}
if($story_translation_url != null)
{
$renderingData['story_translation_url'] = $story_translation_url;
}
if($bStory)
{
$nTextLength = 140;
$sTransText = $this->getWorkTranslationDesc($translation_id);
if(empty($sTransText))
{
$sTransText = $this->getExplanationContents($translation_id);
}
$sMetaDesc = $this->fixWorkText($sTransText);
$sMetaDesc = $this->getTextWithinLength($sMetaDesc, $nTextLength, "...");
$renderingData['story_meta_desc'] = $sMetaDesc;
}
else if(empty($column3Details) && $columnNum == 2 && isset($renderingData['verse_meta_desc']))
{
if($bExplainedVersePage)
{
$sTransTitle = $columnDetails['translation']->getTranslatedTitle();
$renderingData['verse_explanation_meta_desc'] = $sTransTitle . " - ". $renderingData['verse_meta_desc'];
}
}
}
}
if(!empty($sLastColNewUrl))
{
// redirect
$renderingData['multicolumn_route_params']['column'.$nLastColNum.'Details'] = $sLastColNewUrl;
return $this->redirect($this->get('router')->generate($renderingData['multicolumn_path'], $renderingData['multicolumn_route_params']), 301);
}
if($bExplainedChapter)
{
foreach($renderingData['columns'] as $columnNum => $columnDetails) {
if($columnDetails['column_type'] === 'bible' && $columnNum == 1) {
$renderingData['chapter_explanation_page'] = true;
break;
}
}
}
else if($bExplainedVerse)
{
foreach($renderingData['columns'] as $columnNum => $columnDetails) {
if($columnDetails['column_type'] === 'bible' && $columnNum == 1) {
$renderingData['verse_explanation_page'] = true;
break;
}
}
}
$this->setCurrentUrl($request);
$nTempChapterID_Bible = $request->getSession()->get('current_explanation_cchapter_id_temp_bible');
$nTempChapterID_Trans = $request->getSession()->get('current_explanation_cchapter_id_temp_trans');
if($nTempChapterID_Trans != '')
{
$nTempTransID_Trans = $request->getSession()->get('current_explanation_translation_id_temp_trans');
$request->getSession()->set('current_explanation_cchapter_id', $nTempChapterID_Trans);
$request->getSession()->set('current_explanation_translation_id', $nTempTransID_Trans);
}
else if($nTempChapterID_Bible != '')
{
$nTempTransID_Bible = $request->getSession()->get('current_explanation_translation_id_temp_bible');
$request->getSession()->set('current_explanation_cchapter_id', $nTempChapterID_Bible);
$request->getSession()->set('current_explanation_translation_id', $nTempTransID_Bible);
}
// If no dependencies, can proceed with normal page generation
return $this->createMulticolumnView($renderingData, $request);
}
protected function assembleMulticolumnWithDependencies($renderingData, $column1Details, $column2Details, Request $request, $column3Details = null)
{
$numColumns = count($renderingData['columns']);
// We want an array of column dependencies for each column; a non-dependent column doesn't have its own, so we'll patch in this array:
$noDependencies = array(1 => 'none', 2 => 'none', 3 => 'none');
// This array says which columns have any dependencies at all (used to determine if we need to process dependencies in the first place)
$isDependent = array();
// And this array says exactly which columns depend on which other ones, and how
$columnDependencies = array();
// While we set up those arrays, we'll try to resolve optional self-dependencies that don't have other dependencies attached
foreach($renderingData['columns'] as $columnNum => $columnData) {
if($columnData['column_type'] === 'dependent') {
$columnDependencies[$columnNum] = $columnData['depends_on'];
$onlyOptionalSelfDependency = true;
foreach($columnDependencies[$columnNum] as $dependencyColumnNum => $dependencyType) {
// Need == here instead of === because we might be comparing strings to integers
if( ($dependencyColumnNum == $columnNum && $dependencyType !== 'optional')
|| ($dependencyColumnNum != $columnNum && $dependencyType !== 'none')
) {
$onlyOptionalSelfDependency = false;
}
}
if($onlyOptionalSelfDependency) {
$columnDetailVar = 'column'.$columnNum.'Details';
$columnData = $this->convertColumnData($columnDetailVar, $columnNum, $request, $columnNum, $renderingData);
$renderingData['columns'][$columnNum] = $columnData;
if($columnData['column_type'] === 'dependent') {
$columnDependencies[$columnNum] = $columnData['depends_on'];
} else {
$columnDependencies[$columnNum] = $noDependencies;
}
}
} else {
$columnDependencies[$columnNum] = $noDependencies;
}
$isDependent[$columnNum] = $columnData['column_type'] === 'dependent';
}
// Double-check that we actually need to resolve dependencies (i.e. at least one column is dependent)
if(!in_array(true, $isDependent)) {
return $this->createMulticolumnView($renderingData, $request);
}
// Check for cycles: make sure no column that has a required dependency on itself ...
if( ($columnDependencies[1][1] === 'required')
|| ($columnDependencies[2][2] === 'required')
|| ($numColumns === 3 && $columnDependencies[3][3] === 'required')
) {
throw new \Exception('Invalid column specification: Required self-dependency');
}
// ... at least one column can, if necessary, be built without using dependencies ...
$numRequiredDependencies = 0;
if($columnDependencies[1][2] === 'required' || $columnDependencies[1][3] === 'required') {
$numRequiredDependencies++;
}
if($columnDependencies[2][1] === 'required' || $columnDependencies[2][3] === 'required') {
$numRequiredDependencies++;
}
if($numColumns === 3 && ($columnDependencies[3][1] === 'required' || $columnDependencies[3][1] === 'required')) {
$numRequiredDependencies++;
}
if($numRequiredDependencies === $numColumns) {
throw new \Exception('Invalid column specification: All columns have required dependencies');
}
// ... and no mutual required dependencies
// (Note: if there are 2 columns, we will have already caught this case because all columns are dependent)
if($numColumns === 3 && (
($columnDependencies[1][2] === 'required' && $columnDependencies[2][1] === 'required')
|| ($columnDependencies[1][3] === 'required' && $columnDependencies[3][1] === 'required')
|| ($columnDependencies[2][3] === 'required' && $columnDependencies[3][2] === 'required')
)) {
throw new \Exception('Invalid column specification: Two columns depend on each other');
}
// Also, let's make sure there are no required dependencies on the third column if it doesn't exist
if($numColumns === 2 && ($columnDependencies[1][3] === 'required' || $columnDependencies[2][3] === 'required')) {
throw new \Exception('Invalid column specification: Required dependency on a nonexistent column');
}
// At this point, we have made sure that:
// (a) at least one dependency needs to be resolved
// (b) there is a way to acceptably resolve all dependencies
// Now we need to actually do the dependency resolution
// (keeping in mind that we should have already resolved optional self-dependencies).
if($numColumns === 2) {
// If only two total columns, then there can only be one required dependency (or we would have thrown an exception earlier)
// ... but there still might be mutual dependencies if at least one is optional, in which case we must process the optional dependency first.
// So we'll process optional dependencies first, then required dependencies.
// In case of mutual optional dependencies, this code should work OK, simply by arbitrarily processing column 1 first.
// In other cases, it will work because there will only be one dependency at most.
if($columnDependencies[1][2] === 'optional') {
$renderingData['columns'][1] = $this->convertColumnData($column1Details, 1, $request, 1, $renderingData);
}
if($columnDependencies[2][1] === 'optional') {
$renderingData['columns'][2] = $this->convertColumnData($column2Details, 2, $request, 2, $renderingData);
}
if($columnDependencies[1][2] === 'required') {
$renderingData['columns'][1] = $this->convertColumnData($column1Details, 1, $request, 1, $renderingData);
}
if($columnDependencies[2][1] === 'required') {
$renderingData['columns'][2] = $this->convertColumnData($column2Details, 2, $request, 2, $renderingData);
}
return $this->createMulticolumnView($renderingData, $request);
}
/*
* If we get to this point, then we should have three columns.
* We'll use the following priority list to process one column at a time until there are no more to process:
* 1. If possible, process a column which doesn't depend on other columns that also have dependencies.
* (In other words, it depends only on non-dependent columns and/or itself.)
* 2. If no such column exists, process a column that meets similar criteria, except that it:
* (a) can also have optional dependencies on columns that have required dependencies
* (b) MUST have another column that depends on it
* 3. If no column fits either of the first two cases, process any column that doesn't have a required dependency on a dependent column.
*
* These criteria will always match at least one column, as long as there isn't a required dependency loop,
* and are intended to maximize the likelihood that required dependencies will have appropriate content in the column they depend on.
* (They probably aren't the best possible rules, but they should at least work well for all common cases and not completely break even in corner cases.)
*
* The numbers 1, 2, 3 are used in some places in the code below to indicate the priority tiers given above.
*/
$strongestDependencies = array(1 => 'none', 2 => 'none', 3 => 'none');
foreach($columnDependencies as $columnNum => $columnDependsOn) {
if(in_array('required', $columnDependsOn)) {
$strongestDependencies[$columnNum] = 'required';
} elseif(in_array('optional', $columnDependsOn)) {
$strongestDependencies[$columnNum] = 'optional';
}
}
for($numProcessed = 0; ; $numProcessed++) {
// When no columns have dependencies left, we can stop with dependency resolution and return to normal view generation
if($strongestDependencies[1] === 'none' && $strongestDependencies[2] === 'none' && $strongestDependencies[3] === 'none') {
return $this->createMulticolumnView($renderingData, $request);
}
if($numProcessed >= 6) {
// If we reach this, then on average, we've run convertColumnData TWICE PER COLUMN and still haven't resolved everything!
// So we'll throw in a failsafe in case we somehow get into an infinite loop
throw new \Exception('Unexpected error: Excessive repeated processing of dependencies');
}
$topPriorityRank = 99; // where 99 is just an arbitrary number later than any priority we actually use
$topPriorityColumnNum = null;
foreach($renderingData['columns'] as $columnNum => $columnData) {
// Non-dependent columns can't be candidates for processing
if($columnData['column_type'] !== 'dependent') {
continue;
}
$runningPriorityMeasure = 1;
foreach($columnData['depends_on'] as $otherColumnNum => $dependencyLevel) {
/*
* The following don't affect priority:
* (optional) self-dependencies
* columns that this column doesn't depend on
* dependencies on non-dependent columns
*/
if($otherColumnNum == $columnNum || $dependencyLevel === 'none' || $strongestDependencies[$otherColumnNum] === 'none') {
continue;
} elseif($dependencyLevel === 'required') {
// We know the other column is dependent (or else we would have fallen into the previous if case).
// A column with a required dependency on a dependent column is never a candidate for dependency resolution.
continue 2;
} elseif($strongestDependencies[$otherColumnNum] === 'optional') {
// A dependency on a column with optional dependencies knocks this column to priority 3
$runningPriorityMeasure = 3;
} elseif($runningPriorityMeasure === 1) {
// Here, we know this is an optional dependency (or else we would have hit the first or second case)
// on a column that has a required dependency (or else we would have hit the first or third case).
// Such a thing can't exist in priority case 1, but can exist in priority case 2.
$runningPriorityMeasure = 2;
}
}
// The above loop figures out where this column's outgoing dependencies fit into the priority scheme.
// For priority 2, we also need to check whether the column has an incoming dependency.
if($runningPriorityMeasure === 2) {
// We'll temporarily set priority to 3, then revert to 2 if we find an incoming dependency
$runningPriorityMeasure = 3;
foreach($columnDependencies as $sourceColumnNum => $dependencyData) {
if($sourceColumnNum == $columnNum) {
// Self-dependencies don't count here
continue;
} elseif($dependencyData[$columnNum] !== 'none') {
// Incoming dependency! No need to continue the loop now that we know such a dependency exists.
$runningPriorityMeasure = 2;
break;
}
}
}
// The value of $runningPriorityMeasure should now indicate the final priority for this column.
// If it's an earlier priority than our previous best, then set this column as the new first priority.
if($runningPriorityMeasure < $topPriorityRank) {
$topPriorityRank = $runningPriorityMeasure;
$topPriorityColumnNum = $columnNum;
}
} // end "find column with top priority" loop foreach($renderingData['columns'] as $columnNum => $columnData)
if($topPriorityColumnNum !== null) {
$columnDetailVar = 'column'.$topPriorityColumnNum.'Details';
$newColumnData = $this->convertColumnData($columnDetailVar, $topPriorityColumnNum, $request, $topPriorityColumnNum, $renderingData);
$renderingData['columns'][$topPriorityColumnNum] = $newColumnData;
if($newColumnData['column_type'] === 'dependent') {
$columnDependencies[$topPriorityColumnNum] = $newColumnData['depends_on'];
if(in_array('required', $newColumnData['depends_on'])) {
$strongestDependencies[$topPriorityColumnNum] = 'required';
} else {
$strongestDependencies[$topPriorityColumnNum] = 'optional';
}
} else {
$columnDependencies[$topPriorityColumnNum] = $noDependencies;
$strongestDependencies[$topPriorityColumnNum] = 'none';
}
} else {
// There must be SOME dependency, or else we would have broken the loop near the beginning of the iteration.
// But we haven't found any column that matches any of our criteria for choosing which column to process ...
throw new \Exception('Unexpected error: Expected a resolvable column dependency but could not find one');
}
} // end dependency processing loop for($numProcessed = 0; ...)
}
protected function createMulticolumnView($renderingData, $request)
{
// Certain types of content require additional data for certain purposes -- e.g. Bible content needs a list of all Bible translations
$this->checkIfOnMobile($request);
$locale = $request->getLocale();
$hasBible = false;
$hasSwedenborg = false;
$hasOther = false;
$hasStory = false;
$nStoryID = null;
$book_translation = null;
$book = null;
$sCommentaryUrl = null;
foreach($renderingData['columns'] as $columnNum => $singleColumnData) {
if($singleColumnData['column_type'] === 'bible') {
$hasBible = true;
$book_translation = $singleColumnData['translation'];
$book = $singleColumnData['book'];
if(isset($singleColumnData['content_category']) && $singleColumnData['content_category'] === 'st')
$hasStory = true;
} elseif($singleColumnData['column_type'] === 'exposition' && !isset($singleColumnData['translation'])) {
// Do nothing (specifically, don't try to use $singleColumnData['translation'] in the next two clauses)
} elseif($singleColumnData['column_type'] === 'exposition') {
if($this->isSwedenborg($singleColumnData['translation']->getId()))
$hasSwedenborg = true;
else
$hasOther = true;
}
elseif($singleColumnData['column_type'] === 'exposition')
{
//$aStory = $singleColumnData['translation']->getWork()->getStories();
$aStory = $this->getStoryInfo($singleColumnData['translation']->getId());
if(!empty($aStory))
{
$nLevelID = $aStory['level_id'];
if($nLevelID == $this->STORY_LEVEL_ID_BIBLE)
{
$hasStory = true;
}
elseif($nLevelID == $this->STORY_LEVEL_ID_CHAPTER)
$renderingData['is_chapter_explanation'] = '1';
elseif($nLevelID == $this->STORY_LEVEL_ID_VERSE)
$renderingData['is_verse_explanation'] = '1';
$nStoryID = $aStory['story_id'];
$renderingData['story_id'] = $nStoryID;
$sCommentaryUrl = "";
if(isset($singleColumnData['translation_url']))
$sCommentaryUrl = $singleColumnData['translation_url'];
}
}
// While we're looping through the columns, we'll also find and apply any uri overrides (used e.g. with story explanations)
if(array_key_exists('column_uri_override', $singleColumnData)) {
$renderingData['multicolumn_route_params']['column'.$columnNum.'Details'] = $singleColumnData['column_uri_override'];
}
// Also, check for unresolved dependencies
if($singleColumnData['column_type'] === 'dependent') {
$singleColumnData['errors'][] = array('code' => '500', 'message' => 'unresolveddependency');
}
}
/* if($hasSwedenborg) {
// $renderingData['swedenborg_works'] = $this->getCategorizedSwedenborgWorks($request);
} */
if($hasStory && $nStoryID != null) {
$aAllStory = array();
$aSearchedStory = $request->getSession()->get('searched_bible_story_list');
if(!empty($aSearchedStory))
{
foreach($aSearchedStory as $s)
{
if($s['commentary_url'] == $sCommentaryUrl)
{
$aAllStory = $aSearchedStory;
break;
}
}
}
if(empty($aAllStory))
{
$aAllStory = $this->getExplainedStoryList($locale);
}
// print_r($aAllStory);
$renderingData['all_stories'] = $aAllStory;
$renderingData['story_explanations'] = $this->getWorkListForStory($locale, $nStoryID);
$renderingData['story_id'] = $nStoryID;
if(!empty($book_translation))
$renderingData['book_translation_url'] = $book_translation['url'];
// if(!empty($sCommentaryUrl))
$renderingData['commentary_url'] = $sCommentaryUrl;
}
$response = null;
$returnErrorStatusCode = null;
foreach($renderingData['columns'] as $columnNum => $singleColumnData) {
if(array_key_exists('errors', $singleColumnData)) {
foreach($singleColumnData['errors'] as $error) {
// If different columns have different problems, we can still only send one HTTP status code.
// Coincidentally, among the four most likely error codes, it's better to send the lower-numbered ones:
// 301 (permanent redirect) over 302 (temporary redirect) over 404 (not found) over 500 (server error)
// (note that this does NOT work with code 200 (OK), which we don't want to use if there's anything remotely like an error)
if($returnErrorStatusCode === null || $error['code'] < $returnErrorStatusCode) {
$returnErrorStatusCode = $error['code'];
}
}
}
}
if($returnErrorStatusCode !== null) {
$response = new Response();
$response->setStatusCode($returnErrorStatusCode);
}
$nLinkTypeID = $this->LINK_TYPE_ID_OTHER;
if(!$hasOther)
{
if($hasBible && !$hasSwedenborg)
{
$nLinkTypeID = $this->LINK_TYPE_ID_BIBLE;
}
else if(!$hasBible && $hasSwedenborg)
{
$nLinkTypeID = $this->LINK_TYPE_ID_SWEDENBORG;
}
}
$renderingData['linktype_id'] = $nLinkTypeID;
return $this->renderView('multicolumn/generic_multicolumn', $renderingData, $response);
}
protected function convertColumnData($columnDetails, $column_number, $request, $targetColumnNum = null, $renderingData = null)
{
$dataElementDetails = explode('_', strtolower($columnDetails));
$domainIndicator = array_shift($dataElementDetails);
if($domainIndicator === $this->MULTI_URL_INDICATOR_BIBLE || $domainIndicator === $this->MULTI_URL_INDICATOR_BIBLE_STORYTEXT) {
return $this->bibleColumnDataNew($columnDetails, $column_number, $request, $targetColumnNum, $renderingData);
}
else if($domainIndicator === $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK || $domainIndicator === $this->MULTI_URL_INDICATOR_EXPLANATION) {
return $this->expositionColumnDataNew($columnDetails, $column_number, $request, $targetColumnNum, $renderingData);
}
else
{
// old functions, keep them for bible stories
/* if($domainIndicator === 'b') {
return $this->bibleColumnData($dataElementDetails, $column_number, $request, $targetColumnNum, $renderingData);
}
else if($domainIndicator === 'e') {
return $this->expositionColumnData($dataElementDetails, $column_number, $request, $targetColumnNum, $renderingData);
} */
}
return $this->badColumnRequestData($columnDetails, $targetColumnNum, $renderingData);
}
protected function badColumnRequestData($columnDetails, $targetColumnNum, $renderingData)
{
$rval = array('column_type' => 'unrecognized');
$rval['errors'][] = array('code' => 404, 'message' => 'badcolumnrequest');
return $rval;
}
protected function bibleColumnData($columnSpec, $column_number, $request, $targetColumnNum = null, $renderingData = null)
{
// Possible formats:
// b_c_### (chapter by id)
// b_c_###-### (chapter range by ids)
// b_v_### (verse by ids)
// b_v_###-### (verse range by ids, possibly spanning multiple chapters)
// To use canonical numbering, replace "c" with "cc" or "v" with "cv" in the above
// b_st_### (bible text for the story with the given id)
// Canonical-numbered content (including stories) will use default or arbitrary translation; adding "_###" to the end specifies the translation ID
//echo 'ttt1:'.time();
$contentCategory = array_shift($columnSpec);
$isCanonical = $this->bibleCategoryIsCanonical[$contentCategory];
$contentIds = explode('-', array_shift($columnSpec));
$chapterExplanation = null;
$qbible_link = null;
$verses = null;
$translation = array();
$nChapterId = null;
$nVerseId = null;
$nextChapter = null;
$prevChapter = null;
$nextVerse = null;
$prevVerse = null;
$chapterStartIndex = null;
$bChapterLevel = false;
$bVerseLevel = false;
if($contentCategory === 'c' || $contentCategory === 'cc') {
$bChapterLevel = true;
$nChapterId = array_shift($contentIds);
$translation = $this->getBibleTranslationByChapter($nChapterId, $isCanonical);
$chapterRepos = $this->bibleData($isCanonical ? 'Canonical\Chapter' : 'Chapter');
$firstChapter = $chapterRepos->findOneById($nChapterId);
if($firstChapter !== null) {
$book = $firstChapter->getBook();
$chapterStartIndex = $firstChapter->getOrdering();
if(empty($contentIds)) {
$lastChapter = null;
$chapterEndIndex = null;
} else {
$lastChapter = $chapterRepos->findOneById(array_shift($contentIds));
$chapterEndIndex = $lastChapter->getOrdering();
}
} else {
return array();
/* $book = null;
$lastChapter = null;
$chapterStartIndex = null;
$chapterEndIndex = null; */
}
$verseStartIndex = null;
$verseEndIndex = null;
$rangeStart = $firstChapter;
$rangeEnd = $lastChapter;
if($chapterExplanation == null && !empty($translation))
{
// get chapter explanation
$chapterExplanation = $this->getChapterExplanation($translation['chapter_id'], $translation['url'], $request);
$nextChapter = $this->getNextChapter($nChapterId);
$prevChapter = $this->getPreviousChapter($nChapterId);
}
} elseif($contentCategory === 'v' || $contentCategory === 'cv' || $contentCategory === 'st') {
if($contentCategory === 'st') {
$storyId = array_shift($contentIds);
if(empty($storyId)) {
$story = null;
$firstVerse = null;
$lastVerse = null;
} else {
$story = $this->bibleData('Stories\Story')->findOneBy(array('id' => $storyId, 'level_id' => $this->STORY_LEVEL_ID_BIBLE, 'isPublic' => true));
if($story === null) {
$firstVerse = null;
$lastVerse = null;
} else {
$firstVerse = $story->getStartVerse();
$lastVerse = $story->getEndVerse();
}
}
} else {
$bVerseLevel = false;
$verseRepos = $this->bibleData($isCanonical ? 'Canonical\Verse' : 'Verse');
$nVerseId = array_shift($contentIds);
$firstVerse = $verseRepos->findOneById($nVerseId);
$lastVerse = empty($contentIds) ? null : $verseRepos->findOneById(array_shift($contentIds));
if(!$isCanonical) {
if($firstVerse !== null) {
$firstVerse = $firstVerse->findMainVerse();
}
if($lastVerse !== null) {
$lastVerse = $lastVerse->findMainVerse();
}
if($chapterExplanation == null)
{
$firstChapter = $firstVerse->getChapter();
$nChapterId = $firstChapter->getCanonicalization()->getId();
$nextChapter = $this->getNextChapter($firstChapter->getId());
$prevChapter = $this->getPreviousChapter($firstChapter->getId());
}
}
if($nVerseId != null && $nVerseId != '')
{
$nextVerse = $this->getNextVerse($nVerseId);
$prevVerse = $this->getPreviousVerse($nVerseId);
}
}
if($firstVerse !== null) {
$firstChapter = $firstVerse->getChapter();
$book = $firstChapter->getBook();
$chapterStartIndex = $firstChapter->getOrdering();
$verseStartIndex = $contentCategory === 'v' ? $firstVerse->getIndexDisplay() : $firstVerse->getOrdering();
if($lastVerse === null) {
$chapterEndIndex = null;
$verseEndIndex = null;
} else {
$chapterEndIndex = $lastVerse->getChapter()->getOrdering();
$verseEndIndex = $contentCategory === 'v' ? $lastVerse->getIndexDisplay() : $lastVerse->getOrdering();
}
} else {
$book = null;
$chapterStartIndex = null;
$verseStartIndex = null;
$chapterEndIndex = null;
$verseEndIndex = null;
}
$rangeStart = $firstVerse;
$rangeEnd = $lastVerse;
}
$nNewBookID = null;
$nTranslationID = null;
// If canonical, convert to translation
if($contentCategory === 'cc' || $contentCategory === 'cv' || $contentCategory === 'st') {
if(empty($columnSpec)) {
// default or arbitrary translation
// TODO: Select language-default translation for current or default language, or use last viewed translation
$nLanguageID = null;
if($this->language1 !== null)
$nLanguageID = $this->language1->getId();
if($book != null)
{
$translation = $this->getBibleTranslationByCanonBookID($book->getId(), $nLanguageID);
if(empty($translation))
$translation = $this->getBibleTranslationByUrl($book->getTranslation()->getUrl(), $nLanguageID); }
else
{
if($nLanguageID != null)
$translation = $this->getBibleTranslationByLanguage($nLanguageID);
else
$translation = $this->getBibleTranslationByUrl($this->DEFAULT_BIBLE_VERSION);
}
} else {
// translation ID provided, use that
$nTranslationID = array_shift($columnSpec);
if($book != null)
{
$translation = $this->getBibleTranslation($nTranslationID, $book->getId());
if(empty($translation))
{
$newbook = $this->getFirstCBook($nTranslationID);
if(!empty($newbook))
$nNewBookID = $newbook['id'];
$chapterStartIndex = 1;
$chapterEndIndex=null;
$verseStartIndex=null;
$verseEndIndex=null;
}
}
else
$translation = $this->getBibleTranslationByID($nTranslationID);
}
// $verses = DataAssembly::decanonicalizeSpan($this->getManager(), $translation['id'], $verses);
} else {
// If not canonical, get translation from book so we know what language to use for referring Swedenborg passages
// (and so we can pass the translation to the template without having to first check whether we've defined it already)
$nLanguageID = null;
if($this->language1 !== null)
$nLanguageID = $this->language1->getId();
if($book != null)
{
$translation = $this->getBibleTranslationByBookID($book->getId(), $nLanguageID);
if(empty($translation))
$translation = $this->getBibleTranslationByUrl($book->getTranslation()->getUrl(), $nLanguageID);
}
else
{
if($nLanguageID != null)
$translation = $this->getBibleTranslationByLanguage($nLanguageID);
}
}
$sStoryTranslationUrl = null;
if($contentCategory === 'st' && isset($translation['url']))
{
$sStoryTranslationUrl = $translation['url'];
}
$book2 = null;
if($book !== null) {
if($isCanonical)
{
if(!empty($translation))
$book2 = $this->bibleData('Book')->getBookFromCanon($book->getId(), $translation['id']);
else
{
if($nNewBookID != null)
$book2 = $this->bibleData('Book')->getBookFromCanon($nNewBookID, $nTranslationID);
}
}
else
$book2 = $book;
$aCheck = $this->checkBookInfo($book2->getId(), $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
if($chapterStartIndex != null && isset($aCheck['chapterStartIndex']))
$chapterStartIndex = $aCheck['chapterStartIndex'];
if($chapterEndIndex != null && isset($aCheck['chapterEndIndex']))
$chapterEndIndex = $aCheck['chapterEndIndex'];
if($verseStartIndex != null && isset($aCheck['verseStartIndex']))
$verseStartIndex = $aCheck['verseStartIndex'];
if($verseEndIndex != null && isset($aCheck['verseEndIndex']))
$verseEndIndex = $aCheck['verseEndIndex'];
$verses = DataAssembly::getVerseRangeFromBook($book2, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
} else {
$verses = array();
}
// To switch translations, we'll use either the 'b_st_###_###' pattern (for stories),
// the 'b_cc_###_###' or 'b_cc_###-###_###' patterns (if we were given a canonical chapter specification),
// or the corresponding 'b_cv_...' patterns (if we were given canonical verses or non-canonical content).
// The "translate pattern" represents everything except the translation ID that needs to get attached to the end (to make things easier in Twig)
$translatePattern = 'b_';
if($contentCategory === 'cc') {
$translatePattern .= 'cc_'.$firstChapter->getId();
if($lastChapter !== null) {
$translatePattern .= '-'.$lastChapter->getId();
}
} elseif($contentCategory === 'st') {
if($story === null) {
$translatePattern = null;
} else {
$translatePattern .= 'st_'.$story->getId();
}
} else {
// get IDs for first and last canonical verses, build pattern similarly
if($contentCategory === 'cv' || $contentCategory === 'st') {
// We used canonical verses in the first place
$firstCanonicalVerse = $firstVerse;
$lastCanonicalVerse = $lastVerse;
} else {
// We used translation-specific verses; need to find first and last canonical verses
$canonicalVerses = DataAssembly::canonicalize($verses);
if(empty($canonicalVerses)) {
$firstCanonicalVerse = null;
$lastCanonicalVerse = null;
} else {
$firstCanonicalChapterVerses = reset($canonicalVerses);
$firstCanonicalVerse = reset($firstCanonicalChapterVerses);
$lastCanonicalChapterVerses = end($canonicalVerses);
$lastCanonicalVerse = end($lastCanonicalChapterVerses);
}
}
if($firstCanonicalVerse !== null) {
$translatePattern .= 'cv_'.$firstCanonicalVerse->getId();
if($lastCanonicalVerse !== null && $lastCanonicalVerse !== $firstCanonicalVerse) {
$translatePattern .= '-'.$lastCanonicalVerse->getId();
}
} else {
// No good way to handle the case where there is no known content, but we have to do something ...
// Setting $translatePattern to null will make it fall into the default case below
$translatePattern = null;
}
}
if($translatePattern !== null) {
$translatePattern .= '_';
} else {
// If we have too little information about the intended content to even be able to convert translations, then we'll redirect to Genesis 1
// $gen1 = $this->bibleData('Canonical\Book')->findOneByUrl('genesis')->getChapters()->first();
$gen1 = $this->getFirstCanonicalBibleChapterID('genesis');
$translatePattern = 'b_cc_'.$gen1.'_';
}
$expositionRefTranslationMap = array();
$allVerses = array_reduce($verses, 'array_merge', array());
$aVerseInfo = $this->getVerseInfo($allVerses);
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array(), true);
// $otle_ref = $aOTLE['otle_nonmusic'];
$otle_ref_music = $aOTLE['otle_music'];
$nChapterNum = current($allVerses)->getChapter()->getOrdering();
// $book_list = array();
if(empty($translation) && !empty($allVerses))
$translation = $this->getBibleTranslationByChapter(current($allVerses)->getChapter()->getId(), false);
if (empty($translation)) {
$right_to_left = False;
} else {
$right_to_left = $translation['righttoleft'];
// $book_list = $this->getBibleBookListForMultiColumn($translation['id']);
}
if($book !== null && $firstChapter !== null && $verses !== null)
$qbible_link = $this->getQBibleUrl($book, $firstChapter, $verses, $isCanonical);
//$verseExplanations = DataAssembly::filterExplainedVerses($verses, $this->getManager());
$verseExplanations = $this->getFirstExplainedVerse($aVerseInfo, $request);
$bible_column_spec = '';
if($bChapterLevel || $bVerseLevel)
$bible_column_spec = $columnSpec;
else
{
$bible_column_spec = $this->getBibleMultiColumnSpec($translation['url'], $book->getUrl(), $chapterStartIndex, $verseStartIndex, $verseEndIndex);
}
$rval = array(
'column_type' => 'bible',
'content_category' => $contentCategory,
'canonically_numbered' => $isCanonical,
'book' => $book,
'translation' => $translation,
'contents' => $verses,
'content_start_bound' => $rangeStart,
'content_end_bound' => $rangeEnd,
'translate_pattern' => $translatePattern,
'has_slider_item' => $bHasSliderItem,
// 'referring_passages' => $referringPassages,
// 'core_passages' => $corePassages,
'verses_concept' => $this->getVerseContentWithConceptLinks($request, $allVerses, $bible_column_spec, $column_number),
'right_to_left' => $right_to_left,
'prev_chapter' => $prevChapter,
'next_chapter' => $nextChapter,
'prev_verse' => $prevVerse,
'next_verse' => $nextVerse,
'chapter_explanation' => $chapterExplanation,
'explained_verse' => $verseExplanations,
'qbible_link' => $qbible_link,
// 'book_list' => $book_list,
'story_translation_url' => $sStoryTranslationUrl,
'chapter_id' => $nChapterId,
'verse_id' => $nVerseId,
'otle_ref_music' => $otle_ref_music
);
if(!empty($chapterExplanation))
{
$nTransID = current($chapterExplanation)['translation_id'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$rval['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$rval['explanation_translation'] = $explanation_translation;
$rval['explanation_passage'] = $passage;
$rval['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$rval['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$chapterData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$rval['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$rval['explanation_col1_ref'] = $this->MULTI_URL_INDICATOR_BIBLE . "_" . $translation['url'] . "_" . $book->getUrl(). "_" . $chapterStartIndex;
$rval['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$rval['explanation_cchapter_id'] = $nCChapterID;
$rval['explanation_translation_id'] = $nTransID;
}
}
}
}
if($book != null)
{
$nBookID = null;
if($isCanonical)
$nBookID = $book->getId();
else
$nBookID = $book->getCanonicalization()->getId();
$rval['translations_by_language'] = $this->getAllBibleTranslationsByLanguage($nBookID, $nChapterNum);
$rval['book_url'] = $book->getUrl();
$rval['chapter_order'] = $chapterStartIndex;
$rval['chapter_index'] = $chapterStartIndex;
}
if($contentCategory === 'st') {
$rval['story'] = $story;
$rval['multi_story_column'] = '1';
} else {
// $rval['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
}
if(count($verses) === 0) {
$rval['errors'][] = array('code' => 404, 'message' => 'translationmismatch.bible');
}
if($translation != null)
{
$msgData = $this->checkBibleTranslationMsg($translation['url']);
if(!empty($msgData))
{
$rval['contents'] = null;
$rval['no_content_msg'] = $msgData['no_content_msg'];
}
$rval['text_style_override'] = $this->getTextStyleOverride($translation['language_id']);
$rval['text_to_speech'] = $this->getTextToSpeech($translation['language_id']);
$rval['translation_url'] = $translation['url'];
}
return $rval;
}
protected function expositionColumnData($columnSpec, $column_number, $request, $targetColumnNum = null, $renderingData = null)
{
// Possible formats:
// e_### (passage by id)
// e_###_### (first number is passage id, second number is translation id)
// e_w_### (first passage of work with given id)
// e_t_### (first passage of translation with given id)
// e_w_###_### (first number is id of a swedenborg work, second is section number -- use this to allow client-side generation of URLs for arbitrary Swedenborg sections)
// e_t_###_### (as above, but first number is id of a specific translation)
// e_xb_# (show explanation, if any, of the Bible story/verse/chapter in the specified column, e.g. e_ex_1 to show explanation)
// e_xb_#_### (as above, but if that column doesn't show explained Bible content, then use the ExpositionTranslation whose ID is the second number)
$locale = $request->getLocale();
$rval = array('column_type' => 'exposition');
$discriminator = array_shift($columnSpec);
$work = null;
$bSwedenborgWork = false;
if($discriminator === 'w' || $discriminator === 't') {
// Find specified work or translation
if($discriminator === 't') {
$rval['lock_translation'] = true;
$rval['translation'] = $this->expositionData('Translation')->findOneBy(array('id' => array_shift($columnSpec), 'isPublic' => true, 'type_id' => $this->TRANSLATION_TYPE_ID_TEXT));
if($rval['translation'] != null) {
$work = $rval['translation']->getWork();
}
else
return array();
} else {
$work = $this->expositionData('Work')->findOneBy(array('id' => array_shift($columnSpec), 'isPublic' => true));
if($work == null)
return array();
else
$rval['translation'] = $work->selectTranslation();
}
if(empty($columnSpec)) {
// No section number specified; use first passage
$rval['passage'] = $work->findFirstPassage();
} else {
// Swedenborg section number specified
if($work->getSwedenborgType() === null) {
$rval['errors'][] = array('code' => 404, 'message' => 'notswedenborg');
return $rval;
}
$sectionNum = array_shift($columnSpec);
$rval['passage'] = $this->expositionData('Passage')->findSwedenborgSection($work, $sectionNum);
if($rval['passage'] === null) {
$rval['passage'] = (intval($sectionNum) <= 1) ? $work->findFirstPassage() : $work->findLastPassage();
}
}
$bSwedenborgWork = ($work->getSwedenborgType() !== null);
if(!$bSwedenborgWork)
$rval['authors'] = $this->getAuthorInfo($request, $rval['translation']->getId());
else
$rval['IsSwedenborgWork'] = 1;
} elseif($discriminator === 'xb') {
$dependentColumnNum = array_shift($columnSpec);
if($renderingData === null) {
// Start by listing no dependencies, then add a dependency for the appropriate column
// (this way we don't have to make sure not to set the wrong dependency to 'none')
$dependencies = array(1 => 'none', 2 => 'none', 3 => 'none');
if(!array_key_exists($dependentColumnNum, $dependencies)) {
throw $this->createNotFoundException('Invalid column specification: Dependency on nonexistent column number "'.$dependentColumnNum.'"');
}
$dependencies[$dependentColumnNum] = empty($columnSpec) ? 'required' : 'optional';
return array('column_type' => 'dependent', 'depends_on' => $dependencies, 'final_column_type' => 'exposition');
}
if(!array_key_exists($dependentColumnNum, $renderingData['columns'])) {
throw new \Exception('Invalid column specification: Dependency on unavailable column number "'.$dependentColumnNum.'"');
}
$dependentColumnData = $renderingData['columns'][$dependentColumnNum];
if($dependentColumnData['column_type'] !== 'bible') {
// If the column this depends on doesn't have Bible content, then we need a fallback in order to display anything
if(empty($columnSpec)) {
throw $this->createNotFoundException('Invalid column specification: Target column does not contain required content type');
}
$fallbackId = array_shift($columnSpec);
$rval['translation'] = $this->expositionData('Translation')->findOneBy(array('id' => $fallbackId, 'isPublic' => true, 'type_id' => $this->TRANSLATION_TYPE_ID_TEXT));
if($rval['translation'] == null) {
$rval['errors'][] = array('code' => 404, 'message' => 'generic.alert.404');
return $rval;
}
else
{
$work = $rval['translation']->getWork();
$rval['passage'] = $work->findFirstPassage();
$rval['lock_translation'] = true;
$rval['authors'] = $this->getAuthorInfo($request, $rval['translation']->getId());
}
return $rval;
}
$explanationOptions = array();
$firstExplanationID = null;
if(isset($dependentColumnData['story'])) {
$explanationOptions = $dependentColumnData['story']->getExplanations()->toArray();
$firstExplanationID = $this->getFirstExplanationID($dependentColumnData['story']->getId());
} elseif(array_key_exists('story', $dependentColumnData)) {
// Should happen if a nonexistent story is requested
$explanationOptions = array();
} else {
// Try to find a Story entity associated with the content being displayed (most likely a verse or chapter?)
$bibleContent = $dependentColumnData['contents'];
$firstBibleChapterContents = reset($bibleContent);
$firstBibleVerse = $firstBibleChapterContents ? reset($firstBibleChapterContents) : null;
if(count($bibleContent) === 1 && count($firstBibleChapterContents) === 1) {
$verseStories = DataAssembly::findVerseStories($firstBibleVerse, $this->getManager());
foreach($verseStories as $story) {
$explanationOptions = array_merge($explanationOptions, $story->getExplanations()->toArray());
}
} else {
// TODO: If we're showing a whole chapter, then we should show chapter explanations once we have them
// TODO: If the text we're showing happens to line up exactly with a story, then we should show an explanation for that story
}
}
if(empty($explanationOptions)) {
// If no explanation available, show fallback content; if no fallback, show "no explanation available" message
if(empty($columnSpec)) {
$rval['errors'][] = array('code' => 404, 'message' => 'noexplanation');
return $rval;
}
$fallbackId = array_shift($columnSpec);
$rval['translation'] = $this->expositionData('Translation')->findOneBy(array('id' => $fallbackId, 'isPublic' => true, 'type_id' => $this->TRANSLATION_TYPE_ID_TEXT));
if($rval['translation'] == null) {
$rval['errors'][] = array('code' => 404, 'message' => 'generic.alert.404');
return $rval;
}
else
{
$work = $rval['translation']->getWork();
$rval['passage'] = $work->findFirstPassage();
$rval['lock_translation'] = true;
$rval['authors'] = $this->getAuthorInfo($request, $rval['translation']->getId());
}
return $rval;
} else {
$explanation = $this->getFirstExplanation($explanationOptions, $firstExplanationID);
$rval['passage'] = $explanation->findFirstPassage();
$rval['translation'] = $explanation->selectTranslation();
if($rval['translation'] == null) {
$rval['errors'][] = array('code' => 404, 'message' => 'generic.alert.404');
return $rval;
}
else
{
$rval['column_uri_override'] = 'e_xb_'.$dependentColumnNum.'_'.$rval['translation']->getId();
$rval['authors'] = $this->getAuthorInfo($request, $rval['translation']->getId());
}
}
} else { // $discriminator isn't 'w' or 't' or 'xb'
// We should normally be able to reach this point only if $discriminator is a numeral
$rval['passage'] = $this->expositionData('Passage')->findOneById($discriminator);
if($rval['passage'] == null) {
$rval['errors'][] = array('code' => 404, 'message' => 'generic.alert.404');
return $rval;
}
if(empty($columnSpec)) {
$work = $rval['passage']->findWork();
$rval['translation'] = $work->selectTranslation();
} else {
$rval['lock_translation'] = true;
$rval['translation'] = $this->expositionData('Translation')->findOneById(array_shift($columnSpec));
if($rval['translation'] == null) {
$rval['errors'][] = array('code' => 404, 'message' => 'generic.alert.404');
return $rval;
}
if($rval['translation']->getWork() != $rval['passage']->findWork()) {
$rval['errors'][] = array('code' => 404, 'message' => 'translationmismatch.exposition');
return $rval;
}
else
$work = $rval['passage']->findWork();
}
if($work != null)
{
$bSwedenborgWork = ($work->getSwedenborgType() !== null);
if(!$bSwedenborgWork)
$rval['authors'] = $this->getAuthorInfo($request, $rval['translation']->getId());
else
$rval['IsSwedenborgWork'] = 1;
}
}
$bCheckTrans = ($this->language1 == null);
if($bCheckTrans)
{
$this->language1 = $rval['translation']->getLanguage();
$this->work1 = $work;
}
if($work !== null && !$bSwedenborgWork) {
// get concept illustrations
$sConceptUrl = $this->getConceptUrl($work->getId());
if($sConceptUrl != '')
{
$sWorkUrl = $work->getUrl();
$concept = $this->getRepository('Concepts\Concept')->findOneByUrl($sWorkUrl);
if($concept !== null) {
$illustrations = $concept->getIllustrations();
$rval['image'] = ($illustrations->isEmpty()) ? null : $illustrations[0]->getImage();
}
}
$bConsider = false;
$bBibleStudy = false;
foreach($work->getCategories() as $category) {
if($category->getId() == 13) {
$bConsider = true;
}
if($category->getId() == 14) {
$bBibleStudy = true;
}
}
if($bConsider)
{
$rval['consider_data'] = $this->getConsiderList($locale);
}
if($bBibleStudy)
{
$rval['biblestudy_data'] = $this->getBibleStudyList($locale);
}
}
if($rval['translation'] != null)
{
$nLanguageID = $rval['translation']->getLanguage()->getId();
$rval['text_style_override'] = $this->getTextStyleOverride($nLanguageID);
$ref_column_spec = '';
if($rval['translation']->getWork()->getSwedenborgType() !== null)
$ref_column_spec = $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK;
else
$ref_column_spec = $this->MULTI_URL_INDICATOR_EXPLANATION;
$ref_column_spec .= '_' . $rval['translation']->getUrl();
if(isset($rval['passage']) && $rval['passage'] != null && $rval['translation']->getWork()->getSwedenborgType() !== null)
$ref_column_spec .= '_' . $rval['passage']->getSwedenborgSection();
$rval['ref_column_spec'] = $ref_column_spec;
$rval['text_to_speech'] = $this->getTextToSpeech($nLanguageID);
$rval['translation_url'] = $rval['translation']->getUrl();
}
if($rval['translation'] != null && $rval['passage'] != null)
{
$rval['previous_passage'] = $this->getPreviousPassageWithContent($rval['passage'], $rval['translation']);
$rval['next_passage'] = $this->getNextPassageWithContent($rval['passage'], $rval['translation']);
if($bSwedenborgWork)
$rval['related_bible_ref'] = $this->getRelatedBibleRefForWork($rval['passage']->getId(),$rval['translation']->getId(), $request);
else
$rval['passage_ref'] = $this->getWorkPassageRefs($rval['passage']->getId(),$rval['translation']->getId(), $request);
$rval['passage_footnote'] = $this->getPassageFootnotes($rval['passage']->getId(),$rval['translation']->getId());
$rval['passage_multilink'] = $this->getWorkPassageMultiLink($rval['passage']->getId(),$rval['translation']->getId(), $request);
if($rval['translation']->getLanguage()->getId() == $this->LANGUAGE_ID_LATIN)
{
$rval['passage_scanimage'] = $this->getWorkPassageScanImageFileName($rval['passage']->getId());
$rval['define_latin_icon'] = 1;
}
}
return $rval;
}
public function storyExplanationAction($storyUrl, Request $request, $bibleTranslationUrl = null, $commentaryUrl = null)
{
$locale = $request->getLocale();
$response = null;
$story = $this->bibleData('Stories\Story')->findOneBy(array('url' =>$storyUrl, 'level_id' => $this->STORY_LEVEL_ID_BIBLE, 'isPublic' => true));
if($story==null)
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
if($locale != 'en')
{
$sStoryName = $this->getBibleStoryName($story->getId(), $locale);
if(!empty($sStoryName))
$story->setName($sStoryName);
}
$sCommentaryUrl = $commentaryUrl;
if($sCommentaryUrl == null)
{
$sCommentaryUrl = $this->getCommentaryUrl($story->getId(), $bibleTranslationUrl);
}
else
{
$sCommentaryUrl = $this->getPublicCommentaryUrl($story->getId(), $commentaryUrl);
}
if($sCommentaryUrl == '')
{
$response = new Response();
$response->setStatusCode(404);
return $this->renderView('no_content_back', array(), $response);
}
$renderingData = array('route_story' => $story);
$renderingData['commentary_url_from_link'] = $commentaryUrl;
$storySpec = $this->MULTI_URL_INDICATOR_BIBLE_STORYTEXT . '_' . $story->getUrl();
$renderingData['right_to_left'] = False;
if($bibleTranslationUrl !== null) {
if($bibleTranslationUrl !== $this->DEFAULT_BIBLE_VERSION)
{
// check bible translation match
$bHasBibleBookForTrans = $this->HasBibleBookForTrans($story->getId(), $bibleTranslationUrl);
if(!$bHasBibleBookForTrans)
{
$bibleTranslationUrl = $this->DEFAULT_BIBLE_VERSION;
if($commentaryUrl != null)
{
return $this->redirect($this->get('router')->generate('bible_translated_story_for_commentary', array(
'storyUrl' => $storyUrl,
'bibleTranslationUrl' => $bibleTranslationUrl,
'commentaryUrl' => $commentaryUrl
)), 301);
}
else
{
return $this->redirect($this->get('router')->generate('bible_translated_story', array(
'storyUrl' => $storyUrl,
'bibleTranslationUrl' => $bibleTranslationUrl
)), 301);
}
}
}
$bibleTranslation = $this->bibleData('Translation')->findOneBy(array('url' => $bibleTranslationUrl, 'enabled' => true));
if($bibleTranslation !== null)
{
$renderingData['route_bible_translation'] = $bibleTranslation;
$storySpec .= '_'.$bibleTranslation->getUrl();
$renderingData['right_to_left'] = $bibleTranslation->getLanguage()->getRightToLeft();
}
}
$renderingData['content_class'] = 'story';
$explanationSpec = $this->MULTI_URL_INDICATOR_EXPLANATION . '_' . $sCommentaryUrl;
$this->setCurrentUrl($request);
return $this->multicolumnAction($storySpec, $explanationSpec, $request, null, $renderingData);
}
public function showExceptionAction()
{
return $this->renderView('no_content', array(), $response);
}
public function storyRedirectAction($storyUrl, Request $request)
{
$bibleTranslationUrl = $this->DEFAULT_BIBLE_VERSION;
$nBibleTransID = $request->getSession()->get('current_bible_translation_id');
if($nBibleTransID != '')
{
// $bibleTranslation = $this->getRepository('Bible\Translation')->findOneById($nBibleTransID);
// $bibleTranslationUrl = $bibleTranslation->getUrl();
$bibleTranslation = $this->getBibleTranslationByID($nBibleTransID);
$bibleTranslationUrl = $bibleTranslation['url'];
}
return $this->redirect($this->get('router')->generate('bible_translated_story', array(
'storyUrl' => $storyUrl,
'bibleTranslationUrl' => $bibleTranslationUrl
)), 301);
//return $this->redirect('/bible/story/'.$storyUrl.'/'.$bibleTranslationUrl);
}
// Anytime you are reading content that has a link to other content, if available,
// link to a translation of the new content in the same language as the content that links to it.
public function checkBibleTranslation($vTranslation, $vLanguage)
{
$ret = $this->bibleData('Translation')->findOneBy(array('language' => $vLanguage, 'enabled'=> true, 'languageDefault' => true));
if($ret == null)
$ret = $this->bibleData('Translation')->findOneBy(array('language' => $vLanguage, 'enabled' => true));
return $ret;
}
function getQBibleUrl($book, $chapter, $verses, $isCanonical)
{
if($isCanonical)
$cbook = $book;
else
$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 getFirstExplanationID($story_id)
{
$sSql = "SELECT work_id"
." FROM story_work"
." WHERE story_id = " . $story_id . " order by ordering";
$sRet = '';
$aRet = $this->getNativeQueryResults($sSql);
if(count($aRet) > 0)
$sRet = implode('', $aRet[0]);
return $sRet;
}
function getFirstExplanation($explanationOptions, $firstExplanationID)
{
$firstExplanation = null;
foreach($explanationOptions as $expanation)
{
if($expanation->getId() == $firstExplanationID)
{
$firstExplanation = $expanation;
break;
}
}
if($firstExplanation == null)
$firstExplanation = $explanationOptions[0];
return $firstExplanation;
}
protected function bibleColumnDataNew($columnDetails, $column_number, $request, $targetColumnNum = null, $renderingData = null)
{
// Old Possible formats:
// b_c_### (chapter by id)
// b_c_###-### (chapter range by ids)
// b_v_### (verse by ids)
// b_v_###-### (verse range by ids, possibly spanning multiple chapters)
// To use canonical numbering, replace "c" with "cc" or "v" with "cv" in the above
// b_st_### (bible text for the story with the given id)
// Canonical-numbered content (including stories) will use default or arbitrary translation; adding "_###" to the end specifies the translation ID
// e.g. bible_king-james-version_genesis_1_2
$dataElementDetails = explode('_', strtolower($columnDetails));
$domainIndicator = array_shift($dataElementDetails);
$columnSpec = $dataElementDetails;
//echo 'ttt1:'.time();
$chapterExplanation = null;
$qbible_link = null;
$verses = null;
$translation = array();
$nChapterId = null;
$nLastChapterId = null;
$nVerseId = null;
$isCanonical = false;
$nextChapter = null;
$prevChapter = null;
$nextVerse = null;
$prevVerse = null;
$nSpecCount = count($columnSpec);
$bChapterLevel = false;
$bVerseLevel = false;
$bStoryText = ($domainIndicator === $this->MULTI_URL_INDICATOR_BIBLE_STORYTEXT);
$aChapter = array();
$aVerse = array();
$nChapterNum = null;
$nLastChapterNum = null;
$sVerseIndex = null;
$sLastVerseIndex = null;
$sTranslationUrl = null;
$firstChapter = null;
if(!$bStoryText)
{
$bChapterLevel = ($nSpecCount == 3);
$bVerseLevel = ($nSpecCount == 4);
$sTranslationUrl = array_shift($columnSpec);
$sBookUrl = array_shift($columnSpec);
$sChapterStr = array_shift($columnSpec);
$aChapter = explode('-', $sChapterStr);
$nChapterNum = $aChapter[0];
if(count($aChapter) > 1)
{
$nLastChapterNum = $aChapter[1];
if ( $nLastChapterNum - $nChapterNum >= 3 )
$nLastChapterNum = $nChapterNum+2;
}
$nChapterIDCount = count($aChapter);
if($bVerseLevel)
{
$sVerseStr = array_shift($columnSpec);
$aVerse = explode('-', $sVerseStr);
$nVerseIDCount = count($aVerse);
$sVerseIndex = $aVerse[0];
if($nVerseIDCount > 1)
$sLastVerseIndex = $aVerse[1];
}
$nChapterId = $this->getBibleChapterID($sTranslationUrl, $sBookUrl, $nChapterNum);
if($nLastChapterNum != null)
$nLastChapterId = $this->getBibleChapterID($sTranslationUrl, $sBookUrl, $nLastChapterNum);
if($nChapterId == null)
{
$nChapterNum = 1;
$bChapterLevel = true;
$nChapterId = $this->getBibleChapterID($sTranslationUrl, $sBookUrl, $nChapterNum);
}
if($nChapterId == null)
return array();
$translation = $this->getBibleTranslationByChapter($nChapterId, $isCanonical);
}
else
{
$sStoryUrl = array_shift($columnSpec);
$sTranslationUrl = array_shift($columnSpec);
}
$contentCategory = '';
if($bStoryText)
$contentCategory = 'st';
else if ($bChapterLevel)
$contentCategory = 'c';
else
$contentCategory = 'v';
if($bChapterLevel) {
$chapterRepos = $this->bibleData($isCanonical ? 'Canonical\Chapter' : 'Chapter');
$firstChapter = $chapterRepos->findOneById($nChapterId);
$lastChapter = null;
$chapterEndIndex = null;
if($firstChapter !== null) {
$book = $firstChapter->getBook();
$chapterStartIndex = $firstChapter->getOrdering();
if($nChapterIDCount == 1 || !empty($nLastChapterId)) {
$lastChapter = null;
$chapterEndIndex = null;
} else {
// $nLastChapterNum = $aChapter[1];
// $nLastChapterId = $this->getBibleChapterID($sTranslationUrl, $sBookUrl, $nLastChapterNum);
if(!empty($nLastChapterId))
{
$lastChapter = $chapterRepos->findOneById($nLastChapterId);
$chapterEndIndex = $lastChapter->getOrdering();
}
}
} else {
$book = null;
$lastChapter = null;
$chapterStartIndex = null;
$chapterEndIndex = null;
}
$verseStartIndex = null;
$verseEndIndex = null;
$rangeStart = $firstChapter;
$rangeEnd = $lastChapter;
if($chapterExplanation == null && !empty($translation))
{
// get chapter explanation
$chapterExplanation = $this->getChapterExplanation($translation['chapter_id'], $sTranslationUrl, $request);
$nextChapter = $this->getNextChapter($nChapterId);
$prevChapter = $this->getPreviousChapter($nChapterId);
}
$nCChapterID = null;
if($isCanonical)
$nCChapterID = $firstChapter->getId();
else
{
$cchapter = $firstChapter->getCanonicalization();
if($cchapter != null)
$nCChapterID = $cchapter->getId();
}
// It's very slow, we will find a better way to do it
$nExplainChapterTranslationID = $this->getExplainChapterTranslation($nCChapterID, $this->getCurrUserID($request), $sTranslationUrl);
if($nExplainChapterTranslationID > -1)
{
if($request->getSession()->get('has_explanation_cchapter_id_temp_bible') == '1')
{
// For multi-column views, explain chapter icon is not shown
// if there are more than 1 chapter column
$request->getSession()->set('current_explanation_cchapter_id_temp_bible', '');
$request->getSession()->set('current_explanation_translation_id_temp_bible', '');
}
else
{
$request->getSession()->set('has_explanation_cchapter_id_temp_bible', '1');
$request->getSession()->set('current_explanation_cchapter_id_temp_bible', $nCChapterID);
$request->getSession()->set('current_explanation_translation_id_temp_bible', $nExplainChapterTranslationID);
}
}
} else {
if($bStoryText) {
$isCanonical = true;
if(empty($sStoryUrl)) {
$story = null;
$firstVerse = null;
$lastVerse = null;
} else {
$story = $this->bibleData('Stories\Story')->findOneBy(array('url' => $sStoryUrl, 'level_id' => $this->STORY_LEVEL_ID_BIBLE, 'isPublic' => true));
if($story === null) {
$firstVerse = null;
$lastVerse = null;
} else {
$firstVerse = $story->getStartVerse();
$lastVerse = $story->getEndVerse();
if($chapterExplanation == null && $firstVerse !== null)
{
$firstChapter = $firstVerse->getChapter();
$CChapter = $firstChapter;
if($CChapter != null)
{
$nChapterId = $CChapter->getId();
$chapterExplanation = $this->getChapterExplanation($nChapterId, $sTranslationUrl, $request);
}
$nextChapter = $this->getNextChapter($firstChapter->getId());
$prevChapter = $this->getPreviousChapter($firstChapter->getId());
}
}
}
} else {
$verseRepos = $this->bibleData($isCanonical ? 'Canonical\Verse' : 'Verse');
$nVerseId = $this->getBibleVerseID($sTranslationUrl, $sBookUrl, $nChapterNum, $sVerseIndex);
if($nVerseId == null)
{
$sTranslationUrl = $this->DEFAULT_BIBLE_VERSION;
$nVerseId = $this->getBibleVerseID($sTranslationUrl, $sBookUrl, $nChapterNum, $sVerseIndex);
}
$firstVerse = $verseRepos->findOneById($nVerseId);
$lastVerse = null;
if($sLastVerseIndex != null)
{
if($nLastChapterNum != null)
$nLastVerseId = $this->getBibleVerseID($sTranslationUrl, $sBookUrl, $nLastChapterNum, $sLastVerseIndex);
else
$nLastVerseId = $this->getBibleVerseID($sTranslationUrl, $sBookUrl, $nChapterNum, $sLastVerseIndex);
$lastVerse = $verseRepos->findOneById($nLastVerseId);
}
if(!$isCanonical) {
if($firstVerse !== null) {
$firstVerse = $firstVerse->findMainVerse();
}
if($lastVerse !== null) {
$lastVerse = $lastVerse->findMainVerse();
}
if($chapterExplanation == null && $firstVerse !== null)
{
$firstChapter = $firstVerse->getChapter();
$CChapter = $firstChapter->getCanonicalization();
if($CChapter != null)
{
$nChapterId = $CChapter->getId();
$chapterExplanation = $this->getChapterExplanation($nChapterId, $sTranslationUrl, $request);
}
$nextChapter = $this->getNextChapter($firstChapter->getId());
$prevChapter = $this->getPreviousChapter($firstChapter->getId());
}
}
if($nVerseId != null && $nVerseId != '')
{
$nextVerse = $this->getNextVerse($nVerseId);
$prevVerse = $this->getPreviousVerse($nVerseId);
}
}
if($firstVerse !== null) {
$firstChapter = $firstVerse->getChapter();
$book = $firstChapter->getBook();
$chapterStartIndex = $firstChapter->getOrdering();
$verseStartIndex = $contentCategory === 'v' ? $firstVerse->getIndexDisplay() : $firstVerse->getOrdering();
if($lastVerse === null) {
$chapterEndIndex = null;
$verseEndIndex = null;
} else {
$chapterEndIndex = $lastVerse->getChapter()->getOrdering();
$verseEndIndex = $contentCategory === 'v' ? $lastVerse->getIndexDisplay() : $lastVerse->getOrdering();
}
} else {
$book = null;
$chapterStartIndex = null;
$verseStartIndex = null;
$chapterEndIndex = null;
$verseEndIndex = null;
}
$rangeStart = $firstVerse;
$rangeEnd = $lastVerse;
}
if($bStoryText) {
if($sTranslationUrl == null) {
// default or arbitrary translation
// TODO: Select language-default translation for current or default language, or use last viewed translation
$nLanguageID = null;
if($this->language1 !== null)
$nLanguageID = $this->language1->getId();
if($book != null)
{
$translation = $this->getBibleTranslationByCanonBookID($book->getId(), $nLanguageID);
if(empty($translation))
$translation = $this->getBibleTranslationByUrl($book->getTranslation()->getUrl(), $nLanguageID); }
else
{
if($nLanguageID != null)
$translation = $this->getBibleTranslationByLanguage($nLanguageID);
else
$translation = $this->getBibleTranslationByUrl($this->DEFAULT_BIBLE_VERSION);
}
} else {
// translation ID provided, use that
$translation = $this->getBibleTranslationByUrl($sTranslationUrl);
}
if($sTranslationUrl == '')
{
$sTranslationUrl = $translation['url'];
}
}
else
{
// If not canonical, get translation from book so we know what language to use for referring Swedenborg passages
// (and so we can pass the translation to the template without having to first check whether we've defined it already)
if($sTranslationUrl != '')
$translation = $this->getBibleTranslationByUrl($sTranslationUrl);
}
$sStoryTranslationUrl = null;
if($bStoryText && isset($translation['url']))
{
$sStoryTranslationUrl = $translation['url'];
}
$curr_book = null;
if($book !== null) {
if($isCanonical)
{
$book2 = null;
if(!empty($translation) && isset($translation['id']))
$book2 = $this->bibleData('Book')->getBookFromCanon($book->getId(), $translation['id']);
if($book2 == null)
{
$book2 = $this->bibleData('Book')->getBookFromCanon($book->getId(), $this->DEFAULT_BIBLE_TRANSLATION_ID);
$sTranslationUrl = $this->DEFAULT_BIBLE_VERSION;
$translation = $this->getBibleTranslationByUrl($sTranslationUrl);
}
}
else
$book2 = $book;
$curr_book = $book2;
$aCheck = $this->checkBookInfo($book2->getId(), $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
if($chapterStartIndex != null && isset($aCheck['chapterStartIndex']))
$chapterStartIndex = $aCheck['chapterStartIndex'];
if($chapterEndIndex != null && isset($aCheck['chapterEndIndex']))
$chapterEndIndex = $aCheck['chapterEndIndex'];
if($verseStartIndex != null && isset($aCheck['verseStartIndex']))
$verseStartIndex = $aCheck['verseStartIndex'];
if($verseEndIndex != null && isset($aCheck['verseEndIndex']))
$verseEndIndex = $aCheck['verseEndIndex'];
$verses = DataAssembly::getVerseRangeFromBook($book2, $chapterStartIndex, $chapterEndIndex, $verseStartIndex, $verseEndIndex);
} else {
// $verses = array();
return array();
}
$expositionRefTranslationMap = array();
$allVerses = array_reduce($verses, 'array_merge', array());
$aTempChapter = array();
if($bChapterLevel)
$aTempChapter[] = $firstChapter;
$aVerseInfo = $this->getVerseInfo($allVerses);
$bHasSliderItem = $this->hasSliderItem($aVerseInfo, false, $request, true);
if($bHasSliderItem)
{
$sSliderUrl = "";
// echo $verseStartIndex . ";;". $verseEndIndex;
$sBookUrl = $book->getUrl();
if($bChapterLevel)
{
$sSliderUrl = $this->get('router')->generate('bible_slider_chapter', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex
));
}
elseif($bVerseLevel)
{
$sSliderUrl = $this->get('router')->generate('bible_slider_verse', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex,
'verseStartIndex' => $verseStartIndex
));
}
else if($chapterEndIndex != null && $verseStartIndex != null)
{
$sSliderUrl = $this->get('router')->generate('bible_slider_chapter_range', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterStartIndex' => $chapterStartIndex,
'chapterEndIndex' => $chapterEndIndex
));
}
else if($chapterEndIndex != null && $verseStartIndex == null)
{
$sSliderUrl = $this->get('router')->generate('bible_slider_chapter_verse_range', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterStartIndex' => $chapterStartIndex,
'chapterEndIndex' => $chapterEndIndex,
'verseStartIndex' => $verseStartIndex,
'verseEndIndex' => $verseEndIndex
));
}
else
{
$sSliderUrl = $this->get('router')->generate('bible_slider_verserange', array(
'translationUrl' => $sTranslationUrl,
'bookUrl' => $sBookUrl,
'chapterIndex' => $chapterStartIndex,
'verseStartIndex' => $verseStartIndex,
'verseEndIndex' => $verseEndIndex
));
}
}
$aOTLE = $this->getOTLERefForBible($aVerseInfo, array(), true);
// $otle_ref = $aOTLE['otle_nonmusic'];
$otle_ref_music = $aOTLE['otle_music'];
// $book_list = array();
if(empty($translation) && !empty($allVerses))
$translation = $this->getBibleTranslationByChapter($nChapterId, false);
if (empty($translation)) {
$right_to_left = False;
} else {
$right_to_left = $translation['righttoleft'];
// $book_list = $this->getBibleBookListForMultiColumn($translation['id']);
}
if($book !== null && $firstChapter !== null && $verses !== null)
$qbible_link = $this->getQBibleUrl($book, $firstChapter, $verses, $isCanonical);
if($book !== null && $firstChapter !== null)
$commentary_with_doc = $this->getCommentaryWithDocForBible($book, $firstChapter->getOrdering(), $isCanonical);
//$verseExplanations = DataAssembly::filterExplainedVerses($verses, $this->getManager());
$verseExplanations = $this->getFirstExplainedVerse($aVerseInfo, $request);
$sTranslatPattern1 = $domainIndicator . '_';
$sTranslatPattern2 = '';
if($bStoryText)
{
$sTranslatPattern1 .= $sStoryUrl . '_';
}
else
{
$sTranslatPattern2 = '_' . $nChapterNum;
if($bVerseLevel)
$sTranslatPattern2 .= '_' . $sVerseIndex;
}
$bible_column_spec = '';
if($bChapterLevel || $bVerseLevel)
$bible_column_spec = $columnDetails;
else
{
$bible_column_spec = $this->getBibleMultiColumnSpec($sTranslationUrl, $book->getUrl(), $chapterStartIndex, $verseStartIndex, $verseEndIndex);
}
$rval = array(
'column_type' => 'bible',
'content_category' => $contentCategory,
'canonically_numbered' => $isCanonical,
'book' => $book,
'curr_book' => $curr_book,
'translation' => $translation,
'contents' => $verses,
'content_start_bound' => $rangeStart,
'content_end_bound' => $rangeEnd,
'translate_pattern1' => $sTranslatPattern1,
'translate_pattern2' => $sTranslatPattern2,
'has_slider_item' => $bHasSliderItem,
'slider_url' => $sSliderUrl,
/* 'referring_passages' => $referringPassages,
'core_passages' => $corePassages, */
'verses_concept' => $this->getVerseContentWithConceptLinks($request, $allVerses, $bible_column_spec, $column_number),
'right_to_left' => $right_to_left,
'prev_chapter' => $prevChapter,
'next_chapter' => $nextChapter,
'prev_verse' => $prevVerse,
'next_verse' => $nextVerse,
'chapter_explanation' => $chapterExplanation,
'explained_verse' => $verseExplanations,
'qbible_link' => $qbible_link,
'commentary_with_doc' => $commentary_with_doc,
// 'book_list' => $book_list,
'story_translation_url' => $sStoryTranslationUrl,
'chapter_id' => $nChapterId,
'verse_id' => $nVerseId,
'otle_ref_music' => $otle_ref_music
);
if(!empty($chapterExplanation))
{
$nTransID = current($chapterExplanation)['translation_id'];
$explanation_translation = $this->expositionData('Translation')->findOneById($nTransID);
if($explanation_translation != null)
{
$passage = $explanation_translation->getWork()->findFirstNonEmptyPassage($explanation_translation);
if($passage != null)
{
$rval['explanation_text_style_override'] = $this->getTextStyleOverride($nTransID);
$rval['explanation_translation'] = $explanation_translation;
$rval['explanation_passage'] = $passage;
$rval['explanation_authors'] = $this->getAuthorInfo($request, $nTransID);
$rval['explanation_text_to_speech'] = $this->getTextToSpeech($explanation_translation->getLanguage()->getId());
$chapterData['passage_ref'] = $this->getWorkPassageRefs($passage->getId(),$nTransID, $request);
$rval['passage_multilink'] = $this->getWorkPassageMultiLink($passage->getId(),$nTransID, $request);
$rval['explanation_col1_ref'] = $columnDetails;
$rval['explanation_col2_ref'] = $this->MULTI_URL_INDICATOR_EXPLANATION . "_" . $explanation_translation->getUrl();
$nExplainChapterID = $this->getExplainChapterID($nTransID, $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
$rval['explanation_cchapter_id'] = $nExplainChapterID;
$rval['explanation_translation_id'] = $nTransID;
}
}
}
}
if($book != null)
{
$nBookID = null;
if($isCanonical)
$nBookID = $book->getId();
else
$nBookID = $book->getCanonicalization()->getId();
$rval['translations_by_language'] = $this->getBibleTranslationsByLanguageForVerses($curr_book->getCanonicalization()->getId(), current($allVerses)->getChapter()->getOrdering(), current($allVerses)->getIndexDisplay(), end($allVerses)->getChapter()->getOrdering(), end($allVerses)->getIndexDisplay());
$rval['cbook_id'] = $curr_book->getCanonicalization()->getId();
$rval['verse_start_index'] = current($allVerses)->getIndexDisplay();
$rval['chapter_end_order'] = end($allVerses)->getChapter()->getOrdering();
$rval['verse_end_index'] = end($allVerses)->getIndexDisplay();
}
if($contentCategory === 'st') {
$rval['story'] = $story;
$rval['multi_story_column'] = '1';
} else {
// $rval['verse_story'] = $this->getStoriesForVerses($aVerseInfo, $request);
}
/* if(count($verses) === 0) {
$rval['errors'][] = array('code' => 404, 'message' => 'translationmismatch.bible');
} */
if($translation != null)
{
$msgData = $this->checkBibleTranslationMsg($translation['url']);
if(!empty($msgData))
{
$rval['contents'] = null;
$rval['no_content_msg'] = $msgData['no_content_msg'];
}
$rval['text_style_override'] = $this->getTextStyleOverride($translation['language_id']);
$rval['text_to_speech'] = $this->getTextToSpeech($translation['language_id']);
$rval['bible_credit'] = $this->getBibleTranslationCredit($translation['url']);
$rval['translation_url'] = $translation['url'];
$rval['book_url'] = $book->getUrl();
$rval['chapter_order'] = $chapterStartIndex;
$rval['chapter_index'] = $chapterStartIndex;
$rval['hide_highlights'] = !$this->showBibleHighlights($translation['language_id']);
$rval['translation_name'] = $translation['name'];
}
if($bVerseLevel)
{
// get meta description
$nTextLength = 140;
$sVerseContent = current($allVerses)->getContent();
$sMetaDesc = $this->fixVerseText($sVerseContent);
$sMetaDesc = $this->getTextWithinLength($sMetaDesc, $nTextLength, "...");
$rval['verse_meta_desc'] = $sMetaDesc;
}
return $rval;
}
protected function expositionColumnDataNew($columnDetails, $column_number, $request, $targetColumnNum = null, $renderingData = null)
{
// Old Possible formats:
// e_### (passage by id)
// e_###_### (first number is passage id, second number is translation id)
// e_w_### (first passage of work with given id)
// e_t_### (first passage of translation with given id)
// e_w_###_### (first number is id of a swedenborg work, second is section number -- use this to allow client-side generation of URLs for arbitrary Swedenborg sections)
// e_t_###_### (as above, but first number is id of a specific translation)
// e_xb_# (show explanation, if any, of the Bible story/verse/chapter in the specified column, e.g. e_ex_1 to show explanation)
// e_xb_#_### (as above, but if that column doesn't show explained Bible content, then use the ExpositionTranslation whose ID is the second number)
// new link e.g. swedenborg_divine-love-and-wisdom-dole_10
// explanation_angels
$bOnMobile = $this->isOnMobile();
$locale = $request->getLocale();
$dataElementDetails = explode('_', strtolower($columnDetails));
$domainIndicator = array_shift($dataElementDetails);
$columnSpec = $dataElementDetails;
$rval = array('column_type' => 'exposition');
$nSpecCount = count($columnSpec);
$bSwedenborgWork = ($domainIndicator === $this->MULTI_URL_INDICATOR_SWEDENBORG_WORK);
$sTranslationUrl = array_shift($columnSpec);
$work = null;
// Find specified work or translation
$rval['lock_translation'] = true;
$rval['translation'] = $this->expositionData('Translation')->findOneBy(array('url' => $sTranslationUrl, 'isPublic' => true, 'type_id' => $this->TRANSLATION_TYPE_ID_TEXT));
if($rval['translation'] != null) {
$work = $rval['translation']->getWork();
}
else
return array();
$rval['is_swedenborg'] = $bSwedenborgWork;
if(empty($columnSpec) || !$bSwedenborgWork) {
// No section number specified; use first passage
$rval['passage'] = $work->findFirstNonEmptyPassage($rval['translation']);
} else {
if($bSwedenborgWork)
{
// Swedenborg section number specified
if($work == null || $work->getSwedenborgType() === null) {
$rval['errors'][] = array('code' => 404, 'message' => 'notswedenborg');
return $rval;
}
$sectionNum = array_shift($columnSpec);
$rval['passage'] = $this->expositionData('Passage')->findSwedenborgSection($work, $sectionNum);
if($rval['passage'] === null) {
$rval['passage'] = (intval($sectionNum) <= 1) ? $work->findFirstNonEmptyPassage($rval['translation']) : $work->findLastPassage();
}
}
}
if($rval['passage'] == null) {
return array();
}
if(!$bSwedenborgWork)
$rval['authors'] = $this->getAuthorInfo($request, $rval['translation']->getId());
else
$rval['IsSwedenborgWork'] = 1;
$bCheckTrans = ($this->language1 == null);
if($bCheckTrans)
{
$this->language1 = $rval['translation']->getLanguage();
$this->work1 = $work;
}
if($work !== null && !$bSwedenborgWork) {
// get concept illustrations
$sConceptUrl = $this->getConceptUrl($work->getId());
if($sConceptUrl != '')
{
$concept = $this->getRepository('Concepts\Concept')->findOneByUrl($sConceptUrl);
if($concept !== null) {
$illustrations = $concept->getIllustrations();
$rval['image'] = ($illustrations->isEmpty()) ? null : $illustrations[0]->getImage();
$rval['concept_prev_next'] = $this->getNextPrevConceptUrl($rval['translation']->getId(), $rval['translation']->getLanguage()->getId(), $locale);
}
}
$bConsider = false;
$bBibleStudy = false;
foreach($work->getCategories() as $category) {
if($category->getId() == 13) {
$bConsider = true;
}
if($category->getId() == 14) {
$bBibleStudy = true;
}
}
if($bConsider)
{
$rval['consider_data'] = $this->getConsiderList($locale);
}
if($bBibleStudy)
{
$rval['biblestudy_data'] = $this->getBibleStudyList($locale);
}
}
if($rval['translation'] != null)
{
$nLanguageID = $rval['translation']->getLanguage()->getId();
$rval['text_style_override'] = $this->getTextStyleOverride($nLanguageID);
$rval['ref_column_spec'] = $columnDetails;
$rval['text_to_speech'] = $this->getTextToSpeech($nLanguageID);
if($bSwedenborgWork)
$rval['biblio_info'] = $this->getBiblioForTranslation($rval['translation']->getId());
else
{
$nExplainChapterID = $this->getExplainChapterID($rval['translation']->getId(), $this->getCurrUserID($request));
if(!empty($nExplainChapterID))
{
if($request->getSession()->get('has_explanation_cchapter_id_temp_trans') == '1')
{
// For multi-column views, explain chapter icon is not shown
// if there are more than 1 chapter column
$request->getSession()->set('current_explanation_cchapter_id_temp_trans', '');
$request->getSession()->set('current_explanation_translation_id_temp_trans', '');
}
else
{
$request->getSession()->set('has_explanation_cchapter_id_temp_trans', '1');
$request->getSession()->set('current_explanation_cchapter_id_temp_trans', $nExplainChapterID);
$request->getSession()->set('current_explanation_translation_id_temp_trans', $rval['translation']->getId());
}
}
}
}
if($rval['translation'] != null && $rval['passage'] != null)
{
$nPassageID = $rval['passage']->getId();
$nTransID = $rval['translation']->getId();
$nLanguageID = $rval['translation']->getLanguage()->getId();
$rval['previous_passage'] = $this->getPreviousPassageWithContent($rval['passage'], $rval['translation']);
$rval['next_passage'] = $this->getNextPassageWithContent($rval['passage'], $rval['translation']);
$rval['translation_shortname'] = $this->getWorkTranslationShortName($nTransID);
if($bSwedenborgWork)
$rval['related_bible_ref'] = $this->getRelatedBibleRefForWork($nPassageID,$nTransID, $request);
else
{
if(!$bOnMobile)
$rval['passage_ref'] = $this->getWorkPassageRefs($nPassageID,$nTransID, $request);
}
$rval['passage_footnote'] = $this->getPassageFootnotes($nPassageID,$nTransID);
$rval['passage_multilink'] = $this->getWorkPassageMultiLink($nPassageID,$nTransID, $request);
if($nLanguageID == $this->LANGUAGE_ID_LATIN)
{
$rval['passage_scanimage'] = $this->getWorkPassageScanImageFileName($nPassageID);
$rval['define_latin_icon'] = 1;
}
if($bSwedenborgWork)
{
$bHasSliderItem = $this->hasSliderItemForWork($nPassageID, $nTransID, $request, $nLanguageID);
$rval['has_slider_item_for_work'] = $bHasSliderItem;
if($bHasSliderItem)
{
$rval['slider_url'] = $this->get('router')->generate('exposition_slider', array(
'translationId' => $nTransID,
'passageId' => $nPassageID
));
}
if($rval['passage']->emptyInTranslation($rval['translation']))
{
$rval['last_passage_num'] = $this->getLastAvailablePassageNum($nTransID);
}
}
$rval['translation_url'] = $rval['translation']->getUrl();
if(!$bSwedenborgWork)
{
if ($this->canEditExplanation($request))
$rval['explanation_translation_id_to_edit'] = $nTransID;
}
else if ($this->canEditWork($request))
{
$rval['work_translation_id_to_edit'] = $nTransID;
$rval['work_passage_num_to_edit'] = $rval['passage']->getSwedenborgSection();
}
// check table of contents
$aTOC = $this->getWorkTranslationTOC($nTransID, true);
if(!empty($aTOC))
{
$rval['has_work_toc'] = true;
}
}
return $rval;
}
}