Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
schemadotorg
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
schemadotorg
Merge requests
!141
Issue
#3448162
: Add relationships to report
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Issue
#3448162
: Add relationships to report
issue/schemadotorg-3448162:3448162-add-relationships
into
1.0.x
Overview
0
Commits
4
Pipelines
5
Changes
17
Merged
Jacob Rockowitz
requested to merge
issue/schemadotorg-3448162:3448162-add-relationships
into
1.0.x
1 year ago
Overview
0
Commits
4
Pipelines
5
Changes
17
Expand
Closes
#3448162
0
0
Merge request reports
Compare
1.0.x
version 4
60504272
1 year ago
version 3
103c0478
1 year ago
version 2
28dd6269
1 year ago
version 1
c58ec99d
1 year ago
1.0.x (base)
and
latest version
latest version
60504272
4 commits,
1 year ago
version 4
60504272
4 commits,
1 year ago
version 3
103c0478
3 commits,
1 year ago
version 2
28dd6269
2 commits,
1 year ago
version 1
c58ec99d
1 commit,
1 year ago
17 files
+
445
−
5
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
17
Search (e.g. *.vue) (Ctrl+P)
modules/schemadotorg_export/src/Controller/SchemaDotOrgExportReportRelationshipsController.php
0 → 100644
+
86
−
0
Options
<?php
declare
(
strict_types
=
1
);
namespace
Drupal\schemadotorg_export\Controller
;
use
Drupal\Component\Utility\NestedArray
;
use
Drupal\schemadotorg_report
\Controller\SchemaDotOrgReportRelationshipsController
;
use
Symfony\Component\DependencyInjection\ContainerInterface
;
use
Symfony\Component\HttpFoundation\StreamedResponse
;
/**
* Returns responses for Schema.org relationships export.
*/
class
SchemaDotOrgExportReportRelationshipsController
extends
SchemaDotOrgExportMappingDefaultBaseController
{
/**
* The Schema.org report relationships controller.
*/
protected
SchemaDotOrgReportRelationshipsController
$controller
;
/**
* {@inheritdoc}
*/
public
static
function
create
(
ContainerInterface
$container
):
static
{
$instance
=
parent
::
create
(
$container
);
$instance
->
controller
=
SchemaDotOrgReportRelationshipsController
::
create
(
$container
);
return
$instance
;
}
/**
* Returns response for Schema.org mapping set CSV export request.
*
* @return \Symfony\Component\HttpFoundation\StreamedResponse
* A streamed HTTP response containing a Schema.org mapping set CSV export.
*/
public
function
index
():
StreamedResponse
{
$response
=
new
StreamedResponse
(
function
():
void
{
$build
=
$this
->
controller
->
index
();
$table
=
$build
[
'table'
];
$handle
=
fopen
(
'php://output'
,
'r+'
);
// Header.
$header
=
[];
foreach
(
$table
[
'#header'
]
as
$table_header
)
{
// Get the header value.
$value
=
NestedArray
::
getValue
(
$table_header
,
[
'data'
,
'#markup'
])
??
NestedArray
::
getValue
(
$table_header
,
[
'data'
])
??
$table_header
;
$header
[]
=
$value
;
}
fputcsv
(
$handle
,
$header
);
// Rows.
foreach
(
$table
[
'#rows'
]
as
$table_row
)
{
$row
=
[];
foreach
(
$table_row
as
$row_id
=>
$item
)
{
// Get the row value.
$value
=
NestedArray
::
getValue
(
$item
,
[
'data'
,
'#markup'
])
??
NestedArray
::
getValue
(
$item
,
[
'data'
,
'#title'
])
??
NestedArray
::
getValue
(
$item
,
[
'data'
,
'#items'
])
??
$item
;
// Prefix all Schema.org type and properties with https://schema.org/.
if
(
is_array
(
$value
)
&&
$row_id
!==
'starterkit'
)
{
$value
=
array_map
(
fn
(
$item
)
=>
'https://schema.org/'
.
(
$item
[
'#title'
]
??
$item
),
$value
);
}
$row
[]
=
implode
(
PHP_EOL
,
(
array
)
$value
);
}
fputcsv
(
$handle
,
$row
);
}
fclose
(
$handle
);
});
$response
->
headers
->
set
(
'Content-Type'
,
'application/force-download'
);
$response
->
headers
->
set
(
'Content-Disposition'
,
'attachment; filename="schemadotorg_relationships.csv"'
);
return
$response
;
}
}
Loading