getRequest()->getActionName()) return; $this->_user = Class_Users::getIdentity(); $this->clearEmprunteurCache(); $this->view->getHelper('PageContext')->setContextHelper('Abonne_Resume', [$this->_user]); } public function preDispatch() { parent::preDispatch(); if ($this->_isMultimediaHoldAction() && !Class_AdminVar::isMultimediaEnabled()) { $this->_helper->notify($this->_('AFI-Multimédia n\'est pas activé')); $this->_redirect('/abonne'); $this->_request->setDispatched(); return; } } protected function _isMultimediaHoldAction() { return 'multimedia' == substr($this->_request->getActionName(), 0, 10); } protected function clearEmprunteurCache() { if (in_array($this->getRequest()->getActionName(), ['prets', 'reservations', 'fiche', 'loans-history'])) Class_WebService_SIGB_EmprunteurCache::newInstance()->remove($this->_user); } public function indexAction() { $this->_forward('fiche'); } public function inscrireSessionAction() { $this->_redirectToReferer(); if ((!$session = Class_SessionActivity::find((int)$this->_getParam('id'))) || $session->isInscriptionClosed()) return $this->_helper->notify($this->_('L\'inscription à cette session est fermée')); $session->addStagiaire($this->_user); if (!$session->save()) return $this->_helper->notify(implode('
', $session->getErrors())); (new Class_Activity_RegistrationMail($session, $this->_user))->send(); $this->_helper->notify($this->_('Vous êtes inscrit à la session du %s de l\'activité %s', $this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'), $session->getLibelleActivity())); } public function desinscrireSessionAction() { if (!$session = Class_SessionActivity::find((int)$this->_getParam('id'))) { $this->_helper->notify($this->_('Session non trouvée')); $this->_redirectToReferer(); return; } $this->_user->removeSessionActivity($session); if ($this->_user->save()) { $this->_helper->notify($this->_('Vous n\'êtes plus inscrit à la session du %s de l\'activité %s', $this->view->humanDate($session->getDateDebut(), 'd MMMM YYYY'), $session->getLibelleActivity())); (new Class_Activity_UnregistrationMail($session, $this->_user))->send(); }; $this->_redirectToReferer(); } public function subscribeNewsletterAction() { $this->_stayOnPage(); if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) { $this->_helper->notify($this->_('Newsletter non trouvée')); return; } $this->_user->addNewsletter($newsletter); if ($this->_user->save()) { $this->_helper->notify($this->_('Vous êtes inscrit à la liste de diffusion: %s', $newsletter->getTitre())); }; } public function unsubscribeNewsletterAction() { $this->_stayOnPage(); if (!$newsletter = Class_Newsletter::find((int)$this->_getParam('id'))) { $this->_helper->notify($this->_('Newsletter non trouvée')); return; } $this->_user->unsubscribeNewsletter($newsletter); if ($this->_user->save()) { $this->_helper->notify($this->_('Vous êtes désinscrit de la liste de diffusion: %s', $newsletter->getTitre())); }; } public function viewavisAction(){ $this->_forward('viewauteur', 'blog', 'opac', ['id' => $this->_user->getId()]); } public function delavisnoticeAction(){ $this->_forward('delavisnotice', 'blog', 'opac', ['id' => $this->_getParam('id'), 'redirect' =>'abonne/viewavis/id/'.$this->_user->getId(), 'js_redirect' => $this->_getParam('expressionRecherche')? true: false]); } public function avisAction() { $id_notice = $this->_getParam('id_notice', 0); $notice = Class_Notice::find($id_notice); $avis = ($avis = $this->_user->getFirstAvisByIdNotice($id_notice)) ? $avis : new Class_AvisNotice(); if ($this->_request->isPost()) { $avis ->setEntete($this->_getParam('avisEntete')) ->setAvis($this->_getParam('avisTexte')) ->setNote($this->_getParam('avisNote')) ->setUser($this->_user) ->setIdNotice($id_notice) ->setClefOeuvre($notice->getClefOeuvre()) ->setTypeDoc($notice->getTypeDoc()) ->setStatut(0); if ($avis->save()) { $this->_user ->setPseudo($this->_request->getParam('avisSignature')) ->save(); $this->_helper->notify($this->_('Votre avis à bien été enregistré')); return $this->_redirectClose($this->_getReferer()); } $this->view->message = implode('.', $avis->getErrors()); } if ($avis != null) { $this->view->id = $avis->getId(); $this->view->avisEntete = $avis->getEntete(); $this->view->avisTexte = $avis->getAvis(); $this->view->avisNote = $avis->getNote(); } $this->view->avisSignature = $this->_user->getNomAff(); $this->view->id_notice = $id_notice; } public function editaviscmsAction () { $user = Class_Users::getIdentity(); if (!$user->isBibliothecaire() || (!$avis = Class_Avis::find((int)$this->_getParam('id')))) { $this->_javascriptRedirectToReferrer(); return; } $this->manageAvisEditWith( $avis, function($form) use ($avis) { $avis ->setAvis($form->avis->getValue()) ->setEntete($form->entete->getValue()); }); } public function editavisnoticeAction() { $user = Class_Users::getIdentity(); if (!$user->isBibliothecaire() || (!$avis = Class_AvisNotice::find((int)$this->_getParam('id')))) { $this->_javascriptRedirectToReferrer(); return; } $this->manageAvisEditWith( $avis, function($form) use ($avis) { $avis ->setAvis($form->avis->getValue()) ->setEntete($form->entete->getValue()); if ($record = $form->url->getRecord()) { $avis->setClefOeuvre($record->getClefOeuvre()); $avis->setTypeDoc($record->getTypeDoc()); } }); } protected function manageAvisEditWith($avis, $set_closure) { $form = ZendAfi_Form_Admin_EditAvis::newWith($avis->toArray()) ->addPermalinkFor($avis) ->addBackUrl(''); $form->setAttrib('action', $this->view->url()); $form->addElement('submit', 'edit-avis-submit', ['label' => 'Valider']); if ($this->_request->isPost() && $form->isValid($this->_request->getPost())) { $set_closure($form); if ($avis->save()) { $this->_javascriptRedirectToReferrer(); return; } $form->addModelErrors($avis); } $this->view->form = $form; $this->renderPopupResult($this->view->_('Modifier l\'avis "%s"', $avis->getEntete()), $this->view->render('abonne/editavisnotice.phtml')); } public function cmsavisAction() { $this->view->titre = $this->_('Votre avis'); // Validation du formulaire if ($this->_request->isPost()) { // Bornage du texte $longueur_min = Class_AdminVar::get("AVIS_MIN_SAISIE"); $longueur_max = Class_AdminVar::get("AVIS_MAX_SAISIE"); if(!$longueur_min) $longueur_min=10; if(!$longueur_max) $longueur_max=250; $filter = new Zend_Filter_StripTags(); $avisSignature = trim($filter->filter($this->_request->getPost('avisSignature'))); $avisEntete = trim($filter->filter($this->_request->getPost('avisEntete'))); $avisTexte = trim($filter->filter($this->_request->getPost('avisTexte'))); $avisNote = trim($filter->filter($this->_request->getPost('avisNote'))); $id = trim($filter->filter($this->_request->getParam('id'))); if ($avisEntete != '' and (strlen($avisTexte)>= $longueur_min and strlen($avisTexte)<= $longueur_max ) and $avisSignature != '') { Class_Avis::ecrireCmsAvis($this->_user->ID_USER, $this->_user->ROLE_LEVEL, $id, $avisNote, $avisEntete, $avisTexte); $this->_user ->setPseudo($avisSignature) ->save(); $this->_redirect('/opac/cms/articleview/id/'.$id); return; } else { if(strlen($avisTexte)< $longueur_min or strlen($avisTexte) > $longueur_max) $this->view->message = $this->_("L'avis doit avoir une longueur comprise entre %d et %d caractères", $longueur_min, $longueur_max); else $this->view->message = $this->_('Il faut compléter tous les champs.'); $this->view->avisSignature = $avisSignature; $this->view->avisEntete = $avisEntete; $this->view->avisTexte = $avisTexte; $this->view->avisNote = $avisNote; $this->view->id = $id; } } // Saisie du formulaire else { $id = $this->_request->getParam('id', 0); $this->view->message = ''; $this->view->id = $id; $this->view->avisSignature = $this->_user->getNomAff(); if (!$avis = Class_Avis::findFirstBy(['id_user' => $this->_user->getId(), 'id_cms' => $id])) $avis = Class_Avis::newInstance(['id_user' => $this->_user->getId(), 'id_cms' => $id]); $this->view->avisEntete = $avis->getEntete(); $this->view->avisTexte = $avis->getAvis(); $this->view->avisNote = $avis->getNote(); } } public function tagnoticeAction() { if (!$this->_request->isPost()) { $this->view->titre = $this->_('Proposer des tags pour cette notice'); $this->view->id = $this->_request->getParam('id_notice', 0); $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setLayoutScript('subModal.phtml'); return; } $filter = new Zend_Filter_StripTags(); $abonneTag1 = trim($filter->filter($this->_request->getPost('abonneTag1'))); $abonneTag2 = trim($filter->filter($this->_request->getPost('abonneTag2'))); $abonneTag3 = trim($filter->filter($this->_request->getPost('abonneTag3'))); $id = trim($filter->filter($this->_request->getPost('id'))); if ($abonneTag1 == '' && $abonneTag2 == '' && $abonneTag3 == '') { $this->getResponse()->setHeader('Content-Type', 'text/html;charset=utf-8'); $this->getResponse()->setBody(""); $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setNoRender(); return; } Class_TagNotice::multiForRecord([$abonneTag1, $abonneTag2, $abonneTag3], $id); $this->_javascriptRedirectToReferrer(); } public function ficheAction() { $fiche_sigb = $this->_user->getFicheSigb(); $this->view->error = isset($fiche_sigb['erreur']) ? $fiche_sigb["erreur"] : ''; $this->view->user = $this->_user; $this->view->interdiction_modif = Class_AdminVar::get('INTERDIRE_MODIF_FICHE_ABONNE'); } public function pretsAction() { if($this->_request->isPost()) return $this->_redirectToRefererWithNewParams(['onhold' => $this->_getPost('onhold'), 'start_date_retour' => $this->_getPost('start_date_retour'), 'end_date_retour' => $this->_getPost('end_date_retour'), 'start_issue_date' => $this->_getPost('start_issue_date'), 'end_issue_date' => $this->_getPost('end_issue_date')]); $cards = new Class_User_Cards($this->_user); $loans = $cards->getLoansWithOutPNB($this->_request->getParams()); $fiche = $this->_user->getFicheSigb(); $error = (isset($fiche['error']) && $fiche['error']) ? $fiche['error'] : ''; $this->view->config = new Class_Entity(['Loans' => $loans, 'RenewableLoansIds' => $cards->getRenewableLoansIds($loans), 'User' => $this->_user, 'Error' => $error, 'Profile' => Class_Profil::getCurrentProfil(), 'RequestParams' => $this->_request->getParams()]); } public function prolongerpretAction() { $id_pret = $this->_getParam('id_pret'); $ids = array_filter(explode(';', $id_pret)); if (!count($ids)) { $this->_renderExtendPopup([$this->_('Aucune prolongation éffectuée.')]); return; } $cards = new Class_User_Cards($this->_user); $results = []; foreach($ids as $id) { $status = $cards->renewLoan($id); $status['id'] = $id; $results[] = $status; } $title = (count($ids)>1) ? $this->_('Prolongation des prêts') : $this->_('Prolongation du prêt'); $this->_renderExtendPopup($this->view->abonne_LoansExtension($cards, $results, $ids)); } protected function _renderExtendPopup($messages) { $this->getHelper('notify')->bePopup(); foreach($messages as $message) $this->_helper->notify($message); $this->_redirectToReferer(); } public function loansHistoryAction() { $this->view->config = new Class_Entity(['Profile' => Class_Profil::getCurrentProfil(), 'RequestParams' => $this->_request->getParams(), 'User' => $this->_user]); try { $this->view->config->setLoans($this->_user->getLoansHistory($this->_request->getParams())); } catch (Class_WebService_Exception $e) { $this->view->config->setError($e->getMessage()); } } public function reservationsAction() { $cards = new Class_User_Cards($this->_user); if ($delete = $this->_getParam('id_delete')) { $title = $cards->getHoldTitle($delete); $result = $cards->cancelHold($delete); $message = array_key_exists('erreur', $result) && $result['erreur'] ? $result['erreur'] : $this->_('Votre réservation du document %s a bien été supprimée.', $title); return $this->_renderExtendPopup([$message]); } if ($delete = $this->_getParam('consultation_id_delete')) Class_CommSigb::getInstance()->onPlaceConsultationCancelBooking(Class_Users::getIdentity(), $delete); $this->view->consultations_reservations = $this->_user->getConsultations(); $this->view->fiche = $this->_user->getFicheSigb(); $this->view->user = $this->_user; } protected function _userForm($user) { $fields_to_show = Class_AdminVar::getChampsFicheUtilisateur(); $form = new Zend_Form; $form ->setAction($this->view->url(['action' => 'edit', 'id' => $user->getId()])) ->setMethod('post') ->setAttrib('id', 'user') ->setAttrib('class', 'zend_form') ->setAttrib('autocomplete', 'off'); $textfields = ['nom' => $this->_('Nom'), 'prenom' => $this->_('Prénom'), 'pseudo' => $this->_('Pseudo'), 'adresse' => $this->_('Adresse'), 'code_postal' => $this->_('Code postal'), 'ville' => $this->_('Ville'), 'mail' => $this->_('E-Mail'), 'telephone' => $this->_('Téléphone')]; foreach($textfields as $field => $label) { if (!in_array($field, $fields_to_show)) continue; $element = $form ->createElement('text', $field) ->setLabel($label) ->setAttrib('size', 30); $form->addElement($element); } if ($mail_element = $form->getElement('mail')) $mail_element->addValidator(new ZendAfi_Validate_EmailAddress()); if ($phone_element = $form->getElement('telephone')) $phone_element->addValidator(new ZendAfi_Validate_PhoneNumber()); if (in_array('password', $fields_to_show)) { $fields_to_show []= 'confirm_password'; $new_password = new Zend_Form_Element_Password('password'); $new_password ->setLabel($this->_('Nouveau mot de passe')) ->addValidator('Identical', false, array('token' => $this->_request->getParam('confirm_password'), 'messages' => array('missingToken' => $this->_('Vous devez confirmer le mot de passe'), 'notSame' => $this->_('Les mots de passe ne correspondent pas')))) ->addValidator('StringLength', false, array(4,24)); $confirm_password = new Zend_Form_Element_Password('confirm_password'); $confirm_password ->setLabel($this->_('Confirmez le mot de passe')) ->addValidator('Identical', false, array('token' => $this->_request->getParam('password'), 'messages' => array('missingToken' => $this->_('Vous devez saisir un mot de passe'), 'notSame' => $this->_('Les mots de passe ne correspondent pas')))) ->setValue($user->getPassword()); $form ->addElement($new_password) ->addElement($confirm_password); } if ($identification_fields = array_intersect(['nom', 'prenom', 'pseudo', 'password', 'confirm_password'], $fields_to_show)) $form->addDisplayGroup($identification_fields, 'identification', ['legend' => 'Identification']); if ($coordonnees_fields = array_intersect(['adresse', 'code_postal', 'ville'], $fields_to_show)) $form->addDisplayGroup($coordonnees_fields, 'coordonnees', ['legend' => 'Coordonnées']); if ($contact_fields = array_intersect(['mail', 'telephone'], $fields_to_show)) $form->addDisplayGroup($contact_fields, 'contact', ['legend' => 'Contact']); if (in_array('mode_contact', $fields_to_show)) { $form->addElement('radio', 'mode_contact', ['label' => '', 'multiOptions' => [Class_Users::MODE_CONTACT_LETTER => $this->_(' par courrier postal'), Class_Users::MODE_CONTACT_MAIL => $this->_(' par E-Mail'), Class_Users::MODE_CONTACT_SMS => $this->_(' par SMS')], 'value' => $user->getModeContact()]); $form->addDisplayGroup(['mode_contact'], 'mode_de_contact', ['legend' => 'Recevoir mes notificactions de réservation et de rappel']); } /* Abonnements aux newsletters*/ $subscriptions = new Zend_Form_Element_MultiCheckbox('subscriptions'); $subscriptions->setLabel($this->_("Abonnement aux lettres d'information")); $newsletters = Class_Newsletter::getPublishedNewsletters(); if (count($newsletters)>0) { $checked_subscriptions = []; foreach($newsletters as $nl) { $subscriptions->addMultiOption($nl->getId(), $nl->getTitre()); if ($nl->hasRecipient($user)) $checked_subscriptions []= $nl->getId(); } $subscriptions->setValue($checked_subscriptions); $form ->addElement($subscriptions) ->addDisplayGroup(['subscriptions'], 'newsletters', ['legend' => 'Lettres d\'information']); } $form ->populate($user->toArray()); return $form; } public function editAction() { $form = $this->_userForm($this->_user); $this->view->form = $form; $this->view->help = nl2br(Class_AdminVar::get('AIDE_FICHE_ABONNE')); if (!$this->getRequest()->isPost()) return ; if (!$form->isValid($_POST)) return; $subscriptions = $this->_request->getParam('subscriptions', []); $newsletters = $subscriptions ? Class_Newsletter::findAllBy(['id' => $subscriptions]) : []; $password = $this->_request->getParam('password'); if (empty($password)) $password = $this->_user->getPassword(); $fields_to_save = Class_AdminVar::getChampsFicheUtilisateur(); $attributes = []; foreach($fields_to_save as $field) $attributes[$field] = $this->_request->getParam($field); $this->_user ->updateAttributes($attributes) ->setPassword($password) ->setNewsletters($newsletters); $patron = $this->_user->getEmprunteur(); $patron->updateFromUser($this->_user); try { if ($this->_user->save()) { $patron->ensureService($this->_user)->save(); $this->_helper->notify($this->_('Vos modifications ont bien été enregistrées')); $this->_redirect('/abonne/fiche'); } $form->addDecorator('Errors'); foreach($this->_user->getErrors() as $error) $form->addError($error); } catch(Exception $e) { $form->addError($e->getMessage()); $form->addDecorator('Errors'); } } public function authenticateAction() { $this->getHelper('ViewRenderer')->setNoRender(); $mode = $this->_getParam('mode', ''); if ($mode === 'holdable-day') return $this->_forward('is-holdable-day', 'multimedia', $this->_request->getModuleName(), $this->_request->getParams()); if ($mode === 'hold') return $this->_forward('hold-device', 'multimedia', $this->_request->getModuleName(), $this->_request->getParams()); if ($mode === 'modified-hold') return $this->_forward('close-holding', 'multimedia', $this->_request->getModuleName(), $this->_request->getParams()); return $this->_forward('authenticate', 'multimedia', $this->_request->getModuleName(), $this->_request->getParams()); } public function multimediaHoldLocationAction() { $bean = Class_Multimedia_ReservationBean::newInSession(); if (null != $this->_getParam('location')) { $bean->location = $this->_getParam('location'); $this->_redirect('/abonne/multimedia-hold-day'); return; } $this->view->locations = array_filter(Class_Multimedia_Location::findAllBy(['order' => 'libelle']), function($location) { return $location->numberOfOuverturesMultimedia() > 0;}); $this->view->timelineActions = $this->_getTimelineActions('location'); } public function multimediaHoldDayAction() { $bean = Class_Multimedia_ReservationBean::current(); /* Vérification du quota sur le jour choisi */ $day = $this->_getParam('day'); $this->view->location = $bean->getLocation()->getLibelleBib(); $quotaErrorType = null; if (null != $day) { $quotaErrorType = $this->_user->getMultimediaQuotaErrorForDay($day); switch ($quotaErrorType) { case Class_Multimedia_DeviceHold::QUOTA_NONE: $this->view->quotaError = $this->_('Vous n\'êtes pas autorisé à effectuer une réservation'); break; case Class_Multimedia_DeviceHold::QUOTA_DAY: $this->view->quotaError = $this->_('Quota déjà atteint ce jour, choisissez un autre jour.'); break; case Class_Multimedia_DeviceHold::QUOTA_WEEK: $this->view->quotaError = $this->_('Quota déjà atteint cette semaine, choisissez une autre semaine.'); break; case Class_Multimedia_DeviceHold::QUOTA_MONTH: $this->view->quotaError = $this->_('Quota déjà atteint ce mois, choisissez un autre mois.'); break; } } /* Choix valide, passage à l'écran suivant */ if (null != $day && null == $quotaErrorType) { $bean->day = $day; $this->_redirect('/abonne/multimedia-hold-hours'); return; } $this->getRequest()->setParam('day', 0); if (!$bean->isCurrentStateValidForRequest($this->getRequest())) { $this->_redirect('/abonne/'.$bean->currentState()); return; } /* Rendu du calendrier avec les jours sélectionnables */ $location = $bean->getLocation(); $this->view->minDate = $location->getMinDate(); $this->view->maxDate = $location->getMaxDate(); $holidayStamps = array_map( function($item) {return $item * 1000;}, array_merge( Class_Date_Holiday::getTimestampsForYear(), Class_Date_Holiday::getTimestampsForYear(date('Y') + 1) ) ); $js_opened_days = implode(',', array_map( function ($day) { return '"'.$day.'"'; }, $location->getHoldableDays())); $beforeShowDay = 'var result = [true, \'\']; var stamps = [' . implode(', ', $holidayStamps) . ']; $.each(stamps, function(i, stamp) { var holiday = new Date(); holiday.setTime(stamp); if (date.getDate() == holiday.getDate() && date.getMonth() == holiday.getMonth() && date.getFullYear() == holiday.getFullYear()) { result[0] = false; return result; } }); if (-1 == $.inArray($.datepicker.formatDate(\'yy-mm-dd\', date), [' . $js_opened_days . '])) { result[0] = false; } return result;'; $this->view->beforeShowDay = $beforeShowDay; $this->view->location = $bean->getLocation()->getLibelleBib(); $this->view->timelineActions = $this->_getTimelineActions('day'); } public function multimediaHoldHoursAction() { if (!$bean = $this->_getDeviceHoldBean()) return; $location = $bean->getLocation(); if ($this->_getParam('time') && $this->_getParam('duration')) { $holdLoader = Class_Multimedia_DeviceHold::getLoader(); $start = $holdLoader->getTimeFromDayAndTime($bean->day, $this->_getParam('time')); $end = $holdLoader->getTimeFromStartAndDuration($start, $this->_getParam('duration')); if (0 < $holdLoader->countBetweenTimesForUser($start, $end, $this->_user)) { $this->view->error = $this->_('Vous avez déjà une réservation dans ce créneau horaire'); } if ($start < $location->getMinTimeForDate($bean->day) || $end > $location->getMaxTimeForDate($bean->day)) { $this->view->error = $this->_('Ce créneau n\'est pas dans les heures d\'ouverture.'); } if (!$this->view->error) { $bean->time = $this->_getParam('time'); $bean->duration = (int)$this->_getParam('duration'); $this->_redirect('/abonne/multimedia-hold-group'); return; } } $this->view->timelineActions = $this->_getTimelineActions('hours'); $this->view->form = $this->multimediaHoldHoursForm($bean, $location); $this->view->day = strftime('%d %B %Y', strtotime($bean->day)); } public function multimediaHoldHoursForm($bean, $location) { return $this->view ->newForm(['id' => 'hold-hours']) ->setMethod('get') ->addElement('select', 'time', ['label' => $this->_('À partir de quelle heure ?'), 'multiOptions' => $location->getStartTimesForDate($bean->day)]) ->addElement('select', 'duration', ['label' => $this->_('Pour quelle durée ?'), 'multiOptions' => $location->getDurations()]) ->addDisplayGroup(['time', 'duration'], 'choix', ['legend' => '']) ->addElement('submit', 'submit', ['label' => $this->_('Choisir')]); } public function multimediaHoldGroupAction() { if (!$bean = $this->_getDeviceHoldBean()) return; $this->view->groups = $bean->getGroups(); $this->view->timelineActions = $this->_getTimelineActions('group'); $this->view->location = $bean->getLocation()->getLibelleBib(); $this->view->day = strftime('%d %B %Y', strtotime($bean->day)); $this->view->time = str_replace(':', 'h', $bean->time); $this->view->duration = $bean->duration . 'mn'; } public function multimediaHoldDeviceAction() { if (!$bean = $this->_getDeviceHoldBean()) return; $this->view->timelineActions = $this->_getTimelineActions('device'); $this->view->devices = $bean->getGroup()->getHoldableDevicesForDateTimeAndDuration($bean->day, $bean->time, $bean->duration); $this->view->location = $bean->getLocation()->getLibelleBib(); $this->view->day = strftime('%d %B %Y', strtotime($bean->day)); $this->view->time = str_replace(':', 'h', $bean->time); $this->view->duration = $bean->duration . 'mn'; $this->view->group = $bean->getGroup()->getLibelle(); } public function multimediaHoldConfirmAction() { if (!$bean = $this->_getDeviceHoldBean()) return; if ($this->_getParam('validate')) { $hold = Class_Multimedia_DeviceHold::getLoader()->newFromBean($bean); $hold->save(); $this->_redirect('/abonne/multimedia-hold-view/id/' . $hold->getId()); return; } $this->view->timelineActions = $this->_getTimelineActions('confirm'); $this->view->location = $bean->getLocation()->getLibelleBib(); $this->view->day = strftime('%d %B %Y', strtotime($bean->day)); $this->view->time = str_replace(':', 'h', $bean->time); $this->view->duration = $bean->duration . 'mn'; $device = $bean->getDevice(); $this->view->device = $device->getLibelle() . ' - ' . $device->getOs(); } public function multimediaHoldViewAction() { if (null == ($hold = Class_Multimedia_DeviceHold::find((int)$this->_getParam('id')))) { $this->_redirect('/abonne/fiche'); return; } if ($this->_user != $hold->getUser()) { $this->_redirect('/abonne/fiche'); return; } if ($this->_getParam('delete')) { $hold->delete(); $this->_redirect('/abonne/fiche'); return; } $this->view->location = $hold->getLibelleBib(); $this->view->day = strftime('%d %B %Y', $hold->getStart()); $this->view->time = strftime('%Hh%M', $hold->getStart()); $this->view->duration = (($hold->getEnd() - $hold->getStart()) / 60) . 'mn'; $this->view->device = $hold->getLibelleDevice() . ' - ' . $hold->getOs(); } /** * @param $current string * @return array */ protected function _getTimelineActions($current) { $knownActions = ['location' => $this->_('Lieu'), 'day' => $this->_('Jour'), 'hours' => $this->_('Horaires'), 'group' => $this->_('Secteur'), 'device' => $this->_('Poste'), 'confirm' => $this->_('Confirmation')]; $actions = array(); foreach ($knownActions as $knownAction => $label) { $action = $this->_getTimelineActionWithNameAndAction($label, $knownAction); if ($current == $knownAction) $action[ZendAfi_View_Helper_Timeline::CURRENT] = true; $actions[] = $action; } return $actions; } /** @return array */ protected function _getTimelineActionWithNameAndAction($name, $action) { return array(ZendAfi_View_Helper_Timeline::LABEL => $name, ZendAfi_View_Helper_Timeline::CURRENT => false, ZendAfi_View_Helper_Timeline::URL => $this->view->url(array('controller' => 'abonne', 'action' => 'multimedia-hold-' . $action), null, true)); } /** @return stdClass */ protected function _getDeviceHoldBean() { $bean = Class_Multimedia_ReservationBean::current(); if (!$bean->isCurrentStateValidForRequest($this->getRequest())) { $this->_redirect('/abonne/'.$bean->currentState()); return null; } return $bean; } public function suggestionAchatAction() { if (Class_AdminVar::areSuggestionsDisabled()) { $this->_forward('suggestion-achat-inactive'); return; } } public function suggestionAchatAddAction() { if (Class_AdminVar::areSuggestionsDisabled()) { $this->_forward('suggestion-achat-inactive'); return; } if (Class_SuggestionAchat::find($this->_getParam('id'))) { $this->_forward('suggestion-achat-ok'); return; } $form = ZendAfi_Form_SuggestionAchat::forUser($this->_user); $form->setAction($this->view->url()); if ($this->_request->isPost()) { $post = $this->_request->getPost(); unset($post['submit']); $suggestion = $form->newBuySuggest($post); if ($form->isValid($suggestion)) { // $suggestion->save(); always return true without considering webservice answers. UX choice ? $suggestion->save(); try { $suggestion->sendMail('noreply@'.$this->_request->getHttpHost()); } catch (Zend_Mail_Exception $e) { $this->_helper->notify($this->_('Aucun courriel envoyé, erreur: %s', $this->_($e->getMessage()))); } $this->_helper->notify($this->_('Suggestion d\'achat enregistrée')); return $this->_redirect(Class_Url::absolute($this->view->url(['action' => 'suggestion-achat']))); } } $this->view->form = $form; $this->view->preferences = Class_Profil::getCurrentProfil()->getCfgModulesPreferences('abonne', 'suggestion-achat-add'); } public function suggestionAchatOkAction() { if (Class_AdminVar::areSuggestionsDisabled()) { $this->_forward('suggestion-achat-inactive'); return; } } public function suggestionAchatInactiveAction() {} public function webkioskReservationAction() { if ($this->_user->isAbonne()) { $url = Class_WebkioskLink::forUser($this->_user)->url(); $this->_redirect($url); return; } $this->_helper->notify($this->_('Votre abonnement ne vous permet pas de réserver un poste multimédia')); $this->_redirect('/abonne/fiche'); } public function getPaniersJsonAction() { $data[] = $this->_user->getPaniersJson(); if ($this->_user->canAccessBackend()) $data[] = (new Class_Catalogue())->getDomainesJson(['removeCheckbox' => true]); $this->_helper->json($data); } public function loanExportAction() { $this->_helper->viewRenderer->setNoRender(); $datas = []; $cards = new Class_User_Cards($this->_user); $emprunts = $cards ->getLoansWithOutPNB($this->_request->getParams()) ->getArrayCopy(); foreach($emprunts as $emprunt) { if (!$exemplaire = $emprunt->getExemplaireOPAC()) continue; $datas[] = $exemplaire->toUnimarcIso2709(); } $filename = 'prets_' . $this->_user->getId() . '-' . uniqid() . '.txt'; $this->_helper->binaryDownload(implode($datas), $filename); } public function loansHistoryUnimarcExportAction() { $this->_helper->viewRenderer->setNoRender(); $datas = []; $emprunts = $this->_user ->getLoansHistory($this->_request->getParams()); foreach($emprunts as $emprunt) { if (!$exemplaire = $emprunt->getExemplaireOPAC()) continue; $datas[] = $exemplaire->toUnimarcIso2709(); } $filename = 'historique_prets_' . $this->_user->getId() . '-' . uniqid() . '.txt'; $this->_helper->binaryDownload(implode($datas), $filename); } public function barcodesExportAction() { $filename = $this->_('prets_codes_barres_%s_%s%s', $this->_user->getId(), uniqid(), '.csv'); $description = (new Class_TableDescription('loans-barcodes')) ->addColumn('', function($loan) { return $loan->getCodeBarre(); }); $cards = new Class_User_Cards($this->_user); $loans = $cards->getLoansWithOutPNB($this->_request->getParams())->getArrayCopy(); $datas = array_filter($loans); $this->_helper->csv($filename, $this->view->renderCsv($description, $datas)); } public function loansHistoryBarcodesExportAction() { $filename = $this->_('historique_prets_codes_barres_%s_%s%s', $this->_user->getId(), uniqid(), '.csv'); $description = (new Class_TableDescription('loans-barcodes')) ->addColumn('', function($loan) { return $loan->getCodeBarre(); }); $datas = array_filter($this->_user ->getLoansHistory($this->_request->getParams()) ->getArrayCopy()); $this->_helper->csv($filename, $this->view->renderCsv($description, $datas)); } public function manageSettingsAction() { if(!Class_Users::getIdentity()) return $this->_forward('popup-login', 'auth', 'opac', ['redirect' => $this->view->url()]); $this->view->form = $form = ZendAfi_Form_User_Settings::forUser($this->_user); if ($this->_request->isPost()) { $data = $this->_request->getPost(); unset($data['id_items']); $this->_user->setSettings(Class_User_Settings::serializeSettings($data)); $this->_user->save(); $this->_helper->notify($this->_('Favoris sauvegardés')); return $this->_redirectClose($this->_getReferer()); } $this->view->titre = $this->view->_('Gérer mes favoris'); } public function settingsAction() { $this->view->titre = $this->view->_('Mes favoris'); $this->view->bookmarked_searches = Class_User_BookmarkedSearch::findAllBy(['id_user' => $this->_user->getId(), 'order' => 'creation_date desc']); $form = ZendAfi_Form_User_Settings::forUser($this->_user); $this->view->form = $form->getElements() ? $form : null; if ($this->_request->isPost()) $this->_forward('manage-settings'); } public function viewableLibrariesJsonAction() { $this->_helper->json([$this->view->TreeSelect_Json_Libraries(Class_Profil::getCurrentProfil()->getLibraries())]); } public function viewableDomainsJsonAction() { $this->_helper->json([$this->view->TreeSelect_Json_Domains(Class_Catalogue::findAllCataloguesAIndexer())]); } public function addLibraryToBookmarksAction() { $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setNoRender(); $this->_user->addLibraryToBookmarks($this->_getParam('library_id', null)); $this->_user->save(); $this->_javascriptRedirectToReferrer(); } public function removeLibraryFromBookmarksAction() { $viewRenderer = $this->getHelper('ViewRenderer'); $viewRenderer->setNoRender(); $this->_user->removeLibraryFromBookmarks($this->_getParam('library_id', null)); $this->_user->save(); $this->_javascriptRedirectToReferrer(); } 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() { return $this->_unlinkCard(['parent_id' => $this->_user->getId(), 'child_id' => (int)$this->_getParam('id')], function($child) { return $this->_('Vous n\'utilisez plus la carte de %s', $child->getNomComplet()); }); } public function unlinkParentCardAction() { return $this->_unlinkCard(['parent_id' => (int)$this->_getParam('id'), 'child_id' => $this->_user->getId()], function($parent) { return $this->_('Votre carte a été retirée à %s', $parent->getNomComplet()); }); } protected function _unlinkCard($params, $message_callback) { if (!$user = Class_Users::find((int)$this->_getParam('id'))) return $this->_unlinkResponseNotFound(); if (!$lc = Class_LinkedCard::findFirstBy($params)) return $this->_unlinkResponseNotFound(); $lc->delete(); $this->_unlinkResponseDone($message_callback($user)); } protected function _unlinkResponseNotFound() { return $this->_unlinkResponseDone($this->_('Carte introuvable')); } protected function _unlinkResponseDone($message) { $this->_helper->notify($message); $this->_redirect('/abonne/cards'); } public function addCardAction() { $this->view->titre = $this->_('Ajouter une carte'); $form = new ZendAfi_Form(); $form ->addElement('text', 'login', ['label' => 'Identifiant', 'required' => true, 'allowEmpty' => false]) ->addElement('password', 'password', ['label' => 'Mot de passe', 'required' => true, 'allowEmpty' => false]) ->setAction($this->view->url()) ->addDisplayGroup(['login', 'password'], 'add-card', ['legend' => $this->_('Carte')]); $this->view->form = $form; if (!$this->_request->isPost() || !$form->isValid($this->_request->getPost())) return $this; if ((!$child = Class_Users::findFirstBy(['login' => $this->_getPost('login'), 'password' => $this->_getPost('password')])) || !$child->isAbonne()) { $this->_helper->notify($this->_('Identifiant et/ou mot de passe incorrect')); return $this->_redirect('/abonne/add-card'); } if ($child->getId() == $this->_user->getId()) { $this->_helper->notify($this->_('Vous ne pouvez pas ajouter votre propre carte')); return $this->_redirect('/abonne/add-card'); } if (Class_LinkedCard::findFirstBy(['parent_id' => $this->_user->getId(), 'child_id' => $child->getId()])) { $this->_helper->notify($this->_('Vous avez déjà ajouté la carte de "%s"', $child->getNomComplet())); return $this->_redirect('/abonne/add-card'); } if($this->_user->addChildCard($child)->save()) { $this->_helper->notify($this->_('Carte de "%s" ajoutée', $child->getNomComplet())); return $this->_javascriptRedirectToReferrer(); } $this->_helper->notify($this->_('Une erreur s\'est produite en ajoutant la carte de "%s" : %s', $child->getNomComplet(), implode(' ', $this->_user->getErrors()))); $this->_redirect('/abonne/add-card'); } public function discardParentLinkNotificationAction() { $this->getHelper('ViewRenderer')->setNoRender(); $links = explode(';', $this->_getParam('id')); $links = array_map(function($item) { return (int)$item; }, $links); foreach(Class_LinkedCard::findAllBy(['parent_id' => $links, 'child_id' => $this->_user->getId()]) as $link) $link->setNotified(1)->save(); $this->_redirectToReferer(); } public function activitiesAction() { $this->view->titre = $this->_('S\'inscrire à une activité'); $this->view->sessions = Class_SessionActivity::findAllAvailable($this->_user); } public function activitiesRegisteredAction() { $this->view->titre = $this->_('Mes inscriptions en cours'); $this->view->sessions = Class_SessionActivity::findAllRegistered($this->_user); } public function activitiesDoneAction() { $this->view->titre = $this->_('Mes activités suivies'); $this->view->sessions = Class_SessionActivity::findAllDone($this->_user); } public function popupEmailAction() { $this->view->redirect = $redirect = $this->_getParam('redirect'); if(!$user = Class_Users::getIdentity()) return $this->_forward('popup-login', 'auth', 'opac', $redirect); $this->view->form = $form = new ZendAfi_Form_User_Email(); $form->setAction($this->view->url(['controller' => 'abonne', 'action' => 'popup-email', 'redirect' => $redirect], null, true)); if($this->_request->isPost() && $form->isValid($this->_getPost())) $user->setMail($this->_getParam('email'))->save(); if($user->hasMail()) return $this->_redirect($redirect); $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(); } }