@@ -90,20 +90,96 @@ function convert_key_type($key, $type, $required, $indentation) {
9090/**
9191 * Print structure ready to use.
9292 */
93- function print_ws_structure ($ name , $ structure , $ useparams ) {
93+ function print_ws_structures ($ structures ) {
94+ foreach ($ structures as $ wsname => $ structure ) {
95+ $ type = getTSTypeFromName ($ wsname );
96+
97+ print_ws_structure ($ wsname , $ type , $ structure , true );
98+ print_ws_structure ($ wsname , $ type , $ structure , false );
99+ }
100+ }
101+
102+ /**
103+ * Print params or return structures.
104+ */
105+ function print_ws_structure ($ wsname , $ type , $ structure , $ useparams ) {
94106 if ($ useparams ) {
95- $ type = implode ('' , array_map ('ucfirst ' , explode ('_ ' , $ name ))) . 'WSParams ' ;
96- $ comment = "Params of $ name WS. " ;
107+ $ comment = "Params of $ wsname WS. " ;
108+ $ type .= 'WSParams ' ;
109+ $ typestructure = $ structure ->parameters_desc ;
110+ $ export = '' ;
97111 } else {
98- $ type = implode ('' , array_map ('ucfirst ' , explode ('_ ' , $ name ))) . 'WSResponse ' ;
99- $ comment = "Data returned by $ name WS. " ;
112+ $ comment = "Data returned by $ wsname WS. " ;
113+ $ type .= 'WSResponse ' ;
114+ $ typestructure = $ structure ->returns_desc ;
115+ $ export = 'export ' ;
100116 }
101117
102118 echo "
103119/**
104- * $ comment
120+ * $ comment " ;
121+ if (!empty ($ structure ->description )) {
122+ echo "
123+ *
124+ * WS Description: $ structure ->description " ;
125+ }
126+ if (isset ($ structure ->deprecated ) && $ structure ->deprecated ) {
127+ echo "
128+ *
129+ * @deprecatedonmoodle since ADDVERSIONHERE. This WS method is deprecated " ;
130+ }
131+ /* echo "
132+ * WS Type: $structure->type
133+ * Allowed from AJAX: " . ($structure->allowed_from_ajax ? 'yes' : 'no') . "
134+ * Read only session: " . ($structure->readonlysession ? 'yes' : 'no') . "
135+ * Login required: " . ($structure->loginrequired ? 'yes' : 'no');*/
136+ echo "
137+ */
138+ $ {export}type $ type = " .convert_to_ts (null , $ typestructure )."; \n" ;
139+ }
140+
141+ /**
142+ * Returns TS Type From WS Name.
105143 */
106- export type $ type = " .convert_to_ts (null , $ structure )."; \n" ;
144+ function getTSTypeFromName ($ wsname ) {
145+ $ type = implode ('' , array_map ('ucfirst ' , explode ('_ ' , $ wsname ) ) );
146+ $ search = [
147+ '/^Block/ ' ,
148+ '/^Mod/ ' ,
149+ '/^Enrol/ ' ,
150+ '/^Gradereport/ ' ,
151+ '/^CoreCalendar/ ' ,
152+ '/^CoreBadges/ ' ,
153+ '/^CoreBlog/ ' ,
154+ '/^CoreCompetency/ ' ,
155+ '/^CoreFiles/ ' ,
156+ '/^CoreMessage/ ' ,
157+ '/^CoreNotes/ ' ,
158+ '/^MessageAirnotifier/ ' ,
159+ '/^ReportInsights/ ' ,
160+ '/^ToolLp/ ' ,
161+ '/^ToolMobile/ ' ,
162+ ];
163+
164+ $ replaces = [
165+ 'AddonBlock ' ,
166+ 'AddonMod ' ,
167+ 'AddonEnrol ' ,
168+ 'CoreGradesGradereport ' ,
169+ 'AddonCalendar ' ,
170+ 'AddonBadges ' ,
171+ 'AddonBlog ' ,
172+ 'AddonCompetency ' ,
173+ 'AddonPrivateFiles ' ,
174+ 'AddonMessages ' ,
175+ 'AddonNotes ' ,
176+ 'AddonMessageOutputAirnotifier ' ,
177+ 'AddonReportInsights ' ,
178+ 'AddonCompetency ' ,
179+ 'CoreSite ' ,
180+ ];
181+
182+ return preg_replace ($ search , $ replaces , $ type );
107183}
108184
109185/**
0 commit comments