Skip to content

Commit

Permalink
Merge branch 'master' of github.com:sourcefabric/Newscoop into consol…
Browse files Browse the repository at this point in the history
…e_commands
  • Loading branch information
takeit committed Mar 25, 2014
2 parents 36e820d + 3548f09 commit 84da387
Show file tree
Hide file tree
Showing 8 changed files with 87 additions and 24 deletions.
4 changes: 2 additions & 2 deletions newscoop/include/smarty/campsite_plugins/function.render.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function smarty_function_render($p_params, &$p_smarty)
$campsiteVector = $smarty->campsiteVector;
foreach ($campsiteVector as $key => $value) {
if (isset($p_params[$key])) {
if (empty($p_params[$key]) || strtolower($p_params[$key]) == 'off') {
if (empty($p_params[$key]) || (is_string($p_params[$key]) && strtolower($p_params[$key]) == 'off')) {
$campsiteVector[$key] = null;
}
if (is_int($p_params[$key])) {
Expand Down Expand Up @@ -82,4 +82,4 @@ function smarty_function_render($p_params, &$p_smarty)
$smarty->campsiteVector = $campsiteVectorBak;
}

?>
?>
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ function smarty_modifier_translate($string, $domain = null, $params = array())
return '';
}

if (!is_null($domain)) {
if (is_null($domain)) {
$domain = 'theme_translation';
}

Expand Down
12 changes: 6 additions & 6 deletions newscoop/install/Resources/sql/campsite_core.sql
Original file line number Diff line number Diff line change
Expand Up @@ -2090,15 +2090,15 @@ CREATE TABLE comment (
fk_thread_id INT NOT NULL,
subject VARCHAR(140) NOT NULL,
message VARCHAR(255) NOT NULL,
thread_level VARCHAR(4) NOT NULL,
thread_order VARCHAR(4) NOT NULL,
status VARCHAR(2) NOT NULL,
thread_level INT NOT NULL,
thread_order INT NOT NULL,
status INT NOT NULL,
ip VARCHAR(39) NOT NULL,
time_created DATETIME NOT NULL,
time_updated DATETIME NOT NULL,
likes VARCHAR(4) NOT NULL,
dislikes VARCHAR(4) NOT NULL,
recommended VARCHAR(1) NOT NULL,
likes INT NOT NULL,
dislikes INT NOT NULL,
recommended INT NOT NULL,
indexed DATETIME DEFAULT NULL,
source VARCHAR(60) NULL DEFAULT NULL,
fk_comment_commenter_id INT DEFAULT NULL,
Expand Down
34 changes: 27 additions & 7 deletions newscoop/library/Newscoop/Entity/Comment.php
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,19 @@ class Comment implements DocumentInterface
protected $message;

/**
* @ORM\Column(length=4)
* @ORM\Column(type="integer", nullable=false)
* @var int
*/
protected $thread_level;

/**
* @ORM\Column(length=4)
* @ORM\Column(type="integer", nullable=false)
* @var int
*/
protected $thread_order;

/**
* @ORM\Column(length=2)
* @ORM\Column(type="integer", nullable=false)
* @var int
*/
protected $status;
Expand All @@ -164,19 +164,19 @@ class Comment implements DocumentInterface
protected $time_updated;

/**
* @ORM\Column(length=4)
* @ORM\Column(type="integer", nullable=false)
* @var int
*/
protected $likes = 0;

/**
* @ORM\Column(length=4)
* @ORM\Column(type="integer", nullable=false)
* @var int
*/
protected $dislikes = 0;

/**
* @ORM\Column(length=1)
* @ORM\Column(type="boolean")
* @var int
*/
protected $recommended = 0;
Expand Down Expand Up @@ -411,7 +411,7 @@ public function setRecommended($recommended)
*/
public function getRecommended()
{
return $this->recommended;
return (bool) $this->recommended;
}

/**
Expand All @@ -438,6 +438,16 @@ public function getCommenter()
return $this->commenter;
}

/**
* Get the commenter's name
*
* @return string
*/
public function getName()
{
return $this->getCommenterName();
}

/**
* Get commenter name
*
Expand All @@ -448,6 +458,16 @@ public function getCommenterName()
return $this->getCommenter()->getName();
}

/**
* Get the commenter's email
*
* @return string
*/
public function getEmail()
{
return $this->getCommenterEmail();
}

/**
* Get commenter email
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public function getArticle($number, $language = null)
->findOneById($language);
}

if ($languageObject instanceof Newscoop\Entity\Language) {
if ($languageObject instanceof \Newscoop\Entity\Language) {
$queryBuilder->andWhere('a.language = :languageId')
->setParameter('languageId', $languageObject->getId());
}
Expand Down
20 changes: 15 additions & 5 deletions newscoop/library/Newscoop/Entity/Repository/CommentRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -225,10 +225,19 @@ public function update(Comment $comment, $values)
{
// get the enitity manager
$em = $this->getEntityManager();
$comment
->setSubject($values['subject'])
->setMessage($values['message'])
->setTimeUpdated(new \DateTime());
if (array_key_exists('subject', $values) && !is_null($values['subject'])) {
$comment->setSubject($values['subject']);
}
if (array_key_exists('message', $values) && !is_null($values['message'])) {
$comment->setMessage($values['message']);
}
if (array_key_exists('recommended', $values) && !is_null($values['recommended'])) {
$comment->setRecommended($values['recommended']);
}
if (array_key_exists('status', $values) && !is_null($values['status'])) {
$comment->setStatus($values['status']);
}
$comment->setTimeUpdated(new \DateTime());

return $comment;
}
Expand Down Expand Up @@ -310,10 +319,11 @@ public function save(Comment $entity, $values)
$threadLevel = $parent->getThreadLevel() + 1;
} else {
$languageRepository = $em->getRepository('Newscoop\Entity\Language');
$language = $languageRepository->findOneByCode($values['language']);

if (is_numeric($values['language'])) {
$language = $languageRepository->findOneById($values['language']);
} else {
$language = $languageRepository->findOneByCode($values['language']);
}

$articleRepository = $em->getRepository('Newscoop\Entity\Article');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -276,16 +276,18 @@ private function processForm($request, $comment = null, $articleNumber = null, $
if (!$comment) {
$comment = new Comment();
$statusCode = 201;
$patch = false;
} else {
$statusCode = 200;
$comment = $em->getRepository('Newscoop\Entity\Comment')->findOneById($comment);

if (!$comment) {
throw new EntityNotFoundException('Result was not found.');
}
$patch = true;
}

$form = $this->createForm(new CommentType(), array());
$form = $this->createForm(new CommentType(array('patch'=>$patch)), array(), array('method'=>$request->getMethod()));
$form->handleRequest($request);

if ($form->isValid()) {
Expand Down
33 changes: 32 additions & 1 deletion newscoop/src/Newscoop/GimmeBundle/Form/Type/CommentType.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/**
* @package Newscoop\NewscoopBundle
* @author Paweł Mikołajczuk <[email protected]>
* @author Yorick Terweijden <[email protected]>
* @copyright 2014 Sourcefabric o.p.s.
* @license http://www.gnu.org/licenses/gpl-3.0.txt
*/
Expand All @@ -12,16 +13,38 @@
use Symfony\Component\Form\FormBuilderInterface;
use Symfony\Component\OptionsResolver\OptionsResolverInterface;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Validator\Constraints\NotBlank;

class CommentType extends AbstractType
{
private $patch;

public function __construct(array $options = array())
{
if (array_key_exists('patch', $options)) {
$this->patch = $options['patch'];
}
}

public function buildForm(FormBuilderInterface $builder, array $options)
{
$defaultRequired = true;
$constraints = array(
new NotBlank
);

if ($this->patch) {
$defaultRequired = false;
$constraints = array();
}


$builder->add('subject', null, array(
'required' => false,
));
$builder->add('message', null, array(
'required' => true,
'required' => $defaultRequired,
'constraints' => $constraints,
));

$builder->add('name', null, array(
Expand All @@ -35,6 +58,14 @@ public function buildForm(FormBuilderInterface $builder, array $options)
$builder->add('parent', null, array(
'required' => false,
));

$builder->add('recommended', 'integer', array(
'required' => false,
));

$builder->add('status', null, array(
'required' => false,
));
}

public function getName()
Expand Down

0 comments on commit 84da387

Please sign in to comment.