| 1 |
<?php |
| 2 |
namespace Depicter\DataSources; |
| 3 |
|
| 4 |
|
| 5 |
use Averta\Core\Utility\Arr; |
| 6 |
use Averta\WordPress\Utility\JSON; |
| 7 |
|
| 8 |
/** |
| 9 |
* DataSource which holds pre-defined content for replacement in document |
| 10 |
*/ |
| 11 |
class Catalogs extends DataSourceBase implements DataSourceInterface |
| 12 |
{ |
| 13 |
/** |
| 14 |
* DataSource name |
| 15 |
* |
| 16 |
* @var string |
| 17 |
*/ |
| 18 |
protected $type = 'catalogs'; |
| 19 |
|
| 20 |
/** |
| 21 |
* DataSource properties |
| 22 |
* |
| 23 |
* @var array |
| 24 |
*/ |
| 25 |
protected $properties = []; |
| 26 |
|
| 27 |
/** |
| 28 |
* Default input params for retrieving dataSource records |
| 29 |
* |
| 30 |
* @var array |
| 31 |
*/ |
| 32 |
protected $defaultInputParams = []; |
| 33 |
|
| 34 |
/** |
| 35 |
* Asset groups of this DataSource |
| 36 |
* |
| 37 |
* @var array |
| 38 |
*/ |
| 39 |
protected $assetGroupNames = [ 'catalog' ]; |
| 40 |
|
| 41 |
/** |
| 42 |
* Retrieves the list of records based on query params |
| 43 |
* |
| 44 |
* @param $args |
| 45 |
* |
| 46 |
* @return array |
| 47 |
*/ |
| 48 |
protected function getRecords( $args ){ |
| 49 |
return $args['catalogs'] ?? []; |
| 50 |
} |
| 51 |
|
| 52 |
public function previewRecords( array $args = [] ) { |
| 53 |
$args = $this->prepare( $args ); |
| 54 |
return $this->getRecords( $args ); |
| 55 |
} |
| 56 |
|
| 57 |
/** |
| 58 |
* Get list of datasheets and corresponding required arguments |
| 59 |
* |
| 60 |
* @param array $args |
| 61 |
* |
| 62 |
* @return array |
| 63 |
*/ |
| 64 |
public function getDataSheetArgs( array $args = [] ){ |
| 65 |
// convert array of objects to associate array |
| 66 |
$sheets = $this->getRecords( $args ); |
| 67 |
return JSON::decode( JSON::encode( $sheets ), true ); |
| 68 |
} |
| 69 |
|
| 70 |
/** |
| 71 |
* Get list of asset groups for this dataSource |
| 72 |
* |
| 73 |
* @param $args |
| 74 |
* |
| 75 |
* @return array |
| 76 |
*/ |
| 77 |
public function getAssets( $args ){ |
| 78 |
$assetGroupNames = $this->getAssetGroupNames(); |
| 79 |
|
| 80 |
$groups = []; |
| 81 |
foreach( $assetGroupNames as $assetGroupName ){ |
| 82 |
$groups[ $assetGroupName ] = $args; |
| 83 |
} |
| 84 |
|
| 85 |
return \Depicter::dataSource()->tagsManager()->getAssetsInGroups( $groups ); |
| 86 |
} |
| 87 |
|
| 88 |
} |
| 89 |
|