Exemple #1
0
 public function add()
 {
     $fotos = new Fotos();
     $fotos->namefoto = $this->name;
     $fotos->deskfoto = $this->desk;
     $fotos->id_album = $this->id_album;
     $fotos->foto_path = $this->foto_path;
     $fotos->save();
     return $fotos;
 }
Exemple #2
0
 public function upload($id)
 {
     if ($this->validate()) {
         foreach ($this->imageFiles as $file) {
             $file_name = date('Y-m-d H:i:s') . "_" . $file->baseName . '.' . $file->extension;
             $file->saveAs('assets/imgOfertas/' . $file_name);
             $foto = new Fotos();
             $foto->idProducto = $id;
             $foto->url = $file_name;
             $foto->save();
         }
         return true;
     } else {
         return false;
     }
 }
Exemple #3
0
 /**
  * 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]);
     }
 }
Exemple #5
0
 protected function beforeDelete($id)
 {
     if ($fotos = Fotos::findAll(['id_album' => $id])) {
         Yii::getLogger()->log('files:' . print_r($fotos, true), YII_DEBUG);
         return $fotos;
     } else {
         return false;
         // throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 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();
 }
Exemple #7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFotos()
 {
     return $this->hasMany(Fotos::className(), ['idProducto' => 'id']);
 }
Exemple #8
0
 /**
  * Finds the Fotos model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param string $id
  * @return Fotos the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Fotos::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }