diff --git a/Entity/Report.php b/Entity/Report.php index 117956cd1..728f65897 100644 --- a/Entity/Report.php +++ b/Entity/Report.php @@ -24,10 +24,14 @@ use Chill\CustomFieldsBundle\Entity\CustomFieldsGroup; namespace Chill\ReportBundle\Entity; +use Chill\MainBundle\Entity\HasCenterInterface; +use Chill\MainBundle\Entity\HasScopeInterface; +use Chill\MainBundle\Entity\Scope; + /** * Report */ -class Report +class Report implements HasCenterInterface, HasScopeInterface { /** * @var integer @@ -50,7 +54,7 @@ class Report private $date; /** - * @var string + * @var Scope */ private $scope; @@ -154,7 +158,7 @@ class Report * * @return Report */ - public function setScope($scope) + public function setScope(Scope $scope) { $this->scope = $scope; @@ -164,7 +168,7 @@ class Report /** * Get scope * - * @return string + * @return Scope */ public function getScope() { @@ -218,4 +222,10 @@ class Report { return $this->cFGroup; } + + public function getCenter() + { + return $this->person->getCenter(); + } + } \ No newline at end of file diff --git a/Resources/config/doctrine/Report.orm.yml b/Resources/config/doctrine/Report.orm.yml index d1dd10031..bf4b5c7de 100644 --- a/Resources/config/doctrine/Report.orm.yml +++ b/Resources/config/doctrine/Report.orm.yml @@ -10,10 +10,6 @@ Chill\ReportBundle\Entity\Report: fields: date: type: datetime - scope: - type: string - length: 255 - nullable: true # TO REMOVE IF SCOPE IS USED cFData: type: json_array manyToOne: @@ -21,6 +17,8 @@ Chill\ReportBundle\Entity\Report: targetEntity: Chill\MainBundle\Entity\User person: targetEntity: Chill\PersonBundle\Entity\Person + scope: + targetEntity: Chill\MainBundle\Entity\Scope cFGroup: targetEntity: Chill\CustomFieldsBundle\Entity\CustomFieldsGroup lifecycleCallbacks: { } \ No newline at end of file diff --git a/Resources/migrations/Version20150622233319.php b/Resources/migrations/Version20150622233319.php new file mode 100644 index 000000000..3ef33fbef --- /dev/null +++ b/Resources/migrations/Version20150622233319.php @@ -0,0 +1,42 @@ +abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', + 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE report ADD scope_id INT DEFAULT NULL'); + $this->addSql('ALTER TABLE report DROP scope'); //before this migration, scope was never used + $this->addSql('ALTER TABLE report ADD CONSTRAINT FK_report_scope ' + . 'FOREIGN KEY (scope_id) ' + . 'REFERENCES scopes (id) NOT DEFERRABLE INITIALLY IMMEDIATE'); + $this->addSql('CREATE INDEX IDX_report_scope ON report (scope_id)'); + } + + /** + * @param Schema $schema + */ + public function down(Schema $schema) + { + $this->abortIf($this->connection->getDatabasePlatform()->getName() != 'postgresql', + 'Migration can only be executed safely on \'postgresql\'.'); + + $this->addSql('ALTER TABLE Report DROP CONSTRAINT FK_C38372B2682B5931'); + $this->addSql('DROP INDEX IDX_C38372B2682B5931'); + $this->addSql('ALTER TABLE Report ADD scope VARCHAR(255) DEFAULT NULL'); + $this->addSql('ALTER TABLE Report DROP scope_id'); + } +}