function createOutput($entry_id, $pdf) { $entry = GFAPI::get_entry($entry_id); $makers = array(); if (strlen($entry['160.3']) > 0) { $makers[] = $entry['160.3'] . ' ' . $entry['160.6']; } if (strlen($entry['158.3']) > 0) { $makers[] = $entry['158.3'] . ' ' . $entry['158.6']; } if (strlen($entry['155.3']) > 0) { $makers[] = $entry['155.3'] . ' ' . $entry['155.6']; } if (strlen($entry['156.3']) > 0) { $makers[] = $entry['156.3'] . ' ' . $entry['156.6']; } if (strlen($entry['157.3']) > 0) { $makers[] = $entry['157.3'] . ' ' . $entry['157.6']; } if (strlen($entry['159.3']) > 0) { $makers[] = $entry['159.3'] . ' ' . $entry['159.6']; } if (strlen($entry['154.3']) > 0) { $makers[] = $entry['154.3'] . ' ' . $entry['154.6']; } //maker 1 bio $bio = filterText($entry['234']); $groupname = $entry['109']; $groupphoto = $entry['111']; $groupbio = filterText($entry['110']); $project_name = filterText($entry['151']); $project_photo = $entry['22']; $project_short = filterText($entry['16']); $project_website = $entry['27']; $project_video = $entry['32']; $project_title = filterText((string) $entry['151']); $project_title = preg_replace('/\\v+|\\\\[rn]/', '<br/>', $project_title); // Project ID $pdf->SetFont('Benton Sans', '', 12); $pdf->setTextColor(168, 170, 172); $pdf->SetXY(240, 20); $pdf->MultiCell(115, 10, $entry_id, 0, 'L'); // Project Title $pdf->setTextColor(0); $pdf->SetXY(12, 75); //auto adjust the font so the text will fit $x = 65; // set the starting font size $pdf->SetFont('Benton Sans', 'B', 65); /* Cycle thru decreasing the font size until it's width is lower than the max width */ while ($pdf->GetStringWidth(utf8_decode($project_title)) > 400) { $x--; // Decrease the variable which holds the font size $pdf->SetFont('Benton Sans', 'B', $x); } $lineHeight = $x * 0.2645833333333 * 1.3; /* Output the title at the required font size */ $pdf->MultiCell(0, $lineHeight, $project_title, 0, 'L'); //field 16 - short description //auto adjust the font so the text will fit $pdf->SetXY(145, 135); //auto adjust the font so the text will fit $sx = 30; // set the starting font size $pdf->SetFont('Benton Sans', '', $sx); // Cycle thru decreasing the font size until it's width is lower than the max width while ($pdf->GetStringWidth(utf8_decode($project_short)) > 1300) { $sx--; // Decrease the variable which holds the font size $pdf->SetFont('Benton Sans', '', $sx); } $lineHeight = $sx * 0.2645833333333 * 1.3; $pdf->MultiCell(125, $lineHeight, $project_short, 0, 'L'); //field 22 - project photo $photo_extension = exif_imagetype($project_photo); if ($photo_extension) { //DEBUG: $project_photo = legacy_get_fit_remote_image_url($project_photo, 450, 450, 0); $pdf->Image($project_photo, 12, 135, null, null, image_type_to_extension($photo_extension, false)); } //print white box to overlay long descriptions or photos /*$pdf->SetXY(10, 255); $pdf->Cell(300,80,'',0,2,'L',true);*/ //maker info, use a background of white to overlay any long images or text $pdf->setTextColor(0, 174, 239); $pdf->SetFont('Benton Sans', 'B', 48); $pdf->SetXY(10, 270); if (!empty($groupbio)) { //auto adjust the font so the text will fit $sx = 48; // set the starting font size // Cycle thru decreasing the font size until it's width is lower than the max width while ($pdf->GetStringWidth(utf8_decode($groupname)) > 240) { $sx--; // Decrease the variable which holds the font size $pdf->SetFont('Benton Sans', 'B', $sx); } $lineHeight = $sx * 0.2645833333333 * 1.3; $pdf->MultiCell(0, $lineHeight, $groupname, 0, 'L', true); $pdf->setTextColor(0); $pdf->SetFont('Benton Sans', '', 24); //auto adjust the font so the text will fit $x = 24; // set the starting font size /* Cycle thru decreasing the font size until it's width is lower than the max width */ while ($pdf->GetStringWidth($groupbio) > 1200) { $x--; // Decrease the variable which holds the font size $pdf->SetFont('Benton Sans', '', $x); } $lineHeight = $x * 0.2645833333333 * 1.3; $pdf->MultiCell(0, $lineHeight, $groupbio, 0, 'L', true); } else { $makerList = implode(', ', $makers); $pdf->SetFont('Benton Sans', 'B', 48); //auto adjust the font so the text will fit $x = 48; // set the starting font size /* Cycle thru decreasing the font size until it's width is lower than the max width */ while ($pdf->GetStringWidth(utf8_decode($makerList)) > 900) { $x--; // Decrease the variable which holds the font size $pdf->SetFont('Benton Sans', '', $x); } $lineHeight = $x * 0.2645833333333 * 1.3; $pdf->MultiCell(0, $lineHeight, $makerList, 0, 'L', true); //if size of makers is 1, then display maker bio if (sizeof($makers) == 1) { $pdf->setTextColor(0); $pdf->SetFont('Benton Sans', '', 24); //auto adjust the font so the text will fit $x = 24; // set the starting font size /* Cycle thru decreasing the font size until it's width is lower than the max width */ while ($pdf->GetStringWidth($bio) > 900) { $x--; // Decrease the variable which holds the font size $pdf->SetFont('Benton Sans', '', $x); } $lineHeight = $x * 0.2645833333333 * 1.37; $pdf->MultiCell(0, $lineHeight, $bio, 0, 'L', true); } } }
function createJson($year = '') { global $wpdb; $ribbonData = array(); $data = array(); $json = array(); $blueList = array(); $redList = array(); $filter = " and year= " . ($year != '' ? $year : date("Y")); $sql = "SELECT entry_id, location, year, ribbonType, numRibbons,project_name,project_photo, post_id, maker_name " . " FROM `wp_mf_ribbons` where entry_id > 0 " . $filter . " " . " ORDER BY ribbonType ASC, numRibbons desc, entry_id"; foreach ($wpdb->get_results($sql, ARRAY_A) as $ribbon) { $entry_id = $ribbon['entry_id']; $link = "/mfarchives/" . $entry_id; $post_id = $ribbon['post_id']; $project_name = $ribbon['project_name']; $project_photo = $ribbon['project_photo']; $project_desc = ''; $maker_name = $ribbon['maker_name']; $location = $ribbon['location']; $year = $ribbon['year']; $ribbonType = $ribbon['ribbonType']; $numRibbons = $ribbon['numRibbons']; //pull the project information - mf_ribbons data takes precedence if ($post_id != 0) { //archived record $makerSQL = "select post.post_content, wp_postmeta.* " . " from wp_posts post " . " right outer join wp_postmeta on " . " post.ID = post_id and " . " ((post_id = {$post_id} and meta_key like '%maker_name%') or " . " (post_id = {$post_id} and meta_key in('project_photo','project_name')) or " . " (post_id = {$post_id} and meta_key like '%project_description%')) " . " where post.ID = {$post_id} ORDER BY `wp_postmeta`.`meta_key` DESC"; foreach ($wpdb->get_results($makerSQL, ARRAY_A) as $projData) { //wpv1 project data is in the post_content field //cs project data is in the meta fields if ($projData['post_content'] != '') { $jsonArray = json_decode($projData['post_content'], true); //if there is an error, try to fix the json if (empty($jsonArray)) { $content = fixWPv1Json($projData['post_content'], $post_id); $jsonArray = json_decode($content, true); } if (!empty($jsonArray)) { if ($jsonArray['form_type'] == 'presenter') { $project_name = $jsonArray['presentation_name']; $project_photo = $jsonArray['presentation_photo']; $maker_name = $jsonArray['presenter_name']; $project_desc = isset($jsonArray['public_description']) ? $jsonArray['public_description'] : ''; } elseif ($jsonArray['form_type'] == 'exhibit') { $project_name = $jsonArray['project_name']; $project_photo = $jsonArray['project_photo']; $maker_name = $jsonArray['maker_name']; $project_desc = isset($jsonArray['public_description']) ? $jsonArray['public_description'] : ''; } elseif ($jsonArray['form_type'] == 'performer') { $project_name = $jsonArray['performer_name']; $project_photo = $jsonArray['performer_photo']; $maker_name = $jsonArray['name']; $project_desc = isset($jsonArray['public_description']) ? $jsonArray['public_description'] : ''; } break; } } $field = $projData['meta_key']; $value = $projData['meta_value']; if ($field == 'project_photo' && $project_photo == '') { if (is_numeric($value)) { $project_photo = wp_get_attachment_url($value); } else { $project_photo = $value; } } if ($field == 'project_name' && $project_name == '') { $project_name = $value; } if (strpos($field, 'maker_name') !== false) { //if maker name has field_ in it, it is not a valid maker name. if (strpos($value, 'field_') === false && $maker_name == '') { $maker_name = $value; } } if ($field == 'project_description' && $project_desc == '') { $project_desc = $value; } } } else { //non archived record $link = "/maker/entry/" . $entry_id; $maker_first_name = $maker_last_name = ''; //check if this is a GF entry $leadSQL = "SELECT wp_rg_lead_detail.field_number,wp_rg_lead_detail.value,wp_rg_lead_detail_long.value as long_value " . " FROM wp_rg_lead_detail " . " left outer join wp_rg_lead_detail_long ON " . " wp_rg_lead_detail.id = wp_rg_lead_detail_long.lead_detail_id " . " WHERE wp_rg_lead_detail.lead_id = " . $entry_id . " order by lead_id, field_number"; foreach ($wpdb->get_results($leadSQL, ARRAY_A) as $projData) { switch ($projData['field_number']) { case '22': $project_photo = $projData['value']; break; case '151': $project_name = $projData['value']; break; case '16': if ($projData['long_value'] != NULL) { $project_desc = $projData['long_value']; } else { $project_desc = $projData['value']; } break; case '160.3': $maker_first_name = $projData['value']; break; case '160.6': $maker_last_name = $projData['value']; break; } $maker_name = $maker_first_name . ' ' . $maker_last_name; } } //do not add to ribbon array if $project_name, $project_photo and $project_desc are blank if ($project_name == '' && $project_photo == '' && $project_desc == '') { //skip } else { //build ribbon data array $currCount = isset($ribbonData[$entry_id]['ribbon'][$ribbonType]['count']) ? $ribbonData[$entry_id]['ribbon'][$ribbonType]['count'] : 0; $ribbonData[$entry_id]['ribbon'][$ribbonType]['count'] = (int) $currCount + (int) $numRibbons; $ribbonData[$entry_id]['fairedata'][] = array('year' => $year, 'faire' => $location, 'ribbonType' => $ribbonType == 0 ? 'blue' : 'red'); $ribbonData[$entry_id]['project_name'] = $project_name; $ribbonData[$entry_id]['project_photo'] = $project_photo; $ribbonData[$entry_id]['project_desc'] = $project_desc; $ribbonData[$entry_id]['maker_name'] = $maker_name; $ribbonData[$entry_id]['link'] = $link; } } foreach ($ribbonData as $entry_id => $data) { $blueCount = isset($data['ribbon'][0]['count']) ? $data['ribbon'][0]['count'] : 0; $redCount = isset($data['ribbon'][1]['count']) ? $data['ribbon'][1]['count'] : 0; $project_photo = $data['project_photo']; $project_photo = legacy_get_fit_remote_image_url($project_photo, 285, 270, 0); $jsondata = array('entryID' => $entry_id, "blueCount" => $blueCount, "redCount" => $redCount, "project_name" => html_entity_decode($data['project_name']), "project_photo" => $project_photo, "maker_name" => $data['maker_name'], "link" => $data['link'], "project_description" => html_entity_decode($data['project_desc']), "faireData" => array_map("unserialize", array_unique(array_map("serialize", $data['fairedata'])))); $json[] = $jsondata; if ($blueCount > 0) { $blueList[$blueCount]['winners'][] = $jsondata; $blueList[$blueCount]['numRibbons'] = $blueCount; } if ($redCount > 0) { $redList[$redCount]['winners'][] = $jsondata; $redList[$redCount]['numRibbons'] = $redCount; } } //blue list is an array of data //$blueList[number of blue ribbons]= array('numRibbons'=>number of blue ribbons // 'winners' =>ribbon data // ) //sort blue list and red list, within each group, alphabetically array_sort_by_column($blueList, 'numRibbons', SORT_DESC); foreach ($blueList as $key => &$value) { if (is_array($value['winners'])) { array_sort_by_column($value['winners'], 'project_name'); } foreach ($value['winners'] as $winnerKey => $winner) { foreach ($winner['faireData'] as $fdKey => $faireData) { if ($faireData['ribbonType'] == 'red') { unset($value['winners'][$winnerKey]['faireData'][$fdKey]); } } } $blueList[$key]['winners'] = $value['winners']; } array_sort_by_column($redList, 'numRibbons', SORT_DESC); foreach ($redList as $key => &$value) { if (is_array($value['winners'])) { array_sort_by_column($value['winners'], 'project_name'); } foreach ($value['winners'] as $winnerKey => $winner) { foreach ($winner['faireData'] as $fdKey => $faireData) { if ($faireData['ribbonType'] == 'blue') { unset($value['winners'][$winnerKey]['faireData'][$fdKey]); } } } $redList[$key]['winners'] = $value['winners']; } $return['json'] = $json; $return['blueList'] = $blueList; $return['redList'] = $redList; return json_encode($return); }