3939 */
4040class PluginFlyvemdmPolicyApn extends PluginFlyvemdmPolicyBase implements PluginFlyvemdmPolicyInterface {
4141
42+ private $ formFields = [];
43+ private $ apnAuthType = [];
44+ private $ apnType = [];
45+
4246 /**
4347 * PluginFlyvemdmPolicyApn constructor.
4448 * @param PluginFlyvemdmPolicy $policy
4549 */
4650 public function __construct (PluginFlyvemdmPolicy $ policy ) {
51+ $ this ->formFields = [
52+ 'apn_name ' => ['label ' => __ ('Name ' , 'flyvemdm ' ), 'type ' => 'text ' ],
53+ 'apn_fqn ' => ['label ' => __ ('APN ' , 'flyvemdm ' ), 'type ' => 'text ' ],
54+ 'apn_proxy ' => ['label ' => __ ('Proxy ' , 'flyvemdm ' ), 'type ' => 'text ' ],
55+ 'apn_port ' => ['label ' => __ ('Port ' , 'flyvemdm ' ), 'type ' => 'text ' ],
56+ 'apn_username ' => ['label ' => __ ('Username ' , 'flyvemdm ' ), 'type ' => 'text ' ],
57+ 'apn_password ' => ['label ' => __ ('Password ' , 'flyvemdm ' ), 'type ' => 'password ' ],
58+ 'apn_server ' => ['label ' => __ ('Server ' , 'flyvemdm ' ), 'type ' => 'text ' ],
59+ 'apn_mmsc ' => ['label ' => __ ('MMSC ' , 'flyvemdm ' ), 'type ' => 'text ' ],
60+ 'apn_proxy_mms ' => ['label ' => __ ('Proxy MMS ' , 'flyvemdm ' ), 'type ' => 'text ' ],
61+ 'apn_proxy_mms_port ' => ['label ' => __ ('Proxy MMC port ' , 'flyvemdm ' ), 'type ' => 'text ' ],
62+ 'apn_mmc ' => ['label ' => __ ('MMC ' , 'flyvemdm ' ), 'type ' => 'text ' ],
63+ 'apn_mnc ' => ['label ' => __ ('MNC ' , 'flyvemdm ' ), 'type ' => 'text ' ],
64+ ];
65+ $ this ->apnType = [__ ('Default ' ), 'MMS ' , 'SUPL ' , 'DUN ' , 'HIPRI ' , 'FOTA ' ];
66+ $ this ->apnAuthType = [__ ('No authentication ' ), 'PAP ' , 'CHAP ' , 'CHAP/PAP ' ];
4767 parent ::__construct ($ policy );
4868 $ this ->symbol = $ policy ->getField ('symbol ' );
4969 $ this ->unicityRequired = ($ policy ->getField ('unicity ' ) != '0 ' );
@@ -58,12 +78,13 @@ public function __construct(PluginFlyvemdmPolicy $policy) {
5878 */
5979 public function integrityCheck ($ value , $ itemtype , $ itemId ) {
6080 // Check the value exists
61- $ inputNames = ['name ' , 'apn ' ];
62- foreach ($ inputNames as $ key ){
63- if (!isset ($ value [$ key ])) {
64- Session::addMessageAfterRedirect (sprintf (__ ('A value for "%s" is mandatory ' , 'flyvemdm ' ), $ value ));
65- return false ;
66- }
81+ if (!isset ($ value ['apn_name ' ]) || !$ value ['apn_name ' ]) {
82+ Session::addMessageAfterRedirect (__ ('APN name is mandatory ' , 'flyvemdm ' ));
83+ return false ;
84+ }
85+ if (!isset ($ value ['apn_fqn ' ]) || !$ value ['apn_fqn ' ]) {
86+ Session::addMessageAfterRedirect (__ ('APN value is mandatory ' , 'flyvemdm ' ));
87+ return false ;
6788 }
6889 return true ;
6990 }
@@ -75,11 +96,12 @@ public function integrityCheck($value, $itemtype, $itemId) {
7596 * @return array|bool
7697 */
7798 public function getMqttMessage ($ value , $ itemtype , $ itemId ) {
78- if (!$ this ->integrityCheck ($ value , $ itemtype , $ itemId )) {
99+ $ decodedValue = json_decode ($ value , JSON_OBJECT_AS_ARRAY );
100+ if (!$ this ->integrityCheck ($ decodedValue , $ itemtype , $ itemId )) {
79101 return false ;
80102 }
81103 $ array = [
82- $ this ->symbol => $ value
104+ $ this ->symbol => $ value,
83105 ];
84106 return $ array ;
85107 }
@@ -88,47 +110,39 @@ public function showValueInput($value = '', $itemType = '', $itemId = 0) {
88110
89111 $ value = json_decode ($ value , JSON_OBJECT_AS_ARRAY );
90112
91- $ fields = [
92- 'apn_name ' => ['label ' => 'Name ' , 'type ' => 'text ' ],
93- 'apn_apn ' => ['label ' => 'APN ' , 'type ' => 'text ' ],
94- 'apn_proxy ' => ['label ' => 'Proxy ' , 'type ' => 'text ' ],
95- 'apn_port ' => ['label ' => 'Port ' , 'type ' => 'text ' ],
96- 'apn_username ' => ['label ' => 'Username ' , 'type ' => 'text ' ],
97- 'apn_password ' => ['label ' => 'Password ' , 'type ' => 'password ' ],
98- 'apn_server ' => ['label ' => 'Server ' , 'type ' => 'text ' ],
99- 'apn_mmsc ' => ['label ' => 'MMSC ' , 'type ' => 'text ' ],
100- 'apn_proxy_mms ' => ['label ' => 'Proxy MMS ' , 'type ' => 'text ' ],
101- 'apn_proxy_mms_port ' => ['label ' => 'Proxy MMC port ' , 'type ' => 'text ' ],
102- 'apn_mmc ' => ['label ' => 'MMC ' , 'type ' => 'text ' ],
103- 'apn_mnc ' => ['label ' => 'MNC ' , 'type ' => 'text ' ],
104- ];
105-
106113 $ data = [];
107- foreach ($ fields as $ inputName => $ inputOptions ) {
114+ foreach ($ this -> formFields as $ inputName => $ inputOptions ) {
108115 $ data ['inputs ' ][] = [
109- 'id ' => $ inputName ,
116+ 'name ' => " value[ $ inputName] " ,
110117 'label ' => $ inputOptions ['label ' ],
111118 'type ' => $ inputOptions ['type ' ],
112119 'value ' => ($ value [$ inputName ]) ? $ value [$ inputName ] : '' ,
113120 ];
114121 }
115122
116- $ apnAuthType = Dropdown::showFromArray ('apn_auth_type ' ,
117- ['No authentication ' , 'PAP ' , 'CHAP ' , 'CHAP/PAP ' ], ['display ' => false ]);
118- $ apnType = Dropdown::showFromArray ('apn_type ' ,
119- ['default ' , 'mms ' , 'supl ' , 'dun ' , 'hipri ' , 'fota ' ], ['display ' => false ]);
123+ $ apnAuthType = ($ value ['apn_auth_type ' ]) ? $ value ['apn_auth_type ' ] : 0 ;
124+ $ apnType = ($ value ['apn_type ' ]) ? $ value ['apn_type ' ] : 0 ;
120125
121126 $ data ['apnAuthType ' ] = [
122- 'label ' => 'Authentication Type ' ,
123- 'dropdown ' => $ apnAuthType ,
127+ 'label ' => 'Authentication Type ' ,
128+ 'dropdown ' => Dropdown::showFromArray ('value[apn_auth_type] ' ,
129+ $ this ->apnAuthType ,
130+ ['display ' => false , 'value ' => $ apnAuthType ]),
124131 ];
125132 $ data ['apnType ' ] = [
126- 'label ' => 'APN Type ' ,
127- 'dropdown ' => $ apnType ,
133+ 'label ' => 'APN Type ' ,
134+ 'dropdown ' => Dropdown::showFromArray ('value[apn_type] ' ,
135+ $ this ->apnType ,
136+ ['display ' => false , 'value ' => $ apnType ]),
128137 ];
129138
130139 $ twig = plugin_flyvemdm_getTemplateEngine ();
131140 return $ twig ->render ('policy_apn_form.html.twig ' , $ data );
132141 }
133142
143+ public function showValue (PluginFlyvemdmTask $ task ) {
144+ $ values = json_decode ($ task ->getField ('value ' ), JSON_OBJECT_AS_ARRAY );
145+ $ stringValues = $ values ['apn_name ' ];
146+ return $ stringValues ;
147+ }
134148}
0 commit comments