Attach CategoryID to Comments

@param array $Comments
423752
protected function JoinCategory(&$Comments) {
      $DiscussionIDs = array();
      
      foreach ($Comments as &$Comment)
         $DiscussionIDs[$Comment['DiscussionID']] = TRUE;
      $DiscussionIDs = array_keys($DiscussionIDs);
      
      $Discussions = Gdn::SQL()->Select('d.*')
         ->From('Discussion d')
         ->WhereIn('DiscussionID', $DiscussionIDs)
         ->Get()->Result(DATASET_TYPE_ARRAY);
      
      $DiscussionsByID = array();
      foreach ($Discussions as $Discussion)
         $DiscussionsByID[$Discussion['DiscussionID']] = $Discussion;
      unset($$Discussions);
      
      foreach ($Comments as &$Comment) {
         $Comment['Discussion'] = $DiscussionsByID[$Comment['DiscussionID']];
         $Comment['CategoryID'] = GetValueR('Discussion.CategoryID', $Comment);
      }
   }
1100385
public function setComments($comments)
    {
        foreach ($comments as $comment) {
            $comment->setPortfolio($this);
        }

        $this->comments = $comments;

        return $this;
    }
163051
public function setComments($comments)
    {
        if (is_array($comments)) {
            $comments = implode($comments, ' ');
        }

        $this->comments = $comments;

        return $this;
    }
710945
public function setCategories($categories)
    {
        foreach ($categories as $category) {
            $category->setBlog($this);
        }
        $this->categories = $categories;

        return $this;
    }
1347917
public function setCategories($post)
	{
		foreach ($post->getCategories() as $category) 
		{
			$categoryName = strtolower($category->getName());
			if(in_array($categoryName, array_map('strtolower', $this->categoriesName)))
			{
				$this->categories[$categoryName]->setPost($post);
				continue;
			}

			$this->categories[$categoryName] = new Category($categoryName);
			$this->categories[$categoryName]->setPost($post);
			$this->categoriesName[] = $categoryName;			
		}
	}
1084355
public function addComment(\Innova\CollecticielBundle\Entity\CommentRead $comments)
    {
        $this->comments[] = $comments;

        return $this;
    }
1337438
protected function addCategory()
    {
        if (!$this->isError()) {
            $id = $this->category->add($this->getSubmitted());
            if (empty($id)) {
                $this->errorAndExit($this->text('Unexpected result'));
            }
            $this->line($id);
        }
    }
195184
private function SaveCategoryPage($categoryID)
    {
        $category = Category::Schema()->ByID($categoryID);
        if ($category) {
            $category->SetPage($this->Page());
            $category->Save();
        }
    }
40371
public function addCategory(BlogCategory $category)
    {
        $category->setBlog($this);
        $this->categories->add($category);

        return $this;
    }
1058097
public function renderHeader(array $comments = []) : void
    {
        if ($this->isSilent()) {
            return;
        }

        $this->logger->debug('rendering comments');

        foreach ($comments as $comment) {
            fwrite($this->file, ';;; ' . $comment . PHP_EOL);
        }

        fwrite($this->file, PHP_EOL);
    }
883143
public function addCategory($category)
    {
        if (!($category instanceof Category)) {
            $category = new Category($category);
        }
        $this->categories[] = $category;
    }
327311
public function addComment($creditmemoIncrementId, $comment = null, $notifyCustomer = null, $includeComment = null)
    {
        return $this->__createAction('order_creditmemo.addComment', func_get_args());
    }
95260
public function setCategoryId($categoryId = '')
    {
        $this->categoryId = $categoryId;
        $this->logger->info(__FUNCTION__, 'setCategoryId: ' . $this->categoryId);
    }
130693
public function addCategory(CategoryInterface $category)
    {
        if (! $this->hasCategory($category)) {
            $this->categories->add($category);
        }

        return $this;
    }
1058323
public function addComment($comment)
	{
		if(Yii::app()->params['commentNeedApproval'])
			$comment->status=Comment::STATUS_PENDING;
		else
			$comment->status=Comment::STATUS_APPROVED;
		$comment->post_id=$this->id;
		return $comment->save();
	}
224303
public function setWidgetsAttribute($widgets)
    {
        if (! $this->exists) {
            $this->queuedWidgets = $widgets;

            return;
        }

        $this->attachWidgets($widgets);
    }
1297269
protected function recordDoc(array $comments)
    {
        $callable = $this->phpdocFactory;

        foreach ($comments as $comment) {
            if ($comment instanceof Doc) {
                $this->doc[] = $callable($comment->getText(), $this->context);
            }
        }
    }