/**
  * Updates an existing Device model.
  * If update is successful, the browser will be redirected to the 'view' page.
  * @param integer $id
  * @return mixed
  */
 public static function actionUpdate($id, $param_data = null, $new_exp = null)
 {
     // update multi RadCheck enteries with new data
     if ($param_data && is_numeric($new_exp)) {
         $user_devices_ar = Device::find()->where(['user_id' => $param_data['user_id']])->all();
         foreach ($user_devices_ar as $key => $value) {
             $radcheck_mdl = RadCheck::find()->where(['attribute' => 'expiration', 'username' => $value->getAttribute('device_name')])->one();
             $radcheck_mdl->value = (string) $new_exp;
             $radcheck_mdl->save();
         }
         if (count($radcheck_mdl->getErrors()) == 0) {
             return true;
         }
         Yii::$app->getSession()->setFlash('error', 'Unable to update the system.');
         return false;
     }
     $model = $this->findModel($id);
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('update', ['model' => $model]);
     }
 }
 /**
  * Get the users current expiration time, OR current timestamp OR future expiration time
  *
  * @version  0.6.5
  * @since 0.6.5
  * @param  object $param_data
  * @return integer $return_data
  */
 private static function getCurrentExpiration($param_data)
 {
     $prev_expiration = Device::find()->where(['user_id' => $param_data['user_id']])->one();
     // calculate the new expiration time
     $return_data = isset($prev_expiration) && count($prev_expiration) > 0 ? $prev_expiration->getAttribute('expiration') : time();
     // if the form wants to set a new expiratin time
     if ($param_data->getAttribute('time_amount_id') !== null) {
         $return_data = $return_data + TimeAmountOptions::find()->where(['id' => $param_data->getAttribute('time_amount_id')])->one()->getAttribute('value');
     }
     return $return_data;
 }
 /**
  * Lists all Device models.
  * @return mixed
  */
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Device::find()]);
     return $this->render('index', ['dataProvider' => $dataProvider]);
 }
 public function actionIndex()
 {
     $dataProvider = new ActiveDataProvider(['query' => Purchase::find()]);
     $deviceProvider = new ActiveDataProvider(['query' => Device::find()->where(['user_id' => Yii::$app->user->id])]);
     return $this->render('index', ['dataProvider' => $dataProvider, 'deviceProvider' => $deviceProvider]);
 }
Exemple #5
0
<?php

use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use yii\helpers\Html;
use yii\helpers\ArrayHelper;
$device = \common\models\Device::find()->select('id')->where(['user_id' => Yii::$app->user->id])->andWhere(['deleted_at' => NULL])->all();
NavBar::begin();
$menuItems[] = ['label' => 'History', 'url' => ['/purchase/index']];
// if the user has no devices, show the init purchase form w/ device count AND time
if (!$device) {
    $menuItems[] = ['label' => 'Purchase', 'url' => ['/purchase/create']];
    // else show the option to update time OR update device count
} else {
    $menuItems[] = ['label' => 'Add Device', 'url' => ['/purchase/adddevice']];
    $menuItems[] = ['label' => 'Add Time', 'url' => ['/purchase/addtime']];
}
// if the user has no devices then show the init 'purchase' VW option.
echo Nav::widget(['options' => ['class' => 'navbar-nav navbar-left'], 'items' => $menuItems]);
NavBar::end();