/** * Set and get a specific thread * * @param mixed $id ID (integer) or alias (string) * @return object */ public function thread($id = null) { if (!isset($this->_cache['thread']) || $id !== null && (int) $this->_cache['thread']->get('id') != $id) { $this->_cache['thread'] = null; if (isset($this->_cache['threads']) && $this->_cache['threads'] instanceof ItemList) { foreach ($this->_cache['threads'] as $key => $thread) { if ((int) $thread->get('id') == $id) { $this->_cache['thread'] = $thread; break; } } } if (!$this->_cache['thread']) { $this->_cache['thread'] = Thread::getInstance($id); } if (!$this->_cache['thread']->exists()) { $this->_cache['thread']->set('scope', $this->get('scope')); $this->_cache['thread']->set('scope_id', $this->get('scope_id')); } } return $this->_cache['thread']; }