示例#1
0
 /**
  * Returned results for the MonthsAndDaysCounter function
  * value for "days"               return $numbers_of_days_per_month
  * value for "months"             return $sum_month
  * value == "years"               return floor($sum_month/12)	                                        	                        
  * If value incorrect or missing  return JText::_( 'TCE_PLG_ERROR_AVERAGE' )
  */
 static function MonthsAndDaysCounter($day, $month, $year, $value)
 {
     $sum_month = 0;
     $number_days_per_month = 0;
     $numbers_of_days_per_month = 0;
     for ($year_counter = $year; $year_counter <= date("Y", modLastPlayedHelper::UserTimestamp()); $year_counter++) {
         if ($year_counter == $year && $year_counter != date("Y", modLastPlayedHelper::UserTimestamp())) {
             /*
              * Number of month of the first year *****************************************
              */
             for ($month_counter = $month + 1; $month_counter <= 12; $month_counter++) {
                 $sum_month = $sum_month + 1;
                 $calc_num_day = mktime(0, 0, 0, $month_counter, 1, $year_counter);
                 $number_days_per_month = $number_days_per_month + date("t", $calc_num_day);
             }
         } elseif ($year_counter >= $year && $year_counter != date("Y", modLastPlayedHelper::UserTimestamp())) {
             /*
              * Number of month for the next years *****************************************************
              */
             for ($month_counter = 1; $month_counter <= 12; $month_counter++) {
                 $sum_month = $sum_month + 1;
                 $calc_num_day = mktime(0, 0, 0, $month_counter, 1, $year_counter);
                 $number_days_per_month = $number_days_per_month + date("t", $calc_num_day);
             }
         } elseif ($year_counter == date("Y", modLastPlayedHelper::UserTimestamp()) && $year != date("Y", modLastPlayedHelper::UserTimestamp())) {
             /*
              * Numbers of months for the last year ***************************************
              */
             for ($month_counter = 1; $month_counter <= date("m", modLastPlayedHelper::UserTimestamp()); $month_counter++) {
                 $sum_month = $sum_month + 1;
                 $calc_num_day = mktime(0, 0, 0, $month_counter, 1, $year_counter);
                 $number_days_per_month = $number_days_per_month + date("t", $calc_num_day);
             }
         } else {
             /*
              * If only one year
              */
             $numbers_of_days_per_month = 0;
             for ($month_counter = $month; $month_counter <= date("m", modLastPlayedHelper::UserTimestamp()); $month_counter++) {
                 $sum_month = $sum_month + 1;
                 $calc_num_day = mktime(0, 0, 0, $month_counter, 1, $year_counter);
                 if ($sum_month == 1 && $month != date("m", modLastPlayedHelper::UserTimestamp())) {
                     /*
                      * Days of the frist month****************************************************
                      */
                     $numbers_of_days_per_month = date("t", $calc_num_day) - $day;
                 } elseif ($sum_month == 1 && $month == date("m", modLastPlayedHelper::UserTimestamp())) {
                     /*
                      * Days of the frist month****************************************************
                      */
                     $numbers_of_days_per_month = date("d", modLastPlayedHelper::UserTimestamp()) - $day;
                 } elseif ($month_counter <= date("m", modLastPlayedHelper::UserTimestamp())) {
                     /*
                      * Days of last month****************************************************
                      */
                     $numbers_of_days_per_month = $numbers_of_days_per_month + date("d", modLastPlayedHelper::UserTimestamp());
                 } else {
                     /*
                      * Days of a complete month*******************************************************************
                      */
                     $calc_num_day = mktime(0, 0, 0, $month_counter, 1, $year_counter);
                     $numbers_of_days_per_month = $numbers_of_days_per_month + date("t", $calc_num_day);
                 }
             }
         }
     }
     if ($value == "days") {
         return $numbers_of_days_per_month;
     } elseif ($value == "months") {
         return $sum_month;
     } elseif ($value == "years") {
         return floor($sum_month / 12);
     } else {
         return JText::_('TCE_PLG_ERROR_AVERAGE');
     }
 }