public static function dateWithOffSet($str = '') { $userTZ = DiscussDateHelper::getOffSet(); $date = DiscussHelper::getDate($str); if (DiscussHelper::getJoomlaVersion() >= '1.6') { $user = JFactory::getUser(); $config = DiscussHelper::getConfig(); $jConfig = DiscussHelper::getJConfig(); // temporary ignore the dst in joomla 1.6 if ($user->id != 0) { $userTZ = $user->getParam('timezone'); } if (empty($userTZ)) { $userTZ = $jConfig->get('offset'); } $tmp = new DateTimeZone($userTZ); $date->setTimeZone($tmp); } else { $date->setOffset($userTZ); } return $date; }
public function getComments($postId, $limit = null, $limitstart = null) { $db = DiscussHelper::getDBO(); $date = DiscussDateHelper::getDate(); $offset = DiscussDateHelper::getOffSet(true); $query = 'SELECT DATEDIFF(' . $db->Quote($date->toMySQL(true)) . ', DATE_ADD(a.`created`, INTERVAL ' . $offset . ' HOUR ) ) as `noofdays`, ' . ' DATEDIFF(' . $db->Quote($date->toMySQL(true)) . ', DATE_ADD(a.`created`, INTERVAL ' . $offset . ' HOUR ) ) as `daydiff`, ' . ' TIMEDIFF(' . $db->Quote($date->toMySQL(true)) . ', DATE_ADD(a.`created`, INTERVAL ' . $offset . ' HOUR ) ) as `timediff`, ' . ' a.* '; $query .= ' FROM `#__discuss_comments` AS a'; if (is_array($postId)) { if (count($postId) == 1) { $query .= ' WHERE a.`post_id` = ' . $db->Quote($postId); $query .= ' ORDER BY a.`created` ASC'; } else { $query .= ' WHERE a.`post_id` IN (' . implode(',', $postId) . ')'; $query .= ' ORDER BY a.post_id, a.`created` ASC'; } } else { $query .= ' WHERE a.`post_id` = ' . $db->Quote($postId); $query .= ' ORDER BY a.`created` ASC'; } if ($limit !== null) { if ($limitstart !== null) { $query .= ' LIMIT ' . $limitstart . ',' . $limit; } else { $query .= ' LIMIT ' . $limit; } } $db->setQuery($query); $result = $db->loadObjectList(); return $result; }
public function store($alterOrdering = false) { if (empty($this->created)) { $offset = DiscussDateHelper::getOffSet(); $newDate = DiscussHelper::getDate('', $offset); $this->created = $newDate->toMySQL(); } else { $newDate = DiscussHelper::getDate($this->created); $this->created = $newDate->toMySQL(); } $this->setAlias(); // Figure out the proper nested set model // No parent id, we use the current lft,rgt if ($alterOrdering) { if ($this->parent_id) { $left = $this->getLeft($this->parent_id); $this->lft = $left; $this->rgt = $this->lft + 1; // Update parent's right $this->updateRight($left); $this->updateLeft($left); } else { $this->lft = $this->getLeft() + 1; $this->rgt = $this->lft + 1; } } return parent::store(); }