@@ -267,7 +267,7 @@ public function renderConstants()
267267 return $ this ->renderFile ();
268268 }
269269
270- public function renderConstantsTestInterface ()
270+ public function renderConstantsInterface_Version_Zyspec ()
271271 {
272272 $ pc = Modulebuilder \Files \CreatePhpCode::getInstance ();
273273
@@ -283,14 +283,29 @@ public function renderConstantsTestInterface()
283283 $ contentFile = $ this ->getHeaderFilesComments ($ module , null , $ namespace );
284284 $ contentFile .= $ pc ->getPhpCodeDefined ();
285285 $ contentFile .= $ pc ->getPhpCodeCommentMultiLine (['Interface ' => $ this ->className ]);
286- $ contentClass = '' ;
286+
287+ $ contentClass = $ pc ->getPhpCodeBlankLine ();
288+ $ contentClass .= $ pc ->getPhpCodeCommentLine ('Constants for tables ' , '' , "\t" );
289+ foreach (array_keys ($ tables ) as $ t ) {
290+ $ tablePermissions [] = $ tables [$ t ]->getVar ('table_permissions ' );
291+ $ stuTableName = mb_strtoupper ($ tables [$ t ]->getVar ('table_name ' ));
292+ $ contentClass .= $ pc ->getPhpCodeConstant ("TABLE_ " . $ stuTableName , $ t , "\t" ,'protected static ' );
293+ }
294+
295+ $ contentClass .= $ pc ->getPhpCodeBlankLine ();
296+ $ contentClass .= $ pc ->getPhpCodeCommentLine ('Constants for status ' , '' , "\t" );
297+ $ contentClass .= $ pc ->getPhpCodeConstant ("STATUS_NONE " , 0 , "\t" ,'protected static ' );
298+ $ contentClass .= $ pc ->getPhpCodeConstant ("STATUS_OFFLINE " , 1 , "\t" ,'protected static ' );
299+ $ contentClass .= $ pc ->getPhpCodeConstant ("STATUS_SUBMITTED " , 2 , "\t" ,'protected static ' );
300+ $ contentClass .= $ pc ->getPhpCodeConstant ("STATUS_APPROVED " , 3 , "\t" ,'protected static ' );
301+ $ contentClass .= $ pc ->getPhpCodeConstant ("STATUS_BROKEN " , 4 , "\t" ,'protected static ' );
287302 if (in_array (1 , $ tablePermissions )) {
288303 $ constPerm = $ pc ->getPhpCodeBlankLine ();
289304 $ constPerm .= $ pc ->getPhpCodeCommentLine ('Constants for permissions ' , '' , "\t" );
290- $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_NONE " , 0 , 'protected static ' , "\t" );
291- $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_VIEW " , 1 , 'protected static ' , "\t" );
292- $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_SUBMIT " , 2 , 'protected static ' , "\t" );
293- $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_APPROVE " , 3 , 'protected static ' , "\t" );
305+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_NONE " , 0 , "\t" , 'protected static ' );
306+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_VIEW " , 1 ,"\t" , 'protected static ' );
307+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_SUBMIT " , 2 ,"\t" , 'protected static ' );
308+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_APPROVE " , 3 ,"\t" , 'protected static ' );
294309 $ contentClass .= $ constPerm ;
295310 }
296311 $ contentClass .= $ pc ->getPhpCodeBlankLine ();
@@ -308,4 +323,66 @@ public function renderConstantsTestInterface()
308323 return $ this ->renderFile ();
309324 }
310325
326+ public function renderConstantsInterface ()
327+ {
328+ $ pc = Modulebuilder \Files \CreatePhpCode::getInstance ();
329+
330+ $ module = $ this ->getModule ();
331+ $ filename = $ this ->getFileName ();
332+ $ tables = $ this ->getTables ();
333+ $ tablePermissions = [];
334+ foreach (array_keys ($ tables ) as $ t ) {
335+ $ tablePermissions [] = $ tables [$ t ]->getVar ('table_permissions ' );
336+ }
337+ $ moduleDirname = $ module ->getVar ('mod_dirname ' );
338+ $ ucfModuleDirname = ucfirst ($ moduleDirname );
339+ $ namespace = $ pc ->getPhpCodeNamespace (['XoopsModules ' , $ moduleDirname ]);
340+ $ contentFile = $ this ->getHeaderFilesComments ($ module , null , $ namespace );
341+ $ contentFile .= $ pc ->getPhpCodeDefined ();
342+ $ contentFile .= $ pc ->getPhpCodeBlankLine ();
343+
344+ $ contentInterface = $ pc ->getPhpCodeCommentMultiLine (['Interface ' => $ ucfModuleDirname . 'Interface ' ]);
345+
346+
347+ $ contentInterface .= $ pc ->getPhpCodeCommentLine ('Constants for tables ' , '' , "\t" );
348+ foreach (array_keys ($ tables ) as $ t ) {
349+ $ tablePermissions [] = $ tables [$ t ]->getVar ('table_permissions ' );
350+ $ stuTableName = mb_strtoupper ($ tables [$ t ]->getVar ('table_name ' ));
351+ $ contentInterface .= $ pc ->getPhpCodeConstant ("TABLE_ " . $ stuTableName , $ t , "\t" ,'public const ' );
352+ }
353+
354+ $ contentInterface .= $ pc ->getPhpCodeBlankLine ();
355+ $ contentInterface .= $ pc ->getPhpCodeCommentLine ('Constants for status ' , '' , "\t" );
356+ $ contentInterface .= $ pc ->getPhpCodeConstant ("STATUS_NONE " , 0 , "\t" ,'public const ' );
357+ $ contentInterface .= $ pc ->getPhpCodeConstant ("STATUS_OFFLINE " , 1 , "\t" ,'public const ' );
358+ $ contentInterface .= $ pc ->getPhpCodeConstant ("STATUS_SUBMITTED " , 2 , "\t" ,'public const ' );
359+ $ contentInterface .= $ pc ->getPhpCodeConstant ("STATUS_APPROVED " , 3 , "\t" ,'public const ' );
360+ $ contentInterface .= $ pc ->getPhpCodeConstant ("STATUS_BROKEN " , 4 , "\t" ,'public const ' );
361+ if (in_array (1 , $ tablePermissions )) {
362+ $ constPerm = $ pc ->getPhpCodeBlankLine ();
363+ $ constPerm .= $ pc ->getPhpCodeCommentLine ('Constants for permissions ' , '' , "\t" );
364+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_NONE " , 0 , "\t" ,'public const ' );
365+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_VIEW " , 1 ,"\t" , 'public const ' );
366+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_SUBMIT " , 2 ,"\t" , 'public const ' );
367+ $ constPerm .= $ pc ->getPhpCodeConstant ("PERM_GLOBAL_APPROVE " , 3 ,"\t" , 'public const ' );
368+ $ contentInterface .= $ constPerm ;
369+ }
370+ $ contentInterface .= $ pc ->getPhpCodeBlankLine ();
371+ $ contentFile .= $ pc ->getPhpCodeInterface ($ ucfModuleDirname . 'Interface ' , $ contentInterface );
372+ $ contentFile .= $ pc ->getPhpCodeBlankLine ();
373+
374+ $ contentClass = $ pc ->getPhpCodeBlankLine ();
375+ $ func = $ pc ->getPhpCodeCommentLine ('trigger a warning if invalid "constant" requested ' , '' , "\t\t" );
376+ $ if = $ pc ->getPhpCodeTriggerError ("\"Invalid Constant requested ('{ \$val}') \"" , 'E_USER_WARNING ' , "\t\t\t" );
377+ $ if .= $ this ->getSimpleString ("return false; " , "\t\t\t" );
378+ $ func .= $ pc ->getPhpCodeConditions ('!defined(constant("self::$val")) ' , null , null , $ if , false , "\t\t" );
379+ $ func .= $ this ->getSimpleString ('return constant("self::$val"); ' , "\t" );
380+ $ contentClass .= $ pc ->getPhpCodeFunction ('getConstant ' , '$val ' , $ func , 'final public static ' , false , "\t" );
381+
382+ $ contentFile .= $ pc ->getPhpCodeClass ($ this ->className , $ contentClass , null , null , $ ucfModuleDirname . 'Interface ' );
383+
384+ $ this ->create ($ moduleDirname , 'class ' , $ filename , $ contentFile , _AM_MODULEBUILDER_FILE_CREATED , _AM_MODULEBUILDER_FILE_NOTCREATED );
385+
386+ return $ this ->renderFile ();
387+ }
311388}
0 commit comments