/**
  * Update QUESTION_TAGS tags counter
  *
  * @return object $this
  */
 protected function addTags()
 {
     $o = Qtagscounter::factory($this->Registry);
     $Question = $this->Question;
     if (count($Question['a_tags']) > 0) {
         $callable = function () use($o, $Question) {
             $o->parse($Question);
         };
         d('cp');
         runLater($callable);
     }
     return $this;
 }
Esempio n. 2
0
 /**
  * Delete all questions by this user
  * as well as remove tags
  * and add ip address of every question
  * as key to $this->aIPs array
  * (as keys and not as values so that
  * only unique values are added)
  *
  * If question is unanswered, also remove from
  * UNANSWERED_TAGS collection
  *
  * @return object $this
  */
 protected function deleteQuestions()
 {
     $coll = $this->Registry->Mongo->QUESTIONS;
     $uid = (int) $this->Request['uid'];
     $cur = $coll->find(array('i_uid' => $uid));
     if ($cur && $cur->count() > 0) {
         d('got ' . $cur->count() . ' questions to delete');
         foreach ($cur as $a) {
             if (!empty($a['ip'])) {
                 $this->aIPs[$a['ip']] = 1;
             }
             /**
              * If this question is unanswered then also
              * remove from UNANSWERED_TAGS
              */
             if (empty($a['i_sel_ans']) && !empty($a['a_tags'])) {
                 d('going to add to Unanswered tags');
                 \Lampcms\UnansweredTags::factory($this->Registry)->remove($a['a_tags']);
             }
             /**
              * Remove from QUESTION_TAGS
              */
             if (!empty($a['a_tags'])) {
                 \Lampcms\Qtagscounter::factory($this->Registry)->removeTags($a['a_tags']);
             }
         }
         /**
          * Now delete actual question
          */
         $res = $coll->remove(array('i_uid' => $uid), array('safe' => true));
         d('questions removed: ' . print_r($res, 1));
     }
     return $this;
 }
Esempio n. 3
0
 /**
  * Update USER_TAGS and QUESTION_TAGS collections
  * to add new tags that belong to this questions
  *
  * @return object $this
  */
 protected function addNewTags()
 {
     if (count($this->aSubmitted) > 0) {
         \Lampcms\Qtagscounter::factory($this->Registry)->parse($this->Question);
         \Lampcms\UserTags::factory($this->Registry)->addTags($this->Question['i_uid'], $this->Question);
         \Lampcms\Relatedtags::factory($this->Registry)->addTags($this->Question);
         if (0 === $this->Question['i_sel_ans']) {
             d('going to add to Unanswered tags');
             \Lampcms\UnansweredTags::factory($this->Registry)->set($this->Question);
         }
     }
     return $this;
 }
Esempio n. 4
0
 /**
  * Now update tags counter to decrease tags count
  * but ONLY if deleted item is Question
  *
  * @return object $this;
  */
 protected function updateTags()
 {
     if (!$this->requested) {
         if ('QUESTIONS' === $this->collection) {
             $Question = $this->Resource;
             \Lampcms\Qtagscounter::factory($this->Registry)->removeTags($Question);
             if (0 === $this->Resource['i_sel_ans']) {
                 d('going to remove to Unanswered tags');
                 \Lampcms\UnansweredTags::factory($this->Registry)->remove($Question);
             }
         } else {
             $Question = new \Lampcms\Question($this->Registry);
             $Question->by_id($this->Resource->getQuestionId());
             d('tags: ' . print_r($Question['a_tags'], 1));
         }
         /**
          * Must extract uid from $this->Resource because in case
          * the resource is an answer, then the
          * $Question has different owner, thus
          * will remove user tags for the wrong user
          *
          */
         $uid = $this->Resource->getOwnerId();
         \Lampcms\UserTags::factory($this->Registry)->removeTags($Question, $uid);
     }
     return $this;
 }
Esempio n. 5
0
 /**
  * Update QUESTION_TAGS tags counter
  *
  * @return object $this
  */
 protected function addTags()
 {
     $o = Qtagscounter::factory($this->Registry);
     $Question = $this->Question;
     if (count($Question['a_tags']) > 0) {
         $callable = function () use($o, $Question) {
             try {
                 $o->parse($Question);
             } catch (\Exception $e) {
                 if (function_exists('d')) {
                     d('Error: Unable to add tags: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on ' . $e->getLine());
                 }
             }
         };
         d('cp');
         runLater($callable);
     }
     return $this;
 }