示例#1
0
文件: Shred.php 项目: codex73/LampCMS
 /**
  * Delete all answers made by user
  * Also update questions affected by
  * deletion of those answers
  *
  * @return object $this
  */
 protected function deleteAnswers()
 {
     $coll = $this->Registry->Mongo->ANSWERS;
     $cur = $coll->find(array('i_uid' => $this->Request['uid']));
     if ($cur && $cur->count() > 0) {
         foreach ($cur as $a) {
             $Question = new \Lampcms\Question($this->Registry);
             try {
                 $Answer = new Answer($this->Registry, $a);
                 $Question->by_id((int) $Answer->getQuestionId());
                 $Question->removeAnswer($Answer);
                 $Question->save();
                 /**
                  * setSaved() because we don't need auto-save feature
                  * to save each answer
                  * since all answers will be removed at end of this method
                  */
                 $Answer->setSaved();
             } catch (\MongoException $e) {
                 d('Question not found by _id: ' . $a['i_qid']);
             }
             if (!empty($a['cc'])) {
                 $this->aCountries[] = $a['cc'];
             }
         }
         $res = $coll->remove(array('i_uid' => $this->Request['uid']), array('safe' => true));
         d('questions removed: ' . print_r($res, 1));
     }
     return $this;
 }