/**
  * Finds the File model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return File the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = File::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 /**
  * @param $id
  * @return $this
  * @throws \yii\web\NotFoundHttpException
  */
 public function actionAttachmentDownload($id)
 {
     $model = File::findOne($id);
     if (!$model) {
         throw new NotFoundHttpException();
     }
     return \Yii::$app->response->sendStreamAsFile(\Yii::$app->fileStorage->getFilesystem()->readStream($model->file_index), $model->file_name);
 }
 /**
  * Displays a single Todo model.
  * @param integer $id
  * @return mixed
  */
 public function actionView($id)
 {
     $model = $this->findModel($id);
     if (Yii::$app->user->can('viewProject', ['project' => $model->functionality->project])) {
         return $this->render('view', ['model' => $model, 'dataProvider' => new ActiveDataProvider(['query' => File::find()->where(['todo_id' => $id])])]);
     }
     throw new NotFoundHttpException('The requested page does not exist.');
 }
Ejemplo n.º 4
0
 public function deleteFiles($event)
 {
     $this->_data();
     $files = \common\models\File::find()->where(['nid' => $this->id, 'model' => $this->model])->all();
     foreach ($files as $file) {
         if (is_file($_SERVER['DOCUMENT_ROOT'] . '/' . $file->path . '/' . $file->filename)) {
             unlink($_SERVER['DOCUMENT_ROOT'] . '/' . $file->path . '/' . $file->filename);
         }
     }
     \common\models\File::deleteAll('nid = :nid AND model = :model', [':nid' => $this->id, ':model' => $this->model]);
 }
Ejemplo n.º 5
0
 public function run($id, $hex)
 {
     // return "deleted";
     if (Yii::$app->request->isGet) {
         $file = \common\models\File::findOne($id);
         if ($file->id && $hex == md5(Yii::$app->request->cookieValidationKey . $_SERVER['REMOTE_ADDR'] . $file->filename . $file->id)) {
             $dir = $_SERVER['DOCUMENT_ROOT'] . '/' . $file->path;
             if (is_file($dir . '/' . $file->filename)) {
                 unlink($dir . '/' . $file->filename);
             }
             $file->delete();
             $styles = scandir($dir);
             foreach ($styles as $style) {
                 if (is_dir($dir . '/' . $style) && is_file($dir . '/' . $style . '/' . $file->filename)) {
                     unlink($dir . '/' . $style . '/' . $file->filename);
                 }
             }
             Yii::$app->db->createCommand('UPDATE {{file}} SET delta = delta -1 WHERE nid=:nid AND model=:model  AND field=:field AND delta > :delta', [':nid' => $file->nid, ':model' => $file->model, ':field' => $file->field, ':delta' => $file->delta])->execute();
             return "deleted";
         }
         return false;
     }
 }
Ejemplo n.º 6
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['id' => 'id_file'])->via('studentResultFiles');
 }
Ejemplo n.º 7
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['id' => 'id_file'])->via('disciplineFiles');
 }
Ejemplo n.º 8
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAvatar()
 {
     return $this->hasOne(File::className(), ['nid' => 'id']);
 }
 /**
  * 
  * @param Model $step
  * @param integer $project_id
  * @param integer $uid
  * @return string $comments
  */
 private function saveFunctionalities($step, $project_id, $uid)
 {
     $comment = '';
     foreach ($step->attributes as $key => $attribute) {
         if (!empty($attribute)) {
             if ($key == 'comment') {
                 $comment = $attribute;
             } else {
                 $bidpart = BidPart::find()->where(['attribute_name' => $key])->one();
                 if ($bidpart->file_upload) {
                     $file = new File();
                     $file->name = $attribute->baseName . '.' . $attribute->extension;
                     $file->description = $bidpart->description;
                     $file->project_id = $project_id;
                     $file->todo_id = null;
                     $file->deleted = 0;
                     $file->creator_id = $uid;
                     $file->updater_id = $uid;
                     $file->save();
                     rename($this->tempFileLocation . $file->name, $this->permFileLocation . $project_id . '/' . $file->name);
                 } else {
                     $functionality = new Functionality();
                     $functionality->name = $bidpart->name;
                     $functionality->description = $attribute;
                     $functionality->project_id = $project_id;
                     $functionality->deleted = 0;
                     $functionality->amount = 1;
                     $functionality->price = $bidpart->price;
                     $functionality->creator_id = $uid;
                     $functionality->updater_id = $uid;
                     $functionality->monthly_costs = $bidpart->monthly_costs;
                     $functionality->save(false);
                 }
             }
         }
     }
     return $comment;
 }
Ejemplo n.º 10
0
 protected function createQuery($idParent)
 {
     return File::find()->join('INNER JOIN', 'program_file', 'program_file.id_file = file.id')->where(['program_file.id_program' => $idParent]);
 }
Ejemplo n.º 11
0
 public function getAvatar()
 {
     return $this->hasOne(File::className(), ['nid' => 'id'])->where('model="Profile" AND field="avatar"');
 }
Ejemplo n.º 12
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['id' => 'file_id'])->viaTable('page_file', ['page_id' => 'id']);
 }
Ejemplo n.º 13
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles0()
 {
     return $this->hasMany(File::className(), ['updater_id' => 'id']);
 }
Ejemplo n.º 14
0
 protected function createQuery($idParent)
 {
     return File::find()->join('INNER JOIN', 'discipline_file', 'discipline_file.id_file = file.id')->where(['discipline_file.id_discipline_name' => $idParent]);
 }
Ejemplo n.º 15
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['member_id' => 'member_id']);
 }
Ejemplo n.º 16
0
 protected function createQuery($idParent)
 {
     return File::find()->join('INNER JOIN', 'student_result_file', 'student_result_file.id_file = file.id')->where(['student_result_file.id_student_result' => $idParent]);
 }
Ejemplo n.º 17
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['project_id' => 'project_id']);
 }
Ejemplo n.º 18
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFiles()
 {
     return $this->hasMany(File::className(), ['evaluate_id' => 'evaluate_id']);
 }
Ejemplo n.º 19
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getIdFile()
 {
     return $this->hasOne(File::className(), ['id' => 'id_file']);
 }
Ejemplo n.º 20
0
    <h2><?php 
echo Yii::t('project', 'Functionalities for this project');
?>
</h2>
    
    <p>
        <?php 
echo Yii::$app->user->can('editProject') ? Html::a(Yii::t('project', 'Add functionality'), ['functionality/create', 'pid' => $model->project_id], ['class' => 'btn btn-success']) : Html::a('');
?>
</p>
    
	<?php 
echo GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => Functionality::findNonDeleted(['project_id' => $model->project_id])->with('creator', 'updater')]), 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'description', 'price:currency', 'todoAmount', ['class' => 'yii\\grid\\ActionColumn', 'controller' => 'functionality']]]);
?>
    
    <h2><?php 
echo Yii::t('project', 'Files for this project');
?>
</h2>
    
    <p><?php 
echo Html::a(Yii::t('file', 'Create file'), ['/file/create', 'pid' => $model->project_id], ['class' => 'btn btn-success']);
?>
</p>
    
    <?php 
echo GridView::widget(['dataProvider' => new ActiveDataProvider(['query' => File::findNonDeleted(['project_id' => $model->project_id])->with('creator', 'updater')]), 'columns' => [['class' => 'yii\\grid\\SerialColumn'], 'name', 'description', ['class' => 'yii\\grid\\ActionColumn', 'controller' => 'file']]]);
?>
</div>
</div>