public function actionCreate()
 {
     if (Yii::$app->user->can('createResource')) {
         $firmwareId = Yii::$app->request->get('firmware_id');
         if ($firmwareId) {
             $firmware = Firmware::findOne(['id' => $firmwareId]);
             $job = new Job();
             $job->firmware_id = $firmware->id;
             $job->insert();
             $job->setCurrentStatus(JobStatus::INIT);
             return $this->render('edit', ['model' => $job]);
         }
     } else {
         Yii::$app->getSession()->setFlash('error', 'Not allowed.');
     }
     return $this->redirect(['index']);
 }
Exemplo n.º 2
0
use Yii;
use yii\helpers\Html;
use yii\grid\GridView;
use yii\data\ActiveDataProvider;
use common\models\Firmware;
use frontend\models\UploadForm;
use yii\bootstrap\ActiveForm;
use yii\bootstrap\Button;
use kartik\file\FileInput;
// @var $this yii\web\View
// @var $form yii\bootstrap\ActiveForm
// @var $model \common\models\UploadForm
$this->title = 'Firmwares';
$this->params['breadcrumbs'][] = $this->title;
$dataProvider = new ActiveDataProvider(['query' => Yii::$app->user->can('admin') ? Firmware::find() : Firmware::findByUser(Yii::$app->user->identity->username), 'pagination' => ['pageSize' => 20]]);
?>

<div class="box">
  <div class="box-body">
<?php 
$form = ActiveForm::begin(['id' => 'upload-form', 'action' => '/firmware/upload', 'options' => ['enctype' => 'multipart/form-data', 'class' => 'form-inline']]);
echo $form->field($model = new UploadForm(), 'file')->widget(FileInput::classname(), ['pluginOptions' => ['showPreview' => false, 'showCaption' => true, 'showRemove' => true, 'showUpload' => true, 'browseLabel' => 'Add firmware']]);
ActiveForm::end();
?>
  </div>
</div>

<div class="box">
  <div class="box-body">
<?php 
Exemplo n.º 3
0
 /**
  *
  * @return \yii\db\ActiveQuery
  */
 public function findByUserAndUpload($id, Upload $upload)
 {
     return Firmware::find()->where(['created_by' => $id, 'upload_id' => $upload->id]);
 }
 public function actionDelete()
 {
     if (Yii::$app->user->can('deleteResource')) {
         $id = Yii::$app->request->get('id');
         if ($id) {
             $model = Firmware::findOne(['id' => $id]);
             if ($model->delete()) {
                 Yii::$app->getSession()->setFlash('success', 'Firmware deleted.');
             } else {
                 Yii::$app->getSession()->setFlash('error', 'Failed to delete firmware.');
             }
         }
     } else {
         Yii::$app->getSession()->setFlash('error', 'Not allowed.');
     }
     return $this->redirect(['index']);
 }
Exemplo n.º 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getFirmware()
 {
     return $this->hasOne(Firmware::className(), ['id' => 'firmware_id']);
 }