/** * Formats a date according to a customized pattern. * @param string $pattern the pattern (See {@link http://www.unicode.org/reports/tr35/#Date_Format_Patterns}) * @param mixed $time UNIX timestamp or a string in strtotime format * @return string formatted date time. */ public function format($pattern, $time) { if (is_string($time)) { if (ctype_digit($time)) { $time = (int) $time; } else { $time = strtotime($time); } } // var_dump("TIME--- "); // var_dump($time); // var_dump(" ----END TIME"); if (!is_numeric($time)) { $date = new DateTime(); $time = $date->getTimestamp(); } $date = CTimestamp::getDate($time, false, false); $tokens = $this->parseFormat($pattern); foreach ($tokens as &$token) { if (is_array($token)) { // a callback: method name, sub-pattern $token = $this->{$token[0]}($token[1], $date); } } return implode('', $tokens); }
public function init() { $dateInfo = CTimestamp::getDate(time()); $month = $dateInfo['mon']; $day = $dateInfo['mday']; $yDay = $dateInfo['yday']; foreach ($this->signsOrder as $key => $val) { $arr = explode('-', $val); $start = explode('.', $arr[0]); $end = explode('.', $arr[1]); settype($start[0], 'integer'); settype($start[1], 'integer'); settype($end[0], 'integer'); settype($end[1], 'integer'); if ($month >= $start[1] && $month <= $end[1]) { if ($day >= $start[0] || $day <= $end[0]) { $signMonth = $key; break; } } } $this->_data = Yii::app()->db->createCommand('SELECT p.`post_id`, p.`gallery_id`, h.`content`, h.`publication_date`, p.`title`, p.`created_date`, ph.`filename` FROM horoscope AS h LEFT JOIN posting AS p ON h.`post_id` = p.`post_id` LEFT JOIN gallery AS g ON p.`gallery_id` = g.`gallery_id` LEFT JOIN photo AS ph ON ph.`gallery_id` = g.`gallery_id` WHERE p.`title` LIKE :sign')->queryRow(true, array(':sign' => $this->signs[$signMonth])); // этот метод будет вызван внутри CBaseController::beginWidget() parent::init(); }
public function init() { $dateInfo = CTimestamp::getDate(time()); $month = $dateInfo['mon']; $day = $dateInfo['mday']; $year = $dateInfo['year']; $this->_data = Yii::app()->db->createCommand('SELECT m.`magazine_id`, m.`publication_year`, m.`publication_month`, m.title, m.filename AS magazine, p.`filename` FROM magazine AS m LEFT JOIN gallery AS g ON m.`gallery_id` = g.`gallery_id` LEFT JOIN photo AS p ON p.`gallery_id` = g.`gallery_id` WHERE m.`is_shown` = 1 AND m.`publication_year` <= :year AND m.`publication_month` <= :month ORDER BY m.publication_year DESC, m.publication_month DESC LIMIT 1')->queryRow(true, array(':month' => $month, ':year' => $year)); // этот метод будет вызван внутри CBaseController::beginWidget() parent::init(); }
/** * Formats a date according to a customized pattern. * * @param string $pattern the pattern (See {@link http://www.unicode.org/reports/tr35/#Date_Format_Patterns}) * @param mixed $time UNIX timestamp or a string in strtotime format * * @return string formatted date time. */ public function format($pattern, $time) { if (is_string($time)) { if (ctype_digit($time)) { $time = (int) $time; } else { $time = strtotime($time); } } $date = CTimestamp::getDate($time, false, false); $tokens = $this->parseFormat($pattern); foreach ($tokens as &$token) { if (is_array($token)) { $token = $this->{$token[0]}($token[1], $date); } } return implode('', $tokens); }
/** * Formats a date according to a customized pattern. * @param string $pattern the pattern (See {@link http://www.unicode.org/reports/tr35/tr35-dates.html#Date_Format_Patterns}) * @param mixed $time UNIX timestamp or a string in strtotime format * @return string formatted date time. Null if $time is null. (the null value check is available since Yii 1.1.11) */ public function format($pattern, $time) { if ($time === null) { return null; } if (is_string($time)) { if (ctype_digit($time) || $time[0] == '-' && ctype_digit(substr($time, 1))) { $time = (int) $time; } else { $time = strtotime($time); } } $date = CTimestamp::getDate($time, false, false); $tokens = $this->parseFormat($pattern); foreach ($tokens as &$token) { if (is_array($token)) { // a callback: method name, sub-pattern $token = $this->{$token[0]}($token[1], $date); } } return implode('', $tokens); }