public function _assignToDefault($categoryId) { $defaultCategory = FaqCategory::getDefault($this->getAccountId()); $condition = ['isDeleted' => false, 'faqCategoryId' => $categoryId]; $results = Faq::find()->where($condition)->all(); foreach ($results as $result) { $result['faqCategoryId'] = $defaultCategory->_id . ''; $result->save(); } }
public function actionIndex() { $accountId = $this->getAccountId(); $params = $this->getQuery(); $condition = ['accountId' => $accountId, 'isDeleted' => Faq::NOT_DELETED]; if (!empty($params['faqCategoryId'])) { $condition['faqCategoryId'] = $params['faqCategoryId']; } $totalCount = Faq::count($condition); $currentPage = $params['page']; $perPage = $params['per-page']; $offset = ($currentPage - 1) * $perPage; $pageCount = (int) (($totalCount - 1) / $perPage + 1); $faqs = Faq::search($condition, $offset, $perPage); return ['totalCount' => $totalCount, 'currentPage' => $currentPage, 'perPage' => $perPage, 'pageCount' => $pageCount, 'faqs' => $faqs]; }
public function getQuestions() { $condition = ['isDeleted' => false, 'accountId' => $this->accountId, 'faqCategoryId' => $this->_id . '']; return Faq::find()->where($condition)->orderBy(['createdAt' => SORT_DESC])->all(); }