/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Curtidas::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_curtida' => $this->id_curtida, 'id_usuario' => $this->id_usuario, 'criado_por' => $this->criado_por, 'criado_em' => $this->criado_em, 'modificado_por' => $this->modificado_por, 'modificado_em' => $this->modificado_em, 'ativo' => 1]); $query->andFilterWhere(['like', 'motivo', $this->motivo]); return $dataProvider; }
/** * @return \yii\db\ActiveQuery */ public function getTotalCurtidasMes() { $curtidas = $this->hasMany(Curtidas::className(), ['id_usuario' => 'id_usuario'])->where(['ativo' => 1])->all(); $totalMes = 0; $esteMes = date("m-Y"); foreach ($curtidas as $curtida) { $criado_em = date_format(date_create($curtida->criado_em), "m-Y"); if ($criado_em == $esteMes) { $totalMes++; } } return $totalMes; }
/** * Finds the Curtidas model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Curtidas the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Curtidas::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }