Пример #1
0
 /**
  * Returns current period instance
  *
  * @return <Doctrine_Object> instance of Period
  */
 public static function getCurrentPeriod()
 {
     $date = Period::getCurPeriodDate();
     $oPeriod = PeriodTable::getInstance()->findOneByDate($date);
     if (!$oPeriod instanceof Period) {
         // выставить новые тарифы на новый период
         UserTable::setNewTariffs();
         $oPeriod = new Period();
         // вычислить стоимость 1к знаков
         if (($prev = Period::getPrevPeriod()) === false) {
             $price1k = SettingTable::getOptionByName('price1k')->getValue();
         } else {
             // рассчитать веса пользователей
             UserTable::countWeights($prev);
             if (($price1k = VoteTable::getVoted1k($prev)) === false) {
                 $price1k = $prev->get1k();
             }
         }
         $oPeriod->set1k(number_format((double) $price1k, 2));
         // выставить процент
         $oPeriod->setR2rShare(number_format(Setting::getValueByName('percent_r2r'), 2, '.', ''));
         // --
         $oPeriod->setDate($date);
         $oPeriod->save();
         //throw new sfException('Cannot get current period. Error in DB data');
     }
     return $oPeriod;
 }