modelsManager->createBuilder(); $builder->from(CourseTopicModel::class); $builder->where('1 = 1'); if (!empty($where['course_id'])) { $builder->andWhere('course_id = :course_id:', ['course_id' => $where['course_id']]); } if (!empty($where['topic_id'])) { $builder->andWhere('topic_id = :topic_id:', ['topic_id' => $where['topic_id']]); } switch ($sort) { default: $orderBy = 'id DESC'; break; } $builder->orderBy($orderBy); $pager = new PagerQueryBuilder([ 'builder' => $builder, 'page' => $page, 'limit' => $limit, ]); return $pager->paginate(); } /** * @param int $courseId * @param int $topicId * @return CourseTopicModel|Model|bool */ public function findCourseTopic($courseId, $topicId) { return CourseTopicModel::findFirst([ 'conditions' => 'course_id = :course_id: AND topic_id = :topic_id:', 'bind' => ['course_id' => $courseId, 'topic_id' => $topicId], ]); } /** * @param array $topicIds * @return ResultsetInterface|Resultset|CourseTopicModel[] */ public function findByTopicIds($topicIds) { return CourseTopicModel::query() ->inWhere('topic_id', $topicIds) ->execute(); } /** * @param array $courseIds * @return ResultsetInterface|Resultset|CourseTopicModel[] */ public function findByCourseIds($courseIds) { return CourseTopicModel::query() ->inWhere('course_id', $courseIds) ->execute(); } }