public static function assignees() { $session_logic = Session_Logic::getInstance(); $database_users = Database_Users::getInstance(); $database_bibles = Database_Bibles::getInstance(); $myuser = $session_logic->currentUser(); $mylevel = $session_logic->currentLevel(); // Bibles the user has write access to. $mybibles = array(); $bibles = $database_bibles->getBibles(); foreach ($bibles as $bible) { if (Access_Bible::write($bible, $myuser)) { $mybibles[] = $bible; } } // This holds the assignees. $assignees = array(); // Process all users. $users = $database_users->getUsers(); sort($users); foreach ($users as $user) { // Assignees should have a level less than or equal to $mylevel. $level = $database_users->getUserLevel($user); if ($level <= $mylevel) { // Assignees should have access to $mybibles or no access to any Bible. // The admin has all users assigned. $userBibles = $database_users->getBibles4User($user); $biblesInCommon = array_intersect($userBibles, $mybibles); if (!empty($biblesInCommon) || empty($userBibles) || $mylevel >= Filter_Roles::ADMIN_LEVEL) { $assignees[] = $user; } } } return $assignees; }
public static function scheduleWeb($bible) { $database_bibles = Database_Bibles::getInstance(); $books = $database_bibles->getBooks($bible); foreach ($books as $book) { Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/web.php", $bible, $book)); } }
public static function startAll() { $database_bibles = Database_Bibles::getInstance(); $bibles = $database_bibles->getBibles(); foreach ($bibles as $bible) { self::start($bible); } }
public function tearDown() { $database_bibles = Database_Bibles::getInstance(); $database_modifications = Database_Modifications::getInstance(); Filter_Client::set(false); $database_bibles->deleteBible("phpunit"); $database_modifications->truncateTeams(); Filter_Rmdir::rmdir($this->temporary_folder); }
public function tearDown() { $database_search = Database_Search::getInstance(); $database_search->create(); $database_bibles = Database_Bibles::getInstance(); $database_check = Database_Check::getInstance(); $database_bibles->deleteBible("phpunit"); $database_check->truncateOutput(""); $database_check->release(0); $database_check->release(1); $database_check->release(2); }
public function tearDown() { $database_bibles = Database_Bibles::getInstance(); $database_bibles->deleteBible("phpunit"); $database_bibles->deleteBible("phpunit2"); $database_search = Database_Search::getInstance(); $database_search->create(); $database_search->checkup(true); $database_search->deleteBook("phpunit", 1); $database_search->deleteBook("phpunit", 2); $database_search->deleteBook("phpunit", 3); }
/** * Creates book template with ID $book in Bible $bible. * If a $chapter is given instead of NULL, it creates that chapter only. */ public static function create($bible, $book, $chapter, &$feedback) { $database_bibles = Database_Bibles::getInstance(); $database_versifications = Database_Versifications::getInstance(); $database_books = Database_Books::getInstance(); $database_logs = Database_Logs::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); $bible_id = $database_bibles->getID($bible); if ($bible_id == 0) { $feedback[] = Locale_Translate::_("Bible {$bible} does not exist: Cannot create book"); return false; } if ($book == 0) { $feedback[] = Locale_Translate::_("Invalid book while creating a book template"); return false; } // The chapters that have been created. $chaptersCreated = array(); // Chapter 0. if (!isset($chapter) || $chapter == 0) { $data = "\\id " . $database_books->getUsfmFromId($book) . "\n"; $data .= "\\h " . $database_books->getEnglishFromId($book) . "\n"; $data .= "\\toc2 " . $database_books->getEnglishFromId($book) . "\n"; Bible_Logic::storeChapter($bible, $book, 0, $data); $chaptersCreated[] = 0; } // Subsequent chapters. $versification = $database_config_bible->getVersificationSystem($bible); $versification_data = $database_versifications->getBooksChaptersVerses($versification); foreach ($versification_data as $row) { if ($book == $row["book"]) { $ch = $row["chapter"]; $verse = $row["verse"]; if (!isset($chapter) || $chapter == $ch) { $data = "\\c {$ch}\n"; $data .= "\\p\n"; for ($i = 1; $i <= $verse; $i++) { $data .= "\\v {$i}\n"; } Bible_Logic::storeChapter($bible, $book, $ch, $data); $chaptersCreated[] = $ch; } } } // Done. if (count($chaptersCreated) == 0) { $feedback[] = Locale_Translate::_("No chapters have been craeted"); return false; } $chaptersCreated = implode(" ", $chaptersCreated); $feedback[] = Locale_Translate::_("The following chapters have been created:") . " " . $chaptersCreated; return true; }
public static function bibles($user = "") { $database_bibles = Database_Bibles::getInstance(); $bibles = $database_bibles->getBibles(); foreach ($bibles as $offset => $bible) { if (!self::read($bible, $user)) { unset($bibles[$offset]); } } $bibles = array_values($bibles); return $bibles; }
public static function getBible($bible) { $database_bibles = Database_Bibles::getInstance(); $books = $database_bibles->getBooks($bible); $checksum = array(); foreach ($books as $book) { $checksum[] = self::getBook($bible, $book); } $checksum = implode("", $checksum); $checksum = md5($checksum); return $checksum; }
/** * This filter produces files in USFM, html and text format. * The text files are to be used for showing the differences between them. * The files contain all verses that differ. * $bible: The Bible to go through. * $directory: The existing directory where to put the files. * Two files are created: verses_old.usfm and verses_new.usfm. * The book chapter.verse precede each verse. */ public static function produceVerseLevel($bible, $directory) { $database_bibles = Database_Bibles::getInstance(); $database_modifications = Database_Modifications::getInstance(); $database_books = Database_Books::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); $stylesheet = $database_config_bible->getExportStylesheet($bible); $old_vs_usfm = array(); $new_vs_usfm = array(); $filter_text_old = new Filter_Text($bible); $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible")); $filter_text_old->text_text = new Text_Text(); $filter_text_new = new Filter_Text($bible); $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible")); $filter_text_new->text_text = new Text_Text(); $books = $database_modifications->getTeamDiffBooks($bible); foreach ($books as $book) { $bookname = $database_books->getEnglishFromId($book); $chapters = $database_modifications->getTeamDiffChapters($bible, $book); foreach ($chapters as $chapter) { // Go through the combined verse numbers in the old and new chapter. $old_chapter_usfm = $database_modifications->getTeamDiff($bible, $book, $chapter); $new_chapter_usfm = $database_bibles->getChapter($bible, $book, $chapter); $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm); $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm); $verses = array_merge($old_verse_numbers, $new_verse_numbers); $verses = array_unique($verses); sort($verses, SORT_NUMERIC); foreach ($verses as $verse) { $old_verse_text = Filter_Usfm::getVerseText($old_chapter_usfm, $verse); $new_verse_text = Filter_Usfm::getVerseText($new_chapter_usfm, $verse); if ($old_verse_text != $new_verse_text) { $usfmCode = "\\p {$bookname} {$chapter}.{$verse} {$old_verse_text}"; $old_vs_usfm[] = $usfmCode; $filter_text_old->addUsfmCode($usfmCode); $usfmCode = "\\p {$bookname} {$chapter}.{$verse} {$new_verse_text}"; $new_vs_usfm[] = $usfmCode; $filter_text_new->addUsfmCode($usfmCode); } } } } file_put_contents("{$directory}/verses_old.usfm", implode("\n", $old_vs_usfm)); file_put_contents("{$directory}/verses_new.usfm", implode("\n", $new_vs_usfm)); $filter_text_old->run($stylesheet); $filter_text_new->run($stylesheet); $filter_text_old->html_text_standard->save("{$directory}/verses_old.html"); $filter_text_new->html_text_standard->save("{$directory}/verses_new.html"); $filter_text_old->text_text->save("{$directory}/verses_old.txt"); $filter_text_new->text_text->save("{$directory}/verses_new.txt"); }
public function recordOutput($bible, $book, $chapter, $verse, $data) { $database_bibles = Database_Bibles::getInstance(); $bible = $database_bibles->getID($bible); $book = Database_SQLiteInjection::no($book); $chapter = Database_SQLiteInjection::no($chapter); if ($verse == "") { $verse = 0; } $verse = Database_SQLiteInjection::no($verse); $data = Database_SQLiteInjection::no($data); $query = "INSERT INTO output VALUES ({$bible}, {$book}, {$chapter}, {$verse}, '{$data}');"; Database_SQLite::exec($this->db, $query); }
public static function safeStoreChapter($bible, $book, $chapter, $usfm) { $database_bibles = Database_Bibles::getInstance(); $database_logs = Database_Logs::getInstance(); $database_books = Database_Books::getInstance(); // Existing chapter contents. $existing = $database_bibles->getChapter($bible, $book, $chapter); // Bail out if the existing chapter equals the USFM to be saved. if ($usfm == $existing) { return true; } // The length of the new USFM code should not differ more than 20% from the existing USFM code. $existingLength = strlen($existing); $newLength = strlen($usfm); $percentage = 100 * ($newLength - $existingLength) / $existingLength; $percentage = abs($percentage); $percentage = round($percentage); if ($percentage > 20) { $database_logs->log("The chapter was not saved for safety reasons. The length differs {$percentage}% from the existing chapter. Make minor changes and save often."); $database_logs->log("{$bible} " . $database_books->getEnglishFromId($book) . " {$chapter}"); $database_logs->log($usfm); return false; } // The text of the new chapter should not differ more than 20% from the existing text. similar_text($existing, $usfm, $percentage); $percentage = abs($percentage); $percentage = 100 - $percentage; $percentage = round($percentage); if ($percentage > 20) { $database_logs->log("The chapter was not saved for safety reasons. The new text differs {$percentage}% from the existing text. Make minor changes and save often."); $database_logs->log("{$bible} " . $database_books->getEnglishFromId($book) . " {$chapter}"); $database_logs->log($usfm); return false; } // Safety checks have passed: Save chapter. Bible_Logic::storeChapter($bible, $book, $chapter, $usfm); return true; }
public static function deleteBible($bible) { $database_bibles = Database_Bibles::getInstance(); $database_modifications = Database_Modifications::getInstance(); $database_bibleactions = Database_BibleActions::getInstance(); // Record data of the Bible to be deleted prior to deletion. if (Filter_Client::enabled()) { // Client stores Bible actions. $books = $database_bibles->getBooks($bible); foreach ($books as $book) { $chapters = $database_bibles->getChapters($bible, $book); foreach ($chapters as $chapter) { $usfm = $database_bibles->getChapter($bible, $book, $chapter); $database_bibleactions->record($bible, $book, $chapter, $usfm); } } } else { // Server stores diff data. $database_modifications->storeTeamDiffBible($bible); } // Delete the Bible from the database. $database_bibles->deleteBible($bible); }
public static function getOrdered($bible) { $database_bibles = Database_Bibles::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); // The available books from the Bible. $projectbooks = $database_bibles->getBooks($bible); // The book order from the settings, if any. $orderedbooks = $database_config_bible->getBookOrder($bible); $orderedbooks = explode(" ", $orderedbooks); // Remove books not available in the Bible. $orderedbooks = array_intersect($orderedbooks, $projectbooks); // Books in the Bible but not in the settings: Add them to the end. $orderedbooks = array_merge($orderedbooks, $projectbooks); $orderedbooks = array_unique($orderedbooks); $orderedbooks = array_values($orderedbooks); return $orderedbooks; }
public function testSyncGitChapterToBibleUpdateChapters() { // The git repository has Psalm 0, Psalm 11, and Song of Solomon 2. // Put that into the Bible database. $database_bibles = Database_Bibles::getInstance(); Filter_Git::syncGit2Bible($this->repository, $this->bible); // Update some chapters in the git repository. file_put_contents($this->repository . "/Psalms/11/data", "\\c 11"); file_put_contents($this->repository . "/Song of Solomon/2/data", "\\c 2"); // Run updates on the two chapters. Filter_Git::syncGitChapter2Bible($this->repository, $this->bible, 19, 11); Filter_Git::syncGitChapter2Bible($this->repository, $this->bible, 22, 2); // Check that the database is updated accordingly. $usfm = $database_bibles->getChapter($this->bible, 19, 0); $this->assertEquals($this->psalms_0_data, $usfm); $usfm = $database_bibles->getChapter($this->bible, 19, 11); $this->assertEquals("\\c 11", $usfm); $usfm = $database_bibles->getChapter($this->bible, 22, 2); $this->assertEquals("\\c 2", $usfm); }
public static function queueAll($now) { $database_config_bible = Database_Config_Bible::getInstance(); $database_bibles = Database_Bibles::getInstance(); $database_config_general = Database_Config_General::getInstance(); $bibles = $database_bibles->getBibles(); foreach ($bibles as $bible) { if ($database_config_bible->getRemoteRepositoryUrl($bible) != "") { if ($database_config_bible->getRepeatSendReceive($bible) || $now) { self::queuebible($bible); } } } }
public function testGetTeamDiffCount() { $database_bibles = Database_Bibles::getInstance(); $database_modifications = Database_Modifications::getInstance(); Bible_Logic::storeChapter("phpunit", 3, 1, "chapter text"); Bible_Logic::storeChapter("phpunit2", 3, 3, "chapter text"); Bible_Logic::storeChapter("phpunit2", 3, 5, "chapter text"); $count = $database_modifications->getTeamDiffCount("phpunit"); $this->assertEquals(1, $count); $count = $database_modifications->getTeamDiffCount("phpunit2"); $this->assertEquals(2, $count); $count = $database_modifications->getTeamDiffCount("phpunit3"); $this->assertEquals(0, $count); }
public function response() { // The databases to access. $database_config_user = Database_Config_User::getInstance(); $database_volatile = Database_Volatile::getInstance(); $database_bibles = Database_Bibles::getInstance(); // The resources to display in the Consistency tool. $resources = array(); $resources[] = Access_Bible::clamp($database_config_user->getBible()); $resources = array_merge($resources, $database_config_user->getConsistencyResources()); // The passages entered in the Consistency tool. $passages = $database_volatile->getValue($this->id, "passages"); $passages = trim($passages); $passages = Filter_String::string2array($passages); // The translations from the Consistency tool. $translations = $database_volatile->getValue($this->id, "translations"); $translations = trim($translations); $translations = Filter_String::string2array($translations); // Contains the response to display. $response = array(); // Go through the passages interpreting them. $previousPassage = array(1, 1, 1); foreach ($passages as $line) { $line = trim($line); if ($line == "") { continue; } $range_sequence = Filter_Books::handleSequencesRanges($line); foreach ($range_sequence as $line) { $passage = Filter_Books::interpretPassage($previousPassage, $line); if ($passage[0] != 0) { $book = $passage[0]; $chapter = $passage[1]; $verse = $passage[2]; $line = Filter_Books::linkForOpeningEditorAt($book, $chapter, $verse); $line .= " "; // Check whether the chapter identifier has changed for this reference. // If so, set a flag so the data can be re-assembled for this verse. // If there was no change, then the data can be fetched from the volatile database. $redoPassage = false; $passageKey = "{$book}.{$chapter}.{$verse}"; $currentChapterId = $database_bibles->getChapterId($resources[0], $book, $chapter); $storedChapterId = $database_volatile->getValue($this->id, "{$passageKey}.id"); if ($currentChapterId != $storedChapterId) { $database_volatile->setValue($this->id, "{$passageKey}.id", $currentChapterId); $redoPassage = true; } // Go through each resource. foreach ($resources as $resource) { // Produce new verse text if the passage is to be redone, or else fetch the existing text. if ($redoPassage) { $text = $this->verseText($resource, $book, $chapter, $verse); if ($translations != "") { $text = Filter_Markup::words($translations, $text); } $database_volatile->setValue($this->id, "{$passageKey}.{$resource}", $text); } else { $text = $database_volatile->getValue($this->id, "{$passageKey}.{$resource}"); } // Formatting. if (count($resources) > 1) { $line .= "<br>"; } $line .= $text; } $response[] = $line; $previousPassage = $passage; } else { $response[] = '<span class="error">' . Locale_Translate::_("Unknown passage") . " " . $line . '</span>'; } } } $output = ""; foreach ($response as $line) { $output .= "<div>{$line}</div>\n"; } return $output; }
public function updateSearchFields($name, $book, $chapter) { $database_bibles = Database_Bibles::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); $usfm = $database_bibles->getChapter($name, $book, $chapter); $stylesheet = $database_config_bible->getExportStylesheet($name); // Data to store. $usfmraw = array(); $usfmlower = array(); $plainraw = array(); $plainlower = array(); // Get the verses in the chapter. $verses = Filter_Usfm::getVerseNumbers($usfm); $verses = array_unique($verses); sort($verses, SORT_NUMERIC); // One column contains the raw USFM as it is, and another one the lowercase text. foreach ($verses as $verse) { $raw = Filter_Usfm::getVerseText($usfm, $verse); $lower = mb_convert_case($raw, MB_CASE_LOWER); $usfmraw[$verse] = $raw; $usfmlower[$verse] = $lower; } // Text filter for getting the plain text. $filter_text = new Filter_Text($name); $filter_text->text_text = new Text_Text(); $filter_text->initializeHeadingsAndTextPerVerse(); $filter_text->addUsfmCode($usfm); $filter_text->run($stylesheet); // Get the clean verse texts. $texts = $filter_text->getVersesText(); foreach ($texts as $verse => $text) { if (!isset($plainraw[$verse])) { $plainraw[$verse] = ""; } $plainraw[$verse] .= "{$text}\n"; } // Add any clean headings. $headings = $filter_text->verses_headings; foreach ($headings as $verse => $heading) { if (!isset($plainraw[$verse])) { $plainraw[$verse] = ""; } $plainraw[$verse] .= "{$heading}\n"; } // Create the lower case plain text. foreach ($plainraw as $verse => $raw) { $plainlower[$verse] = mb_convert_case($raw, MB_CASE_LOWER); } // Get all possible verses. $allverses = array_merge(array_keys($usfmraw), array_keys($plainraw)); $allverses = array_unique($allverses); // Store everything. Database_SQLite::exec($this->db, "BEGIN;"); $name = Database_SQLiteInjection::no($name); $book = Database_SQLiteInjection::no($book); $chapter = Database_SQLiteInjection::no($chapter); $query = "DELETE FROM bibles WHERE bible = '{$name}' AND book = {$book} AND chapter = {$chapter};"; Database_SQLite::exec($this->db, $query); foreach ($allverses as $verse) { if ($verse == "") { $verse = 0; } $verse = (int) $verse; @($ur = Database_SQLiteInjection::no($usfmraw[$verse])); @($ul = Database_SQLiteInjection::no($usfmlower[$verse])); @($pr = Database_SQLiteInjection::no($plainraw[$verse])); @($pl = Database_SQLiteInjection::no($plainlower[$verse])); $query = "INSERT INTO bibles (bible, book, chapter, verse, usfmraw, usfmlower, plainraw, plainlower) VALUES ('{$name}', {$book}, {$chapter}, {$verse}, '{$ur}', '{$ul}', '{$pr}', '{$pl}');"; Database_SQLite::exec($this->db, $query); } Database_SQLite::exec($this->db, "COMMIT;"); }
function processIdentifiers($user, $bible, $book, $chapter, $oldId, $newId, &$email) { if ($oldId != 0) { $database_modifications = Database_Modifications::getInstance(); $database_config_user = Database_Config_User::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); $database_bibles = Database_Bibles::getInstance(); $database_history = Database_History::getInstance(); $stylesheet = $database_config_bible->getExportStylesheet($bible); $old_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $oldId); $old_chapter_usfm = $old_chapter_usfm['oldtext']; $new_chapter_usfm = $database_modifications->getUserChapter($user, $bible, $book, $chapter, $newId); $new_chapter_usfm = $new_chapter_usfm['newtext']; $timestamp = $database_modifications->getUserTimestamp($user, $bible, $book, $chapter, $newId); $old_verse_numbers = Filter_Usfm::getVerseNumbers($old_chapter_usfm); $new_verse_numbers = Filter_Usfm::getVerseNumbers($new_chapter_usfm); $verses = array_merge($old_verse_numbers, $new_verse_numbers); $verses = array_unique($verses); sort($verses, SORT_NUMERIC); foreach ($verses as $verse) { $old_verse_usfm = Filter_Usfm::getVerseText($old_chapter_usfm, $verse); $new_verse_usfm = Filter_Usfm::getVerseText($new_chapter_usfm, $verse); if ($old_verse_usfm != $new_verse_usfm) { $filter_text_old = new Filter_Text($bible); $filter_text_new = new Filter_Text($bible); $filter_text_old->html_text_standard = new Html_Text(Locale_Translate::_("Bible")); $filter_text_new->html_text_standard = new Html_Text(Locale_Translate::_("Bible")); $filter_text_old->text_text = new Text_Text(); $filter_text_new->text_text = new Text_Text(); $filter_text_old->addUsfmCode($old_verse_usfm); $filter_text_new->addUsfmCode($new_verse_usfm); $filter_text_old->run($stylesheet); $filter_text_new->run($stylesheet); $old_html = $filter_text_old->html_text_standard->getInnerHtml(); $new_html = $filter_text_new->html_text_standard->getInnerHtml(); $old_text = $filter_text_old->text_text->get(); $new_text = $filter_text_new->text_text->get(); if ($old_text != $new_text) { $modification = Filter_Diff::diff($old_text, $new_text); $email .= "<div>"; $email .= Filter_Books::passageDisplay($book, $chapter, $verse); $email .= " "; $email .= $modification; $email .= "</div>"; if ($database_config_user->getUserUserChangesNotificationsOnline($user)) { $changeNotificationUsers = array($user); $database_modifications->recordNotification($changeNotificationUsers, "☺", $bible, $book, $chapter, $verse, $old_html, $modification, $new_html); } $database_history->record($timestamp, $user, $bible, $book, $chapter, $verse, $old_html, $modification, $new_html); } } } } }
public function getBible() { $bible = $this->getValue("bible", ""); // If the Bible does not exist, take the first one available. $database_bibles = Database_Bibles::getInstance(); $bibles = $database_bibles->getBibles(); if (!in_array($bible, $bibles)) { // There may not even be a first Bible: Suppress error. @($bible = $bibles[0]); $this->setBible($bible); } return $bible; }
public function getTeamDiffBooks($bible) { if (is_numeric($bible)) { $database_bibles = Database_Bibles::getInstance(); $bible = $database_bibles->getName($bible); } $books = array(); $files = glob($this->teamFolder() . "/{$bible}.*"); foreach ($files as $file) { $file = basename($file); $file = explode(".", $file); $books[] = $file[1]; } $books = array_unique($books); sort($books, SORT_NUMERIC); return $books; }
public function testSafeStoreChapterNoChange() { $database_bibles = Database_Bibles::getInstance(); $currentId = $database_bibles->getChapterId("phpunit", 1, 1); $usfm = <<<'EOD' \c 1 \p \v 1 Verse 1. \v 2 Verse 2. \v 3 Verse 3. \v 4 Verse 4. \v 5 Verse 5. EOD; $result = Filter_Bibles::safeStoreChapter("phpunit", 1, 1, $usfm); $this->assertTrue($result); $result = $database_bibles->getChapter("phpunit", 1, 1); $this->assertEquals($this->usfm, $result); $currentId2 = $database_bibles->getChapterId("phpunit", 1, 1); $this->assertEquals($currentId, $currentId2); }
public function testGetOrdered() { $database_bibles = Database_Bibles::getInstance(); $database_config_bible = Database_Config_Bible::getInstance(); $bible = "php unit"; // No ordering. $database_bibles->createBible($bible); $database_bibles->storeChapter($bible, 1, 1, "data"); $database_bibles->storeChapter($bible, 2, 1, "data"); $database_bibles->storeChapter($bible, 3, 1, "data"); $database_bibles->storeChapter($bible, 4, 1, "data"); $database_bibles->storeChapter($bible, 5, 1, "data"); $books = Filter_Books::getOrdered($bible); $standard = array(1, 2, 3, 4, 5); $this->assertEquals($standard, $books); // Existing books re-ordered. $database_config_bible->setBookOrder($bible, "1 3 2 5 4"); $books = Filter_Books::getOrdered($bible); $standard = array(1, 3, 2, 5, 4); $this->assertEquals($standard, $books); // Some books ordered, and Bible has extra books: These are to be added to the end. $database_config_bible->setBookOrder($bible, "1 3 2"); $books = Filter_Books::getOrdered($bible); $standard = array(1, 3, 2, 4, 5); $this->assertEquals($standard, $books); // More books ordered than in Bible: Remove the extra ones. $database_config_bible->setBookOrder($bible, "1 3 2 5 4 6"); $books = Filter_Books::getOrdered($bible); $standard = array(1, 3, 2, 5, 4); $this->assertEquals($standard, $books); }
private static function getPreviousVerse($bible, $book, $chapter, $verse) { $verse--; if ($bible != "") { $database_bibles = Database_Bibles::getInstance(); $verses = Filter_Usfm::getVerseNumbers($database_bibles->getChapter($bible, $book, $chapter)); if (!in_array($verse, $verses)) { $verse = array_shift($verses); } } $passage = array($book, $chapter, $verse); return $passage; }
public function tearDown() { $database_bibles = Database_Bibles::getInstance(); $database_bibles->deleteBible("phpunit1"); $database_bibles->deleteBible("phpunit2"); }
public function testChapterIDs() { $database_bibles = Database_Bibles::getInstance(); $database_bibles->createBible("phpunit"); $database_bibles->storeChapter("phpunit", 1, 2, "\\c 1"); $firstId = $database_bibles->getChapterId("phpunit", 1, 2); $this->assertGreaterThan(0, $firstId); $database_bibles->storeChapter("phpunit", 1, 2, "\\c 1"); $id = $database_bibles->getChapterId("phpunit", 1, 2); $this->assertEquals($firstId + 1, $id); $database_bibles->storeChapter("phpunit", 1, 2, "\\c 1"); $database_bibles->storeChapter("phpunit", 1, 2, "\\c 1"); $id = $database_bibles->getChapterId("phpunit", 1, 2); $this->assertEquals($firstId + 3, $id); $database_bibles->storeChapter("phpunit", 2, 3, "\\c 1"); $id = $database_bibles->getChapterId("phpunit", 1, 2); $this->assertEquals($firstId + 3, $id); }
public static function syncGitChapter2Bible($git, $bible, $book, $chapter) { // The databases. $database_bibles = Database_Bibles::getInstance(); $database_books = Database_Books::getInstance(); $database_logs = Database_Logs::getInstance(); // Filename for the chapter. $bookname = $database_books->getEnglishFromId($book); $filename = "{$git}/{$bookname}/{$chapter}/data"; if (file_exists($filename)) { // Store chapter in database. $usfm = file_get_contents($filename); Bible_Logic::storeChapter($bible, $book, $chapter, $usfm); $database_logs->log(Locale_Translate::_("A collaborator updated") . " {$bible} {$bookname} {$chapter}"); } else { // Delete chapter from database. Bible_Logic::deleteChapter($bible, $book, $chapter); $database_logs->log(Locale_Translate::_("A collaborator deleted chapter") . " {$bible} {$bookname} {$chapter}"); } }
<?php /* Copyright (©) 2003-2014 Teus Benschop. This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. */ require_once "../bootstrap/bootstrap.php"; page_access_level(Filter_Roles::TRANSLATOR_LEVEL); $bible = $_GET['bible']; $book = $_GET['book']; $chapter = $_GET['chapter']; $database_bibles = Database_Bibles::getInstance(); $usfm = $database_bibles->getChapter($bible, $book, $chapter); echo Checksum_Logic::send($usfm);
public static function getText($resource, $book, $chapter, $verse) { $database_bibles = Database_Bibles::getInstance(); $database_resources = Database_Resources::getInstance(); $database_usfmresources = Database_UsfmResources::getInstance(); $database_offlineresources = Database_OfflineResources::getInstance(); $bibles = $database_bibles->getBibles(); $usfms = $database_usfmresources->getResources(); $externals = $database_resources->getNames(); $isBible = in_array($resource, $bibles); $isUsfm = in_array($resource, $usfms); if ($isBible || $isUsfm) { if ($isBible) { $chapter_usfm = $database_bibles->getChapter($resource, $book, $chapter); } if ($isUsfm) { $chapter_usfm = $database_usfmresources->getUsfm($resource, $book, $chapter); } $verse_usfm = Filter_Usfm::getVerseText($chapter_usfm, $verse); $database_config_user = Database_Config_User::getInstance(); $stylesheet = $database_config_user->getStylesheet(); $filter_text = new Filter_Text($resource); $filter_text->text_text = new Text_Text(); $filter_text->addUsfmCode($verse_usfm); $filter_text->run($stylesheet); $text = $filter_text->text_text->get(); } else { if (in_array($resource, $externals)) { // Use offline copy if it exists, else fetch it online. if ($database_offlineresources->exists($resource, $book, $chapter, $verse)) { $text = $database_offlineresources->get($resource, $book, $chapter, $verse); } else { $text = Resource_Logic::getExternal($resource, $book, $chapter, $verse, true); } $text = Filter_Html::html2text($text); } else { $text = ""; } } return $text; }