コード例 #1
0
 protected function addToCart($data)
 {
     if (empty($data['product_ids'])) {
         return false;
     }
     $store = $this->owner;
     $options = $store->getOptionsByName();
     if (!empty($options['add_to_cart_counter_statistics'])) {
         $option = $options['add_to_cart_counter_statistics'];
     } else {
         $option = new Option();
         $option->name = 'add_to_cart_counter_statistics';
         $option->link('store', $store);
     }
     $stats = [];
     if ($option->value) {
         $stats = Json::decode($option->value);
     }
     foreach ($data['product_ids'] as $product_id) {
         if (empty($stats[$product_id])) {
             $stats[$product_id] = 0;
         }
         $stats[$product_id]++;
     }
     $option->value = Json::encode($stats);
     $option->save();
 }
コード例 #2
0
 public function addCorp(Request $request)
 {
     $this->validate($request, ['name' => 'required', 'value' => 'required|numeric']);
     $option = new Option();
     $option->name = $request->name;
     $option->value = $request->value;
     $option->key = 'allowed_corps';
     $option->type = 'meta';
     $option->save();
     return back();
 }
コード例 #3
0
 /**
  * Store a newly created resource in storage.
  * @param PollRequest $request
  * @return
  */
 public function store(PollRequest $request)
 {
     $input = $request->only('title');
     $input['apartment_id'] = Auth::user()->profile->defaultApartment;
     $input['profile_id'] = Auth::user()->profile->id;
     $poll = Poll::create($input);
     for ($idx = 0; $idx < count($request->option); $idx++) {
         $option = new Option();
         $option->poll_id = $poll->id;
         $option->option = ucfirst($request->option[$idx]);
         $option->save();
     }
     return redirect()->back()->withMessage('Poll Created')->withStatus('success');
 }
コード例 #4
0
 public function saveOptions()
 {
     if ($this->store->id) {
         $options = $this->store->getOptionsByName();
         foreach ($this->attributes() as $attribute) {
             if (!empty($options[$attribute])) {
                 $option = $options[$attribute];
             } else {
                 $option = new Option();
                 $option->name = $attribute;
                 $option->link('store', $this->store);
             }
             $option->value = $this->{$attribute};
             $option->save();
         }
         return true;
     }
     return false;
 }
コード例 #5
0
 public function actionIndex($store_id = 0, $order_id = 0)
 {
     $data = Yii::$app->request->post();
     if ($data) {
         if (empty($data['shop_domain'])) {
             throw new BadRequestHttpException("Shop domain is missing");
         } elseif (empty($data['order_info']['order_id'])) {
             throw new BadRequestHttpException("Order ID is missing");
         } elseif (empty($data['return_url'])) {
             throw new BadRequestHttpException("Return Url is missing");
         } elseif (empty($data['cancel_url'])) {
             throw new BadRequestHttpException("Cancel Url is missing");
         }
         $store = Store::findOne(['domain' => $data['shop_domain']]);
         if (!$store) {
             throw new BadRequestHttpException("Store not found");
         }
         // Save data to option
         $option_name = 'order_' . $data['order_info']['order_id'];
         $option = Option::findOne(['store_id' => $store->id, 'name' => $option_name]);
         if (!$option) {
             $option = new Option();
             $option->link('store', $store);
             $option->name = $option_name;
         }
         $option->value = Json::encode($data);
         $option->save();
         return $this->redirect(['index', 'store_id' => $store->id, 'order_id' => $data['order_info']['order_id']]);
     } elseif ($store_id && $order_id) {
         $store = Store::findOne($store_id);
         $option = $this->getOption($store_id, $order_id);
         $data = Json::decode($option->value);
         return $this->render('index', ['store' => $store, 'data' => $data, 'order_id' => $order_id]);
     } else {
         throw new BadRequestHttpException();
     }
 }
コード例 #6
0
ファイル: OptionService.php プロジェクト: psychodoma/imma
 public function create($option)
 {
     $optionObj = new Option();
     $optionObj->fill($option);
     $optionObj->save();
 }
