/** * @return boolean|quipThread */ public function getThread() { $threadName = $this->getProperty('thread', ''); if (empty($threadName)) { return false; } $this->thread = $this->modx->getObject('quipThread', array('name' => $threadName)); if (empty($this->thread)) { $this->thread = $this->modx->newObject('quipThread'); $this->thread->fromArray(array('name' => $threadName, 'createdon' => strftime('%Y-%m-%d %H:%M:%S', time()), 'moderated' => $this->getProperty('moderate', 0, 'isset'), 'resource' => $this->modx->resource->get('id'), 'idprefix' => $this->getProperty('idprefix', 'qcom')), '', true, true); $this->thread->save(); } /* sync properties with thread row values */ $this->thread->sync($this->getProperties()); $ps = $this->thread->get('quipreply_call_params'); if (!empty($ps)) { $diff = array_diff_assoc($ps, $this->getProperties()); if (empty($diff)) { $diff = array_diff_assoc($this->getProperties(), $ps); } } if (empty($_REQUEST['quip_thread']) && (!empty($diff) || empty($ps))) { /* only sync call params if not on threaded reply page */ $this->thread->set('quipreply_call_params', $this->getProperties()); $this->thread->save(); } /* if in threaded reply page, get the original passing values to QuipReply in the thread's main page and use those */ if (!empty($_REQUEST['quip_thread']) && is_array($ps) && !empty($ps)) { $scriptProperties = array_merge($this->getProperties(), $ps); $this->setProperties($scriptProperties); } unset($ps, $diff); return $this->thread; }
/** * Sync the call parameters to the thread * @return void */ public function sync() { /* ensure thread exists, set thread properties if changed * (prior to 0.5.0 threads will be handled in install resolver) */ if (!$this->thread) { $this->thread = $this->modx->newObject('quipThread'); $this->thread->set('name', $this->threadKey); $this->thread->set('createdon', strftime('%Y-%m-%d %H:%M:%S')); $this->thread->set('moderated', $this->config['moderate']); $this->thread->set('moderator_group', $this->config['moderatorGroup']); $this->thread->set('moderators', $this->config['moderators']); $this->thread->set('resource', $this->getProperty('resource', $this->modx->resource->get('id'))); $this->thread->set('idprefix', $this->getProperty('idPrefix', 'qcom')); $this->thread->set('quip_call_params', $this->scriptProperties); if (!empty($this->scriptProperties['moderatorGroup'])) { $this->thread->set('moderator_group', $this->scriptProperties['moderatorGroup']); } /* save existing parameters to comment to preserve URLs */ $p = $this->modx->request->getParameters(); unset($p['reported'], $p['quip_start'], $p['quip_limit']); $this->thread->set('existing_params', $p); $this->thread->save(); } else { /* sync properties with thread row values */ $this->thread->sync($this->getProperties()); } }