Exemplo n.º 1
0
 public function __construct($data, $row = 'to_user_id', $user_id = 0)
 {
     $db = JO_Db::getDefaultAdapter();
     if (!$user_id) {
         $user_id = (string) JO_Session::get('user[user_id]');
     }
     $rows_users = self::describeTable('users', 'user_');
     $rows_boards = self::describeTable('boards', 'board_');
     $rows_pins = self::describeTable('pins', 'pin_');
     /////other rows
     $rows_pins['pin_gift'] = new JO_Db_Expr('pins.price > 0.0000');
     switch (Helper_Config::get('config_user_view')) {
         case 'username':
             $rows_users['user_fullname'] = new JO_Db_Expr('users.username');
             break;
         case 'firstname':
             $rows_users['user_fullname'] = new JO_Db_Expr('users.firstname');
             break;
         case 'fullname':
         default:
             $rows_users['user_fullname'] = new JO_Db_Expr('CONCAT(users.firstname, " ", users.lastname)');
             break;
     }
     if (JO_Session::get('user[user_id]')) {
         $rows_pins['pin_is_liked'] = new JO_Db_Expr('(' . $db->select()->from('pins_likes', 'COUNT(like_id)')->where('pin_id = pins.pin_id')->where('user_id = ?', JO_Session::get('user[user_id]'))->limit(1) . ')');
     } else {
         $rows_pins['pin_is_liked'] = new JO_Db_Expr("0");
     }
     $rows_boards['latest_pins'] = new JO_Db_Expr("SUBSTRING_INDEX((" . $db->select()->from('pins', 'GROUP_CONCAT(pin_id ORDER BY `pin_id` DESC)')->where('board_id = boards.board_id')->limit(15) . "),',',15)");
     $query = $db->select()->from('users_history')->joinLeft('users', 'users_history.' . ($row == 'to_user_id' ? 'from' : 'to') . '_user_id = users.user_id', $rows_users)->joinLeft('pins', 'users_history.pin_id = pins.pin_id', $rows_pins)->joinLeft('boards', 'IF(pins.board_id,pins.board_id,users_history.board_id) = boards.board_id', $rows_boards)->where($row . ' = ?', $user_id);
     if (isset($data['filter_history_action']) && (int) $data['filter_history_action']) {
         $query->where('history_action = ?', (int) $data['filter_history_action']);
     }
     if (JO_Session::get('user[user_id]')) {
         $query->columns(array('following_board' => new JO_Db_Expr('(' . $db->select()->from('users_following', 'COUNT(users_following_id)')->where('user_id = ?', JO_Session::get('user[user_id]'))->where('following_id = users_history.' . ($row == 'to_user_id' ? 'from' : 'to') . '_user_id')->where('board_id = users_history.board_id')->limit(1) . ')')));
         $query->columns(array('following_user' => new JO_Db_Expr('((' . $db->select()->from('users_following_user', 'COUNT(ufu_id)')->where('user_id = ?', JO_Session::get('user[user_id]'))->where('following_id = users_history.' . ($row == 'to_user_id' ? 'from' : 'to') . '_user_id')->limit(1) . ') + (' . $db->select()->from('users_following', 'COUNT(users_following_id)')->where('user_id = ?', JO_Session::get('user[user_id]'))->where('following_id = users_history.' . ($row == 'to_user_id' ? 'from' : 'to') . '_user_id')->where('board_id = users_history.board_id')->limit(1) . '))')));
     } else {
         $query->columns(array('following_board' => new JO_Db_Expr("0")));
         $query->columns(array('following_user' => new JO_Db_Expr("0")));
     }
     //sort and limit add to query from Model_History_Abstract
     $query = self::sortOrderLimit($query, $data);
     parent::__construct($db->fetchAll($query));
 }
Exemplo n.º 2
0
 public function __construct($data)
 {
     $db = JO_Db::getDefaultAdapter();
     $arr = array('comments' => self::COMMENTPIN, 'follow' => self::FOLLOW_USER, 'like' => self::LIKEPIN, 'repin' => self::REPIN);
     $sql = $db->select()->from('users_history', 'to_user_id');
     if (isset($data['today']) && !is_null($data['today'])) {
         $sql->where('users_history.date_added BETWEEN DATE_ADD(?, INTERVAL -1 DAY) AND ?', $data['today']);
     } elseif (isset($data['week_range'])) {
         $sql->where("DATE(users_history.date_added) BETWEEN '" . $data['week_range']['from'] . "' AND '" . $data['week_range']['to'] . "'");
     }
     $sql->where('history_action IN (' . implode(',', $arr) . ')');
     $query = $db->select()->from('users')->where(isset($data['week_range']) ? '1' : 'email_interval = 2')->where('user_id IN (?)', $sql);
     $results = $db->fetchAll($query);
     $return = array();
     if ($results) {
         switch (Helper_Config::get('config_user_view')) {
             case 'username':
                 $user_fullname = new JO_Db_Expr('users.username');
                 break;
             case 'firstname':
                 $user_fullname = new JO_Db_Expr('users.firstname');
                 break;
             case 'fullname':
             default:
                 $user_fullname = new JO_Db_Expr('CONCAT(users.firstname, " ", users.lastname)');
                 break;
         }
         foreach ($results as $result) {
             foreach ($arr as $k => $v) {
                 $sql2 = $db->select()->from('users_history', new JO_Db_Expr('DISTINCT from_user_id'))->where('to_user_id = ?', $result['user_id'])->where('`history_action` = ?', $v);
                 if (isset($data['today']) && !is_null($data['today'])) {
                     $query->where('users_history.date_added BETWEEN DATE_ADD(?, INTERVAL -1 DAY) AND ?', $data['today']);
                 } elseif (isset($data['week_range'])) {
                     $sql->where("DATE(users_history.date_added) BETWEEN '" . $data['week_range']['from'] . "' AND '" . $data['week_range']['to'] . "'");
                 }
                 $result['history_' . $k] = $db->fetchAll($db->select()->from('users', array('user_id', 'avatar', 'fullname' => $user_fullname, 'store'))->where('user_id IN (?)', $sql2));
             }
             $return[] = $result;
         }
     }
     parent::__construct($return);
 }