Пример #1
0
 /**
  * Has errors
  * @return array
  */
 public function hasErrors()
 {
     if ($this->error === null) {
         return false;
     }
     return count($this->error->all()) > 0;
 }
Пример #2
0
 /**
  * Method to determine if the validation passed
  * @param  array  $data
  * @return boolean
  */
 public function isValid($data)
 {
     // We will use Illuminate's validator to validate our data with
     // given set of rules.
     $v = $this->validator->make($data, $this->getRules(), $this->getCustomMessages());
     // Setting up errors, if any
     $this->errors = $v->errors();
     // Refreshing the stage to 'default' for further calls
     $this->when();
     // true when zero errors, else false
     return count($this->errors->all()) === 0;
 }
Пример #3
0
 public function testFormatIsRespected()
 {
     $container = new MessageBag();
     $container->setFormat('<p>:message</p>');
     $container->add('foo', 'bar');
     $container->add('boom', 'baz');
     $this->assertEquals('<p>bar</p>', $container->first('foo'));
     $this->assertEquals(array('<p>bar</p>'), $container->get('foo'));
     $this->assertEquals(array('<p>bar</p>', '<p>baz</p>'), $container->all());
     $this->assertEquals('bar', $container->first('foo', ':message'));
     $this->assertEquals(array('bar'), $container->get('foo', ':message'));
     $this->assertEquals(array('bar', 'baz'), $container->all(':message'));
 }
Пример #4
0
 /**
  * Determine if the data passes the validation rules.
  *
  * @return bool
  */
 public function passes()
 {
     $this->messages = kernel::single('base_validator_messageBag');
     //echo '<pre>';print_r($this->rules);exit();
     // We'll spin through each rule, validating the attributes attached to that
     // rule. Any error messages will be added to the containers with each of
     // the other error messages, returning true if we don't have messages.
     /*foreach ($this->rules as $attribute => $rules)
       {
           foreach ($rules as $rule)
           {
               $this->validate($attribute, $rule,$this->customMessages[$attribute]);
           }
       }*/
     if ($this->customMessages && is_array($this->customMessages)) {
         foreach ($this->customMessages as $key => $value) {
             $describe[$key] = explode("|", $value);
             //echo '<pre>';print_r($describe);exit();
         }
     }
     foreach ($this->rules as $attribute => $rules) {
         foreach ($rules as $key => $rule) {
             if ($describe) {
                 $this->validate($attribute, $rule, $describe[$attribute][$key]);
             } else {
                 $this->validate($attribute, $rule);
             }
         }
     }
     return count($this->messages->all()) === 0;
 }
Пример #5
0
 /** @test */
 public function errorsAreAdded()
 {
     $session = $this->makeSession();
     $session->put('errors', $bag = new MessageBag(['foo', 'bar']));
     $view = $this->callCreator($session);
     $errors = $view->validationErrors;
     $this->assertEquals($bag->all(), $errors);
 }
Пример #6
0
 /**
  * Renders messages into HTML.
  * @param \Illuminate\Support\MessageBag $messages
  * @return string
  */
 public function renderMessages($messages)
 {
     $html = '<ul>';
     foreach ($messages->all('<li>:message</li>') as $message) {
         $html .= $message;
     }
     $html .= '</ul>';
     return $html;
 }
Пример #7
0
 /**
  * Determine if the data passes the validation rules.
  *
  * @return bool
  */
 public function passes()
 {
     $this->messages = new MessageBag();
     // We'll spin through each rule, validating the attributes attached to that
     // rule. Any error messages will be added to the containers with each of
     // the other error messages, returning true if we don't have messages.
     foreach ($this->rules as $attribute => $rules) {
         foreach ($rules as $rule) {
             $this->validate($attribute, $rule);
         }
     }
     return count($this->messages->all()) === 0;
 }
Пример #8
0
 /**
  * Determine if the data passes the validation rules.
  *
  * @return bool
  */
 public function passes()
 {
     $this->messages = new MessageBag();
     // We'll spin through each rule, validating the attributes attached to that
     // rule. Any error messages will be added to the containers with each of
     // the other error messages, returning true if we don't have messages.
     foreach ($this->rules as $attribute => $rules) {
         foreach ($rules as $rule) {
             $this->validate($attribute, $rule);
         }
     }
     // Here we will spin through all of the "after" hooks on this validator and
     // fire them off. This gives the callbacks a chance to perform all kinds
     // of other validation that needs to get wrapped up in this operation.
     foreach ($this->after as $after) {
         call_user_func($after);
     }
     return count($this->messages->all()) === 0;
 }
Пример #9
0
    });
    $messageBag->add('notice', 'Collection displayed.');
    echo '<hr>';
    // More at http://daylerees.com/codebright/eloquent-collections
    // Fluent
    $personRecord = array('first_name' => 'Mohammad', 'last_name' => 'Gufran');
    $record = new Fluent($personRecord);
    $record->address('hometown, street, house');
    echo $record->first_name . "\n";
    echo $record->address . "\n";
    $messageBag->add('notice', 'Fluent displayed.');
    echo '<hr>';
    // Pluralizer
    $item = 'goose';
    echo "One {$item}, two " . Pluralizer::plural($item) . "\n";
    $item = 'moose';
    echo "One {$item}, two " . Pluralizer::plural($item) . "\n";
    echo '<hr>';
    // Str
    if (Str::contains('This is my fourteenth visit', 'first')) {
        echo 'Howdy!';
    } else {
        echo 'Nice to see you again.';
    }
    echo '<hr>';
    echo "MessageBag ({$messageBag->count()})\n";
    foreach ($messageBag->all() as $message) {
        echo " - {$message}\n";
    }
});
$app->run();
Пример #10
0
 /**
  * Verify if there's an error at saving.
  * @return boolean
  */
 public function hasErrors()
 {
     return \sizeof($this->errors->all()) > 0;
 }
