コード例 #1
0
 static function getObjects($option_ids)
 {
     $options = array();
     foreach ($option_ids as $option_id) {
         array_push($options, Option::find($option_id));
     }
     return $options;
 }
コード例 #2
0
ファイル: BaseController.php プロジェクト: kelliany/TestZilla
 /**
  * Get all autoload options from database.
  * @param  String $optionName - the key of the option
  * @return the value of the option
  */
 private function getOptionValue($optionName)
 {
     if (empty(self::$options)) {
         $resultSet = Option::find("is_autoload = 1");
         foreach ($resultSet as $rowSet) {
             $optionKey = $rowSet->getOptionKey();
             $optionValue = $rowSet->getOptionValue();
             self::$options[$optionKey] = $optionValue;
         }
     }
     if (!array_key_exists($optionName, self::$options)) {
         return NULL;
     }
     return self::$options[$optionName];
 }
コード例 #3
0
 public function post()
 {
     //receive chose-options from contestant
     $answers_contestant = array_values(Input::all());
     $result = 0;
     for ($i = 0; $i < count($answers_contestant); $i++) {
         $option = Option::find($answers_contestant[$i]);
         //if the option is right, result++
         if ($option->is_right == '1') {
             $result += 1;
         }
     }
     //save result from this contestant
     $contestant = Auth::user();
     $contestant->result = $result;
     $contestant->save();
     //show result on 'result'-page
     return Redirect::to('result');
 }
コード例 #4
0
 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();
 }
コード例 #5
0
$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) {
    $restaurant = Restaurant::find($id);
    return $app['twig']->render('restaurant.html.twig', array('restaurant' => $restaurant, 'restaurant_options' => $restaurant->getOptions(), 'all_options' => Option::getAll()));
});
$app->get('/options/{id}', function ($id) use($app) {
    $option = Option::find($id);
    return $app['twig']->render('option.html.twig', array('option' => $option, 'option_restaurants' => $option->getRestaurants(), 'all_restaurants' => Restaurant::getAll()));
});
$app->post('/restaurants/{id}/delete', function ($id) use($app) {
    $restaurant = Restaurant::find($id);
    $restaurant->delete();
    return $app['twig']->render('admin.html.twig', array('restaurants' => Restaurant::getAll(), 'options' => Option::getAll()));
});
$app->post('/options/{id}/delete', function ($id) use($app) {
    $option = Option::find($id);
    $option->delete();
    return $app['twig']->render('admin.html.twig', array('options' => Option::getAll(), 'restaurants' => Restaurant::getAll()));
});
return $app;
コード例 #6
0
*/
Route::filter('before', function () {
    // Do stuff before every request to your application...
});
Route::filter('after', function ($response) {
    // Do stuff after every request to your application...
});
Route::filter('csrf', function () {
    if (Request::forged()) {
        return Response::error('500');
    }
});
Route::filter('auth', function () {
    if (Auth::guest()) {
        return Redirect::to('login');
    }
});
Route::filter('postnotification', function () {
    $u = Option::find('1');
    if ($u->activate_pn == "1") {
        if ($u->basic_name != '' && (!isset($_SERVER['PHP_AUTH_USER']) || $_SERVER['PHP_AUTH_USER'] != $u->basic_name)) {
            return Response::error('401');
        } else {
            if ($u->basic_pass != '' && (!isset($_SERVER['PHP_AUTH_PW']) || $_SERVER['PHP_AUTH_PW'] != $u->basic_pass)) {
                return Response::error('401');
            }
        }
    } else {
        return Response::error('403');
    }
});
コード例 #7
0
 public function delete_tag()
 {
     $id = Request::segment(4);
     $tag = Option::find($id);
     Option::where('id', $id)->delete();
     $message = "Successfully deleted the product tag";
     $type = "success";
     return Redirect::to('/admin/tags')->with('type', $type)->with('message', $message);
 }
コード例 #8
0
ファイル: model.php プロジェクト: rommelsantor/RawMVC
 /**
  *
  */
 public function has_opt($i_key)
 {
     return Option::find(get_called_class(), $this->id, $i_key);
 }
コード例 #9
0
ファイル: ModelTest.php プロジェクト: gigorok/php-orm
 function testCustomPrimaryKey()
 {
     $option = User::find(1)->option();
     $option->name = 'testtest';
     $option->save();
     $this->assertEquals(Option::find(1)->name, 'testtest');
 }
コード例 #10
0
 function test_find()
 {
     //arrange
     $name = "Peanut-free";
     $test_allergy = new Option($name);
     $test_allergy->save();
     $name2 = "Gluten-free";
     $test_allergy2 = new Option($name2);
     $test_allergy2->save();
     //act
     $result = Option::find($test_allergy2->getId());
     //assert
     $this->assertEquals($test_allergy2, $result);
 }