|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
/** |
|
4
|
|
|
* PatientCRUD |
|
5
|
|
|
* |
|
6
|
|
|
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED |
|
7
|
|
|
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK. |
|
8
|
|
|
* |
|
9
|
|
|
* Permission is hereby granted to use or copy this program |
|
10
|
|
|
* for any purpose, provided the above notices are retained on all copies. |
|
11
|
|
|
* Permission to modify the code and to distribute modified code is granted, |
|
12
|
|
|
* provided the above notices are retained, and a notice that the code was |
|
13
|
|
|
* modified is included with the above copyright notice. |
|
14
|
|
|
* |
|
15
|
|
|
* @category Wp |
|
16
|
|
|
* @package Punction |
|
17
|
|
|
* @author Andrzej Marcinkowski <[email protected]> |
|
18
|
|
|
* @copyright 2014 Wojewódzki Szpital Zespolony, Kalisz |
|
19
|
|
|
* @license MIT http://opensource.org/licenses/MIT |
|
20
|
|
|
* @version 1.0 $Format:%H$ |
|
21
|
|
|
* @link http:// |
|
22
|
|
|
* @since File available since Release 1.0.0 |
|
23
|
|
|
* PHP Version 5 |
|
24
|
|
|
*/ |
|
25
|
|
|
namespace Hospitalplugin\Entities; |
|
26
|
|
|
|
|
27
|
|
|
use Hospitalplugin\DB\DoctrineBootstrap; |
|
28
|
|
|
use Hospitalplugin\utils\Utils; |
|
29
|
|
|
use Hospitalplugin\Twig\EscapePLCharsExtension; |
|
30
|
|
|
use Hospitalplugin\Entities\WardCRUD; |
|
31
|
|
|
use Hospitalplugin\Twig\PLTwig; |
|
32
|
|
|
|
|
33
|
|
|
class HospitalForm { |
|
34
|
|
|
public static function load($yaml, $class, $dir) { |
|
|
|
|
|
|
35
|
|
|
try { |
|
36
|
|
|
$em = DoctrineBootstrap::getEntityManager (); |
|
37
|
|
|
|
|
38
|
|
|
$userId = $userId = wp_get_current_user ()->ID; |
|
39
|
|
|
$ward = WardCRUD::getWardForUser ( $userId ); |
|
40
|
|
|
$user = $em->find ( "\Hospitalplugin\Entities\User", $userId ); |
|
41
|
|
|
|
|
42
|
|
|
if (! empty ( $_POST )) { |
|
43
|
|
|
$args = $_POST; |
|
44
|
|
|
$i = new $class ( $args ); |
|
45
|
|
|
$i->setWard ( $ward ); |
|
46
|
|
|
$i->setUser ( $user ); |
|
47
|
|
|
$em->persist ( $i ); |
|
48
|
|
|
$em->flush (); |
|
49
|
|
|
} else { |
|
50
|
|
|
$object = \Hospitalplugin\utils\YAML2Object::getObject ( $yaml ); |
|
51
|
|
|
echo PLTwig::load ( $dir )->render ( 'form.twig', array ( |
|
52
|
|
|
'infections' => $object |
|
53
|
|
|
) ); |
|
54
|
|
|
} |
|
55
|
|
|
} catch ( Exception $e ) { |
|
|
|
|
|
|
56
|
|
|
echo "ERR: " . $e; |
|
57
|
|
|
} |
|
58
|
|
|
} |
|
59
|
|
|
} |
|
60
|
|
|
?> |
|
|
|
|
|
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: