Commit 9918a528 authored by Ghislain Loas's avatar Ghislain Loas
Browse files

dev #64573 reviews on record page

parent 05ba5fdd
Pipeline #6198 failed with stage
in 27 minutes and 10 seconds
......@@ -1317,4 +1317,42 @@ class AbonneController extends ZendAfi_Controller_Action {
$this->renderPopupResult($this->_('Compléter votre adresse email'),
$this->view->render('abonne/ajax-email.phtml'));
}
public function reviewAction() {
if(!$this->_user)
return $this->_forward('popup-login', 'auth', 'opac');
if(!$this->_request->isPost())
return $this->_redirectToReferer();
$form = new ZendAfi_Form_Review;
$post = $this->_request->getPost();
$form->populate($post);
$rating = ($mine = Class_AvisNotice::find($this->_getParam('id')))
? $mine
: new Class_AvisNotice;
$rating
->beImportMode()
->setUser($this->_user)
->setIdNotice($this->_getParam('record_id'))
->setClefOeuvre($this->_getParam('record_key'))
->setUserRole($this->_user)
->updateAttributes($post);
if (!$this->_getPost('entete') && !$this->_getPost('avis'))
$rating->setModerationOK();
if (!$form->isValidModelAndArray($rating, $post))
return $this->_redirectToReferer();
if (!$rating->save())
return false;
$this->_helper->notify($this->_('Votre avis a été pris en compte.'));
return $this->_redirectToReferer();
}
}
\ No newline at end of file
......@@ -235,7 +235,8 @@ class Class_AvisNotice extends Storm_Model_Abstract {
'type_doc' => null,
'avis' => '',
'entete' => '',
'note' => 0];
'note' => 0,
'id_user' => 0];
protected $_notices;
protected $_import_mode = false;
......@@ -435,7 +436,13 @@ class Class_AvisNotice extends Storm_Model_Abstract {
if (null !== $user)
$this->setUserKey($this->getLoader()->keyForUser($user));
$this->setUserRole($user);
}
public function setUserRole($user) {
$this->setAbonOuBib((null !== $user) && $user->isBibliothecaire() ? 1 : 0);
return $this;
}
......
......@@ -159,13 +159,7 @@ class ZendAfi_Auth_Others {
protected function _tryLogOther($other) {
$auth = ZendAfi_Auth::getInstance();
if ($other->isAbonne())
return $auth
->authenticateLoginPassword($other->getLogin(), $other->getPassword());
$auth->logUser($other);
$auth = ZendAfi_Auth::getInstance()->logUser($other);
return true;
}
......
......@@ -268,9 +268,6 @@ class ZendAfi_Controller_Plugin_Manager_Manager extends ZendAfi_Controller_Plugi
$form->populateFormFromGroupsDefinitions($this->_getDisplayGroups());
}
$form = $form->populate($this->_request->getParams());
$form = $form->populate($this->_getFormValues($model));
return $form
->populate($this->_request->getParams())
->populate($this->_getFormValues($model));
......
......@@ -37,8 +37,6 @@ class ZendAfi_Form_Review extends ZendAfi_Form {
->addElement('textarea',
'avis',
['label' => $this->_('Texte'),
'required' => true,
'allowEmpty' => false,
'rows' => 3,
'cols' => 25])
......
......@@ -20,7 +20,7 @@
*/
class ZendAfi_View_Helper_Notice_Reviews extends ZendAfi_View_Helper_BaseHelper {
class Intonation_View_Notice_Reviews extends ZendAfi_View_Helper_BaseHelper {
protected $_record;
......@@ -32,7 +32,7 @@ class ZendAfi_View_Helper_Notice_Reviews extends ZendAfi_View_Helper_BaseHelper
$this->_renderUsers(),
$this->_mine()];
return $this->view->grid(implode($html), [], ['class' => 'justify-content-center']);
return $this->view->grid(implode($html), [], ['class' => '']);
}
......@@ -76,15 +76,16 @@ class ZendAfi_View_Helper_Notice_Reviews extends ZendAfi_View_Helper_BaseHelper
$mine = ($mine = $me->getFirstAvisByIdNotice($this->_record->getId()))
? $mine
: new Class_Avis;
: new Class_AvisNotice;
$params = $mine->isNew()
? ['action' => 'add-review']
: ['action' => 'edit-review',
'id' => $mine->getId()];
$params = ['controller' => 'abonne',
'action' => 'review',
'record_id' => $this->_record->getId(),
'record_key' => $this->_record->getClefOeuvre(),
'id' => $mine->getId()];
$form = ZendAfi_Form_Review::newWith($mine->toArray())
->setAction($this->view->url($params));
->setAction($this->view->url($params,null,true));
return $this->_div(['class' => 'col-12 col-md-6 col-xl-4'],
$this->_tag('h3', $this->_('Votre avis'), ['class' => 'card-title'])
......
......@@ -1759,6 +1759,12 @@ class TemplatesViewRecordTest extends TemplatesIntonationTestCase {
}
/** @test */
public function ratingShouldBeDisplayed() {
$this->assertXPathContentContains('//');
}
/** @test */
public function bagesShouldContainsTopicRoman() {
$this->assertXPathContentContains('//a[contains(@class, "badge")][contains(@href, "/recherche/simple/code_rebond/G13")]', 'Roman');
......@@ -1788,4 +1794,52 @@ class TemplatesDispatchNoticeAjaxResourcesTest extends TemplatesIntonationTestCa
$this->dispatch('/noticeajax/resources/id/34/id_profil/72');
$this->assertXPath('//div', $this->_response->getBody());
}
}
class TemplatesAddReviewTest extends TemplatesIntonationTestCase {
protected $_review;
public function setUp() {
parent::setUp();
$this->postDispatch('/opac/abonne/review/record_id/456/record_key/mykey' ,
['note' => 5,
'entete' => '',
'avis' => '']);
$this->_review = Class_AvisNotice::find(1);
}
/** @test */
public function noEnteteRatingShouldHaveBeenCreated() {
$this->assertNotNull($this->_review);
}
/** @test */
public function ratingShouldBeSetToUser() {
$this->assertEquals(666, $this->_review->getIdUser());
}
/** @test */
public function ratingShouldBeSetToNotice() {
$this->assertEquals(456,$this->_review->getIdNotice());
}
/** @test */
public function ratingShouldBeAutoModerated() {
$this->assertEquals(Trait_Avis::$STATUT_OK, $this->_review->getStatut());
}
/** @test */
public function ratingRecordKeyShouldBeSaved() {
$this->assertEquals('mykey', $this->_review->getClefOeuvre());
}
}
\ No newline at end of file
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