/**
  * @static
  * @param array $usr_ids
  */
 public static function preloadUserObjects(array $usr_ids)
 {
     /**
      * @var $ilDB ilDB
      */
     global $ilDB;
     $usr_ids_to_request = array_diff($usr_ids, self::$requested_usr_ids);
     self::$requested_usr_ids = array_merge(self::$requested_usr_ids, $usr_ids_to_request);
     self::$requested_usr_ids_key_map = array_flip(self::$requested_usr_ids);
     if ($usr_ids_to_request) {
         $in = $ilDB->in('ud.usr_id', $usr_ids_to_request, false, 'integer');
         $query = "\n\t\t\t\tSELECT ud.usr_id, login, firstname, lastname, title, gender, pprof.value public_profile, pgen.value public_gender, pup.value public_upload\n\t\t\t\tFROM usr_data ud\n\t\t\t\tLEFT JOIN usr_pref pprof ON pprof.usr_id = ud.usr_id AND pprof.keyword = %s\n\t\t\t\tLEFT JOIN usr_pref pgen ON pgen.usr_id = ud.usr_id AND pgen.keyword = %s\n\t\t\t\tLEFT JOIN usr_pref pup ON pup.usr_id = ud.usr_id AND pup.keyword = %s\n\t\t\t\tWHERE {$in}\n\t\t\t";
         $res = $ilDB->queryF($query, array('text', 'text', 'text'), array('public_profile', 'public_gender', 'public_upload'));
         while ($row = $ilDB->fetchAssoc($res)) {
             $user = new ilObjUser();
             $user->setId($row['usr_id']);
             $user->setLogin($row['login']);
             $user->setGender($row['gender']);
             $user->setTitle($row['title']);
             $user->setFirstname($row['firstname']);
             $user->setLastname($row['lastname']);
             $user->setPref('public_profile', $row['public_profile']);
             $user->setPref('public_gender', $row['public_gender']);
             $user->setPref('public_upload', $row['public_upload']);
             self::$user_instances[$row['usr_id']] = $user;
         }
     }
 }
 /**
  */
 protected function initUserInstance()
 {
     if ($this->authorEntity instanceof ilObjUser && $this->authorEntity->getId()) {
         $this->author = $this->authorEntity;
     } else {
         if (is_numeric($this->authorEntity) && $this->authorEntity) {
             // Try to read user instance from preloaded cache array
             $this->author = ilForumAuthorInformationCache::getUserObjectById($this->authorEntity);
             if (!$this->author) {
                 // Get a user instance from forum module's cache method
                 $this->author = ilObjForumAccess::getCachedUserInstance($this->authorEntity);
             }
         }
     }
     if (!$this->author) {
         $this->author = new ilObjUser();
         $this->author->setId(0);
         $this->author->setPref('public_profile', 'n');
         $this->author->setGender('');
     }
 }
Пример #3
0
    public function getNestedSetPostChildren($pos_id = null, $expandedNodes = array())
    {
        global $ilUser;
        $data = null;
        $objProperties = ilForumProperties::getInstance($this->getFrmObjId());
        $is_post_activation_enabled = $objProperties->isPostActivationEnabled();
        if ($pos_id !== null) {
            $res = $this->db->queryF("\n\t\t\t\tSELECT\t\tlft, rgt\n\t\t\t\tFROM\t\tfrm_posts_tree\n\t\t\t\tWHERE\t\tpos_fk = %s\n\t\t\t\tAND\t\t\tthr_fk = %s", array('integer', 'integer'), array($pos_id, $this->id));
            $data = $this->db->fetchAssoc($res);
        }
        $query = '
			SELECT			fpt.depth,
							fpt.rgt,
							fpt.parent_pos,
							fp.pos_pk,
							fp.pos_subject,
							fp.pos_usr_alias,
							fp.pos_date,
							fp.pos_update,
							fp.pos_status,
							fp.pos_display_user_id,
							fp.pos_usr_alias,
							fp.import_name,
							fp.pos_author_id,
							fp.is_author_moderator,
							fur.post_id,
							(CASE
							WHEN fur.post_id IS NULL ' . ($ilUser->getId() == ANONYMOUS_USER_ID ? ' AND 1 = 2 ' : '') . '
							THEN 0
							ELSE 1
							END) post_read,
							COUNT(fpt2.pos_fk) children	

			FROM			frm_posts_tree fpt

			INNER JOIN		frm_posts fp
				ON			fp.pos_pk = fpt.pos_fk
				
			LEFT JOIN		frm_posts_tree fpt2
				 ON         fpt2.lft BETWEEN fpt.lft AND fpt.rgt
				 AND		fpt.thr_fk = fpt2.thr_fk
				 AND		fpt.pos_fk != fpt2.pos_fk ';
        $query .= '
			LEFT JOIN		frm_user_read fur
				ON			fur.thread_id = fp.pos_thr_fk
				AND			fur.post_id = fp.pos_pk
				AND			fur.usr_id = ' . $this->db->quote($ilUser->getId(), 'integer') . '

			LEFT JOIN		usr_data ud
				ON			ud.usr_id = fp.pos_display_user_id
		
			WHERE			fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
        if ($data) {
            $query .= '		AND fpt.lft > ' . $this->db->quote($data['lft'], 'integer') . '		AND fpt.lft < ' . $this->db->quote($data['rgt'], 'integer') . ' ';
        }
        if ($is_post_activation_enabled && !$this->is_moderator) {
            $query .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
        }
        if ($expandedNodes) {
            $query .= ' AND ' . $this->db->in('fpt.parent_pos', $expandedNodes, false, 'integer') . ' ';
        }
        $query .= ' GROUP BY fpt.depth,
							fpt.rgt,
							fpt.parent_pos,
							fp.pos_pk,
							fp.pos_subject,
							fp.pos_usr_alias,
							fp.pos_date,
							fp.pos_update,
							fp.pos_status,
							fp.pos_display_user_id,
							fp.pos_usr_alias,
							fp.import_name,
							fp.pos_author_id,
							fp.is_author_moderator,
							fur.post_id
					ORDER BY fpt.rgt DESC
		';
        $queryCounter = '
			SELECT			pos_fk
			FROM			frm_posts_tree fpt
			INNER JOIN		frm_posts fp
				ON			fp.pos_pk = fpt.pos_fk
			WHERE			fpt.thr_fk = ' . $this->db->quote($this->id, 'integer');
        if ($is_post_activation_enabled && !$this->is_moderator) {
            $queryCounter .= ' AND (fp.pos_status = 1 OR fp.pos_status = 0 AND fp.pos_display_user_id = ' . $this->db->quote($ilUser->getId(), 'integer') . ') ';
        }
        $queryCounter .= ' ORDER BY fpt.rgt DESC';
        $resCounter = $this->db->query($queryCounter);
        $counter = array();
        $i = 0;
        while ($row = $this->db->fetchAssoc($resCounter)) {
            $counter[$row['pos_fk']] = $i++;
        }
        $res = $this->db->query($query);
        $children = array();
        $usr_ids = array();
        while ($row = $this->db->fetchAssoc($res)) {
            if ((int) $row['pos_display_user_id']) {
                $usr_ids[] = (int) $row['pos_display_user_id'];
            }
            $row['counter'] = $counter[$row['pos_pk']];
            $children[] = $row;
        }
        require_once 'Modules/Forum/classes/class.ilForumAuthorInformationCache.php';
        ilForumAuthorInformationCache::preloadUserObjects(array_unique($usr_ids));
        return $children;
    }
 /**
  * @return ilForumTopicTableGUI
  */
 public function fetchData()
 {
     $this->determineOffsetAndOrder();
     $excluded_ids = array();
     if ($this->parent_cmd == 'mergeThreads' && $this->getSelectedThread() instanceof ilForumTopic) {
         $excluded_ids[] = $this->getSelectedThread()->getId();
     }
     $params = array('is_moderator' => $this->getIsModerator(), 'excluded_ids' => $excluded_ids);
     $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
     if (!count($data['items']) && $this->getOffset() > 0) {
         $this->resetOffset();
         $data = $this->getMapper()->getAllThreads($this->topicData['top_pk'], $params, (int) $this->getLimit(), (int) $this->getOffset());
     }
     $this->setMaxCount($data['cnt']);
     $this->setData($data['items']);
     // Collect user ids for preloading user objects
     $thread_ids = array();
     $user_ids = array();
     foreach ($data['items'] as $thread) {
         /**
          * @var $thread ilForumTopic
          */
         $thread_ids[] = (int) $thread->getId();
         if ($thread->getUserId() > 0) {
             $user_ids[$thread->getUserId()] = (int) $thread->getUserId();
         }
     }
     $user_ids = array_merge(ilObjForum::getUserIdsOfLastPostsByRefIdAndThreadIds($this->getRefId(), $thread_ids), $user_ids);
     ilForumAuthorInformationCache::preloadUserObjects(array_unique($user_ids));
     return $this;
 }