Пример #1
0
 function actionIndex()
 {
     $page = (int) $this->_context->get('page', 1);
     $orm = Plans::find()->order('plan_id DESC');
     $orm->limitPage($page, 20);
     $this->_view['rs'] = $orm->getAll();
     $this->_view['pg'] = $orm->getPag();
     $form = Form_Common::createForm('', 'manage/plans');
     if ($this->_context->isPOST() && $form->validate($_POST)) {
         $post = $this->_context->post();
         $dsp = array_combine($post['config']['val'], $post['config']['dsp']);
         $tmp = array();
         foreach ($dsp as $val => $dsp) {
             $tmp[] = array('price' => $val, 'print' => $dsp);
         }
         $sku = array_combine($post['config']['key'], $tmp);
         $rs = new Plans();
         $rs->name = $post['name'];
         $rs->groupname = $post['groupname'];
         $rs->desc = $post['desc'];
         $rs->sku = phpversion() >= '5.4' ? json_encode($sku, JSON_UNESCAPED_UNICODE) : json_encode($sku);
         $rs->save();
         return $this->msg($tip = '添加成功', url('manage::plans/index'));
     }
     $groupname_list = Radgroupcheck::find()->group('groupname')->getAll()->toHashMap('groupname', 'groupname');
     $form->element('groupname')->items = $groupname_list;
     $this->_view['form'] = $form;
 }
Пример #2
0
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Plans();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Plans'])) {
         // pre($_POST,true);
         $plan_price = $_POST['PlanPrice'];
         $plan_adv = $_POST['PlanAdvantage'];
         $model->attributes = $_POST['Plans'];
         if ($model->save()) {
             for ($i = 0; $i < count($plan_price['age_group']); $i++) {
                 $planPrice = new PlanPrice();
                 $planPrice->plan = $model->id;
                 $planPrice->age_group = $plan_price['age_group'][$i];
                 $planPrice->policy_tenure = $plan_price['policy_tenure'][$i];
                 $planPrice->policy_amount = $plan_price['policy_amount'][$i];
                 $planPrice->premium = $plan_price['policy_premium'][$i];
                 $planPrice->save();
             }
             for ($j = 0; $j < count($plan_adv['advantage']); $j++) {
                 $planAdv = new PlanAdvantage();
                 $planAdv->plan = $model->id;
                 $planAdv->advantage = $plan_adv['advantage'][$j];
                 $planAdv->tooltip = $plan_adv['policy_tooltip'][$j];
                 $planAdv->save();
             }
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
Пример #3
0
 public function preUp()
 {
     $q = Doctrine_Query::create()->select('a.userid, a.plan, a.edit_text, a.username')->from('Accounts a');
     $plans = $q->execute();
     foreach ($plans as $plan) {
         $p = new Plans();
         $p->user_id = $plan->userid;
         try {
             $p->edit_text = stripslashes($plan->edit_text);
             $p->save();
         } catch (Doctrine_Validator_Exception $e) {
             echo "[{$plan->username}]'s Plan did not update because the generated HTML was too long\n";
             $p->plan = stripslashes($plan->plan);
             $p->save();
         }
     }
 }