Skip to content

Commit

Permalink
add docblocs, add behat tests to travis, smaller fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
ahilles107 committed Dec 3, 2014
1 parent a2f9b61 commit 6a838ff
Show file tree
Hide file tree
Showing 11 changed files with 88 additions and 17 deletions.
3 changes: 1 addition & 2 deletions newscoop/application/controllers/ErrorController.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ public function errorAction()
}

$errors = $this->_getParam('error_handler');
$request = $this->getRequest();

if (!$errors) {
$this->view->message = $translator->trans('You have reached the error page', array(), 'bug_reporting');
Expand Down Expand Up @@ -90,7 +89,7 @@ public function errorAction()
if ($this->getInvokeArg('displayExceptions') == true) {
$this->view->exception = $errors->exception;
}

$this->view->request = $errors->request;
$this->view->errors = $errors;
}
Expand Down
2 changes: 1 addition & 1 deletion newscoop/application/controllers/ImageController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public function cacheAction()
$this->getResponse()->setHeader('Expires', gmdate(self::DATE_FORMAT, date_create('+30 days')->getTimestamp()), true);

try {
$image = $this->_helper->service('image')->generateFromSrc($this->_getParam('src'));
$this->_helper->service('image')->generateFromSrc($this->_getParam('src'));
$this->getResponse()->setHeader('Content-Type', $this->getContentType($this->getPath()), true);
$this->getResponse()->sendHeaders();
$this->getResponse()->setBody(file_get_contents($this->getPath()));
Expand Down
12 changes: 6 additions & 6 deletions newscoop/application/controllers/RegisterController.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public function init()
}

