enyr_napdf.class.php

Go to the documentation of this file.
00001 <?php
00002 /**
00003     \file enyr_napdf.class.php
00004     
00005     \brief This file creates and dumps a ENYR meeting list in PDF form.
00006 */
00007 // Get the napdf class, which is used to fetch the data and construct the file.
00008 require_once ( dirname ( __FILE__ ).'/../pdf_generator/printableList.class.php' );
00009 require_once ( dirname ( __FILE__ ).'/pdf_decls.php' );
00010 
00011 /**
00012     \brief  This creates and manages an instance of the napdf class, and creates
00013     the PDF file.
00014 */
00015 class enyr_napdf extends printableList implements IPrintableList
00016 {
00017     var $weekday_names = array ( "Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday" );
00018     var $pos = array ( 'start' => 1, 'end' => '', 'count' => 0, 'y' => 0, 'weekday' => 1 );
00019     var $right_offset = 0;
00020     var $formats = 0;
00021     var $special_formats = '';
00022     
00023     /********************************************************************
00024         \brief  The constructor for this class does a lot. It creates the instance of the napdf class, gets the data from the
00025         server, then sorts it. When the constructor is done, the data is ready to be assembled into a PDF.
00026         
00027         If the napdf object does not successfully get data from the server, then it is set to null.
00028     */
00029     function __construct ( $in_http_vars    ///< The HTTP parameters we'd like to send to the server.
00030                             )
00031     {
00032         $this->page_x = 4.25;       ///< The width, in inches, of each page
00033         $this->page_y = 5.25;       ///< The height, in inches, of each page.
00034         $this->units = 'in';        ///< The measurement units (inches)
00035         $this->font = 'Times';      ///< The font we'll use
00036         $this->font_size = 7.25;    ///< The font size we'll use
00037         $this->orientation = 'P';   ///< The orientation (portrait)
00038         /// These are the sort keys, for sorting the meetings before display
00039         $this->sort_keys = array (  'weekday_tinyint' => true,          ///< First, weekday
00040                                     'start_time' => true,               ///< Finally, the time the meeting starts
00041                                     'week_starts' => 1                  ///< Our week starts on Sunday (1)
00042                                     );
00043         /// These are the parameters that we send over to the root server, in order to get our meetings.
00044         $this->out_http_vars = array ('do_search' => 'yes',                     ///< Do a search
00045                                     'bmlt_search_type' => 'advanced',           ///< We'll be very specific in our request
00046                                     'advanced_service_bodies' => array (        ///< We will be asking for meetings in specific Service Bodies.
00047                                                                         1,      ///< GNYR
00048                                                                         2,      ///< ENYR
00049                                                                         1001,   ///< SASASC
00050                                                                         1002,   ///< NASC
00051                                                                         1003,   ///< ELIASC
00052                                                                         1004,   ///< SSASC
00053                                                                         1005,   ///< BxASC
00054                                                                         1006,   ///< BkASC
00055                                                                         1007,   ///< KBASC
00056                                                                         1008,   ///< MahASC
00057                                                                         1009,   ///< MHASC
00058                                                                         1010,   ///< NYCASC
00059                                                                         1011,   ///< OAASC
00060                                                                         1012,   ///< RASC
00061                                                                         1013,   ///< SIASC
00062                                                                         1014,   ///< WASC
00063                                                                         1015,   ///< Metro Area ASC
00064                                                                         1016,   ///< QASC
00065                                                                         1017    ///< WQASC
00066                                                                         )
00067                                     );
00068 
00069         $this->lang_search = array ( 'en', 'es' );
00070         
00071         napdf::$sort_callback = 'enyr_napdf::sort_meeting_data_callback_ny';
00072         
00073         parent::__construct ( $in_http_vars, $this->lang_search );
00074     }
00075         
00076     /*************************** INTERFACE FUNCTIONS ***************************/
00077     /********************************************************************
00078         \brief This function actually assembles the PDF. It does not output it.
00079         
00080         \returns a boolean. true if successful.
00081     */
00082     function AssemblePDF ()
00083     {
00084         $ret = false;
00085         
00086         if ( $this->napdf_instance instanceof napdf )
00087             {
00088             $this->DrawFormatPage ( );
00089             $all_meetings = $this->napdf_instance->meeting_data;
00090             $spanish_meetings = array();
00091             foreach ( $all_meetings as $meeting )
00092                 {
00093                 if ( preg_match ( '|ES|i', $meeting['formats'] ) )
00094                     {
00095                     array_push ( $spanish_meetings, $meeting );
00096                     }
00097                 }
00098             
00099             $this->napdf_instance->meeting_data = $spanish_meetings;
00100             while ( !$this->pos['end'] )
00101                 {
00102                 $this->DrawListPage (_PDF_SPANISH);
00103                 }
00104             $this->napdf_instance->meeting_data = $all_meetings;
00105             $this->pos = array ( 'start' => 1, 'end' => '', 'count' => 0, 'y' => 0, 'weekday' => 1 );
00106             while ( !$this->pos['end'] )
00107                 {
00108                 $this->DrawListPage ();
00109                 }
00110             $ret = true;
00111             }
00112         
00113         return $ret;
00114     }
00115     
00116     /********************************************************************
00117     */
00118     function OutputPDF ()
00119     {
00120         $d = date ( "Y_m_d" );
00121         $this->napdf_instance->Output( "ENYR_PrintableList_$d.pdf", "D" );
00122     }
00123     
00124     /*************************** INTERNAL FUNCTIONS ***************************/
00125     /********************************************************************
00126     */
00127     private static function sort_cmp_formats ($a, $b) 
00128     {
00129     $order_array = array(   0=>"O", 1=>"C",
00130                             2=>"ES", 3=>"B", 4=>"M", 5=>"W", 6=>"GL", 7=>"YP", 8=>"BK", 9=>"IP", 10=>"Pi", 11=>"RF", 12=>"Rr",
00131                             13=>"So", 14=>"St", 15=>"To", 16=>"Tr", 17=>"OE", 18=>"D", 19=>"SD", 20=>"TW", 21=>"IL",
00132                             22=>"BL", 23=>"IW", 24=>"BT", 25=>"SG", 26=>"JT",
00133                             27=>"Ti", 28=>"Sm", 29=>"NS", 30=>"CL", 31=>"CS", 32=>"NC", 33=>"SC", 34=>"CH", 35=>"SL", 36=>"WC" );
00134     
00135     if ( in_array ( $a['key_string'], $order_array ) || in_array ( $b['key_string'], $order_array ) )
00136         {
00137         return (array_search ( $a['key_string'], $order_array ) < array_search ( $b['key_string'], $order_array )) ? -1 : 1;
00138         }
00139     else
00140         {
00141         return 0;
00142         }
00143     }
00144 
00145     /********************************************************************
00146         \brief Combines the two languages for a common format display.
00147         
00148         \returns a new array, with the format data sorted out. The Spanish
00149         description is appended to the description by a line feed.
00150     */
00151     private static function sort_formats( $in_format_data   ///< An array of format information
00152                                         )
00153     {
00154         $ret = array();
00155         
00156         foreach ( $in_format_data as $format )
00157             {
00158             if ( $format['lang'] == 'en' )  // We skip the Spanish, and only work on the English.
00159                 {
00160                 $s_desc = ((isset ( $in_format_data[$format['id'].'_es'] )) ? '('.$in_format_data[$format['id'].'_es']['name_string'].') '.$in_format_data[$format['id'].'_es']['description_string'] : null);
00161                 $r_temp = array (   'key_string' => $format['key_string'],
00162                                     'description_string' => '('.$format['name_string'].') '.$format['description_string']
00163                                     );
00164                 if ( $s_desc )
00165                     {
00166                     $r_temp['description_string'] .= "\n$s_desc";
00167                     }
00168                 
00169                 array_push ( $ret, $r_temp );
00170                 }
00171             }
00172         
00173         usort ( $ret, 'enyr_napdf::sort_cmp_formats' );
00174         
00175         return $ret;
00176     }
00177 
00178     /********************************************************************
00179     */
00180     private function DrawFormatPage ( )
00181     {
00182     $formats = self::sort_formats ( $this->napdf_instance->format_data );
00183 
00184     $this->napdf_instance->SetFont ( $this->font, '', $this->font_size );
00185     $heading_height = 9;
00186     $height = ($heading_height/72) + 0.01;
00187     $top = 0.125;
00188     $left = 0.125;
00189     $bottom = $this->napdf_instance->h - 0.125;
00190     $right = $this->napdf_instance->w - 0.125;
00191     $fontFamily = $this->napdf_instance->FontFamily;
00192     $fontSize = $this->napdf_instance->FontSizePt;
00193     $fontSizeSmaller = $fontSize - 0.25;
00194     $fSize = $fontSizeSmaller / 72;
00195     $this->right_offset = 0.4;
00196     $space_needed = (($fontSizeSmaller / 72) * 5) + 0.02;
00197     $y_offset = $bottom - $fSize;
00198     
00199     $newpage = 2;
00200     
00201     $countmax = count ( $formats );
00202     
00203     $this->special_formats = array ( 'WC' => '', 'NC' => '' );
00204         
00205     for ( $count = 0; $count < $countmax; $count++ )
00206         {
00207         $format_code = $formats[$count]['key_string'];
00208         $format_english = $formats[$count]['description_string'];
00209         
00210         if ( isset ( $this->special_formats[$format_code] ) )
00211             {
00212             $this->special_formats[$format_code] = $format_english;
00213             $format_code = null;
00214             }
00215         
00216         if ( $format_code )
00217             {
00218             if ( $newpage )
00219                 {
00220                 $this->napdf_instance->AddPage();
00221                 $this->napdf_instance->SetFont ( $fontFamily, 'B', 7 );
00222                 $this->napdf_instance->Line ( $left, $y_offset - 0.1, $right, $y_offset - 0.1 );
00223                 $this->napdf_instance->SetXY ( $left, $y_offset );
00224                 global $resized;
00225                 
00226                 $this->napdf_instance->Cell ( 0, 0, _PDF_CHANGE_NOTE );
00227                 $this->napdf_instance->SetXY ( $right, $y_offset );
00228                 $this->napdf_instance->Cell ( 0, 0, _PDF_PAGE." ".$this->napdf_instance->PageNo(), 0, 0, "R" );
00229                 $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00230                 $this->napdf_instance->SetFillColor ( 0 );
00231                 $this->napdf_instance->SetTextColor ( 255 );
00232                 $header = ""._PDF_LEGEND_HEADER."";
00233                 if ( $newpage != 2 )
00234                     {
00235                     $header .= _PDF_CONTD;
00236                     }
00237                 
00238                 $this->napdf_instance->SetFont ( $fontFamily, 'B', $heading_height );
00239                 $stringWidth = $this->napdf_instance->GetStringWidth ( $header );
00240                 $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00241                 $this->napdf_instance->Rect ( $left, $top, ($right - $left), $height, "F" );
00242                 $this->napdf_instance->SetXY ( $cellleft, $top + 0.01 );
00243                 $this->napdf_instance->Cell ( 0, $heading_height/72, $header );
00244                 $this->napdf_instance->SetFillColor ( 255 );
00245                 $this->napdf_instance->SetTextColor ( 0 );
00246                 $newpage = "";
00247                 $this->napdf_instance->SetY ( $top + $height );
00248                 }
00249             else
00250                 {
00251                 $this->napdf_instance->Line ( $left, $this->napdf_instance->GetY() + 0.01, $right, $this->napdf_instance->GetY() + 0.01 );
00252                 $this->napdf_instance->SetY ( $this->napdf_instance->GetY() + 0.02 );
00253                 }
00254             
00255             $y = $this->napdf_instance->GetY();
00256             
00257             $this->napdf_instance->SetFont ( $fontFamily, 'B', $fontSizeSmaller );
00258             $this->napdf_instance->SetLeftMargin ( $left );
00259             $this->napdf_instance->SetXY ( $left, $y );
00260             $this->napdf_instance->MultiCell ( $this->right_offset - $left, $fSize, utf8_decode ( $format_code ), 0, "L" );
00261     
00262             $this->napdf_instance->SetFont ( $fontFamily, '', $fontSizeSmaller );
00263             $this->napdf_instance->SetLeftMargin ( $this->right_offset );
00264             $this->napdf_instance->SetXY ( $this->right_offset, $y );
00265             $this->napdf_instance->MultiCell ( $right - $this->right_offset, $fSize, utf8_decode ( $format_english ), 0, "L" );
00266             
00267             if ( ($this->napdf_instance->GetY() + 0.01 + $space_needed) >= $y_offset )
00268                 {
00269                 $newpage = 1;
00270                 }
00271             }
00272         }
00273     
00274     if ( ($this->napdf_instance->GetY() + 0.3 + $fSize/72) > $y_offset )
00275         {
00276         $this->napdf_instance->AddPage();
00277         $y = $y_offset;
00278         }
00279     else
00280         {
00281         $y = $this->napdf_instance->GetY() + 0.3;
00282         }
00283     
00284     $this->napdf_instance->Line ( $left, $y - 0.1, $right, $y - 0.1 );
00285     $this->napdf_instance->SetXY ( $left, $y );
00286     $this->napdf_instance->SetFont ( $fontFamily, 'I', $fontSize );
00287     $this->napdf_instance->Cell ( 0, $fSize/72, _DEFAULT_DURATION );
00288     $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00289     $this->napdf_instance->SetLeftMargin ( $left );
00290     }
00291     
00292     /********************************************************************
00293     */
00294     private function DrawListPage ( $in_header = null )
00295     {
00296     $meetings =& $this->napdf_instance->meeting_data;
00297     
00298     $count_max = count ( $meetings );
00299     
00300     $fontFamily = $this->napdf_instance->FontFamily;
00301     $fontSize = $this->napdf_instance->FontSizePt;
00302     
00303     $top = 0.125;
00304     $left = 0.125;
00305     $bottom = $this->napdf_instance->h - 0.125;
00306     $right = $this->napdf_instance->w - 0.125;
00307     $this->right_offset = 1.5;
00308     
00309     $heading_height = 9;
00310     $height = ($heading_height/72) + 0.01;
00311     $gap2 = 0.02;
00312     
00313     $fSize = $fontSize / 70;
00314     $fSizeSmall = ($fontSize - 1) / 70;
00315 
00316     $height_one_meeting = ($fSize * 3) + $gap2;
00317     
00318     $y_offset = $bottom - $fSize;
00319     
00320     $current_county = " ";
00321     $current_day = " ";
00322     
00323     $extra_height = $height + 0.05;
00324 
00325     $this->napdf_instance->AddPage();
00326     $this->pos['y'] = $top;
00327     $watermark_pos = 1.0;
00328     
00329     if ( $this->pos['start'] )
00330         {
00331         $this->pos['count'] = 0;
00332         }
00333     
00334     while ( !$this->pos['end'] && (($this->pos['y'] + $height_one_meeting + $extra_height + ($fSizeSmall * 2)) < ($y_offset - 0.1)) )
00335         {
00336         $extra = 0;
00337         $contd = "";
00338         $meeting = $meetings[intval($this->pos['count'])];
00339         $this->napdf_instance->SetLeftMargin ( $left );
00340         
00341         $county = $meeting['location_city_subsection'];
00342         if ( !$county )
00343             {
00344             $county = $meeting['location_sub_province'];
00345             }
00346         
00347         if ( $this->pos['start'] || ($current_county != $county) || ($current_day != $meeting['weekday_tinyint']) )
00348             {
00349             $this->napdf_instance->SetFillColor ( 0 );
00350             $this->napdf_instance->SetTextColor ( 255 );
00351             if ( $this->pos['start'] )
00352                 {
00353                 $this->pos['start'] = "";
00354                 }
00355             else
00356                 {
00357                 if ( ($this->pos['y'] == $top) && ($this->pos['weekday'] == $meeting['weekday_tinyint']) && ($this->pos['county'] == $county) )
00358                     {
00359                     $contd = _PDF_CONTD;
00360                     }
00361                 }
00362             if ( ($this->pos['y'] == $top) && ($this->pos['weekday'] == $meeting['weekday_tinyint']) && ($this->pos['county'] == $county) )
00363                 {
00364                 $contd = _PDF_CONTD;
00365                 }
00366             
00367             if ( $current_day != $meeting['weekday_tinyint'] )
00368                 {
00369                 $this->pos['weekday'] = $meeting['weekday_tinyint'];
00370                 $current_day = $this->pos['weekday'];
00371                 }
00372             
00373             if ( $current_county != $county )
00374                 {
00375                 $this->pos['county'] = $county;
00376                 $current_county = $this->pos['county'];
00377                 }
00378             
00379             $header = $current_county." - ".$this->weekday_names[$current_day - 1];
00380             $header .= $in_header;
00381             $header .= $contd;
00382             
00383             $current_county = $meeting['location_city_subsection'];
00384             if ( !$current_county )
00385                 {
00386                 $current_county = $meeting['location_sub_province'];
00387                 }
00388             
00389             $this->napdf_instance->SetFont ( $fontFamily, 'B', $heading_height );
00390             $this->napdf_instance->Rect ( $left, $this->pos['y'], ($right - $left), $height, "F" );
00391             $stringWidth = $this->napdf_instance->GetStringWidth ( $header );
00392             $cellleft = (($right + $left) / 2) - ($stringWidth / 2);
00393             $this->napdf_instance->SetXY ( $cellleft, $this->pos['y'] + 0.005 );
00394             $this->napdf_instance->Cell ( 0, $heading_height/72, $header );
00395             $this->pos['y'] += ($height);
00396             }
00397         else
00398             {
00399             $this->napdf_instance->Line ( $left, $this->pos['y'], $right, $this->pos['y'] );
00400             }
00401         
00402         $this->napdf_instance->SetFillColor ( 255 );
00403         $this->napdf_instance->SetTextColor ( 0 );
00404         
00405         $cell_top = $this->pos['y'] + $gap2;
00406         $this->napdf_instance->SetXY ( $left, $cell_top );
00407         
00408         $this->napdf_instance->SetFont ( $fontFamily, 'B', $fontSize );
00409         
00410         $left_string = self::translate_time ( $meeting['start_time'] );
00411         $meeting['duration_time'] = trim ( $meeting['duration_time'] );
00412         
00413         if ( isset ( $meeting['duration_time'] ) && $meeting['duration_time'] && ('01:30:00' != $meeting['duration_time']) )
00414             {
00415             $left_string .= " (".self::translate_duration ( $meeting['duration_time'] ).")";
00416             }
00417             
00418         $left_string .= " (".$this->RearrangeFormats ( $meeting['formats'] ).")";
00419         
00420         $this->napdf_instance->SetX ( $left );
00421         $this->napdf_instance->MultiCell ( $this->right_offset - $left, $fSize, utf8_decode ( $left_string ), 0, "L" );
00422 
00423         $left_string = $meeting['location_neighborhood'];
00424         
00425         if ( !$left_string )
00426             {
00427             $left_string = $meeting['location_municipality'];
00428             }
00429         
00430         if ( $meeting['location_province'] != 'NY' )
00431             {
00432             if ( $left_string )
00433                 {
00434                 $left_string .= ', ';
00435                 }
00436             
00437             $left_string .= trim ( $meeting['location_province'] );
00438             }
00439             
00440         $this->napdf_instance->SetX ( $left );
00441         $this->napdf_instance->MultiCell ( $this->right_offset - $left, $fSize, utf8_decode ( $left_string ), 0, "L" );
00442         
00443         $desc = $this->Get_Special_Format_Text ( $meeting['formats'] );
00444         
00445         if ( $meeting['description_string'] )
00446             {
00447             if ( $desc )
00448                 {
00449                 $desc .= ", ";
00450                 }
00451             $desc = $meeting['description_string'];
00452             }
00453         
00454         if ( $meeting['comments'] )
00455             {
00456             if ( $desc )
00457                 {
00458                 $desc .= ", ";
00459                 }
00460             $desc .= $meeting['comments'];
00461             }
00462         
00463         $desc = preg_replace ( "/[\n|\r]/", ", ", $desc );
00464         $desc = preg_replace ( "/,\s*,/", ",", $desc );
00465         $desc = stripslashes ( stripslashes ( $desc ) );
00466         
00467         $trueLeft = $left;
00468         
00469         $yMax = $this->napdf_instance->GetY ( );
00470         
00471         // Done with the left side. Now for the right side.
00472         
00473         $this->napdf_instance->SetLeftMargin ( $this->right_offset );
00474         $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00475         $right_string = $meeting['meeting_name'];
00476         $this->napdf_instance->SetXY ( $this->right_offset, $cell_top );
00477         
00478         if ( isset ( $meeting['location_text'] ) )
00479             {
00480             $meeting['location_text'] = trim ( $meeting['location_text'] );
00481             
00482             if ( $meeting['location_text'] )
00483                 {
00484                 $right_string .= " (".$meeting['location_text'].")";
00485                 }
00486             }
00487 
00488         $this->napdf_instance->MultiCell ( $right - $this->right_offset, $fSize, utf8_decode ( $right_string ), 0, "L" );
00489         
00490         $right_string = $meeting['location_street'];
00491         
00492         if ( isset ( $meeting['location_info'] ) )
00493             {
00494             $meeting['location_info'] = trim ( $meeting['location_info'] );
00495             
00496             if ( $meeting['location_info'] )
00497                 {
00498                 $right_string .= " (".$meeting['location_info'].")";
00499                 }
00500             }
00501 
00502         $this->napdf_instance->SetX ( $this->right_offset );
00503         $this->napdf_instance->MultiCell ( $right - $this->right_offset, $fSize, utf8_decode ( $right_string ), 0, "L" );
00504         
00505         $yMax = max ( $yMax, $this->napdf_instance->GetY ( ) );
00506 
00507         if ( $desc )
00508             {
00509             $extra = ($fSizeSmall * 3);
00510             $this->napdf_instance->SetFont ( $fontFamily, 'I', $fontSize - 1 );
00511             $this->napdf_instance->SetXY ( $left, $yMax );
00512             $this->napdf_instance->MultiCell ( $right - $left, $fSizeSmall, utf8_decode ( $desc ), 0, "L" );
00513             }
00514         
00515         $yMax = max ( $yMax, $this->napdf_instance->GetY ( ) ) + $gap2;
00516         $this->pos['y'] = $yMax;
00517         $this->pos['count']++;
00518         
00519         if ( $this->pos['count'] == $count_max )
00520             {
00521             $this->pos['end'] = 1;
00522             }
00523         else
00524             {
00525             $next_meeting = $meetings[intval($this->pos['count'])];
00526             
00527             $next_meeting_county = $next_meeting['location_city_subsection'];
00528             if ( !$next_meeting_county )
00529                 {
00530                 $next_meeting_county = $next_meeting['location_sub_province'];
00531                 }
00532             
00533             if (    ($current_county != $next_meeting_county)
00534                 ||  ($current_day != $next_meeting['weekday_tinyint']))
00535                 {
00536                 $extra_height = $height + 0.05;
00537                 }
00538             else
00539                 {
00540                 $extra_height = 0;
00541                 }
00542             }
00543         }
00544     
00545     $this->napdf_instance->SetFont ( $fontFamily, 'B', 7 );
00546     $this->napdf_instance->Line ( $left, $y_offset - 0.1, $right, $y_offset - 0.1 );
00547     $this->napdf_instance->SetXY ( $left, $y_offset );
00548     $this->napdf_instance->Cell ( 0, 0, _PDF_CHANGE_NOTE );
00549     $this->napdf_instance->SetXY ( $right, $y_offset );
00550     $this->napdf_instance->Cell ( 0, 0, _PDF_PAGE." ".$this->napdf_instance->PageNo(), 0, 0, "R" );
00551     $this->napdf_instance->SetFont ( $fontFamily, '', $fontSize );
00552     }
00553 
00554     /********************************************************************
00555     */
00556     private function Get_Special_Format_Text ( $inFormats )
00557     {
00558     $ret = "";
00559     
00560     $format_array = split ( ",", $inFormats );
00561 
00562     foreach ( $format_array as $format )
00563         {
00564         if ( $this->special_formats[$format] )
00565             {
00566             if ( $ret )
00567                 {
00568                 $ret .= ", ";
00569                 }
00570             
00571             $ret .= $this->special_formats[$format];
00572             }
00573         }
00574     
00575     return $ret;
00576     }
00577 
00578     /********************************************************************
00579     */
00580     private function RearrangeFormats ( $inFormats )
00581     {
00582     $inFormats = split ( ",", $inFormats );
00583     
00584     if ( !in_array ( "C", $inFormats ) && !in_array ( "O", $inFormats ) )
00585         {
00586         array_push ( $inFormats, "C" );
00587         }
00588     
00589     if ( !$ignore_bk && !in_array ( "BK", $inFormats ) && ((in_array ( "BT", $inFormats ) || in_array ( "IW", $inFormats ) || in_array ( "JT", $inFormats ) || in_array ( "SG", $inFormats ))) )
00590         {
00591         array_push ( $inFormats, "BK" );
00592         }
00593     
00594     for ( $c = 0; $c < count ( $inFormats ); $c++ )
00595         {
00596         if ( array_key_exists ( $inFormats[$c], $this->special_formats ) )
00597             {
00598             $inFormats[$c] = null;
00599             unset ( $inFormats[$c] );
00600             }
00601         }
00602     
00603     uasort ( $inFormats, 'enyr_napdf::sort_cmp' );
00604     
00605     $tFormats = $inFormats;
00606     
00607     $inFormats = array();
00608     
00609     foreach ( $tFormats as $format )
00610         {
00611         $format = trim ( $format );
00612         if ( $format )
00613             {
00614             array_push ( $inFormats, $format );
00615             }
00616         }
00617     
00618     return join ( ",", $inFormats );
00619     }
00620 
00621     /********************************************************************
00622     */
00623     private static function sort_cmp ($a, $b) 
00624     {
00625     $order_array = array(   0=>"O", 1=>"C",
00626                             2=>"ES", 3=>"B", 4=>"M", 5=>"W", 6=>"GL", 7=>"YP", 8=>"BK", 9=>"IP", 10=>"Pi", 11=>"RF", 12=>"Rr",
00627                             13=>"So", 14=>"St", 15=>"To", 16=>"Tr", 17=>"OE", 18=>"D", 19=>"SD", 20=>"TW", 21=>"IL",
00628                             22=>"BL", 23=>"IW", 24=>"BT", 25=>"SG", 26=>"JT",
00629                             27=>"Ti", 28=>"Sm", 29=>"NS", 30=>"CL", 31=>"CS", 32=>"NC", 33=>"SC", 34=>"CH", 35=>"SL", 36=>"WC" );
00630     
00631     if ( in_array ( $a, $order_array ) || in_array ( $b, $order_array ) )
00632         {
00633         return (array_search ( $a, $order_array ) < array_search ( $b, $order_array )) ? -1 : 1;
00634         }
00635     else
00636         {
00637         return 0;
00638         }
00639     }
00640 
00641     /********************************************************************
00642     */
00643     private static function translate_time ( $in_time_string ) 
00644     {
00645         $split = split ( ":", $in_time_string );
00646         if ( $in_time_string == "12:00:00" )
00647             {
00648             return "Noon";
00649             }
00650         elseif ( ($split[0] == "23") && (intval ( $split[1] ) > 45) )
00651             {
00652             return "Midnight";
00653             }
00654         else
00655             {
00656             return date ( "g:i A", strtotime ( $in_time_string ) );
00657             }
00658     }
00659 
00660     /********************************************************************
00661     */
00662     private static function translate_duration ( $in_time_string ) 
00663     {
00664         $t = split ( ":", $in_time_string );
00665         $hours = intval ( $t[0] );
00666         $minutes = intval ( $t[1] );
00667         
00668         $ret = '';
00669         
00670         if ( $hours )
00671             {
00672             $ret .= "$hours hour";
00673             
00674             if ( $hours > 1 )
00675                 {
00676                 $ret .= "s";
00677                 }
00678                 
00679             if ( $minutes )
00680                 {
00681                 $ret .= " and ";
00682                 }
00683             }
00684         
00685         if ( $minutes )
00686             {
00687             $ret .= "$minutes minutes";
00688             }
00689         
00690         return $ret;
00691     }
00692     
00693     /**
00694         \brief  This is a static callback function to be used for sorting the multi-dimensional meeting_data
00695                 array. It uses the sort_order_keys array to determine the sort.
00696                 
00697         \returns an integer. -1 if a < b, 0 if a == b, or 1 if a > b.
00698     */
00699     static function sort_meeting_data_callback_ny ( &$in_a,     ///< The first meeting array to compare
00700                                                     &$in_b      ///< The second meeting array to compare
00701                                                     )
00702     {
00703         $ret = 0;
00704         
00705         if ( is_array ( $in_a ) && is_array ( $in_b ) && is_array ( napdf::$sort_order_keys ) )
00706             {
00707             // We reverse the array, in order to sort from least important to most important.
00708             $sort_keys = array_reverse ( napdf::$sort_order_keys, true );
00709 
00710             foreach ( $sort_keys as $key => $value )
00711                 {
00712                 if ( isset ( $in_a[$key] ) && isset ( $in_b[$key] ) )
00713                     {
00714                     $val_a = trim ( $in_a[$key] );
00715                     $val_b = trim ( $in_b[$key] );
00716 
00717                     if ( ('weekday_tinyint' == $key) && (napdf::$week_starts > 1) && (napdf::$week_starts < 8) )
00718                         {
00719                         $val_a -= napdf::$week_starts;
00720 
00721                         if ( $val_a < 0 )
00722                             {
00723                             $val_a += 8;
00724                             }
00725                         else
00726                             {
00727                             $val_a += 1;
00728                             }
00729                         
00730                         $val_b -= napdf::$week_starts;
00731                         
00732                         if ( $val_b < 0 )
00733                             {
00734                             $val_b += 8;
00735                             }
00736                         else
00737                             {
00738                             $val_b += 1;
00739                             }
00740                         }
00741 
00742                     // We know a few keys already, and we can determine how the sorting goes from there.
00743                     switch ( $key )
00744                         {
00745                         case 'start_time':
00746                         case 'duration_time':
00747                             $val_a = strtotime ( $val_a );
00748                             $val_b = strtotime ( $val_b );
00749                         case 'weekday_tinyint':
00750                         case 'id_bigint':
00751                         case 'shared_group_id_bigint':
00752                         case 'service_body_bigint':
00753                             $val_a = intval ( $val_a );
00754                             $val_b = intval ( $val_b );
00755                         case 'longitude':
00756                         case 'latitude':
00757                             if ( $val_a > $val_b )
00758                                 {
00759                                 $ret = 1;
00760                                 }
00761                             elseif ( $val_b > $val_a )
00762                                 {
00763                                 $ret = -1;
00764                                 }
00765                         break;
00766                         
00767                         default:
00768                             // We ignore blank values
00769                             if ( strlen ( $val_a ) && strlen ( $val_b ) )
00770                                 {
00771                                 $tmp = strcmp ( strtolower ( $val_a ), strtolower ( $val_b ) );
00772                                 
00773                                 if ( $tmp != 0 )
00774                                     {
00775                                     $ret = $tmp;
00776                                     }
00777                                 }
00778                         break;
00779                         }
00780                     }
00781                 
00782                 if ( !$value )
00783                     {
00784                     $ret = -$ret;
00785                     }
00786                 }
00787             
00788             $county_a = trim ( $in_a['location_city_subsection'] );
00789             if ( !$county_a )
00790                 {
00791                 $county_a = trim ( $in_a['location_sub_province'] );
00792                 }
00793             
00794             $county_b = trim ( $in_b['location_city_subsection'] );
00795             if ( !$county_b )
00796                 {
00797                 $county_b = trim ( $in_b['location_sub_province'] );
00798                 }
00799             
00800             if ( isset ( $county_a ) && isset ( $county_b ) )
00801                 {
00802                 $tmp = strcmp ( strtolower ( $county_a ), strtolower ( $county_b ) );
00803                 
00804                 if ( $tmp != 0 )
00805                     {
00806                     $ret = $tmp;
00807                     }
00808                 }
00809             }
00810         
00811         return $ret;
00812     }
00813 };
00814 ?>
 All Data Structures Files Functions Variables Enumerations