Skip to content

Commit

Permalink
UPDATE ehw-randverse_tmpl__out.php: Replace majority of code with cod…
Browse files Browse the repository at this point in the history
…e from tree.php WORKS
  • Loading branch information
codewizard13 committed Feb 7, 2022
1 parent 78806db commit 814345a
Showing 1 changed file with 107 additions and 75 deletions.
182 changes: 107 additions & 75 deletions includes/ehw-randverse_tmpl__out.php
Original file line number Diff line number Diff line change
@@ -1,103 +1,135 @@
<?php /* ehw-randverse-scripts.php */

// $var = array(
// "green" => array("one", "two"),
// "red" => array("three", "four"),
// "yellow" => array("five", "six")
// );

// $color = array_rand($var); //here yoy get random first of array(green or red or yellow)
// // echo $var[$color][array_rand($var[$section])]; //here you get random element of this array
// echo $var[$color][array_rand($var[$color])];
// exit;

$verse1 = 'For I know the thoughts that I think toward you,' .
'saith the LORD, thoughts of peace, and not of evil,' .
'to give you an expected end.';

$verse2 = 'For God so loved the world, that he gave his only '.
'begotten Son, that whosoever believeth in him should not perish,'.
'but have everlasting life.';

$verse3 = 'And we know that all things work together for good to '.
'them that love God, to them who are the called according to his'.
'purpose.';

$verses['Jeremiah'][29][11] = $verse1;
$verses['John'][3][16] = $verse2;
$verses['Romans'][8][28] = $verse3;

// SAMPLE $verses array (King James Version, KJV):
$verses['Jeremiah'][29][11] = 'For I know the thoughts that I think toward you, saith the LORD, thoughts of peace, and not of evil, to give you an expected end.';
$verses['John'][3][16] = 'For God so loved the world, that he gave his only begotten Son, that whosoever believeth in him should not perish, but have everlasting life.';
$verses['Romans'][8][28] = 'And we know that all things work together for good to them that love God, to them who are the called according to his purpose.';
$verses['John'][1][1] = "In the beginning was the Word, and the Word was with God, and the Word was God.";
$verses['John'][1][3] = "All things were made by him; and without him was not any thing made that was made.";

/**
* @purpose:
* Reads through multidimensional array of bible verses (book name, chapter
* number, verse number), with the applicable verse text being the assisgnment
* value, and builds a new array of arrays. The new array elements look like
* objects, having as their key a string built of "book-ch-num" concatenated.
* The properties of each first-level array consist of book_name, ch_num,
* verse_num, and verse_txt. An additional property of 'html_01' builds
* the formatted verse text that gets displayed.
*
* @usage:
*
* // Returns array of formattedVerse array objects
* $my_vs = buildFormattedVerses($verses);
*
* // Get all book-ch-verse array keys
* $my_verse_ids = array_keys($my_vs);
*
* // Get verse text for John 3:16
* $my_vs['John-03-16']['verse_text']
*
* @args:
* - Array $tree: any array structure
* - Array $verses: an associative array of bible verses with depth of 3
*
* @requires:
* - CSS styles loaded via wp_enqueue_styles() hook for .ehw-rbv
*
* @returns:
* - String - HTML $markup
* - Array $out_arr: array of object-like arrays
*/
function treeOut($tree, $lev=0) {
$markup = '';

foreach ($tree as $branch => $twig) {
function buildFormattedVerses($verses) {
$markup = [];
$out_arr = [];

foreach ($verses as $book_name => $book_val) {

foreach ($book_val as $ch_num => $ch_val) {

foreach ($ch_val as $verse_num => $verse_val) {

// Pad chapter and verse numbers with leading zeros
$ch_num_p = str_pad($ch_num, 2, 0, STR_PAD_LEFT);
$v_num_p = str_pad($verse_num, 2, 0, STR_PAD_LEFT);

// unique key for this verse
$markup_key = $book_name.'-'.$ch_num_p.'-'.$v_num_p;

// output html version one
$html_out = "<section class='ehw-rbv'>";
$html_out .= "<h3>$book_name $ch_num_p:$v_num_p</h3>";
$html_out .= "<p>$verse_val</p>";
$html_out .= "</section>";

$markup[$markup_key] = [
'book_name' => $book_name,
'ch_num' => $ch_num_p,
'verse_num' => $v_num_p,
'verse_txt' => $verse_val,
'html_01' => $html_out
];

$markup .= '<li>';
$cur_depth = $lev+1;
}

if (is_array($twig)) {
$markup .= "<h$cur_depth>" .$branch. "</h$cur_depth>" . treeOut($twig, $cur_depth);
} else {
$markup .= "<h$cur_depth>" .$branch. "</h$cur_depth>" . $twig;
}

$markup .= '</li>';
}
} // /END foreach

$out_arr = $markup;

return '<ul>' . $markup . '</ul>';
return $out_arr;
}
?>

echo "I'll put the TREE OUT here<br>";
echo "<section class='ehw-rbv'>";
echo treeOut($verses);
echo "</section>";
exit;
<link rel="stylesheet" href="../../css/style.css">

<?php

// var_dump($verses);
$john_ch_count = count(array_keys($verses['John']));
$ttl_v_count = count($verses);
echo '<p>Total Verses: ' . $ttl_v_count . '</p>';
// exit;
$my_vs = buildFormattedVerses($verses);
$my_verse_ids = array_keys($my_vs);

//$out = count( $verses['John'][array_keys($verses['John'])] );
//echo 'Total verses in John: ' .$out;
// exit;
echo "<H2>VERSES FORMATTED:</H2>";

function get_rand_verse($verses) {
// test verse
$verse = $verses['John'][3][16];
var_dump($my_verse_ids);

$out = '';
/**
* @args:
* - Array $va: array of verses built with buildFormattedVerses()
*/
function displayFormattedVerses($va) {
foreach ($va as $verse => $key) {
echo $key['html_01']. "<br>";
}
}
displayFormattedVerses($my_vs);

$book_names = array_keys($verses);
echo '<h3>Book Names Array:</h3>';
var_dump($book_names);
/**
*
* @usage:
*
* // display formatted verse html segment
* echo $output['html_01'];
*
* @requires:
* - CSS styles loaded via wp_enqueue_styles() hook for .ehw-rbv
*
* @args:
* - Array $va: array of verses built with buildFormattedVerses()
*
* @returns:
* - Array obj $verse:
*/
function getRandVerse($va) {

foreach ($verses as $verse) {
$rand_keys = array_rand($va);

foreach ($verse as $ch) {
foreach ($ch as $verse_text) {
echo '<hr>';
echo $verse_text . '<br>';
}
}
}
$out_verse = $va[$rand_keys];

return $verse;
return $out_verse;
}

$output = get_rand_verse($verses);

$output = getRandVerse($my_vs);
echo($output['html_01']);
exit;

// $verses = [$verse1, $verse2, $verse3];
// $rand_keys = array_rand($verses);
Expand Down

0 comments on commit 814345a

Please sign in to comment.