コード例 #1
0
ファイル: tag.php プロジェクト: ErickLopez76/offiria
 public function updateTrending($tag, $group_id, $add = true)
 {
     $db = JFactory::getDbo();
     $now = new JXDate();
     $nowDate = $now->format('Y-m-d');
     $tagTrending = JTable::getInstance('TagTrend', 'StreamTable');
     $exist = $tagTrending->load(array('tag' => $tag, 'group_id' => $group_id, 'occurrence_date' => $nowDate));
     if ($add) {
         if ($exist) {
             // Record's there, just update it
             $tagTrending->frequency++;
         } else {
             // Create a new record
             $tagTrending->bind(array('tag' => $tag, 'frequency' => 1, 'group_id' => $group_id, 'occurrence_date' => $nowDate));
         }
         $tagTrending->store();
     } else {
         if ($exist) {
             // If it's the last frequency count, delete the record
             if ($tagTrending->frequency > 1) {
                 $tagTrending->frequency--;
             } else {
                 $tagTrending->delete();
             }
             $tagTrending->store();
         }
     }
 }
コード例 #2
0
ファイル: xuser.php プロジェクト: ErickLopez76/offiria
 /**
  * This will return the user timezone
  * @param int $user_id id of the user
  * @param String $forDisplay get the display, if true then return value will be formatted to the proper display
  * @return String depends on the value of format
  */
 public static function getUserTime($user_id = null, $forDisplay = false)
 {
     $config = new JXConfig();
     $user = JFactory::getUser($user_id);
     // First load account setting (if any) timezone to override timezone in language file
     $defaultTz = $config->getTimezone() != '' ? $config->getTimezone() : JText::_('JXLIB_DEFAULT_TIMEZONE');
     $my = !$user instanceof JUser && !$user instanceof JXUser ? JXFactory::getUser() : $user;
     $timeZoneStr = $my->getParam('timezone');
     // Second load user personalize timezone (if any) to override system default timezone
     $timeZoneStr = empty($timeZoneStr) ? $defaultTz : $timeZoneStr;
     $tz = new DateTimeZone($timeZoneStr);
     $date2 = new JDate('now', $tz);
     $offset = $date2->getOffset() / 3600;
     $date = new JDate();
     $date->setOffset($offset);
     $xdate = new JXDate();
     /* if the value want to be used as display purposes */
     if ($forDisplay) {
         return $xdate->formatDate($date);
     } else {
         return $xdate->format($date);
     }
 }