當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Plan::deleteOldPlanfeatures方法代碼示例

本文整理匯總了PHP中Plan::deleteOldPlanfeatures方法的典型用法代碼示例。如果您正苦於以下問題:PHP Plan::deleteOldPlanfeatures方法的具體用法?PHP Plan::deleteOldPlanfeatures怎麽用?PHP Plan::deleteOldPlanfeatures使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Plan的用法示例。


在下文中一共展示了Plan::deleteOldPlanfeatures方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: edit

 public function edit()
 {
     $options = $this->config->config['period_qualifier'];
     $error = array();
     $plan = new Plan();
     $features = new Feature();
     $request = $this->getRequest();
     //check if data was sent
     if ($this->isRequestMethod('POST')) {
         $weight = $request->request->get('plan_weight', '') ?: (int) $plan->getActualPlans()->weight + 1;
         $plan->clear();
         $plan->get_by_id($request->request->get('id'));
         $plan->weight = $weight;
         $plan->name = $request->request->get('name');
         $trial = $request->request->get('trial');
         $plan->trial = !empty($trial);
         $special = $request->request->get('special');
         $plan->special = !empty($special);
         $featuresIds = $request->request->get('feature');
         $saveFeatures = array();
         $saveFeaturesIds = array();
         //check if features was selected
         if (implode('', $featuresIds) == '') {
             $error[] = lang('attached_features_count_error');
         } else {
             $weight = 1;
             //save features of plan
             foreach ($featuresIds as $id) {
                 if ($id) {
                     $plansFeature = new Plans_feature($request->request->get('feature_' . $id . '_plansfeatureid', ''));
                     $plansFeature->feature_id = $id;
                     if ($request->request->has('feature_' . $id . '_value')) {
                         $value = $request->request->get('feature_' . $id . '_value');
                         $featureValidator = new Feature($id);
                         if ($featureValidator->validValue($value)) {
                             $plansFeature->value = $value;
                         } else {
                             $error[] = lang('attached_features_type_error', [$featureValidator->name, $featureValidator->type]);
                         }
                     }
                     $plansFeature->weight = $weight;
                     if ($plansFeature->save()) {
                         $saveFeatures[] = $plansFeature;
                         $saveFeaturesIds[] = $plansFeature->id;
                         $weight++;
                     }
                 }
             }
         }
         //save periods of plan
         $savePeriods = array();
         $savePeriodsIds = array();
         if ($count = count($request->request->get('period_id'))) {
             $periodId = $request->request->get('period_id');
             $period = $request->request->get('period');
             $qualifier = $request->request->get('qualifier');
             $price = $request->request->get('price');
             for ($i = 0; $i < $count; $i++) {
                 $planPeriod = new Plans_period($periodId[$i]);
                 $planPeriod->period = $period[$i];
                 $planPeriod->qualifier = $qualifier[$i];
                 $planPeriod->price = $price[$i];
                 if ($planPeriod->save()) {
                     $savePeriods[] = $planPeriod;
                     $savePeriodsIds[] = $planPeriod->id;
                 }
                 if ($planPeriod->error->string) {
                     $error[] = $planPeriod->error->string;
                 }
             }
         }
         //save plan with related features and period
         if (empty($error)) {
             $plan->save(array($saveFeatures, $savePeriods));
             $plan->createStripePlans();
         }
         if ($plan->errors->string) {
             $error[] = $plan->errors->string;
         }
         if (!empty($error)) {
             $this->addFlash(implode('', $error));
             $this->session->set_flashdata('recent', $request->request->all());
             $planParam = $plan->id ? '?plan=' . $plan->id : '';
             redirect('/admin/manage_plans/edit' . $planParam);
         } else {
             $plan->deleteOldPlanPeriods($savePeriodsIds);
             $plan->deleteOldPlanfeatures($saveFeaturesIds);
         }
         redirect('/admin/manage_plans/');
     }
     $planId = $request->query->get('plan', '');
     $plan->get_by_id($planId);
     $plansFeatures = $plan->getAttachedFeatures();
     $plansPeriod = $plan->plans_period->get();
     //fill data after bad validation
     if ($recent = $this->session->flashdata('recent')) {
         //recent selected features
         foreach ($plansFeatures as $planFeature) {
             $featureId = $planFeature->feature_id;
             if (in_array($featureId, $recent['feature'])) {
//.........這裏部分代碼省略.........
開發者ID:andrewkrug,項目名稱:repucaution,代碼行數:101,代碼來源:manage_plans.php


注:本文中的Plan::deleteOldPlanfeatures方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。