Ejemplo n.º 1
0
 public static function getInstance()
 {
     if (empty(self::$instance)) {
         self::$instance = new Database_Versifications();
     }
     return self::$instance;
 }
Ejemplo n.º 2
0
 public static function verses($bible, $book, $chapter, $verses)
 {
     // Get verses in this chapter according to the versification system for the Bible.
     $database_versifications = Database_Versifications::getInstance();
     $database_config_bible = Database_Config_Bible::getInstance();
     $versification = $database_config_bible->getVersificationSystem($bible);
     $standardVerses = $database_versifications->getVerses($versification, $book, $chapter);
     // Look for missing and extra verses.
     $absentVerses = array_diff($standardVerses, $verses);
     $extraVerses = array_diff($verses, $standardVerses);
     $database_check = Database_Check::getInstance();
     foreach ($absentVerses as $verse) {
         $database_check->recordOutput($bible, $book, $chapter, $verse, "This verse is missing according to the versification system");
     }
     foreach ($extraVerses as $verse) {
         //if (($chapter == 0) && ($verse == 0)) continue;
         $database_check->recordOutput($bible, $book, $chapter, $verse, "This verse is extra according to the versification system");
     }
     // Look for verses out of order.
     $previousVerse = 0;
     foreach ($verses as $key => $verse) {
         if ($key > 0) {
             if ($verse != $previousVerse + 1) {
                 $database_check->recordOutput($bible, $book, $chapter, $verse, "The verse is out of sequence");
             }
         }
         $previousVerse = $verse;
     }
 }
Ejemplo n.º 3
0
 /**
  * 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;
 }
Ejemplo n.º 4
0
 public function testAvailableBooks()
 {
     $database_versifications = Database_Versifications::getInstance();
     $data = $database_versifications->getBooksChaptersVerses("English");
     $books = array();
     foreach ($data as $row) {
         $book = $row["book"];
         $books[] = $book;
     }
     $books = array_unique($books, SORT_NUMERIC);
     $fault = array_diff($books, array(10));
     Checks_Versification::books("Bible", $fault);
     $database_check = Database_Check::getInstance();
     $result = $database_check->getHits();
     $standard = array(array('rowid' => "1", 'bible' => "0", 'book' => "10", 'chapter' => "1", 'verse' => "1", 'data' => "This book is absent from the Bible"));
     $this->assertEquals($standard, $result);
 }
Ejemplo n.º 5
0
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::MANAGER_LEVEL);
$view = new Assets_View(__FILE__);
$database_resources = Database_Resources::getInstance();
$database_offlineresources = Database_OfflineResources::getInstance();
$database_versifications = Database_Versifications::getInstance();
@($name = $_GET['name']);
$view->view->name = $name;
if (isset($_GET['download'])) {
    $versification = "English";
    $books = $database_versifications->getBooks($versification);
    foreach ($books as $book) {
        // Schedule the task with low priority so it does not get in the way of regular tasks.
        Tasks_Logic::queue(Tasks_Logic::PHP, array(__DIR__ . "/downloadcli.php", $name, $book));
    }
    Filter_Url::redirect("../journal/index.php");
    die;
}
if (isset($_GET['clear'])) {
    $database_offlineresources->delete($name);
}
Ejemplo n.º 6
0
 public static function getVersesFragment($bible, $book, $chapter, $verse)
 {
     $database_bibles = Database_Bibles::getInstance();
     if ($bible == "") {
         $database_versifications = Database_Versifications::getInstance();
         $verses = $database_versifications->getVerses("English", $book, $chapter);
     } else {
         $verses = Filter_Usfm::getVerseNumbers($database_bibles->getChapter($bible, $book, $chapter));
     }
     $html = "";
     foreach ($verses as $vs) {
         $selected = "";
         if ($verse == $vs) {
             $selected = " selected";
         }
         $html .= "<option{$selected}>" . $vs . "</option>";
     }
     return $html;
 }
Ejemplo n.º 7
0
    public function testImportExport()
    {
        $database_versifications = Database_Versifications::getInstance();
        $xml = <<<'EOD'
<?xml version="1.0" encoding="UTF-8"?>
<bibledit-versification-system>
  <triad>
    <book>Genesis</book>
    <chapter>1</chapter>
    <verse>31</verse>
  </triad>
  <triad>
    <book>Genesis</book>
    <chapter>2</chapter>
    <verse>25</verse>
  </triad>
</bibledit-versification-system>
EOD;
        $database_versifications->importBibleditXml($xml, "phpunit");
        $id = $database_versifications->getID("phpunit");
        $this->assertEquals(1000, $id);
        $data = $database_versifications->getBooksChaptersVerses("phpunit");
        $this->assertEquals(2, count($data));
        $this->assertEquals(25, $data[1]['verse']);
        $export = $database_versifications->exportBibleditXmlFile("phpunit");
        $this->assertEquals(trim($xml), trim($export));
    }