コード例 #1
0
 public function getEdit($id)
 {
     try {
         $policy = Policy::findOrFail($id);
         return View::make('admin.policies.add-edit')->with('policy', $policy);
     } catch (Illuminate\Database\Eloquent\ModelNotFoundException $e) {
         App::abort(404);
     }
 }
コード例 #2
0
 public static function generate($input)
 {
     $res = [];
     $plan = Plan::findOrFail($input['plan_id']);
     $voucher['expires_on'] = self::_makeExpiry($input['validity'], $input['validity_unit']);
     $voucher['created_at'] = time();
     $voucher['plan_name'] = $plan->name;
     $voucher['plan_type'] = $plan->plan_type;
     $voucher['sim_sessions'] = $plan->sim_sessions;
     $voucher['interim_updates'] = $plan->interim_updates;
     $voucher['price'] = $plan->price;
     $voucher['validity'] = $plan->validity;
     $voucher['validity_unit'] = $plan->validity_unit;
     $voucher['policy_type'] = $plan->policy_type;
     if ($plan->plan_type == 1) {
         //if limited
         $limit = $plan->limit->toArray();
         if ($plan->limit->aq_access == 1) {
             // $limit['aq_access'] = 1;
             $aq_policy = Policy::findOrFail($plan->limit->aq_policy);
             $limit['aq_policy'] = mikrotikRateLimit($aq_policy->toArray());
         }
         $voucher_limit = VoucherLimit::create($limit);
         $voucher['limit_id'] = $voucher_limit->id;
     }
     if ($plan->policy_type == 'Policy') {
         $policy = new VoucherPolicy(['bw_policy' => mikrotikRateLimit($plan->policy->toArray())]);
         $policy->save();
     } elseif ($plan->policy_type == 'PolicySchema') {
         $days = ['mo' => 'monday', 'tu' => 'tuesday', 'we' => 'wednesday', 'th' => 'thursday', 'fr' => 'friday', 'sa' => 'saturday', 'su' => 'sunday'];
         foreach ($days as $d => $day) {
             $tpl = $plan->policy->{$day}->toArray();
             $type = ['bw_policy', 'pr_policy', 'sec_policy'];
             foreach ($type as $t) {
                 if (!is_null($tpl[$t])) {
                     $policy = Policy::find($tpl[$t])->toArray();
                     $tpl[$t] = mikrotikRateLimit($policy);
                 }
             }
             $template = VoucherPolicySchemaTemplate::create($tpl);
             $schema[$d] = $template->id;
         }
         $policy = VoucherPolicySchema::create($schema);
     }
     $voucher['policy_id'] = $policy->id;
     for ($i = 0; $i < $input['count']; $i++) {
         $voucher['pin'] = self::generatePin();
         $voucher['expires_on'] = self::_makeExpiry($input['validity'], $input['validity_unit']);
         $v = new Voucher($voucher);
         if (!$v->save()) {
             return FALSE;
         }
         $res[] = $v->pin;
     }
     return $res;
 }
コード例 #3
0
 public static function AssignPlan($user_id, $plan_id, $price = NULL)
 {
     DB::transaction(function () use($user_id, $plan_id, $price) {
         $oldPlan = APActivePlan::where('user_id', $user_id)->first();
         if (!is_null($oldPlan)) {
             self::updatePlanHistory($oldPlan);
         } else {
             $oldPlan = new ApActivePlan();
         }
         $plan = Plan::findOrFail($plan_id);
         $newPlan = ['user_id' => $user_id, 'plan_name' => $plan->name, 'plan_type' => $plan->plan_type, 'policy_type' => $plan->policy_type, 'sim_sessions' => $plan->sim_sessions, 'interim_updates' => $plan->interim_updates, 'aq_invocked' => 0, 'price' => $plan->price, 'time_balance' => NULL, 'data_balance' => NULL, 'assigned_on' => date("Y-m-d H:i:s"), 'validity' => $plan->validity, 'validity_unit' => $plan->validity_unit];
         if ($price != NULL) {
             $newPlan['price'] = $price;
         }
         if ($plan->plan_type == LIMITED) {
             $limit = $plan->limit;
             if ($limit->limit_type == TIME_LIMIT || $limit->limit_type == BOTH_LIMITS) {
                 $newPlan['time_balance'] = $limit->time_limit * constant($limit->time_unit);
             }
             if ($limit->limit_type == DATA_LIMIT || $limit->limit_type == BOTH_LIMITS) {
                 $newPlan['data_balance'] = $limit->data_limit * constant($limit->data_unit);
             }
             if ($limit->aq_access == ALLOWED) {
                 $aq_policy = Policy::findOrFail($limit->aq_policy);
                 $limit->aq_policy = mikrotikRateLimit($aq_policy->toArray());
             }
             $planLimit = APLimit::create($limit->toArray());
             $newPlan['limit_id'] = $planLimit->id;
         }
         if ($plan->policy_type == 'Policy') {
             $policy = APPolicy::create(['bw_policy' => mikrotikRateLimit($plan->policy->toArray())]);
         } elseif ($plan->policy_type == 'PolicySchema') {
             $days = ['mo' => 'monday', 'tu' => 'tuesday', 'we' => 'wednesday', 'th' => 'thursday', 'fr' => 'friday', 'sa' => 'saturday', 'su' => 'sunday'];
             foreach ($days as $d) {
                 $tpl = $plan->policy->{$day}->toArray();
                 $types = ['bw_policy', 'pr_policy', 'sec_policy'];
                 foreach ($types as $t) {
                     if (!is_null($tpl[$t])) {
                         $policy = Policy::find($tpl[$t])->toArray();
                         $tpl[$t] = mikrotikRateLimit($policy);
                     }
                 }
                 $template = APPolicySchemaTemplate::create($tpl);
                 $schema[$d] = $template->id;
             }
             $policy = APPolicySchema::create($schema);
         }
         $newPlan['policy_id'] = $policy->id;
         $oldPlan->fill($newPlan);
         $oldPlan->save();
         return TRUE;
     });
 }