/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = PdfsRules::find(); $dataProvider = new ActiveDataProvider(['query' => $query]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andFilterWhere(['id' => $this->id, 'pdf_id' => $this->pdf_id, 'question_id' => $this->question_id, 'options_id' => $this->options_id, 'progress' => $this->progress, 'is_active' => $this->is_active, 'created_at' => $this->create_at, 'updated_at' => $this->updated_at]); return $dataProvider; }
private function getPdfRule($member, $pdf) { $pdf_rules = PdfsRules::find()->where(['is_active' => 1, 'pdf_id' => $pdf->id]); $pdfsDelay = Yii::$app->PdfsComponent->getPdfDelaySettings() * 3600; $progressUpdateTime = strtotime($member->created_at); $diffTime = time() - $progressUpdateTime; if ($diffTime < $pdfsDelay) { return false; } if ($pdf_rules->count() > 0) { $memberAnswers = MembersQuestionsAnswers::find()->where(['member_id' => $member->id]); foreach ($pdf_rules->all() as $rule) { $progressUpdateTime = strtotime(Yii::$app->MappingComponent->getCategoryProgressDate($rule->category_id, $member->id)); $diffTime = time() - $progressUpdateTime; if ($diffTime < $pdfsDelay) { return false; } $memberAnswers->andWhere(['in', 'option_id', $rule->options_id]); } return $memberAnswers->count(); } }
/** * Finds the PdfsRules model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return PdfsRules the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = PdfsRules::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @return \yii\db\ActiveQuery */ public function getPdfsRules() { return $this->hasMany(PdfsRules::className(), ['pdf_id' => 'id']); }