Commit 193359b5 authored by lecluse's avatar lecluse
Browse files

Mise à niveau des templates et nouveaux générateurs de code

parent 3a394059
......@@ -23,50 +23,35 @@ $form->add(ElementMaker::text('alias', 'Alias d\'entité'));
$form->add(ElementMaker::submit('generate', 'Générer le service'));
$form->setData($controller->getRequest()->getPost());
echo $this->form()->openTag($form->prepare());
echo $this->formControlGroup($form->get('entity'));
echo $this->formControlGroup($form->get('alias'));
echo $this->formRow($form->get('generate'));
echo $this->form()->closeTag();
Util::displayForm($form);
if ($controller->getRequest()->isPost() && $form->isValid()) {
$module = 'Application';
$entity = $form->get('entity')->getValue();
$name = 'application'.$entity;
$nsclassname = $module . '\\Service\\' . $entity . 'Service';
$params = [
'module' => $module,
'entity' => $entity,
'alias' => $form->get('alias')->getValue(),
'name' => $name,
'classname' => Util::baseClassName($nsclassname),
'namespace' => Util::namespaceClass($nsclassname),
'wmclassname' => Util::truncatedClassName($module, $nsclassname),
'author' => Util::getAuthor(),
];
$fileName = Util::classNameToFileName($nsclassname);
$configFileName = 'module.config.php';
$module = 'Application';
$entity = $form->get('entity')->getValue();
$alias = $form->get('alias')->getValue();
$name = 'application' . $entity;
$targetFullClass = $module . '\\Service\\' . $entity . 'Service';
$sCodeGenerator = $controller->getServiceLocator()->get('UnicaenCode\CodeGenerator');
/* @var $sCodeGenerator \UnicaenCode\Service\CodeGenerator */
$params = $sCodeGenerator->generateServiceParams($targetFullClass, $name, $module);
$params['entity'] = $entity;
$params['alias'] = $alias;
$configFileName = 'module.config.php';
?>
<h3>Etape 2 : Création des fichiers sources du service</h3>
<?php
$sCodeGenerator->setTemplate('EntityService')->setParams($params)->generateToHtml($fileName)->generateToFile($fileName);
$sCodeGenerator->setTemplate('EntityService')->setParams($params)->generateToHtml($params['fileName'])->generateToFile($params['fileName']);
$p = $sCodeGenerator->generateServiceTraitParams($nsclassname, $name, $module.'\Service');
$fileName = $p['fileName'];
$sCodeGenerator->setTemplate('ServiceAwareTrait')->setParams($p)->generateToHtml($fileName)->generateToFile($fileName);
$p = $sCodeGenerator->generateServiceTraitParams($targetFullClass, $name, $module . '\Service');
$sCodeGenerator->setTemplate('ServiceAwareTrait')->setParams($p)->generateToHtml($p['fileName'])->generateToFile($p['fileName']);
$p = $sCodeGenerator->generateServiceInterfaceParams($nsclassname, $name, $module.'\Service');
$fileName = $p['fileName'];
$sCodeGenerator->setTemplate('ServiceAwareInterface')->setParams($p)->generateToHtml($fileName)->generateToFile($fileName);
$p = $sCodeGenerator->generateServiceInterfaceParams($targetFullClass, $name, $module . '\Service');
$sCodeGenerator->setTemplate('ServiceAwareInterface')->setParams($p)->generateToHtml($p['fileName'])->generateToFile($p['fileName']);
?>
<div class="alert alert-info">Les fichiers sont récupérables dans le
......
<?php
use UnicaenCode\Form\ElementMaker;
use UnicaenCode\Util;
/**
* @var $this \Zend\View\Renderer\PhpRenderer
* @var $controller \Zend\Mvc\Controller\AbstractController
* @var $viewName string
*/
?>
<h1>Création d'un nouveau formulaire OSE (hérité d'AbstractForm)</h1>
<h3>Etape 1 : Paramétrage</h3>
<?php
$form = new \Zend\Form\Form();
$form->add(ElementMaker::selectModule(
'module', 'Module dans lequel sera placé votre formulaire'
));
$form->add(ElementMaker::text(
'classname', 'Nom de classe du formulaire (en CamelCase, avec éventuellement un namespace avant : MonNamespace\Exemple)', 'Exemple'
));
$form->add(ElementMaker::checkbox(
'useHydrator', 'Implémenter un hydrateur spécifique'
));
$form->add(ElementMaker::submit('generate', 'Générer le formulaire'));
$form->setData($controller->getRequest()->getPost());
Util::displayForm($form);
if ($controller->getRequest()->isPost() && $form->isValid()) {
$module = $form->get('module')->getValue();
$useHydrator = $form->get('useHydrator')->getValue();
$classname = $form->get('classname')->getValue();
$name = str_replace('\\', '', $classname);
$targetFullClass = $module . '\\Form\\' . $classname . 'Form';
$sCodeGenerator = $controller->getServiceLocator()->get('UnicaenCode\CodeGenerator');
/* @var $sCodeGenerator \UnicaenCode\Service\CodeGenerator */
$params = $sCodeGenerator->generateFormParams($targetFullClass, 'Form', $name, $module, $useHydrator);
$params['useSubForm'] = false !== strpos($classname,'\\');
$configFileName = 'module.config.php';
?>
<h3>Etape 2 : Création des fichiers sources du formulaire</h3>
<?php
$sCodeGenerator->setTemplate('Form')->setParams($params)->generateToHtml($params['fileName'])->generateToFile($params['fileName']);
$p = $sCodeGenerator->generateFormTraitParams($targetFullClass, $name, $module . '\Form');
$sCodeGenerator->setTemplate('FormAwareTrait')->setParams($p)->generateToHtml($p['fileName'])->generateToFile($p['fileName']);
$p = $sCodeGenerator->generateFormInterfaceParams($targetFullClass, $name, $module . '\Form');
$sCodeGenerator->setTemplate('FormAwareInterface')->setParams($p)->generateToHtml($p['fileName'])->generateToFile($p['fileName']);
?>
<div class="alert alert-info">Les fichiers sont récupérables dans le
dossier <?php echo $sCodeGenerator->getOutputDir() ?></div>
<h3>Etape 3 : Déclaration dans le fichier de configuration</h3>
<?php $sCodeGenerator->setTemplate('FormConfig')->setParams($params)->generateToHtml($configFileName); ?>
<div class="alert alert-warning">
Vous devez vous-même placer ces informations dans le fichier de configuration de votre
module.
</div>
<?php
}
\ No newline at end of file
<?php
namespace <namespace>;
<if useSubForm>
use Application\Form\AbstractForm;
<endif useSubForm>
<if useHydrator>
use Zend\Stdlib\Hydrator\HydratorInterface;
<endif useHydrator>
/**
* Description of <classname>
*
* @author <author>
*/
class <classname> extends AbstractForm
{
public function init()
{
<if useHydrator>
$hydrator = new <classname>Hydrator;
$this->setHydrator($hydrator);
<endif useHydrator>
$this->setAttribute('action',$this->getCurrentUrl());
/* Ajoutez vos éléments de formulaire ici */
$this->add([
'name' => 'submit',
'type' => 'Submit',
'attributes' => [
'value' => 'Enregistrer',
'class' => 'btn btn-primary',
],
]);
}
/**
* Should return an array specification compatible with
* {@link Zend\InputFilter\Factory::createInputFilter()}.
*
* @return array
*/
public function getInputFilterSpecification()
{
return [
/* Filtres et validateurs */
];
}
}
<if useHydrator>
class <classname>Hydrator implements HydratorInterface
{
/**
* @param array $data
* @param $object
*
* @return object
*/
public function hydrate(array $data, $object)
{
/* on peuple l'objet à partir du tableau de données */
return $object;
}
/**
* @param $object
*
* @return array
*/
public function extract($object)
{
$data = [
/* On peuple le tableau avec les données de l'objet */
];
return $data;
}
}
<endif useHydrator>
\ No newline at end of file
......@@ -8,9 +8,9 @@ join intervenant i on i.id = ie.intervenant_id
join wf_etape e on e.id = ie.etape_id
left join structure s on s.id = ie.structure_id
where
i.source_code = '2298'
i.id = 517
--and ie.structure_id is null
AND i.annee_id = 2015
order by e.ordre;
......@@ -48,8 +48,10 @@ values (
*/
begin
ose_workflow.update_intervenant_etapes(35465);
--ose_workflow.update_all_intervenants_etapes;
DBMS_OUTPUT.ENABLE;
-- ose_workflow.update_intervenant_etapes(517);
ose_workflow.update_all_intervenants_etapes(2014);
end;
/
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