示例#1
0
 /**
  * @param $data
  * @param $form
  * @throws ValidationException
  * @throws null
  * Handle submit signup
  */
 public function Submit($data, $form)
 {
     foreach ($data as $k => &$v) {
         if ($v === 'false') {
             $data[$k] = false;
         } elseif ($v === 'true') {
             $data[$k] = true;
         }
         if ($k === 'Title') {
             $v = $v + 1;
         }
     }
     Session::set('SignupData', $data);
     $Signup = new Signup();
     $Signup->update($data);
     $type = Session::get('Signup');
     if ($type['type'] === 'PowerPlan') {
         $plan = PowerPlan::get_by_id('PowerPlan', $type['id']);
     } elseif ($type['type'] === 'GasPlan') {
         $plan = GasPlan::get_by_id('GasPlan', $type['id']);
     }
     $Signup->Plan = $plan->Name;
     $Signup->Company = $plan->Company()->Name;
     $SignupID = $Signup->write();
     if ($SignupID) {
         Session::clear('SignupData');
         Session::clear('Signup');
         $this->redirect('signup/result?result=success');
     } else {
         $this->redirect('signup/result?result=fail');
     }
 }
示例#2
0
 public function Calculate()
 {
     $plans = PowerPlan::get('PowerPlan', "AreaID = '{$this->area->ID}'")->toArray();
     foreach ($plans as &$plan) {
         $this->CalPower($plan);
     }
     $result['PowerPlans'] = ArrayList::create($plans);
     if ($this->withGas) {
         $gPlans = GasPlan::get('GasPlan')->toArray();
         foreach ($gPlans as &$gPlan) {
             $this->CalGas($gPlan);
         }
         $result['GasPlans'] = ArrayList::create($gPlans);
     }
     return $result;
 }