Skip to content

Commit

Permalink
Move methods to comment classes
Browse files Browse the repository at this point in the history
  • Loading branch information
CatoTH committed Oct 12, 2024
1 parent 3cda1c6 commit 7ac4b2a
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 44 deletions.
8 changes: 4 additions & 4 deletions controllers/ConsultationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -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),
]));
}

Expand Down Expand Up @@ -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),
]));
}

Expand Down
28 changes: 28 additions & 0 deletions models/db/AmendmentComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
26 changes: 26 additions & 0 deletions models/db/MotionComment.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
40 changes: 0 additions & 40 deletions models/db/User.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 7ac4b2a

Please sign in to comment.