Commit d1138728 authored by Patrick Barroca's avatar Patrick Barroca 🐧

dev #69586 : add articles selection to newsletter

parent 40f018f2
Pipeline #3271 passed with stage
in 26 minutes and 44 seconds
'69586' =>
['Label' => $this->_('Inclure des articles dans les newsletters'),
'Desc' => '',
'Image' => '',
'Video' => '',
'Category' => '',
'Right' => function($feature_description, $user) {return true;},
'Wiki' => '',
'Test' => '',
'Date' => '2018-01-10'],
\ No newline at end of file
- ticket #69586 : Newsletter : Ajout de la possibilité d'inclure des articles dans les newsletters
\ No newline at end of file
<?php
$adapter = Zend_Db_Table_Abstract::getDefaultAdapter();
try {
$adapter->query("ALTER TABLE `newsletters` ADD `id_categorie` varchar(255) NULL default null, ADD `id_items` varchar(255) NULL default NULL");
} catch(Exception $e) {}
......@@ -89,7 +89,9 @@ class Class_Newsletter extends Storm_Model_Abstract {
protected $_notices_finder;
protected $_recipent_size = 20;
protected $_default_attribute_values = ['titre' => '',
'draft' => 0];
'draft' => 0,
'id_categorie' => '',
'id_items' => ''];
public function describeAssociationsOn($associations) {
......
......@@ -62,6 +62,7 @@ class ZendAfi_Form_Admin_Newsletter extends ZendAfi_Form {
'value' => 0,
'validators' => [new Zend_Validate_Int()]])
->addDisplayGroup(['titre', 'expediteur', 'draft'],
'letter',
['legend' => $this->_('Lettre')])
......@@ -74,4 +75,32 @@ class ZendAfi_Form_Admin_Newsletter extends ZendAfi_Form {
'notices',
['legend' => $this->_('Notices')]);
}
public function populate($datas) {
parent::populate($datas);
$this->addElement('treeSelect',
'articles_selector',
['IdItems' => isset($datas['id_items']) ? $datas['id_items'] : '',
'ItemRenderer' => function($id)
{
if ($model = Class_Article::find($id))
return $model->getTitre();
},
'IdCategories' => isset($datas['id_categorie']) ? $datas['id_categorie'] : '',
'CategoryRenderer' => function($id)
{
if ($model = Class_ArticleCategorie::find($id))
return implode(' > ', $model->getPathParts());
},
'UrlDataSource' => Class_Url::assemble(['module' => 'admin',
'controller' => 'bib',
'action' => 'articles'])]);
$this->addDisplayGroup(['articles_selector'], 'articles',
['legend' => $this->_('Articles')]);
return $this;
}
}
......@@ -316,6 +316,8 @@ class Admin_NewsletterControllerEditActionTest extends Admin_NewsletterControlle
'titre' => 'Nouveautés',
'contenu'=>'Notre sélection du mois',
'expediteur' => 'laurent@free.fr',
'id_categorie' => '2',
'id_items' => '6-42',
'user_groups' => [Class_UserGroup::find(14),
Class_UserGroup::find(15)]]);
......@@ -359,6 +361,19 @@ class Admin_NewsletterControllerEditActionTest extends Admin_NewsletterControlle
public function testSubmitButton() {
$this->assertXPath("//div//button[contains(@onclick,\"submit()\")]");
}
/** @test */
public function articlesTabShouldBePresent() {
$this->assertXPathContentContains('//form//fieldset//legend', 'Articles');
}
/** @test */
public function articleSelectionFieldsShouldBePresent() {
$this->assertXPath('//form//input[@name="id_categorie"][@value="2"]');
$this->assertXPath('//form//input[@name="id_items"][@value="6-42"]');
}
}
......@@ -374,7 +389,9 @@ class Admin_NewsletterControllerAddActionPostTest extends Admin_NewsletterContro
'contenu' => 'Plein les yeux',
'id_catalogue' => '',
'id_panier' => '',
'nb_notices' => 2];
'nb_notices' => 2,
'id_categorie' => '667-34-22',
'id_items' => '6-42'];
$this->postDispatch('/admin/newsletter/add', $data);
$this->_new = Class_Newsletter::findFirstBy(['titre' => 'Fêtes du lac']);
......@@ -404,6 +421,18 @@ class Admin_NewsletterControllerAddActionPostTest extends Admin_NewsletterContro
$this->assertEquals('Groupe manuel pour la lettre "Fêtes du lac"',
$this->_new->getDedicatedGroup()->getLibelle());
}
/** @test */
public function idCategorieShouldBe667_34_22() {
$this->assertEquals('667-34-22', $this->_new->getIdCategorie());
}
/** @test */
public function idItemsShouldBe6_42() {
$this->assertEquals('6-42', $this->_new->getIdItems());
}
}
......
......@@ -1995,3 +1995,26 @@ class UpgradeDB_341_Test extends UpgradeDBTestCase {
$this->assertEquals(0, $datas['numberOf']);
}
}
class UpgradeDB_342_Test extends UpgradeDBTestCase {
public function prepare() {
try {
$this->query('ALTER TABLE newsletters DROP column id_categorie');
$this->query('ALTER TABLE newsletters DROP column id_items');
} catch(Exception $e) {}
}
/** @test */
public function idCategorieShouldBePresent() {
$this->assertColumn('newsletters', 'id_categorie');
}
/** @test */
public function idItemsShouldBePresent() {
$this->assertColumn('newsletters', 'id_items');
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment