Last active
May 22, 2020 10:23
-
-
Save voltel/94568fc39964cbbb287d2d9e7039fc89 to your computer and use it in GitHub Desktop.
Files supporting question on Slack
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entity\Work\Phrase; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="phrase_work_last_shot", uniqueConstraints={ | |
* @ORM\UniqueConstraint(columns={"phrase", "user"}) | |
* }) | |
*/ | |
class PhraseWorkLastShot | |
{ | |
/** | |
* @ORM\Id | |
* @ORM\GeneratedValue(strategy="AUTO") | |
* @ORM\Column(type="integer") | |
*/ | |
private $id; | |
/** | |
* @ORM\Column(type="string") | |
*/ | |
private $phrase; | |
/** | |
* @ORM\Column(type="string") | |
*/ | |
private $user; | |
/** | |
* @var PhraseWorkShot|null | |
* @ORM\Embedded(class="App\Entity\Work\PhraseWorkShot", columnPrefix=false) | |
*/ | |
private $details; | |
/** | |
* @var PhraseWorkShotLog|null | |
* @ORM\OneToOne(targetEntity="App\Entity\Work\PhraseWorkShotLog", mappedBy="lastShot") | |
*/ | |
private $shotLog; | |
/** | |
* @ORM\Column(type="string") | |
*/ | |
private $repCount; | |
/** | |
* PhraseWorkLastShot constructor. | |
*/ | |
public function __construct() | |
{ | |
$this->details = new PhraseWorkShot(); | |
} | |
public static function createInstance( | |
string $translationProblem = null, | |
string $grammarViolation = null, | |
string $deliveryProblem = null | |
) : self | |
{ | |
$oInstance = new self; | |
$oInstance->details->setTranslationProblem($translationProblem); | |
$oInstance->details->setGrammarViolation($grammarViolation); | |
$oInstance->details->setDeliveryProblem($deliveryProblem); | |
$oLogInstane = PhraseWorkShotLog::createInstance($oInstance); | |
$oInstance->setShotLog($oLogInstane); | |
return $oInstance; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getId() | |
{ | |
return $this->id; | |
} | |
/** | |
* @return PhraseWorkShot|null | |
*/ | |
public function getDetails(): ?PhraseWorkShot | |
{ | |
return $this->details; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getPhrase() | |
{ | |
return $this->phrase; | |
} | |
/** | |
* @param mixed $phrase | |
*/ | |
public function setPhrase($phrase): void | |
{ | |
$this->phrase = $phrase; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getUser() | |
{ | |
return $this->user; | |
} | |
/** | |
* @param mixed $user | |
*/ | |
public function setUser($user): void | |
{ | |
$this->user = $user; | |
} | |
/** | |
* @return PhraseWorkShotLog|null | |
*/ | |
public function getShotLog(): ?PhraseWorkShotLog | |
{ | |
return $this->shotLog; | |
} | |
/** | |
* @param PhraseWorkShotLog|null $shotLog | |
*/ | |
public function setShotLog(?PhraseWorkShotLog $shotLog): void | |
{ | |
$this->shotLog = $shotLog; | |
} | |
/** | |
* @return mixed | |
*/ | |
public function getRepCount() | |
{ | |
return $this->repCount; | |
} | |
/** | |
* @param mixed $repCount | |
*/ | |
public function setRepCount($repCount): void | |
{ | |
$this->repCount = $repCount; | |
} | |
}//end of class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entity\Work\Phrase; | |
use Doctrine\ORM\Mapping as ORM; | |
use Symfony\Component\Validator\Constraints as Assert; | |
use Greg0ire\Enum\Bridge\Symfony\Validator\Constraint\Enum as AssertEnum; | |
/** | |
* Note: This class in embedded into an ORM\Entity | |
* and is used for Serialization | |
* | |
* @ORM\Embeddable() | |
*/ | |
class PhraseWorkShot implements \JsonSerializable | |
{ | |
// see "PhraseProgressTranslationProblemEnum" | |
const TRANSLATION_PROBLEM_ABSENT = 'absent'; // the problem is absent | |
const TRANSLATION_PROBLEM_DEVIATION_SINGLE = 'devn'; | |
const TRANSLATION_PROBLEM_DEVIATION_SEVERAL = 'devs'; | |
const TRANSLATION_PROBLEM_GAP_SINGLE = 'gap'; | |
const TRANSLATION_PROBLEM_GAP_SEVERAL = 'gaps'; | |
const GRAMMAR_VIOLATION_ABSENT = 'absent'; | |
const GRAMMAR_VIOLATION_MINOR_SINGLE = 'minor'; | |
const GRAMMAR_VIOLATION_MINOR_SEVERAL = 'minors'; | |
const GRAMMAR_VIOLATION_MAJOR_SINGLE = 'major'; | |
const GRAMMAR_VIOLATION_MAJOR_SEVERAL = 'majors'; | |
// Read at: https://en.wikipedia.org/wiki/Prosody_(linguistics) | |
const DELIVERY_PROBLEM_ABSENT = 'absent'; | |
const DELIVERY_PROBLEM_MINOR_SINGLE = 'minor'; | |
const DELIVERY_PROBLEM_MINOR_SEVERAL = 'minors'; | |
const DELIVERY_PROBLEM_MAJOR_SINGLE = 'major'; | |
const DELIVERY_PROBLEM_MAJOR_SEVERAL = 'majors'; | |
/** | |
* @Assert\NotNull() | |
* @var \DateTimeImmutable | |
* @ORM\Column(type="datetime_immutable") | |
*/ | |
private $workDate; | |
/** | |
* @AssertEnum(class="App\Entity\Work\PhraseProgressTranslationProblemEnum") | |
* @var string|null | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $translationProblem; | |
/** | |
* @AssertEnum(class="App\Entity\Work\PhraseProgressGrammarViolationEnum") | |
* @var string|null | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $grammarViolation; | |
/** | |
* @AssertEnum(class="App\Entity\Work\PhraseProgressDeliveryProblemEnum") | |
* @var string|null | |
* @ORM\Column(type="string", nullable=true) | |
*/ | |
private $deliveryProblem; | |
public function __construct( | |
string $translationProblem = null, | |
string $grammarViolation = null, | |
string $deliveryProblem = null | |
) | |
{ | |
$this->translationProblem = $translationProblem; | |
$this->grammarViolation = $grammarViolation; | |
$this->deliveryProblem = $deliveryProblem; | |
$this->workDate = new \DateTimeImmutable('now'); | |
}//end of function | |
/** | |
* @return \DateTimeImmutable | |
*/ | |
public function getWorkDate(): \DateTimeInterface | |
{ | |
return $this->workDate; | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getTranslationProblem(): ?string | |
{ | |
return $this->translationProblem; | |
} | |
/** | |
* @param string|null $translationProblem | |
*/ | |
public function setTranslationProblem(?string $translationProblem): void | |
{ | |
PhraseWorkTranslationProblemEnum::assertValidValue($translationProblem); | |
$this->translationProblem = $translationProblem; | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getGrammarViolation(): ?string | |
{ | |
return $this->grammarViolation; | |
} | |
/** | |
* @param string|null $grammarViolation | |
*/ | |
public function setGrammarViolation(?string $grammarViolation): void | |
{ | |
PhraseWorkGrammarViolationEnum::assertValidValue($grammarViolation); | |
$this->grammarViolation = $grammarViolation; | |
} | |
/** | |
* @return string|null | |
*/ | |
public function getDeliveryProblem(): ?string | |
{ | |
return $this->deliveryProblem; | |
} | |
/** | |
* @param string|null $deliveryProblem | |
*/ | |
public function setDeliveryProblem(?string $deliveryProblem): void | |
{ | |
PhraseWorkDeliveryProblemEnum::assertValidValue($deliveryProblem); | |
$this->deliveryProblem = $deliveryProblem; | |
}//end of function | |
/** | |
* Implements \JsonSerializable | |
*/ | |
public function jsonSerialize() | |
{ | |
return [ | |
'workDate' => $this->workDate, | |
'translationProblem' => $this->translationProblem, | |
'grammarViolation' => $this->grammarViolation, | |
'deliveryProblem' => $this->deliveryProblem, | |
]; | |
}//end of function | |
}//end of class |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Entity\Work\Phrase; | |
use Doctrine\ORM\Mapping as ORM; | |
/** | |
* @ORM\Entity | |
* @ORM\Table(name="phrase_work_shot_log") | |
*/ | |
class PhraseWorkShotLog | |
{ | |
/** | |
* Read at: https://www.doctrine-project.org/projects/doctrine-orm/en/latest/tutorials/composite-primary-keys.html#use-case-2-simple-derived-identity | |
* @var PhraseWorkLastShot | |
* @ORM\Id | |
* @ORM\OneToOne(targetEntity="App\Entity\Work\PhraseWorkLastShot", inversedBy="shotLog") | |
*/ | |
private $lastShot; | |
/** | |
* @var integer | |
* @ORM\Column(type="integer") | |
*/ | |
private $repCount = 0; | |
/** | |
* Note: Please, help me decide on the proper value to store my logs and the way to access them | |
* I want it to be an array of PhraseWorkShot objects. | |
* | |
* It would be "cool" to have deserializer to recreate objects. | |
* Will Symfony's "ArrayDenormalizer? be run automatically, or should I denormalize the array every time I need access to the objects. | |
* | |
* What about type="json" or type="array" ? | |
* Should nested objects of class "PhraseWorkShot" implement "JsonSerializable" interface? | |
* | |
* @var PhraseWorkShot[]|null | |
* @ORM\Column(type="array") | |
*/ | |
private $shotLog = []; | |
/** | |
* PhraseWorkShotLog constructor. | |
*/ | |
public function __construct() | |
{ | |
} | |
public static function createInstance( | |
PhraseWorkLastShot $oLastShot | |
) : self | |
{ | |
$oInstance = new self; | |
$oInstance->setLastShot($oLastShot); | |
return $oInstance; | |
}//end of function | |
public function addElementToShotLog(PhraseWorkShot $oShotDetails) : void | |
{ | |
$this->shotLog[] = $oShotDetails; | |
} | |
/** | |
* @return PhraseWorkLastShot | |
*/ | |
public function getLastShot(): PhraseWorkLastShot | |
{ | |
return $this->lastShot; | |
} | |
/** | |
* @param PhraseWorkLastShot $lastShot | |
*/ | |
public function setLastShot(PhraseWorkLastShot $lastShot): void | |
{ | |
$this->lastShot = $lastShot; | |
} | |
/** | |
* @return int | |
*/ | |
public function getRepCount(): int | |
{ | |
return $this->repCount; | |
} | |
/** | |
* @param int $repCount | |
*/ | |
public function setRepCount(int $repCount): void | |
{ | |
$this->repCount = $repCount; | |
} | |
/** | |
* @return array|null | |
*/ | |
public function getShotLog(): ?array | |
{ | |
return $this->shotLog; | |
} | |
/** | |
* @param array|null $shotLog | |
*/ | |
public function setShotLog(?array $shotLog): void | |
{ | |
$this->shotLog = $shotLog; | |
} | |
}//end of class |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment