Exemple #1
0
 public function actionAddPaid($id = 0, $withDate = 0)
 {
     $model = new AddToUserForm();
     $tariffs = TariffPlans::getAllTariffPlans(true, true);
     $tariffsArray = CHtml::listData($tariffs, 'id', 'name');
     $request = Yii::app()->request;
     $data = $request->getPost('AddToUserForm');
     if ($data) {
         $userId = $request->getPost('user_id');
         $withDate = $request->getPost('withDate');
         $model->attributes = $data;
         if ($model->validate()) {
             $user = User::model()->findByPk($userId);
             $tariff = TariffPlans::getFullTariffInfoById($model->tariff_id);
             if (!$tariff || !$user) {
                 throw new CException('Not valid data');
             }
             if (TariffPlans::applyToUser($userId, $tariff['id'], $model->date_end, null, true)) {
                 echo CJSON::encode(array('status' => 'ok', 'userId' => $userId, 'html' => TariffPlans::getTariffPlansHtml($withDate, true, $user)));
                 Yii::app()->end();
             }
         } else {
             echo CJSON::encode(array('status' => 'err', 'html' => $this->renderPartial('_add_to_user', array('id' => $userId, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray), true)));
             Yii::app()->end();
         }
     }
     $renderData = array('id' => $id, 'model' => $model, 'withDate' => $withDate, 'tariffsArray' => $tariffsArray);
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('_add_to_user', $renderData);
     } else {
         $this->render('_add_to_user', $renderData);
     }
 }
Exemple #2
0
 public function actionIndex()
 {
     $this->layout = '//layouts/usercpanel';
     $this->setActiveMenu('tariff_plans');
     $tariffPlanModel = new TariffPlans();
     //$tariffPlans = TariffPlans::getAllTariffPlans(true, true);
     $tariffPlans = TariffPlans::getAllTariffPlans(true, true, true);
     // только активные тарифы, без тарифа по-умолчанию и только со стоимостью больше 0.
     $tariffsArray = CHtml::listData($tariffPlans, 'id', 'name');
     if (!count($tariffsArray)) {
         throw404();
     }
     $renderData = array('model' => $tariffPlanModel, 'tariffsArray' => $tariffsArray, 'tariffPlans' => $tariffPlans);
     if (Yii::app()->request->isAjaxRequest) {
         $this->renderPartial('index', $renderData);
     } else {
         $this->render('index', $renderData);
     }
 }