/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Recursos::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->joinWith('tipoRecurso'); $query->andFilterWhere(['codigo' => $this->codigo, 'total_existente' => $this->total_existente]); $query->andFilterWhere(['like', 'titulo', $this->titulo])->andFilterWhere(['like', 'tipo_recursos.tipo_recurso', $this->id_tipo_recurso])->andFilterWhere(['like', 'autor', $this->autor]); return $dataProvider; }
public function actionDevolucion($id) { $model = $this->findModel($id); $model->id_status = 4; $model->fecha_entregado = date('Y-m-d'); if ($model->save()) { $fecha_actual = strtotime(date('Y-m-d')); $fecha_entrada = strtotime($model->fecha_devolucion); if ($fecha_actual > $fecha_entrada) { $usuario = Usuarios::findOne($model->cedula); $usuario->id_status = 2; $usuario->update(); $recurso = Recursos::findOne($model->codigo); $fecha = strtotime('+5 day', strtotime(date('Y-m-d'))); $activacion = date('d-m-Y', $fecha); $content = "<p>Estimado usuario " . $usuario->nombre . ",</p>"; $content .= "<p>La biblioteca de la institucion le informa que le ha sido suspendido su servicio de prestamo.</p>"; $content .= "<p>Motivo: Devolucion retardada del recurso: " . $recurso->titulo . "</p>"; $content .= "<p>Podra volver a utilizar el servicio a partir de la fecha: " . $activacion . "</p>"; // Enviar mail. Yii::$app->mailer->compose("@app/mail/layouts/html", ["content" => $content])->setFrom(Yii::$app->params['adminEmail'])->setTo($usuario->email)->setSubject("Notificacion suspension")->setTextBody($content)->setHtmlBody($content)->send(); } return $this->redirect(['view', 'id' => $model->id]); } return $this->redirect(['view', 'id' => $model->id]); }
/** * Finds the Recursos model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Recursos the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Recursos::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function getRecurso() { return $this->hasOne(Recursos::className(), ['codigo' => 'codigo']); }