Skip to content

Commit

Permalink
CS-5844: Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
m038 committed Sep 8, 2015
1 parent 8e7270c commit 3d29357
Show file tree
Hide file tree
Showing 13 changed files with 494 additions and 23 deletions.
14 changes: 14 additions & 0 deletions newscoop/install/Resources/sql/campsite_core.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2559,6 +2559,20 @@ INSERT INTO `output` VALUES (1,'Web');
/*!40000 ALTER TABLE `output` ENABLE KEYS */;
UNLOCK TABLES;

--
-- Table structure for table output_publication
--

DROP TABLE IF EXISTS `output_publication`;
CREATE TABLE `output_publication` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fk_publication_id` int(11) unsigned NOT NULL,
`fk_language_id` int(11) unsigned NOT NULL,
`theme_path` varchar(255) NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `publication_language` (`fk_publication_id`,`fk_language_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;

--
-- Table structure for table `output_issue`
--
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
INSERT INTO output_publication (fk_output_id, fk_publication_id, fk_language_id, fk_theme_path_id) SELECT DISTINCT 1, IdPublication, IdLanguage, NULL FROM Issues;
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `output_publication` (
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
`fk_output_id` int(11) unsigned NOT NULL,
`fk_publication_id` int(11) unsigned NOT NULL,
`fk_language_id` int(11) unsigned NOT NULL,
`fk_theme_path_id` int(11) unsigned DEFAULT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `publication_language` (`fk_publication_id`,`fk_language_id`)
) ENGINE=MyISAM DEFAULT CHARSET=utf8;
154 changes: 154 additions & 0 deletions newscoop/library/Newscoop/Entity/Output/OutputSettingsPublication.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
<?php
/**
* @package Newscoop
* @author Mischa Gorinskat <mischa.gorinskat@sourcefabric.org>
* @copyright 2015 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/

namespace Newscoop\Entity\Output;

use Doctrine\ORM\Mapping AS ORM;
use Newscoop\Entity\AbstractEntity;

/**
* Provides the settings for the output for a publication.
*
* @ORM\Entity
* @ORM\Table(name="output_publication", uniqueConstraints={@ORM\UniqueConstraint(name="publication_language", columns={"fk_publication_id", "fk_langyage_id"})})
*/
class OutputSettingsPublication extends AbstractEntity
{
/**
* Provides the class name as a constant.
*/
const NAME_1 = __CLASS__;

/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Output")
* @ORM\JoinColumn(name="fk_output_id", referencedColumnName="id", nullable=FALSE)
* @var Newscoop\Entity\Output
*/
protected $output;

/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Publication", inversedBy="outputSettingsPublication")
* @ORM\JoinColumn(name="fk_publication_id", referencedColumnName="Id")
* @var Newscoop\Entity\Publication
*/
protected $publication;

/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Language")
* @ORM\JoinColumn(name="fk_language_id", referencedColumnName="Id")
* @var Newscoop\Entity\Language
*/
protected $language;


/**
* @ORM\ManyToOne(targetEntity="Newscoop\Entity\Resource")
* @ORM\JoinColumn(name="fk_theme_path_id", referencedColumnName="id")
* @var Newscoop\Entity\Resource
*/
protected $themePath;

/**
* Getter for output
*
* @return mixed
*/
public function getOutput()
{
return $this->output;
}

/**
* Setter for output
*
* @param mixed $output Value to set
*
* @return self
*/
public function setOutput($output)
{
$this->output = $output;

return $this;
}

/**
* Getter for publication
*
* @return \Newscoop\Entity\Publication
*/
public function getPublication()
{
return $this->publication;
}

/**
* Setter for publication
*
* @param \Newscoop\Entity\Publication $publication Value to set
*
* @return self
*/
public function setPublication($publication)
{
$this->publication = $publication;

return $this;
}

/**
* Getter for language
*
* @return \Newscoop\Entity\Language
*/
public function getLanguage()
{
return $this->language;
}

/**
* Setter for language
*
* @param \Newscoop\Entity\Language $language Value to set
*
* @return self
*/
public function setLanguage($language)
{
$this->language = $language;

return $this;
}

/**
* Provides the path of the theme associated.
*
* @return Newscoop\Entity\Resource|null
* The path of the theme.
*/
public function getThemePath()
{
return $this->themePath;
}

/**
* Set the path of the theme associated.
*
* @param Newscoop\Entity\Resource|null $themePath
* The path of the theme, can be empty.
*
* @return Newscoop\Entity\PublicationTheme
* This object for chaining purposes.
*/
public function setThemePath($themePath)
{
$this->themePath = $themePath;

return $this;
}
}
46 changes: 46 additions & 0 deletions newscoop/library/Newscoop/Entity/Publication.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,18 @@ class Publication
*/
protected $metaDescription;

