diff --git a/controllers/ConsultationController.php b/controllers/ConsultationController.php index b402f28020..f25c999fda 100644 --- a/controllers/ConsultationController.php +++ b/controllers/ConsultationController.php @@ -319,8 +319,8 @@ public function actionIndex(): ResponseInterface 'myself' => $myself, 'myMotions' => $myself?->getMySupportedMotionsByConsultation($this->consultation), 'myAmendments' => $myself?->getMySupportedAmendmentsByConsultation($this->consultation), - 'myMotionComments' => $myself?->getMyPrivatelyCommentedMotionsByConsultation($this->consultation), - 'myAmendmentComments' => $myself?->getMyPrivatelyCommentedAmendmentsByConsultation($this->consultation), + 'myMotionComments' => MotionComment::getPrivatelyCommentedByConsultation($myself, $this->consultation), + 'myAmendmentComments' => AmendmentComment::getPrivatelyCommentedByConsultation($myself, $this->consultation), ])); } @@ -594,8 +594,8 @@ private function tagMotionResolutionList(int $tagId, bool $isResolutionList): Re 'tag' => $tag, 'cache' => LayoutHelper::getTagMotionListCache($this->consultation, $tag, $isResolutionList), 'isResolutionList' => $isResolutionList, - 'myMotionComments' => $myself?->getMyPrivatelyCommentedMotionsByConsultation($this->consultation), - 'myAmendmentComments' => $myself?->getMyPrivatelyCommentedAmendmentsByConsultation($this->consultation), + 'myMotionComments' => MotionComment::getPrivatelyCommentedByConsultation($myself, $this->consultation), + 'myAmendmentComments' => AmendmentComment::getPrivatelyCommentedByConsultation($myself, $this->consultation), ])); } diff --git a/models/db/AmendmentComment.php b/models/db/AmendmentComment.php index 2b55a5715e..35d6a9c29f 100644 --- a/models/db/AmendmentComment.php +++ b/models/db/AmendmentComment.php @@ -121,6 +121,34 @@ public static function getNewestByConsultation(Consultation $consultation, int $ })); } + /** + * @return AmendmentComment[] + */ + public static function getPrivatelyCommentedByConsultation(?User $user, Consultation $consultation): array + { + if (!$user) { + return []; + } + + $query = AmendmentComment::find(); + $query->innerJoin( + 'amendment', + 'amendmentComment.amendmentId = amendment.id' + ); + $query->innerJoin('motion', 'motion.id = amendment.motionId'); + $query->where('motion.status != ' . IntVal(Motion::STATUS_DELETED)); + $query->andWhere('amendment.status != ' . IntVal(Motion::STATUS_DELETED)); + $query->andWhere('motion.consultationId = ' . IntVal($consultation->id)); + $query->andWhere('amendmentComment.userId = ' . IntVal($user->id)); + $query->andWhere('amendmentComment.status = ' . AmendmentComment::STATUS_PRIVATE); + $query->orderBy('motion.titlePrefix ASC, amendment.titlePrefix ASC, amendment.dateCreation DESC, amendmentComment.paragraph ASC'); + + /** @var AmendmentComment[] $comments */ + $comments = $query->all(); + + return $comments; + } + public function getMotionTitle(): string { $amendment = $this->getIMotion(); diff --git a/models/db/MotionComment.php b/models/db/MotionComment.php index ccb07d038f..de03c3a71d 100644 --- a/models/db/MotionComment.php +++ b/models/db/MotionComment.php @@ -126,6 +126,32 @@ public static function getNewestByConsultation(Consultation $consultation, int $ })); } + /** + * @return MotionComment[] + */ + public static function getPrivatelyCommentedByConsultation(?User $user, Consultation $consultation): array + { + if (!$user) { + return []; + } + + $query = MotionComment::find(); + $query->innerJoin( + 'motion', + 'motionComment.motionId = motion.id' + ); + $query->where('motion.status != ' . intval(Motion::STATUS_DELETED)); + $query->andWhere('motion.consultationId = ' . intval($consultation->id)); + $query->andWhere('motionComment.userId = ' . intval($user->id)); + $query->andWhere('motionComment.status = ' . MotionComment::STATUS_PRIVATE); + $query->orderBy('motion.titlePrefix ASC, motion.dateCreation DESC, motion.id DESC, motionComment.paragraph ASC'); + + /** @var MotionComment[] $comments */ + $comments = $query->all(); + + return $comments; + } + public function getConsultation(): ?Consultation { $motion = $this->getIMotion(); diff --git a/models/db/User.php b/models/db/User.php index a7e8d34424..bf5d655f95 100644 --- a/models/db/User.php +++ b/models/db/User.php @@ -583,46 +583,6 @@ public function getMySupportedAmendmentsByConsultation(Consultation $consultatio return $supporters; } - /** - * @return MotionComment[] - */ - public function getMyPrivatelyCommentedMotionsByConsultation(Consultation $consultation): array - { - $query = MotionComment::find(); - $query->innerJoin( - 'motion', - 'motionComment.motionId = motion.id' - ); - $query->where('motion.status != ' . intval(Motion::STATUS_DELETED)); - $query->andWhere('motion.consultationId = ' . intval($consultation->id)); - $query->andWhere('motionComment.userId = ' . intval($this->id)); - $query->andWhere('motionComment.status = ' . MotionComment::STATUS_PRIVATE); - $query->orderBy('motion.titlePrefix ASC, motion.dateCreation DESC, motion.id DESC, motionComment.paragraph ASC'); - - return $query->all(); - } - - /** - * @return AmendmentComment[] - */ - public function getMyPrivatelyCommentedAmendmentsByConsultation(Consultation $consultation): array - { - $query = AmendmentComment::find(); - $query->innerJoin( - 'amendment', - 'amendmentComment.amendmentId = amendment.id' - ); - $query->innerJoin('motion', 'motion.id = amendment.motionId'); - $query->where('motion.status != ' . IntVal(Motion::STATUS_DELETED)); - $query->andWhere('amendment.status != ' . IntVal(Motion::STATUS_DELETED)); - $query->andWhere('motion.consultationId = ' . IntVal($consultation->id)); - $query->andWhere('amendmentComment.userId = ' . IntVal($this->id)); - $query->andWhere('amendmentComment.status = ' . AmendmentComment::STATUS_PRIVATE); - $query->orderBy('motion.titlePrefix ASC, amendment.titlePrefix ASC, amendment.dateCreation DESC, amendmentComment.paragraph ASC'); - - return $query->all(); - } - public function getNotificationUnsubscribeCode(): string { return $this->id . '-' . $this->createConfirmationCode('unsubscribe');