コード例 #7
0
 public function questions(Request $request)
 {
     // [1] validate the title and the CSV
     $messages = ['title.required' => 'El título es requerido', 'the-csv.required' => 'El archivo de excel es requerido', 'the-csv.mimetypes' => 'El archivo debe ser excel'];
     $this->validate($request, ['title' => 'bail|required|max:255', 'the-csv' => 'required|mimetypes:application/excel,application/vnd.ms-excel,application/x-excel,application/x-msexcel,application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'], $messages);
     // [2] save the quiz blueprint
     $user = Auth::user();
     $blueprint = new Blueprint();
     $blueprint->title = $request->input("title");
     $blueprint->user_id = $user->id;
     $blueprint->is_closed = 0;
     $blueprint->is_public = 0;
     $blueprint->is_visible = 0;
     $blueprint->type = "generated";
     $blueprint->save();
     // [3] add the questions
     $file = $request->file("the-csv");
     $temp = $file->getPathName();
     Excel::load($temp, function ($reader) use($blueprint) {
         $reader->each(function ($row) use($blueprint) {
             if (trim($row->pregunta) != "") {
                 $question = new Question();
                 //$options  = !empty($row->seccion) ? (int)$row->seccion : 1;
                 $question->blueprint_id = $blueprint->id;
                 $question->question = $row->pregunta;
                 $question->section_id = !empty($row->seccion) ? (int) $row->seccion : 1;
                 $type = strtr(strtolower($row->tipo), "áéíóú", "aeiou");
                 if (in_array($type, ['numero', 'numerico', 'numerica', 'cantidad', 'cifra'])) {
                     $question->type = "number";
                 } elseif ($type == "estado") {
                     $question->type = "location-a";
                 } elseif ($type == "municipio") {
                     $question->type = "location-b";
                 } elseif ($type == "localidad") {
                     $question->type = "location-c";
                 } elseif ($type == "multiple" || $type == "opcion multiple") {
                     $question->type = "multiple";
                 } elseif ($type == "multiple multiple" || $type == "multiple-multiple") {
                     $question->type = "multiple-multiple";
                 } else {
                     $question->type = "text";
                 }
                 $question->save();
                 if (!empty($row->opciones) && ($question->type == "multiple" || $question->type == "multiple-multiple")) {
                     $options = explode("|", $row->opciones);
                     for ($i = 0; $i < count($options); $i++) {
                         $option = new Option();
                         $option->question_id = $question->id;
                         $option->blueprint_id = $blueprint->id;
                         $option->description = $options[$i];
                         $option->value = $i + 1;
                         //$options[$i];//$i+1;
                         $option->name = uniqid();
                         $option->order_num = $i;
                         $option->save();
                     }
                     // for
                 }
                 // if
             }
         });
     })->first();
     $request->session()->flash('status', ['type' => 'create', 'name' => $blueprint->title]);
     return redirect("dashboard/encuestas");
 }
コード例 #8
0
 public function updateQuestion(Request $request, $id)
 {
     // [1] CHECK IF THE BLUEPRINT EXIST AND THE USER CAN CHANGE IT
     $user = Auth::user();
     $question = Question::find($id);
     // here we need more validation
     $blueprint = $question->blueprint;
     $old_section = $question->section_id;
     // [2] CREATE THE QUESTION OBJECT
     $question->section_id = (int) $request->input("section_id");
     $question->question = $request->input("question");
     $question->is_location = $request->input("is_location", 0);
     $question->type = $request->input("type", 'text');
     $question->update();
     $options = [];
     // [3] IF THE QUESTION HAS OPTIONS, CREATE THEM
     if (!empty($request->input('options'))) {
         Option::where("question_id", $question->id)->delete();
         $val = 1;
         foreach ($request->input('options') as $opt) {
             $option = new Option();
             $option->question_id = $question->id;
             $option->blueprint_id = $question->blueprint_id;
             $option->description = $opt;
             $option->value = $val;
             $option->name = uniqid();
             $option->order_num = $val;
             $option->save();
             $options[] = $option;
             $val++;
         }
         $remove_rule = 0;
     } else {
         $remove_rule = Rule::where("blueprint_id", $blueprint->id)->where("question_id", $question->id)->delete();
     }
     if ($old_section != $question->section_id) {
         $remove_rule = 1;
     }
     $question->options = $options;
     $question->remove_rule = $remove_rule;
     // [4] GENERATE A NEW TOKEN TO PREVENT TOKEN MISSMATCH
     $question->new_token = csrf_token();
     // [5] RETURN THE JSON
     return response()->json($question)->header('Access-Control-Allow-Origin', '*');
 }
