public function add($data)
 {
     global $wpdb;
     $entity = new Entity();
     $option = new Option();
     $dataEntity = ['activate' => $data['activate'], 'sm_entity_id' => $data['sm_entity_id'], 'author_id' => wp_get_current_user()->ID, 'name' => $data['name'], 'last_published_message' => date('Y-m-d H:i:s')];
     $entityID = $entity->save($dataEntity);
     foreach ($data['category'] as $key => $value) {
         $dataOption = ['option_id' => 1, 'value' => $value];
         $option->save($dataOption, $entityID);
     }
     $dataOption = ['option_id' => 2, 'value' => $data['display_type']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 3, 'value' => $data['publish_type']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 4, 'value' => $data['link_canonical']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 5, 'value' => $data['image']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 6, 'value' => $data['readmore']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 7, 'value' => $data['noIndex']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 8, 'value' => $data['noFollow']];
     $option->save($dataOption, $entityID);
     $dataOption = ['option_id' => 9, 'value' => $data['morebalise']];
     $option->save($dataOption, $entityID);
 }
示例#2
0
 /**
  * 更新Option的值
  */
 private function set2Db($key, $value)
 {
     $item = Option::model()->find("option_name=:option_name", array("option_name" => $key));
     if (!isset($item)) {
         $item = new Option();
         $item->option_name = $key;
     }
     $item->option_value = $value;
     $item->save();
     return $item;
 }
 /**
  * Run the migrations.
  *
  * @return void
  */
 public function up()
 {
     // import options
     $options = config('options');
     $options['version'] = config('app.version');
     $options['announcement'] = str_replace('{version}', $options['version'], $options['announcement']);
     foreach ($options as $key => $value) {
         Option::set($key, $value);
     }
     Option::save();
 }
 /**
  * Creates a new model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  */
 public function actionCreate()
 {
     $model = new Option();
     // Uncomment the following line if AJAX validation is needed
     // $this->performAjaxValidation($model);
     if (isset($_POST['Option'])) {
         $model->attributes = $_POST['Option'];
         if ($model->save()) {
             $this->redirect(array('view', 'id' => $model->id));
         }
     }
     $this->render('create', array('model' => $model));
 }
 public function actionCreate()
 {
     $model = new Option();
     $description = new OptionDescription();
     $optionValue = new OptionValue();
     $optionValueDes = new OptionValueDescription();
     //$optionValueData = new CArrayDataProvider($this->_optionvalue);
     $this->performAjaxValidation(array($model, $description, $optionValue), 'option-form');
     if (isset($_POST[$this->modelName])) {
         $model->setAttributes($_POST[$this->modelName]);
         $description->setAttributes($_POST[$this->modelName . 'Description']);
         //$optionValue->setAttributes($_POST['OptionValue']);
         $suc = Yii::t('info', 'Option was successfully created');
         $err = Yii::t('info', 'Could not update Option');
         $errOpt = Yii::t('info', 'Please fill in the name and sort number for each option value');
         $description->option_id = 0;
         $description->locale_code = Yii::app()->getLanguage();
         if ($model->validate() && $description->validate() && $this->validateOptionValue()) {
             if ($model->save()) {
                 $description->option_id = $model->id;
                 $description->save();
                 foreach ($this->_optionvalue as $i => $optionvalue) {
                     $optionvalue->option_id = $model->id;
                     $optionvalue->save();
                     $this->_optionvaluedes[$i]->option_value_id = $optionvalue->id;
                     $this->_optionvaluedes[$i]->option_id = $model->id;
                     $this->_optionvaluedes[$i]->save();
                 }
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_SUCCESS, $suc);
                 if (Yii::app()->getRequest()->getIsAjaxRequest()) {
                     $this->renderPartial('_view', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)), false, true);
                     Yii::app()->end();
                 } else {
                     $this->redirect(array('view', 'id' => $model->id));
                 }
             } else {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $err);
             }
         } else {
             $description->validate();
             if (!$this->validateOptionValue()) {
                 Yii::app()->user->setFlash(TbHtml::ALERT_COLOR_ERROR, $errOpt);
             }
         }
     }
     if (Yii::app()->getRequest()->getIsAjaxRequest()) {
         $this->renderPartial('_form', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)), false, true);
         Yii::app()->end();
     }
     $this->render('create', array('model' => $model, 'description' => $description, 'optionValue' => $this->_optionvalue, 'optionValueDes' => $this->_optionvaluedes, 'optionValueData' => new CArrayDataProvider($this->_optionvalue)));
 }
 /**
  * Make changes to the database.
  *
  * @return void
  */
 public function up()
 {
     //
     Schema::create('options', function ($table) {
         $table->increments('id');
         $table->boolean('activate_pn');
         $table->string('basic_name');
         $table->string('basic_pass');
         $table->timestamps();
     });
     $o = new Option();
     $o->activate_pn = 0;
     $o->save();
 }
