Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
clinicaltrials
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
david Chavalarias
clinicaltrials
Commits
90ad614a
Commit
90ad614a
authored
Jul 06, 2017
by
Romain Loth
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
json output mode for php (1/2: for our new csv queries)
parent
099ce9c5
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
53 additions
and
31 deletions
+53
-31
csv_div.php
twbackends/phpAPI/csv_div.php
+48
-31
parameters_details.php
twbackends/phpAPI/parameters_details.php
+5
-0
No files found.
twbackends/phpAPI/csv_div.php
View file @
90ad614a
...
...
@@ -7,47 +7,49 @@ error_reporting(-1);
// DISPLAY THE RESULTS
function
displayDoc
(
$docId
,
$score
,
$base
)
{
$output
=
""
;
function
displayDoc
(
$docId
,
$score
,
$base
,
$outmode
)
{
// POSS score should have a data-score attribute
$output
=
"<li class='searchhit' title='"
.
$score
.
"'>"
;
// shortcut to doc
$doc
=
$base
[
$docId
];
// £TODO new concept: use searchhit-templates
$has_template
=
False
;
if
(
$has_template
)
{
// fallback "universal" values
$title
=
try_attrs_until_you_find
(
$doc
,
[
'title'
,
'tit'
,
't'
]);
$source
=
try_attrs_until_you_find
(
$doc
,
[
'source'
,
'journal'
,
'j'
]);
$keywords
=
try_attrs_until_you_find
(
$doc
,
[
'keywords'
,
'keyword'
,
'kw'
]);
$author
=
try_attrs_until_you_find
(
$doc
,
[
'authors'
,
'author'
,
'auth'
,
'au'
]);
$doccontent
=
try_attrs_until_you_find
(
$doc
,
[
'text'
,
'txt'
,
'abstract'
,
'content'
]);
}
else
{
// fallback "universal" values
$title
=
try_attrs_until_you_find
(
$doc
,
[
'title'
,
'tit'
,
't'
]);
$source
=
try_attrs_until_you_find
(
$doc
,
[
'source'
,
'journal'
,
'j'
]);
$keywords
=
try_attrs_until_you_find
(
$doc
,
[
'keywords'
,
'keyword'
,
'kw'
]);
$author
=
try_attrs_until_you_find
(
$doc
,
[
'authors'
,
'author'
,
'auth'
,
'au'
]);
$doccontent
=
try_attrs_until_you_find
(
$doc
,
[
'text'
,
'txt'
,
'abstract'
,
'content'
]);
$date
=
try_attrs_until_you_find
(
$doc
,
[
'pubdate'
,
'publication_year'
,
'date'
]);
// detailed dates, gargantext-compatible
$month
=
try_attrs_until_you_find
(
$doc
,
[
'publication_month'
]);
$day
=
try_attrs_until_you_find
(
$doc
,
[
'publication_day'
]);
if
(
$month
)
{
$date
.=
"/"
.
$month
;
if
(
$day
)
{
$date
.=
"/"
.
$day
;
}
}
// "universal" template
$date
=
try_attrs_until_you_find
(
$doc
,
[
'pubdate'
,
'publication_year'
,
'date'
]);
// detailed dates, gargantext-compatible
$month
=
try_attrs_until_you_find
(
$doc
,
[
'publication_month'
]);
$day
=
try_attrs_until_you_find
(
$doc
,
[
'publication_day'
]);
if
(
$month
)
{
$date
.=
"/"
.
$month
;
if
(
$day
)
{
$date
.=
"/"
.
$day
;
}
}
// "universal" template
if
(
$outmode
==
'html'
)
{
$output
=
"<li class='searchhit' title='"
.
$score
.
"'>"
;
$output
.=
"<p><b>
$title
</b> by <span class='author'>
$author
</span>, <i>
$source
</i> [
$date
]</p>"
;
if
(
strlen
(
$keywords
))
{
$output
.=
"<p><b>keywords:</b>
$keywords
</p>"
;
}
$output
.=
"<p><span class='hit-text'>
$doccontent
</span></p>"
;
$output
.=
"</li>"
;
}
// json mode
else
{
$output
=
array
(
"tit"
=>
$title
,
"au"
=>
$author
,
"src"
=>
$source
,
"kws"
=>
$keywords
,
"txt"
=>
$doccontent
,
"date"
=>
$date
);
}
$output
.=
"</li>"
;
return
$output
;
}
...
...
@@ -67,6 +69,7 @@ function try_attrs_until_you_find($doc_obj, $attr_names_array) {
$htmlout
=
"<ul class=infoitems>
\n
"
;
$jsonout
=
array
();
$nb_displayed
=
0
;
foreach
(
$sims
as
$doc
=>
$freq
)
{
// doc limit
...
...
@@ -75,16 +78,30 @@ foreach ($sims as $doc => $freq) {
}
$rowid
=
ltrim
(
$doc
,
'd'
);
$thisdoc
=
displayDoc
(
$rowid
,
$freq
,
$base
);
$thisdoc
=
displayDoc
(
$rowid
,
$freq
,
$base
,
$output_mode
);
// echodump("doc", $thisdoc);
$htmlout
.=
$thisdoc
.
"
\n
"
;
if
(
$output_mode
==
"html"
)
{
$htmlout
.=
$thisdoc
.
"
\n
"
;
}
else
{
array_push
(
$jsonout
,
$thisdoc
);
}
// doc limit
$nb_displayed
++
;
}
$htmlout
.=
"</ul>
\n
"
;
echo
'<br/><h4><font color="#0000FF"> Full text of top '
.
$max_item_displayed
.
"/"
.
count
(
$sims
)
.
' related publications:</font></h4>'
.
$htmlout
;
if
(
$output_mode
==
"html"
)
{
echo
'<br/><h4><font color="#0000FF"> Full text of top '
.
$nb_displayed
.
"/"
.
count
(
$sims
)
.
' related publications:</font></h4>'
;
echo
$htmlout
;
}
else
{
echo
json_encode
(
array
(
'hits'
=>
$jsonout
,
'nhits'
=>
$nb_displayed
));
}
// to see the entire results array:
// --------------------------------
...
...
twbackends/phpAPI/parameters_details.php
View file @
90ad614a
...
...
@@ -3,6 +3,11 @@
// GLOBAL PARAMS
// -------------
// 0 - output mode: 'json' or 'html'
// > json is for new use cases where styling is applied via template import in the js
// > html is the classical use where data is styled in this php scripts
$output_mode
=
"json"
;
// 1 - relative urls
$our_php_root
=
"twbackends/phpAPI"
;
// our php scripts relative URL
$our_libs_root
=
"twbackends/phpAPI"
;
// for our few icons and jquery-ui
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment