From 814345a5663906f13c1f6a175752fafe7b8fbd56 Mon Sep 17 00:00:00 2001 From: "Eric L. Hepperle" Date: Mon, 7 Feb 2022 06:50:23 -0600 Subject: [PATCH] UPDATE ehw-randverse_tmpl__out.php: Replace majority of code with code from tree.php WORKS --- includes/ehw-randverse_tmpl__out.php | 182 ++++++++++++++++----------- 1 file changed, 107 insertions(+), 75 deletions(-) diff --git a/includes/ehw-randverse_tmpl__out.php b/includes/ehw-randverse_tmpl__out.php index cfce77e..5ae8a80 100644 --- a/includes/ehw-randverse_tmpl__out.php +++ b/includes/ehw-randverse_tmpl__out.php @@ -1,103 +1,135 @@ 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 = "
"; + $html_out .= "

$book_name $ch_num_p:$v_num_p

"; + $html_out .= "

$verse_val

"; + $html_out .= "
"; + + $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 .= '
  • '; - $cur_depth = $lev+1; + } - if (is_array($twig)) { - $markup .= "" .$branch. "" . treeOut($twig, $cur_depth); - } else { - $markup .= "" .$branch. "" . $twig; } - - $markup .= '
  • '; - - } + + } // /END foreach + + $out_arr = $markup; - return ''; + return $out_arr; } +?> -echo "I'll put the TREE OUT here
    "; -echo "
    "; -echo treeOut($verses); -echo "
    "; -exit; + + +Total Verses: ' . $ttl_v_count . '

    '; -// 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 "

    VERSES FORMATTED:

    "; -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']. "
    "; + } +} +displayFormattedVerses($my_vs); - $book_names = array_keys($verses); - echo '

    Book Names Array:

    '; - 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 '
    '; - echo $verse_text . '
    '; - } - } - } + $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);