示例#7
0
 public static function refresh()
 {
     $defaults = Config::get('options.defaults');
     foreach ($defaults as $d => $v) {
         $opt = Option::where('varname', $d)->first();
         if ($opt) {
         } else {
             $opt = new Option();
             $opt->varname = $d;
             foreach ($v as $k => $v) {
                 $opt->{$k} = $v;
             }
             $opt->save();
         }
     }
 }
 public function postQuestionChange()
 {
     //message-notification
     $messages = array();
     //handle navigation
     $admin_navigation = new AdminNavigation();
     if ($admin_navigation->isNavigate()) {
         return $admin_navigation->goToN();
     }
     //handle chapter-text change
     //redirect after changed
     if (Input::has('chapter_change')) {
         $chapter = Chapter::find(Input::get('chapter_change'));
         $chapter->text = Input::get('chapter_text');
         $chapter->save();
         $messages['chapter_change_text'] = 'chapter-' . $chapter->id . ':saved';
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //handle delete-question
     //redirect after deleted, no need to modify other inputs
     if (Input::has('delete_question')) {
         $question = Question::find(Input::get('delete_question'));
         $store_question_id = $question->id;
         $question->delete();
         $messages['delete_question'] = 'question-' . $store_question_id . ':deleted';
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //handle change on a question (both this one, and it's options)
     //redirect after all-changes saved
     if (Input::has('question_change')) {
         $question = Question::find(Input::get('question_change'));
         //question-change, change question-text
         if (Input::has('question_text')) {
             $question->text = Input::get('question_text');
             $question->save();
             $messages['question_change_text'] = 'question-' . $question->id . ':saved';
         }
         //question-change, change question-chapter_id
         if (Input::has('chapter_id')) {
             $question->chapter_id = Input::get('chapter_id');
             $question->save();
             $new_chapter = $question->getChapter;
             $messages['question_change_chapter_id'] = 'question-' . $question->id . ':now belongs to chapter-' . $new_chapter->id;
         }
         //options-change
         if (Input::has('options')) {
             $options = Input::get('options');
             //save options-change
             $i = -1;
             foreach ($options as $option_id => $option_text) {
                 $option = Option::find($option_id);
                 $option->text = $option_text;
                 //reset all option-is_right = 0
                 //is_right set again with input-is_right checked
                 $option->is_right = 0;
                 $option->save();
                 $messages['options_change[' . ++$i . ']'] = 'option-' . $option->id . ':saved';
             }
             //modify option-is_right
             if (Input::has('is_right')) {
                 $option = Option::find(Input::get('is_right'));
                 //this option set is_right = 1
                 $option->is_right = 1;
                 $option->save();
                 $messages['options_change_is_right'] = 'option-' . $option->id . '-is_right:saved';
             }
         }
         //send message-notification
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //new-question
     //redirect after create new-one
     if (Input::has('new_question')) {
         //save new question
         $question = new Question();
         //delete + auto_increment >>> modify question-id not continuous
         //manually change question-id
         $last_question = Question::all()->last();
         $question->id = $last_question->id + 1;
         $question->text = Input::get('question_text');
         $question->chapter_id = Input::get('chapter_id');
         $question->save();
         $question_id = $question->id;
         $messages['new_question'] = 'question-' . $question->id . ':saved';
         //save new options
         $options_text = Input::get('options');
         $created_options = array();
         for ($i = 0; $i < 4; $i++) {
             $option = new Option();
             $option->text = $options_text[$i];
             $option->question_id = $question_id;
             $option->is_right = 0;
             $option->save();
             //store in array new-option in $created_options, to add is_right on which
             $created_options[$i] = $option;
             $messages['option[' . $i . ']'] = 'option-' . $option->id . ':saved';
         }
         if (Input::has('is_right')) {
             $right_option = Input::get('is_right');
             //get option from store-$created_options, which selected is_right
             $option = $created_options[$right_option];
             $option->is_right = 1;
             $option->save();
             $messages['option_is_right'] = 'option-' . $option->id . '-is_right:saved';
         }
         //send message-notification
         $this->messageController->send($messages, $this::MESSAGE_KEY);
         return Redirect::back();
     }
     //as a fallback
     //send message-notification
     $this->messageController->send($messages, $this::MESSAGE_KEY);
     return Redirect::back();
 }
 public function postConfigSave()
 {
     if (Payment::VeryPayment() == false) {
         return View::make('clinic.payment.renews-payment');
     }
     $data = array("name" => Input::get("name"), "insurance" => Input::get("insurance"), "lang" => Input::get("lang"), "picture" => Input::file("picture"), "phone" => Input::get("phone"));
     $rules = array("name" => 'required|min:1|max:255', "insurance" => 'required|min:1|max:255', "lang" => 'required|min:1|max:10', "picture" => 'mimes:jpeg,gif,png', "phone" => 'required|numeric|min:1');
     $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen :attribute debe ser jpg, git, png');
     $validation = Validator::make(Input::all(), $rules, $messages);
     //si la validación falla redirigimos al formulario de registro con los errores
     //y con los campos que nos habia llenado el usuario
     if ($validation->fails()) {
         return Redirect::to('/clinic/config-data/')->withErrors($validation)->withInput();
     } else {
         $id = Input::get("id");
         $clinic = Clinic::find($id);
         $clinic->name = Input::get("name");
         $clinic->phone = Input::get("phone");
         $clinic->insurances = Input::get("insurance");
         if (Input::file('picture') != NULL) {
             //agrega imagen de logo
             $file_logo = Input::file('picture');
             $ext = Input::file('picture')->getClientOriginalExtension();
             $nameIMG = date('YmdHis');
             $logo = $nameIMG . '.' . $ext;
             $logo = 'assets/clinic/images/logo/logo_' . $logo;
             $file_logo->move("assets/clinic/images/logo/", $logo);
             $clinic->picture = $logo;
         }
         $clinic->save();
         $adress = Address::find($clinic->address_id);
         $adress->my_address = Input::get("address");
         $adress->save();
         $lang = Option::where('name', $clinic->id . '-clinic-lang')->first();
         if ($lang) {
             $lang->key = Input::get("lang");
             $lang->save();
         } else {
             $langadd = new Option();
             $langadd->key = Input::get("lang");
             $langadd->name = $clinic->id . '-clinic-lang';
             $langadd->save();
         }
         return Redirect::back();
     }
 }
示例#10
0
    $suitable_option_ids = Option::getIdsFromNames($suitable_option_names);
    $options = Option::getObjects($suitable_option_ids);
    $suitable_restaurants = Restaurant::suitableRestaurants($suitable_option_ids);
    return $app['twig']->render('results.html.twig', array('suitable_restaurants' => $suitable_restaurants, 'options' => $options));
});
$app->get('/admin', function () use($app) {
    return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
});
$app->post('/add_restaurants', function () use($app) {
    $restaurant_name = new Restaurant($_POST['restaurant_name']);
    $restaurant_name->save();
    return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
});
$app->post('/add_options', function () use($app) {
    $option_name = new Option($_POST['option_name']);
    $option_name->save();
    return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
});
$app->post('/add_restaurant_options', function () use($app) {
    $restaurant = Restaurant::find($_POST['restaurant_id']);
    $option = Option::find($_POST['option_id']);
    $restaurant->addOption($option);
    return $app['twig']->render('restaurant.html.twig', array('restaurant' => $restaurant, 'restaurant_options' => $restaurant->getOptions(), 'all_options' => Option::getAll()));
});
$app->post('/add_option_restaurants', function () use($app) {
    $option = Option::find($_POST['option_id']);
    $restaurant = Restaurant::find($_POST['restaurant_id']);
    $option->addRestaurant($restaurant);
    return $app['twig']->render('option.html.twig', array('option' => $option, 'option_restaurants' => $option->getRestaurants(), 'all_restaurants' => Restaurant::getAll()));
});
$app->get('/restaurants/{id}', function ($id) use($app) {
 public function save_tag()
 {
     $id = Input::get('id');
     $tag = Option::find($id);
     if (!$tag) {
         $tag = new Option();
     }
     $tag->name = Input::get('name');
     $tag->save();
     $message = "Successfully updated the product tag";
     $type = "success";
     return Redirect::to('/admin/tags')->with('type', $type)->with('message', $message);
 }
 public function getConfigSave()
 {
     if (Payment::VeryPayment() == false) {
         return View::make('clinic.payment.renews-payment');
     }
     $data = array("insurance" => Input::get("insurance"), "lang" => Input::get("lang"));
     $rules = array("insurance" => 'required|min:1|max:100', "lang" => 'required|min:1|max:100');
     $messages = array('required' => 'El campo :attribute es obligatorio.', 'min' => 'El campo :attribute no puede tener menos de :min carácteres.', 'email' => 'El campo :attribute debe ser un email válido.', 'max' => 'El campo :attribute no puede tener más de :max carácteres.', 'numeric' => 'El campo :attribute debe contener solo numeros', 'mimes' => 'El formato de la imagen logo debe ser jpg, git, png');
     $validation = Validator::make(Input::all(), $rules, $messages);
     //si la validación falla redirigimos al formulario de registro con los errores
     //y con los campos que nos habia llenado el usuario
     if ($validation->fails()) {
         return Redirect::to('/clinic/config-data/')->withErrors($validation)->withInput();
     } else {
         $id = Doctor::doctorLogin();
         $doctor = Doctor::where('id', $id)->first();
         $lang = Option::where('name', $id . '-doctor-lang')->first();
         if ($lang) {
             $lang->key = Input::get("lang");
             $lang->save();
         } else {
             $langadd = new Option();
             $langadd->key = Input::get("lang");
             $langadd->name = $id . '-doctor-lang';
             $langadd->save();
         }
         $opcionSeg = Option::where('name', $id . '-doctor-insurance')->first();
         if ($opcionSeg) {
             $segs = explode(',', Input::get("insurance"));
             $segok = '';
             foreach ($segs as $seg) {
                 $very = Insurance::where('name', 'like', '%' . $seg . '%')->first();
                 if ($very) {
                     $segok = $segok . ',' . $seg;
                 }
             }
             $opcionSeg->key = $segok;
             $opcionSeg->save();
         } else {
             $segs = explode(',', Input::get("insurance"));
             $seguok = '';
             foreach ($segs as $seg) {
                 $very = Insurance::where('name', $seg)->first();
                 if ($very) {
                     $seguok = $seguok . ',' . $seg;
                 }
             }
             $addseg = new Option();
             $addseg->name = $id . '-doctor-insurance';
             $addseg->key = $seguok;
             $addseg->save();
         }
         return Redirect::back();
     }
 }
示例#13
0
 /**
  * Save an entry
  *
  * @return  void
  */
 public function saveTask()
 {
     // Check for request forgeries
     Request::checkToken();
     $fields = array('id' => Request::getInt('id', 0, 'post'), 'title' => Request::getVar('title', '', 'post'), 'alias' => Request::getVar('alias', '', 'post'), 'lag' => Request::getVar('lag', '', 'post'), 'published' => Request::getVar('published', '', 'post'), 'open' => Request::getVar('open', '', 'post'));
     // Save the poll parent information
     $row = Poll::oneOrNew($fields['id'])->set($fields);
     if (!$row->save()) {
         Notify::error($row->getError());
         return $this->editTask($row);
     }
     $row->checkin();
     // Save the poll options
     $options = Request::getVar('polloption', array(), 'post');
     foreach ($options as $i => $text) {
         $option = new Option();
         $option->pollid = (int) $row->id;
         $option->text = htmlspecialchars($text, ENT_QUOTES, 'UTF-8');
         if ($fields['id']) {
             $option->id = (int) $i;
         }
         if (!$option->save()) {
             Notify::error($option->getError());
         }
     }
     Notify::success(Lang::txt('COM_POLL_ITEM_SAVED'));
     if ($this->_task == 'apply') {
         return $this->editTask($row);
     }
     App::redirect(Route::url('index.php?option=com_poll', false));
 }
 function test_suitableRestaurants()
 {
     // arrange
     $restaurant_name = "Taco Hell";
     $test_restaurant = new Restaurant($restaurant_name);
     $test_restaurant->save();
     $restaurant_name2 = "Burger Queen";
     $test_restaurant2 = new Restaurant($restaurant_name2);
     $test_restaurant2->save();
     $option_name = "Shellfish-free";
     $test_option = new Option($option_name);
     $test_option->save();
     $option_name2 = "Gasoline-free";
     $test_option2 = new Option($option_name2);
     $test_option2->save();
     $option_name3 = "Soy-free";
     $test_option3 = new Option($option_name3);
     $test_option3->save();
     // act
     $test_restaurant->addOption($test_option2);
     $test_restaurant->addOption($test_option3);
     $test_restaurant2->addOption($test_option);
     $test_restaurant2->addOption($test_option2);
     $test_restaurant2->addOption($test_option3);
     $option_ids = array();
     array_push($option_ids, $test_option->getId());
     array_push($option_ids, $test_option3->getId());
     $result = Restaurant::suitableRestaurants($option_ids);
     // assert
     $this->assertEquals([$test_restaurant2], $result);
 }
 function test_getIdsFromNames()
 {
     //arrange
     $name = "peanut-free";
     $test_option = new Option($name);
     $test_option->save();
     $name2 = "soy-free";
     $test_option2 = new Option($name2);
     $test_option2->save();
     //act
     $suitable_options_names = array($test_option->getName(), $test_option2->getName());
     $result = Option::getIdsFromNames($suitable_options_names);
     //assert
     $this->assertEquals([$test_option->getId(), $test_option2->getId()], $result);
 }