public function indexAction()
{
{
$translator = \Zend_Registry::get('container')->getService('translator');
$form = new Application_Form_Register();
$form->setMethod('POST');
Expand Down Expand Up @@ -55,21 +55,21 @@ public function indexAction()

$this->view->form = $form;
}

public function createUserAction()
{
$parameters = $this->getRequest()->getParams();

$user = $this->_helper->service('user')->findBy(array(
'email' => $parameters['email'],
));

if ($user) {
echo '0';
exit;
} else {
$user = $this->_helper->service('user')->createPending($parameters['email'], $parameters['first_name'], $parameters['last_name'], $parameters['subscriber_id']);

$this->_helper->service('email')->sendConfirmationToken($user);
echo '1';
exit;
Expand Down Expand Up @@ -124,7 +124,7 @@ public function confirmAction()
} else {
$adapter = $this->_helper->service('auth.adapter');
$adapter->setEmail($user->getEmail())->setPassword($values['password']);
$result = $auth->authenticate($adapter);
$auth->authenticate($adapter);
$token = $this->_helper->service('user')->loginUser($user, 'frontend_area');
$session->set('_security_frontend_area', serialize($token));
$OAuthtoken = $this->_helper->service('user')->loginUser($user, 'oauth_authorize');
Expand Down
8 changes: 4 additions & 4 deletions newscoop/library/Newscoop/Entity/Article.php
Original file line number Diff line number Diff line change
Expand Up @@ -841,9 +841,9 @@ public function getPublished()
/**
* Set published
*
* @param Datetime|null $published
* @param \Datetime|null $published
*
* @return string
* @return self
*/
public function setPublished($published)
{
Expand Down Expand Up @@ -1551,7 +1551,7 @@ public function getPublic()
/**
* Sets the value of public.
*
* @param string $public the public
* @param boolean $public the public
*
* @return self
*/
Expand Down Expand Up @@ -1667,7 +1667,7 @@ public function getIsIndexed()
/**
* Sets the value of isIndexed.
*
* @param string $isIndexed the is indexed
* @param boolean $isIndexed the is indexed
*
* @return self
*/
Expand Down
3 changes: 3 additions & 0 deletions newscoop/library/Newscoop/Entity/AuthorType.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ class AuthorType
*/
protected $authors;

/**
* @param string $type
*/
public function __construct($type = null)
{
$this->authors = new ArrayCollection();
Expand Down
26 changes: 26 additions & 0 deletions newscoop/library/Newscoop/Entity/Repository/ArticleRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,13 @@ public function getArticlesForSection($publication, $sectionNumber)
return $query;
}

/**
* Get number of articles assigned to Publication
*
* @param integer $publicationId
*
* @return \Doctrine\ORM\Query
*/
public function getArticlesCountForPublication($publicationId)
{
$articlesCount = $this->createQueryBuilder('a')
Expand Down Expand Up @@ -477,6 +484,15 @@ public function countByAuthor(User $user)
return (int) $count;
}

/**
* Get new minimal article order value
*
* @param integer $publication
* @param integer $issue
* @param integer $section
*
* @return \Doctrine\ORM\Query
*/
public function getMinArticleOrder($publication = null, $issue = null, $section = null)
{
$qb = $this->getEntityManager()->createQueryBuilder();
Expand All @@ -502,6 +518,16 @@ public function getMinArticleOrder($publication = null, $issue = null, $section
return $qb->getQuery();
}

/**
* Update article order
*
* @param integer $increment
* @param integer $publication
* @param integer $issue
* @param integer $section
*
* @return \Doctrine\ORM\Query
*/
public function updateArticleOrder($increment, $publication = null, $issue = null, $section = null)
{
$qb = $this->getEntityManager()->createQueryBuilder('a');
Expand Down
10 changes: 10 additions & 0 deletions newscoop/library/Newscoop/Entity/Repository/AutoIdRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@
class AutoIdRepository extends EntityRepository
{

/**
* Get next translations phrase Id.
*
* @return integer
*/
public function getNextTranslationPhraseId()
{
$em = $this->getEntityManager();
Expand All @@ -29,6 +34,11 @@ public function getNextTranslationPhraseId()
return $autoId->getTranslationPhraseId();
}

/**
* Get next article number
*
* @return integer
*/
public function getNextArticleNumber()
{
$em = $this->getEntityManager();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public function getLatestByPublication($publicationId, $maxResults = 1)
->getArrayResult();

if (count($issuesIds) == 0) {
return false;
return null;
}

$ids = array();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,10 @@ public function installDatabaseSchema($connection, $host = null, $publicationNam

$connection->executeQuery('INSERT IGNORE INTO Aliases VALUES (2,?,1)', array($host));
$connection->executeQuery('INSERT IGNORE INTO Publications (`Id`, `Name`, `IdDefaultLanguage`, `IdDefaultAlias`, `IdURLType`, `fk_forum_id`, `comments_enabled`, `comments_article_default_enabled`, `comments_subscribers_moderated`, `comments_public_moderated`, `comments_public_enabled`, `comments_captcha_enabled`, `comments_spam_blocking_enabled`, `comments_moderator_to`, `comments_moderator_from`, `url_error_tpl_id`, `seo`, `meta_title`, `meta_keywords`, `meta_description`) VALUES ("1", ?, "1", "2", "2", NULL, "1", "1", NULL, "0", NULL, NULL, "1", NULL, NULL, NULL, "a:1:{s:4:\"name\";s:2:\"on\";}", NULL, NULL, NULL)', array($publicationName));

// needed for tests - sample new article type
$connection->executeQuery("CREATE TABLE `Xnews` (`NrArticle` int(11) NOT NULL,`IdLanguage` int(11) NOT NULL,`Fhighlight` tinyint(1) NOT NULL DEFAULT '0',`Fdeck` mediumblob,`Ffull_text` mediumblob,PRIMARY KEY (`NrArticle`,`IdLanguage`)) ENGINE=InnoDB DEFAULT CHARSET=utf8;");
$connection->executeQuery("INSERT INTO `ArticleTypeMetadata` VALUES ('news','NULL',NULL,0,1,NULL,NULL,NULL,0,NULL),('news','lead',2,0,0,NULL,'longtext',NULL,0,NULL),('news','content',3,0,0,NULL,'body','editor_size=750',1,NULL);");
}

/**
Expand Down
33 changes: 32 additions & 1 deletion newscoop/library/Newscoop/Services/ArticleService.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

use Doctrine\ORM\EntityManager;
use Newscoop\Entity\Article;
use Newscoop\Entity\User;
use Symfony\Component\HttpFoundation\Request;

/**
Expand Down Expand Up @@ -75,6 +76,7 @@ public function getArticleMetadata()

/**
* Resolve article from provided data
*
* @param Request $request Request object
*
* @return Article $article Article entity object
Expand Down Expand Up @@ -123,6 +125,19 @@ public function articleResolver(Request $request)
}
}

/**
* Create new article
*
* @param string $articleType
* @param integer $language
* @param User $user
* @param integer $publication
* @param array $attributes
* @param integer $issue
* @param integer $section
*
* @return Article
*/
public function createArticle($articleType, $language, $user, $publication, $attributes = array(), $issue = null, $section = null)
{
$this->checkForArticleConflicts($attributes['name'], $publication, $issue, $section);
Expand All @@ -143,7 +158,7 @@ public function createArticle($articleType, $language, $user, $publication, $att


$increment = $minArticleOrder > 0 ? 1 : 2;
$result = $this->em->getRepository('Newscoop\Entity\Article')
$this->em->getRepository('Newscoop\Entity\Article')
->updateArticleOrder($increment, $publication, $issue, $section)
->getResult();

Expand Down Expand Up @@ -184,6 +199,14 @@ public function createArticle($articleType, $language, $user, $publication, $att
return $article;
}

/**
* Update article
*
* @param Article $article
* @param array $attributes
*
* @return Article
*/
public function updateArticle($article, $attributes)
{
$this->checkForArticleConflicts(
Expand All @@ -208,6 +231,14 @@ public function updateArticle($article, $attributes)
return $article;
}

/**
* Update Article static properties
*
* @param Article $article
* @param array $attributes
*
* @return Article
*/
private function updateArticleMeta($article, $attributes)
{
$article->setName($attributes['name']);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,6 @@ public function patchArticleAction(Request $request, $number, $language)
'number' => $article->getId(),
), true))
);

return $response;
} else {
// TODO add support for global for errors handler
}
Expand Down

0 comments on commit 6a838ff

Please sign in to comment.