/** * @return Period */ public static function getCurrentPeriod() { if (!self::$current) { $start = new DateTime(); $start->setDate($start->format('Y'), $start->format('n'), 1)->setTime(0, 0, 0); $end = clone $start; $end = $end->modify('+' . cal_days_in_month(CAL_GREGORIAN, $start->format('n'), $start->format('Y')) . ' day')->modify('-1 sec'); $period = Period::model()->findByAttributes(array('period_from' => $start->format(Task::DF_INTER), 'period_to' => $end->format(Task::DF_INTER))); if ($period == NULL) { $period = new Period(); $period->period_from = $start->format(Task::DF_INTER); $period->period_to = $end->format(Task::DF_INTER); $period->status = self::STATUS_ACTIVE; $period->name = $start->format('F, Y'); try { $period->save(); } catch (Exception $e) { } } self::$current = $period; } return self::$current; }