Updating a lot of stuff
Took 1 hour 48 minutes
This commit is contained in:
@ -14,9 +14,12 @@ class website
|
||||
try {
|
||||
$website = file_get_contents( __DIR__ . '/website_score.html' );
|
||||
$website = $this->replaceDefaultThings( $website );
|
||||
|
||||
$website = $this->setScore( $website );
|
||||
return $website;
|
||||
} catch( Exception $e )
|
||||
{
|
||||
|
||||
throw new RuntimeException( 'Cannot load the score file', 201 );
|
||||
}
|
||||
}
|
||||
|
||||
@ -93,9 +96,9 @@ HTML;
|
||||
foreach( language::$lang_file['questions'] as $number => $question )
|
||||
{
|
||||
$questions .= <<<CHECKBOX
|
||||
<label>
|
||||
<label style="font-size: 1.15em;">
|
||||
<input name="question_$number" type="checkbox" class="filled-in" />
|
||||
<span>$question</span>
|
||||
<span class="black-text text-lighten-3">$question</span>
|
||||
</label><br>
|
||||
CHECKBOX;
|
||||
|
||||
@ -106,7 +109,7 @@ HTML;
|
||||
$submit = language::$lang_file[language::CALCULATE];
|
||||
$form_end = <<<HTML
|
||||
<br>
|
||||
<button class="btn waves-effect btn-large waves-light " type="submit" name="action">{$submit}
|
||||
<button class="btn waves-effect btn-large waves-light" type="submit" name="submit" value="checked">{$submit}
|
||||
<i class="material-icons right">send</i>
|
||||
</button>
|
||||
</form>
|
||||
@ -119,4 +122,55 @@ HTML;
|
||||
|
||||
return $website;
|
||||
}
|
||||
|
||||
private function calculateScore() : int
|
||||
{
|
||||
$score = count( language::$lang_file['questions'] );
|
||||
foreach( language::$lang_file['questions'] as $number => $question )
|
||||
{
|
||||
if( isset( $_POST["question_$number"] ) && $_POST["question_$number"] === 'checked' )
|
||||
{
|
||||
$score--;
|
||||
}
|
||||
}
|
||||
return $score;
|
||||
}
|
||||
|
||||
private function setScore ( string $a_website ): string
|
||||
{
|
||||
$score = $this->calculateScore();
|
||||
$html = <<<HTML
|
||||
<div class="row">
|
||||
<div class="col s12">
|
||||
<div class="card blue-grey darken-1">
|
||||
<div class="card-content white-text">
|
||||
<span class="card-title">[SCORE_TITLE]</span>
|
||||
<div class="row">
|
||||
<div class="col s5">
|
||||
<p>[SCORE_DESCRIPTION]</p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="col s2 l2">
|
||||
<span class="black-text" style="font-size: 8.5em;">52</span>
|
||||
</div>
|
||||
<div class="col s4"></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="card-action right-align">
|
||||
<a href="#">[SCORE_SHARE] <i class="material-icons" style="font-size: 1.2em;">share</i></a>
|
||||
<a href="#">[SCORE_SAVE] <i class="material-icons" style="font-size: 1.2em;">save</i></a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
HTML;
|
||||
|
||||
$html = str_replace( ['[SCORE_TITLE]', '[SCORE_DESCRIPTION]', '[SCORE_SHARE]', '[SCORE_SAVE]'], [language::$lang_file['SCORE_TITLE'], language::$lang_file['SCORE_DESCRIPTION'], language::$lang_file['SCORE_SHARE'], language::$lang_file['SCORE_SAVE']], $html );
|
||||
|
||||
$a_website = str_replace( '[CONTENT]', $html, $a_website );
|
||||
return $a_website;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user