Skip to content
This repository has been archived by the owner on Jan 2, 2024. It is now read-only.

Commit

Permalink
PHP 7 update
Browse files Browse the repository at this point in the history
  • Loading branch information
jan-martinek committed Sep 20, 2018
1 parent bce1160 commit 1918baf
Show file tree
Hide file tree
Showing 38 changed files with 1,272 additions and 574 deletions.
12 changes: 8 additions & 4 deletions app/components/HomeworkForm.php
Expand Up @@ -9,6 +9,9 @@
use Model\Entity\Solution;
use DateTime;

/**
* @property string $questionIdentifier
*/
class AssignmentForm extends Form
{
private $presenter;
Expand Down Expand Up @@ -38,6 +41,7 @@ public function __construct($presenter, $questions)
$maxKb = $course->uploadMaxFilesizeKb;
$input = $questionsContainer
->addUpload($id, $label)
->setRequired(false)
->addRule(
Form::MAX_FILE_SIZE,
$translator->translate(
Expand Down Expand Up @@ -113,14 +117,14 @@ public function formSucceeded(AssignmentForm $form, $values)

if ($this->presenter->isAjax()) {
$this->presenter->flashMessage($this->presenter->translator->translate('messages.solution.saved'));
$this->presenter->invalidateControl('flashMessages');
$this->presenter->invalidateControl('formInfo');
$this->presenter->redrawControl('flashMessages');
$this->presenter->redrawControl('formInfo');
foreach ($form['questions']->getControls() as $q) {
if ($q instanceof \Nette\Forms\Controls\UploadControl) {
$this->presenter['questionsRenderer']->invalidateControl('question-' . $q->name);
$this->presenter['questionsRenderer']->redrawControl('question-' . $q->name);
}
}
$this->presenter['questionsRenderer']->invalidateControl('assignmentQuestions');
$this->presenter['questionsRenderer']->redrawControl('assignmentQuestions');
} else {
$this->presenter->redirect('this');
}
Expand Down
2 changes: 1 addition & 1 deletion app/components/PhasesControl/phases.latte
Expand Up @@ -4,7 +4,7 @@
{continueIf $phaseName == 'draft'}
{var $dateAttrName = $phaseName ? $phaseName . '_since' : NULL}
{var $nextPhaseDateAttrName = $unit->nextPhaseName ? $unit->nextPhaseName . '_since' : NULL}
{var isCurrent = $phaseName === $unit->currentPhaseName}
{var isCurrent = $phaseName === $unit->getCurrentPhaseName()}
<span class="label time">
{$unit->$dateAttrName|date: "%a %e %h"}<br>
{$unit->$dateAttrName|date: "%k.%M"}
Expand Down
48 changes: 24 additions & 24 deletions app/components/QuestionsControl/templates/questions.latte
Expand Up @@ -24,7 +24,7 @@
{/if}
</p>

{!$question->text|md}
{$question->text|md|noescape}

</div></div>

Expand Down Expand Up @@ -83,7 +83,7 @@
{else}
{if isset($question->entity->answer->comments)}
<b>{_messages.solution.comments}:</b>
{!=nl2br(htmlspecialchars($question->entity->answer->comments))}
{=nl2br(htmlspecialchars($question->entity->answer->comments))|noescape}
{else}
<b>{_messages.solution.noComment}</b>
{/if}
Expand All @@ -98,18 +98,18 @@
<div class="row"><div class="columns">

{if $review}
{var answers = $review->assessmentSet}
{? if ($answers && $reviewForm) $reviewForm['rubrics']->setValues($answers)}
{var answers = $review->getAssessmentSet()}
{php if ($answers && $reviewForm) $reviewForm['rubrics']->setValues($answers)}
{/if}

{foreach $question->rubrics as $rubric}
{if $reviewForm}
{include rubric, name => $rubricPos, rubric => $reviewForm['rubrics'][$rubricPos]}
{? $control->renderedRubrics[] = $rubricPos}
{? $rubricPos++}
{php $control->renderedRubrics[] = $rubricPos}
{php $rubricPos++}
{else}
{include rubricPreview, rubric => $rubric, answer => isset($answers) ? $answers[$rubricPos] : null}
{? $rubricPos++}
{php $rubricPos++}
{/if}
{/foreach}
</div></div>
Expand All @@ -119,7 +119,7 @@
{define rubric}
<div class="rubric {=get_class($rubric)|webalize}">
{if $rubric instanceof \Model\Ontology\DefaultRubric && !is_null($review->score)}
{? $rubric->setValue($review->score)}
{php $rubric->setValue($review->score)}
{/if}

<div class="description">
Expand All @@ -129,7 +129,7 @@
{if $rubric instanceof \Nette\Forms\Controls\TextArea}
{input $rubric, 'rows' => '5'}
{else}
{?$rubric->getSeparatorPrototype()->setName(NULL)}
{php $rubric->getSeparatorPrototype()->setName(NULL)}
{input $rubric}
{/if}

Expand All @@ -142,39 +142,39 @@
{if $rubric instanceof \Model\Ontology\DefaultRubric}
<ol start="0">
{var scale = array(0, 1, 2, 3);}
<li n:foreach="$scale as $i" n:class="$answer === $i ? selected">{!$i|stars} {_messages.review.score.$i}</li>
<li n:foreach="$scale as $i" n:class="$answer === $i ? selected">{$i|stars|noescape} {_messages.review.score.$i}</li>
</ol>
{elseif $rubric instanceof \Model\Ontology\Rubric}
<div class="description">
<p>{!$rubric->metric|imd}</p>
<p>{$rubric->metric|imd|noescape}</p>
</div>
<ol start="0">
<li n:foreach="$rubric->scale as $score => $description" n:class="$answer === $score ? selected">{!$score|stars} {!$description|imd}</li>
<li n:foreach="$rubric->scale as $score => $description" n:class="$answer === $score ? selected">{$score|stars|noescape} {$description|imd|noescape}</li>
</ol>
{elseif $rubric instanceof \Model\Ontology\Checklist}
<div class="description">
{!$rubric->description|md}
{$rubric->description|md|noescape}
</div>
<label n:foreach="$rubric->items as $order => $item">
{? $rubric->setRaw($answer)}
{php $rubric->setRaw($answer)}
{var $raw = $rubric->getRaw()}
<input type="checkbox" {if in_array($order, $raw)}checked{/if} disabled> {!$item->metric|imd}
<input type="checkbox" {if in_array($order, $raw)}checked{/if} disabled> {$item->metric|imd|noescape}
<span class="label secondary weight" title="{_messages.review.checklist.weight}"><i class="fa fa-pie-chart" aria-hidden="true"></i> <b>{$item->weight}</b></span>
</label>
{var $score = $rubric->calcScore()}
<p n:ifset="$score"><b>{_messages.review.checklist.weightedSum}: {!$score|stars} {!$score}</b></p>
<p n:ifset="$score"><b>{_messages.review.checklist.weightedSum}: {$score|stars|noescape} {$score|noescape}</b></p>
{elseif $rubric instanceof \Model\Ontology\Comment}
<div class="description">
{!$rubric->instructions|md}
{$rubric->instructions|md|noescape}
</div>
<div class="panel">{if $answer}{!=nl2br(htmlspecialchars($answer))}{else}{_messages.review.verbalAssessment}.{/if}</div>
<div class="panel">{if $answer}{=nl2br(htmlspecialchars($answer))|noescape}{else}{_messages.review.verbalAssessment}.{/if}</div>
{/if}
</div>
{/define}

{define reading}
<div n:if="!$review" class="row content"><div class="columns">
{!$item->text|md}
{$item->text|md|noescape}
</div></div>
{/define}

Expand All @@ -199,8 +199,8 @@
{else}
{include question}
{/if}
{? $rubricPos += count($question->rubrics)}
{? $qNumber += 1}
{php $rubricPos += count($question->rubrics)}
{php $qNumber += 1}
{elseif $item instanceof Model\Ontology\Reading}
{include reading}
{/if}
Expand All @@ -211,16 +211,16 @@
<div class="row"><div class="columns">
{if $reviewForm}
{if $review}
{var answers = $review->assessmentSet}
{? if ($answers && $reviewForm) $reviewForm['rubrics']->setValues($answers)}
{var answers = $review->getAssessmentSet()}
{php if ($answers && $reviewForm) $reviewForm['rubrics']->setValues($answers)}
{/if}

<div n:foreach="$reviewForm['rubrics']->controls as $name => $rubric" n:if="!in_array($name, $control->renderedRubrics)">
{include rubric, rubric => $rubric}
</div>
{else}
{if $review}
{var answers = $review->assessmentSet}
{var answers = $review->getAssessmentSet()}
{var answerOffset = count($assignment->getAllRubrics()) - count($assignment->rubrics)}
{/if}

Expand Down
4 changes: 2 additions & 2 deletions app/components/ReviewsControl/reviews.latte
@@ -1,7 +1,7 @@
{block content}
{if !count($reviews)}
<div class="panel">
{!_messages.unit.noReviewsFound|md}
{_messages.unit.noReviewsFound|md|noescape}
</div>
{else}
<ul class="no-bullet">
Expand All @@ -20,7 +20,7 @@
<span style="color: #f90; font-weight: bold">
{if !is_null($review->score)}
{var score = round($review->score)}
{!$score|stars}
{$score|stars|noescape}
{else}
&mdash;
{/if}
Expand Down
4 changes: 3 additions & 1 deletion app/forms/SignFormFactory.php
Expand Up @@ -6,8 +6,10 @@
use Nette\Application\UI\Form;
use Nette\Security\User;

class SignFormFactory extends Nette\Object
class SignFormFactory
{
use Nette\SmartObject;

/** @var User */
private $user;

Expand Down
4 changes: 3 additions & 1 deletion app/model/CourseRegistry.php
Expand Up @@ -9,8 +9,10 @@
use Model\Entity\Review;
use Model\Entity\ReviewComment;

class CourseRegistry extends \Nette\Object
class CourseRegistry
{
use \Nette\SmartObject;


/** @var Course */
public $course;
Expand Down
4 changes: 3 additions & 1 deletion app/model/Mailer.php
Expand Up @@ -6,8 +6,10 @@
use PHPMailer;
use Nette\Utils\Html;

class Mailer extends \Nette\Object
class Mailer
{
use \Nette\SmartObject;

public function sendPasswordResetEmail($presenter, $email, $token)
{
$mail = new PHPMailer();
Expand Down
4 changes: 3 additions & 1 deletion app/model/Ontology/AbstractDefinition.php
Expand Up @@ -2,8 +2,10 @@

namespace Model\Ontology;

abstract class AbstractDefinition extends \Nette\Object implements IDefinition
abstract class AbstractDefinition implements IDefinition
{
use \Nette\SmartObject;

/** @var CourseFactory */
private $factory;

Expand Down
4 changes: 3 additions & 1 deletion app/model/Ontology/AssignmentDefinition.php
Expand Up @@ -8,8 +8,10 @@
use Model\Ontology\Reading;
use DateTime;

class AssignmentDefinition extends \Nette\Object implements IDefinition, \Countable
class AssignmentDefinition implements IDefinition, \Countable
{
use \Nette\SmartObject;

/** @var CourseFactory */
private $factory;

Expand Down
6 changes: 3 additions & 3 deletions app/model/Ontology/CourseDefinition.php
Expand Up @@ -2,10 +2,10 @@

namespace Model\Ontology;

use Symfony\Component\Yaml\Parser;

class CourseDefinition extends \Nette\Object implements IDefinition
class CourseDefinition implements IDefinition
{
use \Nette\SmartObject;

/** @var CourseFactory */
private $factory;

Expand Down
8 changes: 5 additions & 3 deletions app/model/Ontology/CourseFactory.php
Expand Up @@ -2,7 +2,7 @@

namespace Model\Ontology;

use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;
use Model\Repository\CourseRepository;
use Model\Repository\UnitRepository;
use Model\Repository\AssignmentRepository;
Expand All @@ -15,8 +15,10 @@
use Model\Ontology\CourseLoader;


class CourseFactory extends \Nette\Object
class CourseFactory
{
use \Nette\SmartObject;

/** @var Path to the directory where Course definitions are stored */
private $path;

Expand Down Expand Up @@ -50,7 +52,7 @@ public function __construct(
)
{
$this->path = $path;
$this->yaml = new Parser;
$this->yaml = new Yaml;

$this->courseRepository = $courseRepository;
$this->unitRepository = $unitRepository;
Expand Down
12 changes: 7 additions & 5 deletions app/model/Ontology/CourseLoader.php
Expand Up @@ -2,10 +2,12 @@

namespace Model\Ontology;

use Symfony\Component\Yaml\Parser;
use Symfony\Component\Yaml\Yaml;

class CourseLoader extends \Nette\Object
class CourseLoader
{
use \Nette\SmartObject;

/** @var Path to the directory where Course definition is stored */
private $path;

Expand All @@ -18,7 +20,7 @@ class CourseLoader extends \Nette\Object
public function __construct($courseName, $courseDirPath)
{
$this->path = $courseDirPath . '/' . $courseName;
$this->yaml = new Parser;
$this->yaml = new Yaml;
}

public function loadUnits($course)
Expand Down Expand Up @@ -80,7 +82,7 @@ private function loadReading($unitName, $filename)

public function loadYaml($name)
{
return $this->yaml->parse($this->loadFile($name));
return $this->yaml::parse($this->loadFile($name));
}

public function loadFile($name)
Expand Down Expand Up @@ -153,7 +155,7 @@ private function parseUnitResources($resources)
$yamlDocs = preg_split('/\n---\s*\n/', $source);
foreach ($yamlDocs as $i => $yamlDoc) {
if (trim($yamlDoc) != '') {
$unitData[] = $this->yaml->parse(trim($yamlDoc));
$unitData[] = $this->yaml::parse(trim($yamlDoc));
}
if ($i > 0) {
$unitData[count($unitData) - 1]['content'] = 'question';
Expand Down
4 changes: 3 additions & 1 deletion app/model/Ontology/Params.php
Expand Up @@ -2,8 +2,10 @@

namespace Model\Ontology;

class Params extends \Nette\Object implements \Countable
class Params implements \Countable
{
use \Nette\SmartObject;

/** @var Combinations @see enumerateCombinations() */
private $combinations;

Expand Down
11 changes: 9 additions & 2 deletions app/model/Ontology/Products.php
Expand Up @@ -3,11 +3,12 @@
namespace Model\Ontology;

use DateTime;
use Nette\Object;
use Model\Entity\Entity;

abstract class AbstractProduct extends Object
abstract class AbstractProduct
{
use \Nette\SmartObject;

public $id;
public $entity;

Expand All @@ -32,6 +33,12 @@ class CourseProduct extends AbstractProduct
public $gaCode;
}

/**
* @property int $currentPhase
* @property string $currentPhaseName
* @property array $phaseNames
* @property string $nextPhaseName
*/
class UnitProduct extends AbstractProduct
{
public $name;
Expand Down

0 comments on commit 1918baf

Please sign in to comment.