/** * Creates data provider instance with search query applied * * @param array $params * * @return ActiveDataProvider */ public function search($params) { $query = Fotos::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, 'idProducto' => $this->idProducto]); $query->andFilterWhere(['like', 'url', $this->url]); return $dataProvider; }
/** * Updates an existing Productos model. * If update is successful, the browser will be redirected to the 'view' page. * @param string $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $img_model = new UploadForm(); if ($model->load(Yii::$app->request->post()) && $model->save()) { $request = Yii::$app->request; $id_producto = $model->id; $fotos = Fotos::find()->where(['idProducto' => $id_producto])->all(); foreach ($fotos as $foto) { Fotos::deleteFoto($foto); } $img_model->imageFiles = UploadedFile::getInstances($img_model, 'imageFiles'); if ($img_model->upload($model->id)) { if ($model->tipo == 0) { return $this->redirect(['view', 'id' => $model->id]); } else { if ($model->tipo == 1) { $porTiempo = Temporales::find()->where(['idproducto' => $model->id])->one(); $porTiempo->fecha = $request->post('fecha'); $porTiempo->idproducto = $model->id; $porTiempo->save(); return $this->redirect(['view', 'id' => $model->id]); } else { $stock = Stock::find()->where(['idproducto' => $model->id])->one(); $cantidad = $request->post('cant'); $stock->stock = $cantidad; $stock->idproducto = $model->id; $stock->save(); return $this->redirect(['view', 'id' => $model->id]); } } } } else { return $this->render('update', ['model' => $model, 'img_model' => $img_model]); } }
public function actionAlbum($id) { $query = Fotos::find()->where(['id_album' => $id]); // $model=Fotos::findAll(['id_album'=>$id]); $pagination = new Pagination(['defaultPageSize' => 9, 'totalCount' => $query->count()]); $model = $query->offset($pagination->offset)->limit($pagination->limit)->all(); return $this->render('albumview', ['model' => $model, 'id' => $id, 'pagination' => $pagination]); }
public static function borrarFoto(Request $request) { $fotor = null; if ($request->tipo == 1) { $fotor = FotoCabina::find($request->idr); } else { $fotor = FotoCliente::find($request->idr); } $foto = Fotos::find($request->id); if (File::exists(public_path() . $foto->imagenurl)) { File::delete(public_path() . $foto->imagenurl); } if (File::exists(public_path() . $foto->imagenurlcompact)) { File::delete(public_path() . $foto->imagenurlcompact); } $fotor->delete(); $foto->delete(); }