public function postInsert($event) { $oStatistics = new Statistics(); $oStatistics->setCategoryId($this->getId()); try { $iPeriod = Period::getCurrentPeriod(); } catch (sfException $e) { return; } if (false !== $iPeriod) { $oStatistics->setPeriodId($iPeriod); $oStatistics->save(); } }
/** * Returns row by input data * * @param integer $iPeriodId * @param integer $iCategoryId: null * @return Statistics */ public function getFullStatistics($iPeriodId, $iCategoryId = null) { $q = Doctrine_Query::create()->select('s.*')->from('Statistics s')->where('s.period_id=?', $iPeriodId)->limit(1); if (null !== $iCategoryId) { $q->andWhere('s.category_id=?', $iCategoryId); } else { $q->andWhere('s.category_id IS NULL'); } $stat = $q->fetchOne(); if (!is_object($stat)) { $stat = new Statistics(); $stat->setPeriodId($iPeriodId); if (null !== $iCategoryId) { $stat->setCategoryId($iCategoryId); } $stat->save(); } return $stat; }