Пример #11
0
 /**
  * Set a message bag of errors.
  *
  * @author Morten Rugaard <*****@*****.**>
  *
  * @param \Illuminate\Support\MessageBag $errors
  *
  * @return $this
  */
 public function setErrors(MessageBag $errors)
 {
     $this->errors = $errors;
     // Add status message to meta array
     if (!$errors->isEmpty()) {
         $this->addMeta(['errors' => $errors->all()]);
     }
     return $this;
 }
Пример #12
0
 public function check($id, Request $request, TestValidator $testvalidator)
 {
     $test = Test::findOrFail($id);
     $validation = $testvalidator->WithRequest($test, $request);
     $hasPassed = $validation['num_correct'] / $validation['total'] >= 0.5;
     $hasPassedFull = $validation['num_correct'] == $validation['total'];
     $minimumToPass = ceil($validation['total'] * 0.5);
     $customErrors = new MessageBag();
     $errors = [];
     if (!Auth::check()) {
         $authenticationType = $request->input('authentication_type');
         switch ($authenticationType) {
             case 0:
                 $authvalidator = \Validator::make($request->all(), ['user-name' => 'required', 'user-email' => 'required|email|unique:users,email', 'user-password' => 'required|min:8|confirmed'], ['user-name.required' => 'Nimi on pakollinen.', 'user-email.required' => 'Sähköpostiosoite on pakollinen.', 'user-email.email' => 'Annettu sähköpostiosoite ei ole pätevä.', 'user-email.unique' => 'Tunnus samalla sähköpostiosoitteella on jo olemassa.', 'user-password.required' => 'Salasana on pakollinen.', 'user-password.min' => 'Salasanan pitää olla ainakin :min merkkiä pitkä.', 'user-password.confirmed' => 'Salasanat eivät täsmää.']);
                 break;
             case 1:
                 $authvalidator = \Validator::make($request->all(), ['user-login-email' => 'required|email', 'user-login-password' => 'required'], ['user-login-email.required' => 'Sähköpostiosoite on pakollinen.', 'user-login-email.email' => 'Annettu sähköpostiosoite ei ole pätevä.', 'user-login-password.required' => 'Salasana on pakollinen.']);
                 break;
         }
         $group = false;
         $shouldJoinGroup = false;
         if (strlen($request->input('group-code')) > 0) {
             $group = Group::where('code', $request->input('group-code'));
             if (!$group->exists()) {
                 $customErrors->add('group-code', 'Annettua ryhmää ei löytynyt. Syötä oikea ryhmäkoodi.');
             } else {
                 $shouldJoinGroup = true;
             }
         }
         if ($authvalidator->passes() && $customErrors->isEmpty()) {
             switch ($authenticationType) {
                 case 0:
                     $user = new User();
                     $user->name = $request->input('user-name');
                     $user->email = $request->input('user-email');
                     $user->password = Hash::make($request->input('user-password'));
                     $user->access_level = 'USER';
                     $user->save();
                     Mail::send('email.user_account_created', ['user' => $user], function ($m) use($user) {
                         $m->to($user->email, $user->name)->subject('Käyttäjätunnus luotu Media7 raamattuopistoon');
                     });
                     Auth::login($user);
                     if ($shouldJoinGroup) {
                         $group->first()->join();
                     }
                     break;
                 case 1:
                     $credentials = ['email' => $request->input('user-login-email'), 'password' => $request->input('user-login-password')];
                     $remember = $request->input('remember_me');
                     if (!Auth::attempt($credentials, $remember)) {
                         $customErrors->add('user-login-email', 'Kirjautuminen annetuilla tunnuksilla ei onnistunut!');
                     } else {
                         if ($shouldJoinGroup) {
                             $group->first()->join();
                         }
                         return redirect('/test/' . $test->id);
                     }
                     break;
             }
         }
         $errors = array_merge($authvalidator->errors()->all(), $customErrors->all());
     }
     if (Auth::check() && $customErrors->isEmpty()) {
         $archive = Auth::user()->archives()->where('test_id', $id)->first();
         $data = $validation;
         if (!$archive) {
             $archive = new Archive();
             $archive->user_id = Auth::user()->id;
             $archive->test_id = $test->id;
         } else {
             $old_data = json_decode($archive->data, true);
             if (@$old_data['feedback']) {
                 $data['feedback'] = $old_data['feedback'];
             }
         }
         $archive->data = json_encode($data);
         $archive->save();
     }
     return view('test.show')->with(array_merge($validation, ['test' => $test, 'feedback' => @$data['feedback'], 'hasPassed' => @$hasPassed, 'hasPassedFull' => @$hasPassedFull, 'minimumToPass' => @$minimumToPass, 'authentication_type' => @$authenticationType, 'isMaterialPage' => false, 'authFailed' => !Auth::check() && !$authvalidator->passes(), 'old' => $request->all()]))->withInput($request)->withErrors(@$errors);
 }
Пример #13
0
 /**
  * Return all errros
  *
  * @return array
  */
 public function all()
 {
     return $this->error->all();
 }