/**
* @ORM\OneToMany(targetEntity="Newscoop\Entity\Output\OutputSettingsPublication", mappedBy="publication")
* @var Doctrine\Common\Collections\ArrayCollection
*/
protected $outputSettingsPublication;

/**
*/
public function __construct()
{
$this->issues = new ArrayCollection();
$this->outputSettingsPublication = new ArrayCollection();
}

/**
Expand Down Expand Up @@ -595,6 +602,45 @@ public function setMetaDescription($metaDescription)
return $this;
}

/**
* Getter for outputSettingsPublication
*
* @return mixed
*/
public function getOutputSettingsPublication()
{
return $this->outputSettingsPublication;
}

/**
* Setter for outputSettingsPublication
*
* @return self
*/
public function setOutputSettingsPublication($outputSettingsPublication)
{
$this->outputSettingsPublication = $outputSettingsPublication;

return $this;
}

/**
* Setter for outputSettingsPublication
*
* @param Newscoop\Entity\OutputSettingsPublication $outputSettingsPublication
*
* @return self
*/
public function addOutputSettingsPublication($outputSettingsPublication)
{
if (!$this->outputSettingsPublication->contains($outputSettingsPublication)) {
$this->outputSettingsPublication->add($outputSettingsPublication);
}

return $this;
}


/**
* Gets the value of commentsArticleDefaultEnabled.
*
Expand Down
18 changes: 12 additions & 6 deletions newscoop/library/Newscoop/Services/IssueService.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,19 +137,21 @@ public function issueResolver(Request $request)
}

// TODO: Check if we should add locale from request here
return $this->getLatestPublishedIssue();
return $this->getLatestPublishedIssue($request->getLocale());
}

/**
* {@inheritDoc}
*/
public function getLatestPublishedIssue($language = null)
public function getLatestPublishedIssue($languageCode = null)
{
$publication = $this->publicationService->getPublication();
if (!$publication) {
return;
}

$language = $this->em->getRepository('Newscoop\Entity\Language')
->findOneByCode($languageCode);
if (!($language instanceof \Newscoop\Entity\Language)) {
$language = $publication->getDefaultLanguage();
}
Expand All @@ -165,10 +167,14 @@ public function getLatestPublishedIssue($language = null)
if ($this->cacheService->contains($cacheKey)) {
$issue = $this->cacheService->fetch($cacheKey);
} else {
$issue = $this->em
->getRepository('Newscoop\Entity\Issue')
->getLastPublishedByPublicationAndLanguage($publicationId, $languageId)
->getSingleResult();
try {
$issue = $this->em
->getRepository('Newscoop\Entity\Issue')
->getLastPublishedByPublicationAndLanguage($publicationId, $languageId)
->getSingleResult();
} catch(\Doctrine\ORM\NoResultException $e) {
throw new \Newscoop\NewscoopException("There is no published issue for this language.");
}

$this->cacheService->save($cacheKey, $issue);
}
Expand Down
Loading

0 comments on commit 3d29357

Please sign in to comment.