コード例 #9
0
 public function updateHooks($event)
 {
     $store = $this->owner;
     $client = $this->getClient();
     $current_scheme = Yii::$app->request->isSecureConnection ? 'https' : 'http';
     $options = $store->getOptionsByName();
     $scripts = [];
     // Snowfall
     if (isset($options['snowfall_enable'])) {
         if (!empty($options['snowfall_script_tag_hash'])) {
             $option_hash = $options['snowfall_script_tag_hash'];
             if ($option_hash->value) {
                 // remove previos if exists
                 $client->deleteRequest('script_tags/' . $option_hash->value);
             }
         } else {
             $option_hash = new Option();
             $option_hash->name = 'snowfall_script_tag_hash';
             $option_hash->link('store', $store);
         }
         // Enable
         if ($options['snowfall_enable']->value) {
             // Script tag
             $res = $client->createRequest('script_tags', ['src' => Url::to('@web/js/lib/snowfall/snowfall.jquery.js', $current_scheme)]);
             if (!empty($res['src_hash'])) {
                 $option_hash->value = $res['src_hash'];
                 $option_hash->save();
             }
             // Template hook
             $scripts[] = '
                 var snowfallLoad = function(){
                     if ($.snowfall) {
                         $(document).snowfall({flakeCount: 100, maxSpeed: 5, maxSize: 4, shadow: true});
                     } else {
                         setTimeout(function(){
                             snowfallLoad();
                         }, 300);
                     }
                 };
                 snowfallLoad();
             ';
             // Disable
         } else {
             $option_hash->delete();
         }
     }
     // Welcome popup
     if (isset($options['welcome_popup_enable'])) {
         if ($options['welcome_popup_enable']->value) {
             $welcome_popup_data = ['title' => Html::encode($options['welcome_popup_title']->value), 'content' => nl2br(Html::encode($options['welcome_popup_content']->value))];
             $welcome_popup_data_json = Json::encode($welcome_popup_data);
             $scripts[] = "\n                    \$(function(){\n                        var welcome_popup_data = {$welcome_popup_data_json};\n                        if (!\$.cookie.get('welcome_popup_displayed')) {\n                            \$.cookie.set('welcome_popup_displayed', true);\n                            \$.ceNotification('show', {\n                                type: 'I',\n                                title: welcome_popup_data.title,\n                                message: '<div style=\"margin: 0 20px 0 20px;\">' + welcome_popup_data.content + '</div>',\n                                message_state: 'S'\n                            }, 'popupmodal');\n                        }\n                    });\n                ";
         }
     }
     // "Add to cart" counter
     if (isset($options['add_to_cart_counter_enable'])) {
         if (!empty($options['add_to_cart_counter_webhook_id'])) {
             $option_webhook = $options['add_to_cart_counter_webhook_id'];
             if ($option_webhook->value) {
                 // remove previos if exists
                 $client->deleteRequest('webhooks/' . $option_webhook->value);
             }
         } else {
             $option_webhook = new Option();
             $option_webhook->name = 'add_to_cart_counter_webhook_id';
             $option_webhook->link('store', $store);
         }
         if ($options['add_to_cart_counter_enable']->value) {
             $res = $client->createRequest('webhooks', ['event' => 'add_to_cart', 'url' => Url::to(['/webhook', 'store_id' => $store->id], $current_scheme)]);
             if (!empty($res['webhook_id'])) {
                 $option_webhook->value = $res['webhook_id'];
                 $option_webhook->save();
             }
         } else {
             $option_webhook->delete();
         }
     }
     // Payment
     if (isset($options['payment_enable'])) {
         if ($options['payment_enable']->value) {
             $data = ['processor' => Yii::$app->params['applicationName'], 'redirect_url' => Url::to(['/payment'], $current_scheme)];
             if (!empty($options['payment_processor_id'])) {
                 // Update
                 $client->updateRequest('payment_processors/' . $options['payment_processor_id']->value, $data);
             } else {
                 // Create
                 $res = $client->createRequest('payment_processors', $data);
                 if (!empty($res['processor_id'])) {
                     $option_processor = new Option();
                     $option_processor->name = 'payment_processor_id';
                     $option_processor->value = $res['processor_id'];
                     $option_processor->link('store', $store);
                     $option_processor->save();
                 }
             }
         } else {
             if (!empty($options['payment_processor_id'])) {
                 $client->deleteRequest('payment_processors/' . $options['payment_processor_id']->value);
                 $options['payment_processor_id']->delete();
             }
         }
     }
     if ($scripts) {
         $body = '{literal}' . '<script type="text/javascript">' . '(function(_, $) {' . implode(PHP_EOL, $scripts) . '}(Tygh, Tygh.$));' . '</script>' . '{/literal}';
         if (!empty($options['scripts_hook_id'])) {
             // Update
             $client->updateRequest('template_hooks/' . $options['scripts_hook_id']->value, ['body' => $body]);
         } else {
             // Create
             $res = $client->createRequest('template_hooks', ['hookname' => 'index:scripts', 'type' => 'post', 'body' => $body]);
             if (!empty($res['hook_id'])) {
                 $option_hook = new Option();
                 $option_hook->name = 'scripts_hook_id';
                 $option_hook->value = $res['hook_id'];
                 $option_hook->link('store', $store);
                 $option_hook->save();
             }
         }
     } else {
         if (!empty($options['scripts_hook_id'])) {
             $client->deleteRequest('template_hooks/' . $options['scripts_hook_id']->value);
             $options['scripts_hook_id']->delete();
         }
     }
 }