Exemple #1
0
function getBibleByCode($bible_code)
{
    # Get bible object
    $bible_object = BibleQuery::create()->filterByCode($bible_code)->findOne();
    # Return bible object
    return $bible_object;
}
Exemple #2
0
 public function findOrCreateOne($bible_code, $bible_name)
 {
     # Attempt to find bible
     $bible = BibleQuery::create()->filterByCode($bible_code)->findOne();
     # Return or create bible
     if ($bible) {
         return $bible;
     } else {
         $bible = new Bible();
         $bible->setCode($bible_code)->setName($bible_name)->save();
         return $bible;
     }
 }
Exemple #3
0
function getPassageData($reference_string, $bible_code = 'kjv')
{
    # Stop if no reference string provided
    if (!$reference_string) {
        return;
    }
    # Get reference data
    $reference_data = getReferenceData($reference_string);
    # Get bible object
    $bible_object = BibleQuery::create()->filterByCode($bible_code)->findOne();
    # Get book object
    $book_object = BookQuery::create()->filterByName($reference_data['book'])->findOne();
    # Define passage data
    $passage_data = ['bible' => ['code' => ['default' => $bible_object->getCode(), 'formatted' => strtoupper($bible_object->getCode())], 'id' => $bible_object->getId(), 'name' => $bible_object->getName()], 'book' => ['id' => $book_object->getId(), 'name' => $book_object->getName()], 'chapter' => ['number' => $reference_data['chapter']], 'reference' => ['string' => $reference_string], 'verses' => $reference_data['verses']];
    # Return passage data
    return $passage_data;
}
Exemple #4
0
function find_passages($passage, $bible_code = 'KJV')
{
    # Find bible
    $bible = BibleQuery::create()->filterByCode($bible_code)->findOne();
    # Get passage data
    $passage_data = convert_passage_string($passage);
    # Find book
    $book = BookQuery::create()->filterByName($passage_data['book'])->findOne();
    # Find passages
    $passages = PassageQuery::create()->filterByBible($bible)->filterByBookId($book->getId())->filterByChapterNumber($passage_data['chapter']);
    if ($passage_data['starting_verse'] && !$passage_data['ending_verse']) {
        $passages->filterByVerseNumber($passage_data['starting_verse']);
    } elseif ($passage_data['starting_verse'] && $passage_data['ending_verse']) {
        $passages->filterByVerseNumber(['min' => $passage_data['starting_verse'], 'max' => $passage_data['ending_verse']]);
    }
    $passages->find();
    # Handle passages
    foreach ($passages as $passage) {
        $passages_array[] = ['bible' => ['code' => $bible->getCode(), 'name' => $bible->getName()], 'book' => ['name' => $passage_data['book']], 'chapter' => ['number' => $passage_data['chapter']], 'text' => $passage->getText(), 'verse' => ['id' => $passage->getVerseId(), 'number' => $passage->getVerseNumber()]];
    }
    # Return passages
    return $passages_array;
}
Exemple #5
0
<?php

# Include autoloader
require_once 'vendor/autoload.php';
# Include config
require_once 'generated-conf/config.php';
# Find or create bible
$bible = BibleQuery::create()->findOrCreateOne('KJV', 'King James (Authorized Version)');
# Define books and number of chapters
$books = [];
foreach ($books as $book_name => $book_chapters) {
    # Find or create book
    $book = BookQuery::create()->findOrCreateOne($book_name);
    # Import each chapter
    for ($current_chapter = 1; $current_chapter <= $book_chapters; $current_chapter++) {
        $passage = $book_name . ' ' . $current_chapter;
        $passage = str_replace(' ', '%20', $passage);
        $url = 'https://getbible.net/json?passage=' . $passage;
        $curl_object = curl_init($url);
        curl_setopt($curl_object, CURLOPT_CONNECTTIMEOUT, 0);
        curl_setopt($curl_object, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl_object, CURLOPT_TIMEOUT, 60);
        curl_setopt($curl_object, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
        $json_response = curl_exec($curl_object);
        $json_response = substr($json_response, 1, -2);
        $passage_data = json_decode($json_response);
        foreach ($passage_data->chapter as $verse_object) {
            # Create passage
            $passage = new Passage();
            $passage->setBible($bible)->setText($verse_object->verse)->setBook($book)->setChapterNumber($current_chapter)->setVerseNumber($verse_object->verse_nr)->save();
        }
<?php

require_once '../vendor/autoload.php';
require_once '../generated-conf/config.php';
$books_array = [];
$bible_object = BibleQuery::create()->filterByCode('kjv')->filterByName('King James (Authorized Version)')->findOneOrCreate();
if ($bible_object->isNew()) {
    $bible_object->save();
}
foreach ($books_array as $book_data) {
    $book_object = BookQuery::create()->filterByChapterCount($book_data['chapter_count'])->filterByName($book_data['name'])->findOneOrCreate();
    if ($book_object->isNew()) {
        $book_object->save();
    }
    for ($current_chapter = 1; $current_chapter <= $book_data['chapter_count']; $current_chapter++) {
        $passage = $book_data['name'] . ' ' . $current_chapter;
        $passage = str_replace(' ', '%20', $passage);
        $url = 'https://getbible.net/json?passage=' . $passage;
        $curl_object = curl_init($url);
        curl_setopt($curl_object, CURLOPT_CONNECTTIMEOUT, 0);
        curl_setopt($curl_object, CURLOPT_RETURNTRANSFER, true);
        curl_setopt($curl_object, CURLOPT_TIMEOUT, 60);
        curl_setopt($curl_object, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.2.12) Gecko/20101026 Firefox/3.6.12');
        $json_response = curl_exec($curl_object);
        $json_response = substr($json_response, 1, -2);
        $passage_data = json_decode($json_response);
        foreach ($passage_data->chapter as $verse_data) {
            $word_count = substr_count($verse_data->verse, ' ') + 1;
            $verse_translation_object = new VerseTranslation();
            $verse_translation_object->setBible($bible_object)->setText($verse_data->verse)->setWordCount($word_count);
            $verse_object = new Verse();