Completed
Push — master ( be0f20...97e950 )
by Vitaly
02:23
created

GeneratorApi::createTableRowClass()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 27
Code Lines 19

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 1
Metric Value
c 3
b 0
f 1
dl 0
loc 27
rs 8.8571
cc 2
eloc 19
nc 2
nop 2
1
<?php
2
//[PHPCOMPRESSOR(remove,start)]
3
/**
4
 * Created by PhpStorm.
5
 * User: VITALYIEGOROV
6
 * Date: 09.12.15
7
 * Time: 14:34
8
 */
9
namespace samsoncms\api;
10
11
use samsoncms\api\generator\exception\ParentEntityNotFound;
12
use samsoncms\api\generator\Generator;
13
use samsoncms\api\generator\Metadata;
14
use samsonframework\orm\DatabaseInterface;
15
16
/**
17
 * Entity classes generator.
18
 * @package samsoncms\api
19
 */
20
class GeneratorApi extends Generator
21
{
22
23
    /**
24
     * Generator constructor.
25
     * @param DatabaseInterface $database Database instance
26
     * @throws ParentEntityNotFound
27
     * @throws \samsoncms\api\exception\AdditionalFieldTypeNotFound
28
     */
29
    public function __construct(DatabaseInterface $database)
30
    {
31
        parent::__construct($database);
32
33
        /**
34
         * Fill metadata only with structures which have to be generated
35
         */
36
        $this->fillMetadata();
37
    }
38
39
    /**
40
     * Generate entity classes.
41
     *
42
     * @param string $namespace Base namespace for generated classes
43
     *
44
     * @return string Generated PHP code for entity classes
45
     * @throws ParentEntityNotFound
46
     * @throws \samsoncms\api\exception\AdditionalFieldTypeNotFound
47
     */
48
    public function createEntityClasses($namespace = __NAMESPACE__)
49
    {
50
        $classes = "\n" . 'namespace ' . $namespace . '\\generated;';
51
        $classes .= "\n";
52
        $classes .= "\n" . 'use ' . $namespace . '\renderable\FieldsTable;';
53
        $classes .= "\n" . 'use ' . $namespace . '\field\Row;';
54
        $classes .= "\n" . 'use \samsoncms\api\Entity;';
55
        $classes .= "\n" . 'use \samsonframework\core\ViewInterface;';
56
        $classes .= "\n" . 'use \samsonframework\orm\ArgumentInterface;';
57
        $classes .= "\n" . 'use \samsonframework\orm\QueryInterface;';
58
        $classes .= "\n" . 'use \samson\activerecord\dbQuery;';
59
        $classes .= "\n";
60
61
        // Iterate all entities metadata
62
        foreach ($this->metadata as $metadata) {
63
            // Generate classes of default type
64
            if ($metadata->type === Metadata::TYPE_DEFAULT) {
65
                // Generate entity class
66
                $classes .= $this->createEntityClass($metadata);
67
                // Generate query class for queries
68
                $classes .= $this->createQueryClass($metadata);
69
                // Generate collection class for rendering
70
                $classes .= $this->createCollectionClass(
71
                    $metadata,
72
                    $this->fullEntityName($metadata->entity . 'Query', $namespace),
73
                    array(\samsoncms\api\Renderable::class)
74
                );
75
76
                // Generate Gallery classes for this entity
77
                $classes .= $this->createGalleryClass($metadata);
78
79
                // Generate classes of table type
80
            } elseif ($metadata->type === Metadata::TYPE_TABLE) {
81
                $classes .= $this->createTableRowClass($metadata);
82
                $classes .= $this->createTableClass($metadata);
83
            }
84
        }
85
86
        // Make correct code formatting
87
        return $this->formatTab($classes);
88
    }
89
90
    /**
91
     * Create entity PHP class code.
92
     *
93
     * @param Metadata $metadata  Entity metadata
94
     * @param string   $namespace Namespace of generated class
95
     * @return string Generated entity query PHP class code
96
     */
97
    protected function createEntityClass(Metadata $metadata, $namespace = __NAMESPACE__)
98
    {
99
        /**
100
         * TODO: Parent problem
101
         * Should be changed to merging fields instead of extending with OOP for structure_relation support
102
         * or creating traits and using them on shared parent entities.
103
         */
104
105
        $this->generator
106
            ->multiComment(array('"' . $metadata->entityRealName . '" entity class'))
107
            ->defClass($metadata->entity, null !== $metadata->parent ? $this->fullEntityName($metadata->parent->entity, $namespace) : 'Entity')
108
            ->commentVar('string', '@deprecated Entity full class name, use ::class')
109
            ->defClassConst('ENTITY', $this->fullEntityName($metadata->entity, $namespace))
110
            ->commentVar('string', 'Entity manager full class name')
111
            ->defClassConst('MANAGER', $this->fullEntityName($metadata->entity, $namespace) . 'Query')
112
            ->commentVar('string', 'Entity database identifier')
113
            ->defClassConst('IDENTIFIER', $metadata->entityID)
114
            ->commentVar('string', 'Not transliterated entity name')
115
            ->defClassVar('$viewName', 'protected static', $metadata->entityRealName);
116
117
        foreach ($metadata->allFieldIDs as $fieldID => $fieldName) {
118
            $this->generator
119
                ->commentVar('string', $metadata->fieldDescriptions[$fieldID] . ' variable name')
120
                ->defClassConst('F_' . $fieldName, $fieldName)
121
                ->commentVar('string', $metadata->fieldDescriptions[$fieldID] . ' additional field identifier')
122
                ->defClassConst('F_' . $fieldName . '_ID', $fieldID)
123
                ->commentVar($metadata->allFieldTypes[$fieldID], $metadata->fieldDescriptions[$fieldID])
124
                ->defClassVar('$' . $fieldName, 'public');
125
        }
126
127
        return $this->generator
128
            ->commentVar('array', 'Collection of navigation identifiers')
129
            ->defClassVar('$navigationIDs', 'protected static', array($metadata->entityID))
130
            ->defClassVar('$_sql_select', 'public static ', $metadata->arSelect)
131
            ->defClassVar('$_attributes', 'public static ', $metadata->arAttributes)
132
            ->defClassVar('$_map', 'public static ', $metadata->arMap)
133
            ->defClassVar('$_sql_from', 'public static ', $metadata->arFrom)
134
            ->defClassVar('$_own_group', 'public static ', $metadata->arGroup)
135
            ->defClassVar('$_relation_alias', 'public static ', $metadata->arRelationAlias)
136
            ->defClassVar('$_relation_type', 'public static ', $metadata->arRelationType)
137
            ->defClassVar('$_relations', 'public static ', $metadata->arRelations)
138
            ->defClassVar('$fieldIDs', 'protected static ', $metadata->allFieldIDs)
139
            ->defClassVar('$fieldValueColumns', 'protected static ', $metadata->allFieldValueColumns)
140
            ->endClass()
141
            ->flush();
142
    }
143
144
    /**
145
     * Create entity query PHP class code.
146
     *
147
     * @param Metadata $metadata      Entity metadata
148
     * @param string   $defaultParent Parent class name
149
     * @param array    $use           Collection of traits
150
     * @param string   $namespace     Namespace of generated class
151
     *
152
     * @return string Generated entity query PHP class code
153
     */
154
    protected function createQueryClass(Metadata $metadata, $defaultParent = '\samsoncms\api\query\Entity', $use = array(), $namespace = __NAMESPACE__)
155
    {
156
        $this->generateQuerableClassHeader($metadata, 'Query', $defaultParent, $use, $namespace);
157
158
        foreach ($metadata->allFieldIDs as $fieldID => $fieldName) {
159
            // TODO: Add different method generation depending on their field type
160
            $this->generator->text($this->generateFieldConditionMethod(
161
                $fieldName,
162
                $fieldID,
163
                $metadata->allFieldTypes[$fieldID]
164
            ));
165
        }
166
167
        return $this->generator
168
            ->commentVar('array', 'Collection of real additional field names')
169
            ->defClassVar('$fieldRealNames', 'public static', $metadata->realNames)
170
            ->commentVar('array', 'Collection of additional field names')
171
            ->defClassVar('$fieldNames', 'public static', $metadata->allFieldNames)
172
            // TODO: two above fields should be protected
173
            ->commentVar('array', 'Collection of navigation identifiers')
174
            ->defClassVar('$navigationIDs', 'protected static', array($metadata->entityID))
175
            ->commentVar('string', 'Entity full class name')
176
            ->defClassVar('$identifier', 'protected static', $this->fullEntityName($metadata->entity, $namespace))
177
            ->commentVar('array', 'Collection of localized additional fields identifiers')
178
            ->defClassVar('$localizedFieldIDs', 'protected static', $metadata->localizedFieldIDs)
179
            ->commentVar('array', 'Collection of NOT localized additional fields identifiers')
180
            ->defClassVar('$notLocalizedFieldIDs', 'protected static', $metadata->notLocalizedFieldIDs)
181
            ->commentVar('array', 'Collection of localized additional fields identifiers')
182
            ->defClassVar('$fieldIDs', 'protected static', $metadata->allFieldIDs)
183
            ->commentVar('array', 'Collection of additional fields value column names')
184
            ->defClassVar('$fieldValueColumns', 'protected static', $metadata->allFieldValueColumns)
185
            ->endClass()
186
            ->flush();
187
    }
188
189
    /**
190
     * Start quearable class declaration.
191
     *
192
     * @param Metadata $metadata      Entity metadata
193
     * @param string   $suffix        Entity class name suffix
194
     * @param string   $defaultParent Parent class name
195
     * @param array    $use           Collection of traits
196
     * @param string   $namespace     Namespace of generated class
197
     */
198
    protected function generateQuerableClassHeader(Metadata $metadata, $suffix, $defaultParent, $use, $namespace = __NAMESPACE__)
199
    {
200
        $this->generator
201
            ->multiComment(array(
202
                'Class for fetching "' . $metadata->entityRealName . '" instances from database',
203
                '@method ' . $this->fullEntityName($metadata->entity, $namespace) . ' first();',
204
                '@method ' . $this->fullEntityName($metadata->entity, $namespace) . '[] find();',
205
            ))
206
            ->defClass($metadata->entity . $suffix, $defaultParent);
207
208
209
        // Add traits to generated classes
210
        $this->generateTraitsUsage($use);
211
    }
212
213
    /**
214
     * Generate class traits usage.
215
     *
216
     * @param array $use Collection of trait names
217
     */
218
    protected function generateTraitsUsage($use = array())
219
    {
220
        // Add traits to generated classes
221
        foreach ($use as $trait) {
222
            $this->generator->newLine();
223
            $this->generator->tabs('use \\' . ltrim($trait, '\\') . ';');
224
        }
225
        $this->generator->newLine();
226
    }
227
228
    /**
229
     * Generate Query::where() analog for specific field.
230
     *
231
     * @param string $fieldName Field name
232
     * @param string $fieldId Field primary identifier
233
     * @param string $fieldType Field PHP type
234
     * @return string Generated PHP method code
235
     */
236
    protected function generateFieldConditionMethod($fieldName, $fieldId, $fieldType)
237
    {
238
        $code = "\n\t" . '/**';
239
        $code .= "\n\t" . ' * Add '.$fieldName.'(#' . $fieldId . ') field query condition.';
240
        $code .= "\n\t" . ' * @param ' . $fieldType . ' $value Field value';
241
        $code .= "\n\t" . ' * @return $this Chaining';
242
        $code .= "\n\t" . ' * @see Generic::where()';
243
        $code .= "\n\t" . ' */';
244
        $code .= "\n\t" . 'public function ' . $fieldName . '($value, $relation = ArgumentInterface::EQUAL)';
245
        $code .= "\n\t" . "{";
246
        $code .= "\n\t\t" . 'return $this->where("' . $fieldName . '", $value, $relation);';
247
248
        return $code . "\n\t" . "}"."\n";
249
    }
250
251
    /**
252
     * Create entity collection PHP class code.
253
     *
254
     * @param Metadata $metadata      Entity metadata
255
     * @param string   $suffix        Generated class name suffix
256
     * @param string   $defaultParent Parent class name
257
     * @param array    $use           Collection of traits
258
     * @param string   $namespace     Namespace of generated class
259
     *
260
     * @return string Generated entity query PHP class code
261
     */
262
    protected function createCollectionClass(Metadata $metadata, $defaultParent, $use = array(), $suffix = 'Collection', $namespace = __NAMESPACE__)
0 ignored issues
show
Unused Code introduced by
The parameter $suffix is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
263
    {
264
        $this->generateQuerableClassHeader($metadata, 'Collection', $defaultParent, $use, $namespace);
265
266
        return $this->generator
267
            ->text($this->generateConstructorCollectionClass())
268
            ->endClass()
269
            ->flush();
270
    }
271
272
    /**
273
     * Generate constructor for collection class.
274
     */
275 View Code Duplication
    protected function generateConstructorCollectionClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
276
    {
277
        $class = "\n\t".'/**';
278
        $class .= "\n\t".' * @param ViewInterface $renderer Rendering instance';
279
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
280
        $class .= "\n\t".' * @param string $locale Localization identifier';
281
        $class .= "\n\t".' */';
282
        $class .= "\n\t" . 'public function __construct(ViewInterface $renderer, QueryInterface $query = null, $locale = null)';
283
        $class .= "\n\t".'{';
284
        $class .= "\n\t\t" . '$this->renderer = $renderer;';
285
        $class .= "\n\t\t" . 'parent::__construct(isset($query) ? $query : new dbQuery(), $locale);';
286
        $class .= "\n\t".'}'."\n";
287
288
        return $class;
289
    }
290
291
    /**
292
     * Generate classes for entity additional field gallery.
293
     *
294
     * @param Metadata $metadata Entity metadata
295
     *
296
     * @return string Generated Gallery additional field class
297
     */
298
    public function createGalleryClass(Metadata $metadata)
299
    {
300
        // Iterate entity additional fields
301
        foreach ($metadata->allFieldCmsTypes as $fieldID => $fieldType) {
302
            // We need only gallery fields
303
            if ($fieldType === Field::TYPE_GALLERY) {
304
                $fieldName = $metadata->allFieldIDs[$fieldID];
305
                // Declare class
306
                $this->generateQuerableClassHeader(
307
                    $metadata,
308
                    ucfirst($fieldName) . 'Gallery',
309
                    '\\' . \samsoncms\api\Gallery::class,
310
                    array(\samsoncms\api\Renderable::class)
311
                );
312
313
                return $this->generator
314
                    ->text($this->generateConstructorGalleryClass($metadata->entity . '::F_' . strtoupper($fieldName) . '_ID'))
315
                    ->endClass()
316
                    ->flush();
317
            }
318
        }
319
320
321
    }
322
323
    /**
324
     * Generate constructor for gallery class.
325
     */
326 View Code Duplication
    protected function generateConstructorGalleryClass($fieldID)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
327
    {
328
        $class = "\n\t" . '/**';
329
        $class .= "\n\t" . ' * @param ViewInterface $renderer Rendering instance';
330
        $class .= "\n\t" . ' * @param int $materialID Gallery material identifier';
331
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
332
        $class .= "\n\t" . ' */';
333
        $class .= "\n\t" . 'public function __construct(ViewInterface $renderer, $materialID, QueryInterface $query = null)';
334
        $class .= "\n\t" . '{';
335
        $class .= "\n\t\t" . '$this->renderer = $renderer;';
336
        $class .= "\n\t\t" . 'parent::__construct(isset($query) ? $query : new dbQuery(), $materialID, ' . $fieldID . ');';
337
        $class .= "\n\t" . '}' . "\n";
338
339
        return $class;
340
    }
341
342
    /**
343
     * Create fields table row PHP class code.
344
     *
345
     * @param Metadata $metadata metadata of entity
346
     * @param string $namespace Namespace of generated class
347
     *
348
     * @return string Generated entity query PHP class code
349
     * @throws exception\AdditionalFieldTypeNotFound
350
     */
351
    protected function createTableRowClass(Metadata $metadata, $namespace = __NAMESPACE__)
0 ignored issues
show
Unused Code introduced by
The parameter $namespace is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
352
    {
353
        $this->generator
354
            ->multiComment(array('Class for getting "' . $metadata->entityRealName . '" fields table rows'))
355
            ->defClass($this->entityName($metadata->entityRealName) . 'TableRow', 'Row');
356
357
        $fieldIDs = array();
358
        foreach ($this->navigationFields($metadata->entityID) as $fieldID => $fieldRow) {
359
            $fieldName = $this->fieldName($fieldRow['Name']);
360
361
            // Fill field ids array
362
            $fieldIDs[$fieldName] = $fieldID;
363
364
            $this->generator
365
                ->commentVar($metadata->allFieldTypes[$fieldID], $fieldRow['Description'] . ' Field #' . $fieldID . ' variable name')
366
                ->defClassConst('F_' . strtoupper($fieldName), $fieldName)
367
                ->commentVar($metadata->allFieldTypes[$fieldID], $fieldRow['Description'] . ' Field #' . $fieldID . ' row value')
368
                ->defVar('public $' . $fieldName)
369
                ->text("\n");
370
        }
371
372
        return $this->generator
373
            ->commentVar('array', 'Collection of additional fields identifiers')
374
            ->defClassVar('$fieldIDs', 'public static', $fieldIDs)
375
            ->endClass()
376
            ->flush();
377
    }
378
379
    /**
380
     * Create fields table PHP class code.
381
     *
382
     * @param Metadata $metadata metadata of entity
383
     * @param string $namespace Namespace of generated class
384
     * @return string Generated entity query PHP class code
385
     * @throws exception\AdditionalFieldTypeNotFound
386
     */
387
    protected function createTableClass(Metadata $metadata, $namespace = __NAMESPACE__)
0 ignored issues
show
Unused Code introduced by
The parameter $namespace is not used and could be removed.

This check looks from parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
388
    {
389
        $this->generator
390
            ->multiComment(array('Class for getting "'.$metadata->entityRealName.'" fields table'))
391
            ->defClass($this->entityName($metadata->entityRealName) . 'Table', 'FieldsTable');
392
393
        // Add renderable trait
394
        $this->generateTraitsUsage(array(\samsoncms\api\Renderable::class));
395
396
        // Iterate additional fields
397
        $fields = array();
398
        foreach ($this->navigationFields($metadata->entityID) as $fieldID => $fieldRow) {
399
            $fieldName = $this->fieldName($fieldRow['Name']);
400
401
            $this->generator
402
                ->text($this->generateTableFieldMethod(
403
                    $fieldName,
404
                    $fieldRow[Field::F_PRIMARY],
405
                    $fieldRow[Field::F_TYPE]
406
                ))
407
                ->commentVar($metadata->allFieldTypes[$fieldID], $fieldRow['Description'] . ' Field #' . $fieldID . ' variable name')
408
                ->defClassConst('F_' . $fieldName, $fieldName);
409
410
            // Collection original to new one field names
411
            $fields[$fieldRow['Name']] = $fieldName;
412
        }
413
414
        // TODO: Add generator method generation logic
415
        $constructor = $this->generateConstructorTableClass();
416
417
        $this->generator->text($constructor);
418
419
        return $this->generator
420
            ->commentVar('string', 'Entity database identifier')
421
            ->defClassConst('IDENTIFIER', $metadata->entityID)
422
            ->commentVar('array', 'Collection of real additional field names')
423
            ->defClassVar('$fieldsRealNames', 'public static', $fields)
424
            ->commentVar('array', 'Collection of navigation identifiers')
425
            ->defClassVar('$navigationIDs', 'protected static', array($metadata->entityID))
426
            ->commentVar('string', 'Row class name')
427
            ->defClassVar('$identifier', 'protected', $this->fullEntityName($this->entityName($metadata->entityRealName) . 'TableRow'))
428
            ->endClass()
429
            ->flush();
430
    }
431
432
    /**
433
     * Generate FieldsTable::values() analog for specific field.
434
     *
435
     * @param string $fieldName Field name
436
     * @param string $fieldId   Field primary identifier
437
     * @param string $fieldType Field PHP type
438
     *
439
     * @return string Generated PHP method code
440
     */
441
    protected function generateTableFieldMethod($fieldName, $fieldId, $fieldType)
442
    {
443
        $code = "\n\t" . '/**';
444
        $code .= "\n\t" . ' * Get table column ' . $fieldName . '(#' . $fieldId . ') values.';
445
        $code .= "\n\t" . ' * @return array Collection(' . Field::phpType($fieldType) . ') of table column values';
446
        $code .= "\n\t" . ' */';
447
        $code .= "\n\t" . 'public function ' . $fieldName . '()';
448
        $code .= "\n\t" . "{";
449
        $code .= "\n\t\t" . 'return $this->values(' . $fieldId . ');';
450
451
        return $code . "\n\t" . "}" . "\n";
452
    }
453
454
    /**
455
     * Generate constructor for table class.
456
     */
457 View Code Duplication
    protected function generateConstructorTableClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
458
    {
459
        $class = "\n\t" . '/**';
460
        $class .= "\n\t" . ' * @param QueryInterface $query Database query instance';
461
        $class .= "\n\t" . ' * @param ViewInterface $renderer Rendering instance';
462
        $class .= "\n\t" . ' * @param integer $entityID Entity identifier to whom this table belongs';
463
        $class .= "\n\t" . ' * @param string $locale Localization identifier';
464
        $class .= "\n\t" . ' */';
465
        $class .= "\n\t" . 'public function __construct(QueryInterface $query, ViewInterface $renderer, $entityID, $locale = null)';
466
        $class .= "\n\t" . '{';
467
        $class .= "\n\t\t" . 'parent::__construct($query, $renderer, static::$navigationIDs, $entityID, $locale);';
468
        $class .= "\n\t" . '}' . "\n";
469
470
        return $class;
471
    }
472
473
    /**
474
     * Generate Query::where() analog for specific field.
475
     *
476
     * @param string $fieldName Field name
477
     * @param string $fieldId   Field primary identifier
478
     * @param string $fieldType Field PHP type
479
     *
480
     * @return string Generated PHP method code
481
     */
482
    protected function generateLocalizedFieldConditionMethod($fieldName, $fieldId, $fieldType)
483
    {
484
        $code = "\n\t" . '/**';
485
        $code .= "\n\t" . ' * Add ' . $fieldName . '(#' . $fieldId . ') field query condition.';
486
        $code .= "\n\t" . ' * @param ' . Field::phpType($fieldType) . ' $value Field value';
487
        $code .= "\n\t" . ' * @return $this Chaining';
488
        $code .= "\n\t" . ' * @see Generic::where()';
489
        $code .= "\n\t" . ' */';
490
        $code .= "\n\t" . 'public function ' . $fieldName . '($value)';
491
        $code .= "\n\t" . "{";
492
        $code .= "\n\t\t" . 'return $this->where("' . $fieldName . '", $value);';
493
494
        return $code . "\n\t" . "}" . "\n";
495
    }
496
497
    /**
498
     * Generate constructor for application class.
499
     */
500 View Code Duplication
    protected function generateConstructorApplicationClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
501
    {
502
        $class = "\n\t" . '/**';
503
        $class .= "\n\t" . ' * Render materials list with pager';
504
        $class .= "\n\t" . ' *';
505
        $class .= "\n\t" . ' * @param string $navigationId Structure identifier';
506
        $class .= "\n\t" . ' * @param string $search Keywords to filter table';
507
        $class .= "\n\t" . ' * @param int $page Current table page';
508
        $class .= "\n\t" . ' * @return array Asynchronous response containing status and materials list with pager on success';
509
        $class .= "\n\t" . ' * or just status on asynchronous controller failure';
510
        $class .= "\n\t" . ' */';
511
        $class .= "\n\t" . 'public function __async_collection($navigationId = \'0\', $search = \'\', $page = 1)';
512
        $class .= "\n\t" . '{';
513
        $class .= "\n\t\t" . 'return parent::__async_collection(self::$navigation, $search, $page);';
514
        $class .= "\n\t" . '}' . "\n";
515
516
        return $class;
517
    }
518
519
    /**
520
     * Generate constructor for application class.
521
     */
522 View Code Duplication
    protected function generateConstructorApplicationCollectionClass()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
523
    {
524
        $class = "\n\t" . '/**';
525
        $class .= "\n\t" . ' * Generic collection constructor';
526
        $class .= "\n\t" . ' *';
527
        $class .= "\n\t" . ' * @param RenderInterface $renderer View render object';
528
        $class .= "\n\t" . ' * @param QueryInterface $query Query object';
529
        $class .= "\n\t" . ' */';
530
        $class .= "\n\t" . 'public function __async_collection($renderer, $query = null, $pager = null)';
531
        $class .= "\n\t" . '{';
532
        $class .= "\n\t\t" . 'return parent::__async_collection($renderer, $query = null, $pager = null);';
533
        $class .= "\n\t\t" . '$this->fields = array(';
534
        $class .= "\n\t\t\t" . 'new Control(),';
535
        $class .= "\n\t\t" . ');';
536
        $class .= "\n\t" . '}' . "\n";
537
538
        return $class;
539
    }
540
}
541
//[PHPCOMPRESSOR(remove,end)]
542