31536000, 'month' => 2592000, 'week' => 604800, 'day' => 86400, 'hour' => 3600, 'minute' => 60, 'second' => 1); public function getListSelect() { if (null === $this->_select) { parent::getListSelect(); $this->_select->where("`status` = 'approved'"); } return $this->_select; } protected function _prepareList(&$list) { parent::_prepareList($list); foreach ($list as &$item) { $item['timeAgo'] = $this->_getTimeAgo(strtotime($item['date'])); } return $this; } protected function _getTimeAgo($lastDate) { if (!is_int($lastDate)) { return false; } $diff = time() - $lastDate; $part1 = $this->_getFirstPart($diff); if (!empty($part1)) { $part2 = $this->_getFirstPart($part1['diff']); return $part1['str'] . ' ' . $part2['str']; } return $part1['str']; } protected function _getFirstPart($diff) { foreach ($this->_times as $label => $sec) { $p = $diff / $sec; if ($p >= 1) { $rp = floor($p); $s = $rp . ' ' . $label; return array( 'str' => ($rp == 1) ? $s : $s . 's', 'diff' => $diff - $rp*$sec, ); } } return null; } }