示例#1
0
    /**
     * Display subscription items.
     *
     * @return null
     */
    protected function display_items()
    {
        $object_types = array(TITANIA_CONTRIB, TITANIA_TOPIC);
        $subscription_count = $this->get_subscription_count($object_types);
        $this->build_sort($subscription_count);
        $cases = array(TITANIA_CONTRIB => 'c.contrib_last_update', TITANIA_TOPIC => 't.topic_last_post_time');
        $sql_ary = $this->get_subscription_sql_ary($cases, $object_types, TITANIA_CONTRIB);
        $sql_ary['LEFT_JOIN'][] = array('FROM' => array($this->topics_table => 't'), 'ON' => 'w.watch_object_type = ' . TITANIA_TOPIC . '
							AND t.topic_id = w.watch_object_id');
        // Additional tracking for support topics
        $this->tracking->get_track_sql($sql_ary, TITANIA_TOPIC, 't.topic_id');
        $this->tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, 0, 'tsa');
        $this->tracking->get_track_sql($sql_ary, TITANIA_SUPPORT, 't.parent_id', 'tsc');
        $this->tracking->get_track_sql($sql_ary, TITANIA_QUEUE_DISCUSSION, 0, 'tqt');
        // Tracking for contributions
        $this->tracking->get_track_sql($sql_ary, TITANIA_CONTRIB, 'c.contrib_id', 'tc');
        $sql = $this->db->sql_build_query('SELECT', $sql_ary);
        $result = $this->db->sql_query_limit($sql, $this->sort->limit, $this->sort->start);
        $user_ids = $contributions = $topics = $rows = array();
        while ($row = $this->db->sql_fetchrow($result)) {
            $this->tracking->store_from_db($row);
            $rows[] = $row;
            if ($row['watch_object_type'] == TITANIA_TOPIC) {
                $user_ids[] = (int) $row['topic_first_post_user_id'];
                $user_ids[] = (int) $row['topic_last_post_user_id'];
            } else {
                $user_ids[] = (int) $row['contrib_user_id'];
            }
        }
        $this->db->sql_freeresult($result);
        // Get user data
        \users_overlord::load_users($user_ids);
        foreach ($rows as $row) {
            if ($row['watch_object_type'] == TITANIA_TOPIC) {
                // Topic was deleted, remove all subscriptions for it.
                if (!$row['topic_id']) {
                    $this->delete_subscription($row['watch_object_type'], $row['watch_object_id'], false);
                    continue;
                }
                $vars = $this->get_topic_tpl_row($row);
            } else {
                // Contribution no longer exists.
                if (!$row['contrib_id']) {
                    $this->delete_subscription($row['watch_object_type'], $row['watch_object_id'], false);
                    continue;
                }
                $vars = $this->get_contribution_tpl_row($row);
            }
            $this->template->assign_block_vars('subscriptions', $vars);
        }
        $this->template->assign_vars(array('S_WATCHED_ITEMS' => true));
    }