Commit a0016dc2 authored by Laurent's avatar Laurent
Browse files

dev #48981 multicards: display parent cards and implement unlink link

parent cc40caf1
......@@ -1065,14 +1065,35 @@ class AbonneController extends ZendAfi_Controller_Action {
public function cardsAction() {
$this->view->titre = $this->_('Mes cartes');
$this->view->child_cards = new Class_User_Cards($this->_user);
$this->view->parent_cards = $this->_user->getParentCards();
}
public function unlinkCardAction() {
$child = Class_Users::find((int)$this->_getParam('id'));
$lc = Class_LinkedCard::findFirstBy(['parent_id' => $this->_user->getId(),
'child_id' => $this->_getParam('id')]);
'child_id' => $child->getId()]);
$lc->delete();
$this->_helper->notify($this->_('Vous n\'utilisez plus la carte de %s',
$child->getNomComplet()));
$this->_redirect('/abonne/cards');
}
public function unlinkParentCardAction() {
$parent = Class_Users::find((int)$this->_getParam('id'));
$lc = Class_LinkedCard::findFirstBy(['parent_id' => $parent->getId(),
'child_id' => $this->_user->getId()]);
$lc->delete();
$this->_helper->notify($this->_('Votre carte a été retirée à %s',
$parent->getNomComplet()));
$this->_redirect('/abonne/cards');
}
......
<?php
$this->openBoite($this->titre);
?>
<section>
<?php
echo $this->tag('h2', $this->_('J\'utilise les cartes suivantes'));
echo $this->child_cards->isEmpty()
? $this->tag('p', $this->_('Vous n\'avez ajouté aucune carte'))
: $this->tagModelTable(
$this->child_cards,
[$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom'), $this->_('Expire le')],
['login',
'nom',
'prenom',
'subscription_end'],
[ function($user) {
if ($user->getId() == Class_Users::getIdentity()->getId())
return '';
return $this->tagAnchor(['action' => 'unlink-card', 'id' => $user->getId()],
$this->boutonIco('type=del'));
} ],
'child_cards',
null,
['login' => function($user) {
return $user->getId() == Class_Users::getIdentity()->getId()
? $this->_('%s (ma carte)', $user->getLogin())
: $user->getLogin();
},
'subscription_end' => function($user) {
return Class_Date::humanDate($user->getDateFin(), 'dd MMMM yyyy');
}
]);
echo $this->child_cards->isEmpty()
? $this->tag('p', $this->_('Vous n\'avez ajouté aucune carte'))
: $this->tagModelTable($this->child_cards,
[$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom'), $this->_('Expire le')],
['login',
'nom',
'prenom',
'subscription_end'],
[ function($user) {
if ($user->getId() == Class_Users::getIdentity()->getId())
return '';
return $this->tagAnchor(['action' => 'unlink-card', 'id' => $user->getId()],
$this->boutonIco('type=del'));
} ],
'child_cards',
null,
['login' => function($user) {
return $user->getId() == Class_Users::getIdentity()->getId()
? $this->_('%s (ma carte)', $user->getLogin())
: $user->getLogin();
},
'subscription_end' => function($user) {
return Class_Date::humanDate($user->getDateFin(), 'dd MMMM yyyy');}]);
echo $this->tagAnchor(['action' => 'add-card'],
$this->_('Ajouter une carte'),
['data-popup' => 'true',
'class' => 'bouton']);
echo $this->tagAnchor(['action' => 'add-card'],
$this->_('Ajouter une carte'),
['data-popup' => 'true',
'class' => 'bouton']);
?>
</section>
<?php
if ($this->parent_cards) {
?>
<section>
<?php
echo $this->tag('h2', $this->_('Les utilisateurs suivants ont ma carte'));
echo $this->tagModelTable($this->parent_cards,
[$this->_('Identifiant'), $this->_('Nom'), $this->_('Prénom')],
['login',
'nom',
'prenom',
],
[ function($user) {
return $this->tagAnchor(['action' => 'unlink-parent-card', 'id' => $user->getId()],
$this->boutonIco('type=del'));
} ],
'parent_cards',
null);
?>
</section>
<?php } ?>
<?php
$this->closeBoite();
echo $this->abonne_RetourFiche();
?>
......@@ -127,6 +127,12 @@ class Scenario_AbonneMultiCardsCardsActionTest extends Scenario_AbonneMultiCards
public function darkyShouldNotHaveUnlinkLink() {
$this->assertNotXPath('//table//td//a[contains(@href, "unlink-card")]');
}
/** @test */
public function tableParentCardShouldNotBeVisible() {
$this->assertNotXPath('//table[@id="parent_cards"]');
}
}
......@@ -259,6 +265,12 @@ class Scenario_AbonneMultiCardsWithCardsUnlinkActionTest extends Scenario_Abonne
public function responseShouldRedirectToCards() {
$this->assertRedirectTo('/abonne/cards');
}
/** @test */
public function notificationShouldContainsCardRemoved() {
$this->assertFlashMessengerContentContains('Vous n\'utilisez plus la carte de Luke Skywalker');
}
}
......@@ -676,3 +688,67 @@ class Scenario_AbonneMultiCardsDiscardParentLinkNotificationActionTest
$this->assertRedirect();
}
}
class Scenario_AbonneMultiCardsLukeWithParentCardActionTest extends Scenario_AbonneMultiCardsTestCase {
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(2));
Class_Users::getIdentity()
->addParentCard(Class_Users::find(1))
->save();
$this->dispatch('/abonne/cards', true);
}
/** @test */
public function parentCardsTableShouldContainsDarky() {
$this->assertXPathContentContains('//table[@id="parent_cards"]//td', 'darky');
}
/** @test */
public function darkyShouldHaveUnlinkLink() {
$this->assertXPath('//table//td//a[contains(@href, "abonne/unlink-parent-card/id/1")]');
}
}
class Scenario_AbonneMultiCardsLukeWithParentCardUnlinkActionTest extends Scenario_AbonneMultiCardsTestCase {
public function setUp() {
parent::setUp();
ZendAfi_Auth::getInstance()->logUser(Class_Users::find(2));
Class_Users::getIdentity()
->addParentCard(Class_Users::find(1))
->save();
$this->dispatch('/abonne/unlink-parent-card/id/1', true);
}
/** @test */
public function darkyShouldNoLongerBeInLukeParentCards() {
$this->assertEmpty(Class_LinkedCard::findAll());
}
/** @test */
public function responseShouldRedirectToCards() {
$this->assertRedirectTo('/abonne/cards');
}
/** @test */
public function notificationShouldContainsCardRemovedFromDarky() {
$this->assertFlashMessengerContentContains('Votre carte a été retirée à darky');
}
}
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