예제 #1
0
 /**
  * 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]);
     }
 }
예제 #2
0
 /**
  * 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;
 }
예제 #3
0
 /**
  * Finds the Device model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Device the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Device::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
예제 #4
0
 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]);
 }
예제 #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();