[Eleves] Déplacement du code dans EleveManager
This commit is contained in:
parent
1ace33f690
commit
1ebeee196e
5 changed files with 56 additions and 25 deletions
|
@ -3,6 +3,7 @@
|
||||||
use YesWiki\Core\YesWikiAction;
|
use YesWiki\Core\YesWikiAction;
|
||||||
use YesWiki\Bazar\Service\EntryManager;
|
use YesWiki\Bazar\Service\EntryManager;
|
||||||
use YesWiki\Bazar\Service\ListManager;
|
use YesWiki\Bazar\Service\ListManager;
|
||||||
|
use YesWiki\Meeo\Service\EleveManager;
|
||||||
|
|
||||||
class ElevesAction extends YesWikiAction
|
class ElevesAction extends YesWikiAction
|
||||||
{
|
{
|
||||||
|
@ -13,16 +14,7 @@ class ElevesAction extends YesWikiAction
|
||||||
|
|
||||||
public function run()
|
public function run()
|
||||||
{
|
{
|
||||||
$meeo_config = $this->params->get('meeo');
|
$eleveManager = $this->getService(EleveManager::class);
|
||||||
$formId = $meeo_config['elevesFormId'];
|
return $eleveManager->view();
|
||||||
|
|
||||||
$entryManager = $this->getService(EntryManager::class);
|
|
||||||
$eleves = $entryManager->search(['formsIds' => $formId]);
|
|
||||||
// echo '<p>'.var_dump($eleves).'</p>';
|
|
||||||
|
|
||||||
$listManager = $this->getService(ListManager::class);
|
|
||||||
$classes = $listManager->getOne('ListeClasses');
|
|
||||||
|
|
||||||
return $this->render('@meeo/edu_eleves.twig', ['eleves' => $eleves, 'classes' => $classes['label']]);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -10,9 +10,9 @@ services:
|
||||||
autowire: true
|
autowire: true
|
||||||
public: true
|
public: true
|
||||||
|
|
||||||
# YesWiki\MeeO\Service\:
|
YesWiki\Meeo\Service\:
|
||||||
# resource: 'services/*'
|
resource: 'services/*'
|
||||||
|
|
||||||
# Allows to use controllers as services
|
# Allows to use controllers as services
|
||||||
YesWiki\MeeO\Controller\:
|
# YesWiki\MeeO\Controller\:
|
||||||
resource: 'controllers/*'
|
# resource: 'controllers/*'
|
||||||
|
|
|
@ -6,33 +6,30 @@ use Symfony\Component\HttpFoundation\Response;
|
||||||
use Symfony\Component\Routing\Annotation\Route;
|
use Symfony\Component\Routing\Annotation\Route;
|
||||||
use YesWiki\Core\ApiResponse;
|
use YesWiki\Core\ApiResponse;
|
||||||
use YesWiki\Core\YesWikiController;
|
use YesWiki\Core\YesWikiController;
|
||||||
|
use YesWiki\Meeo\Service\EleveManager;
|
||||||
|
|
||||||
class ApiController extends YesWikiController
|
class ApiController extends YesWikiController
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}})
|
* @Route("/api/meeo/eleves",methods={"POST"},options={"acl":{"public"}})
|
||||||
*/
|
*/
|
||||||
public function eleveUpdate(Request $request) {
|
public function eleveUpdate(Request $request) {
|
||||||
|
$eleveController = $this->getService(EleveManager::class);
|
||||||
$content = $request->getContent();
|
$content = $request->getContent();
|
||||||
|
|
||||||
parse_str($content, $parameters);
|
parse_str($content, $parameters);
|
||||||
|
|
||||||
$result = [];
|
$datas = [];
|
||||||
|
|
||||||
foreach ($parameters as $cle => $valeur) {
|
foreach ($parameters as $cle => $valeur) {
|
||||||
$clef_action = explode('_', $cle);
|
$clef_action = explode('_', $cle);
|
||||||
if ($clef_action[1] == 'classe' && $valeur != 'aucune') {
|
if ($clef_action[1] == 'classe' && $valeur != 'aucune') {
|
||||||
$result[] = 'Change la classe de '.$clef_action[0].' pour '.$valeur;
|
$datas[] = $eleveController->updateClasse($clef_action[0], $valeur);
|
||||||
}
|
}
|
||||||
if ($clef_action[1] == 'del') {
|
if ($clef_action[1] == 'del') {
|
||||||
$result[] = 'Suppression de '.$clef_action[0];
|
$eleveController->del($clef_action[0]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return new ApiResponse(
|
return $this->wiki->redirect('?Eleves', 200);
|
||||||
['result'=> $result],
|
|
||||||
Response::HTTP_CREATED
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
42
services/EleveManager.php
Normal file
42
services/EleveManager.php
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
<?php
|
||||||
|
|
||||||
|
namespace YesWiki\Meeo\Service;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ParameterBag\ParameterBagInterface;
|
||||||
|
use YesWiki\Bazar\Service\EntryManager;
|
||||||
|
use YesWiki\Bazar\Service\ListManager;
|
||||||
|
use YesWiki\Wiki;
|
||||||
|
|
||||||
|
class EleveManager {
|
||||||
|
|
||||||
|
private $formId;
|
||||||
|
private $entryManager;
|
||||||
|
private $listManager;
|
||||||
|
private $wiki;
|
||||||
|
|
||||||
|
public function __construct( Wiki $wiki, ParameterBagInterface $params, EntryManager $entryManager, ListManager $listManager)
|
||||||
|
{
|
||||||
|
$meeo_config = $params->get('meeo');
|
||||||
|
$this->wiki = $wiki;
|
||||||
|
$this->formId = $meeo_config['elevesFormId'];
|
||||||
|
$this->entryManager = $entryManager;
|
||||||
|
$this->listManager = $listManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function del($id) {
|
||||||
|
$this->entryManager->delete($id);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function updateClasse($id, $classe) {
|
||||||
|
return $this->entryManager->update($id, ['listeListeClassesbf_classe' => $classe, 'antispam' => true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function view() {
|
||||||
|
$eleves = $this->entryManager->search(['formsIds' => $this->formId]);
|
||||||
|
// echo '<p>'.var_dump($eleves).'</p>';
|
||||||
|
|
||||||
|
$classes = $this->listManager->getOne('ListeClasses');
|
||||||
|
|
||||||
|
return $this->wiki->render('@meeo/edu_eleves.twig', ['eleves' => $eleves, 'classes' => $classes['label']]);
|
||||||
|
}
|
||||||
|
}
|
|
@ -11,7 +11,7 @@
|
||||||
<div class="col-sm-3">
|
<div class="col-sm-3">
|
||||||
<select id="{{eleve['id_fiche']}}_classe" name="{{eleve['id_fiche']}}_classe" class="form-control">
|
<select id="{{eleve['id_fiche']}}_classe" name="{{eleve['id_fiche']}}_classe" class="form-control">
|
||||||
{% for identifier, classe in classes %}
|
{% for identifier, classe in classes %}
|
||||||
<option value="{{identifier}}">{{classe}}</option>
|
<option value="{{identifier}}" {% if eleve['listeListeClassesbf_classe'] == identifier %}selected{% endif %} >{{classe}}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
</select>
|
</select>
|
||||||
</div>
|
</div>
|
||||||
|
|
Loading…
Reference in a new issue