-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'feature/fomaExportAPI' into fixedForms_merged_with_formeta
- Loading branch information
Showing
10 changed files
with
748 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
[LINKED_DATA_REPOSITORIES] | ||
REPOS=1 | ||
SNL=1 | ||
NEBIS=1 | ||
RERO=1 | ||
IDSBB=1 | ||
IDSLU=1 | ||
IDSSG=1 | ||
IDSSG2=1 | ||
ALEX=1 | ||
SGBN=1 | ||
SBT=1 | ||
ABN=1 | ||
BGR=1 | ||
CCSA=1 | ||
CHARCH=1 | ||
LIBIB=1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
<?php | ||
namespace Libadmin\Export\System; | ||
|
||
use Libadmin\Services\View\FormetaModel; | ||
use Zend\View\Model\JsonModel; | ||
use Zend\Db\ResultSet\ResultSetInterface; | ||
|
||
use Libadmin\Model\Group; | ||
use Libadmin\Model\Institution; | ||
use Zend\Config\Reader\Ini; | ||
use Zend\Config\Config; | ||
|
||
#use ML\JsonLD\JsonLD; | ||
|
||
/** | ||
* VuFind Export system | ||
* | ||
*/ | ||
class Formeta extends MapPortal | ||
{ | ||
|
||
/** | ||
* @var Config | ||
*/ | ||
protected $configLinkedRepositories; | ||
|
||
/** | ||
* Get vufind json data | ||
* | ||
* @return JsonModel | ||
*/ | ||
public function getFormetaData() | ||
{ | ||
try { | ||
$data = array( | ||
'success' => true, | ||
'data' => $this->getJsonPayloadData() | ||
); | ||
} catch (\Exception $e) { | ||
$data = array( | ||
'success' => false, | ||
'data' => array(), | ||
'error' => $e->getMessage() | ||
); | ||
} | ||
|
||
|
||
return new FormetaModel($data); | ||
} | ||
|
||
/** | ||
* Extract required data from institution | ||
* | ||
* @param Institution $institution | ||
* @return Array | ||
*/ | ||
protected function extractAllInstitutionData(Institution $institution, $groupCode) | ||
{ | ||
$test = ""; | ||
|
||
return ['institution' => [ | ||
|
||
'id' => $institution->getBib_code(), | ||
'sysDbId' => $institution->getId(), | ||
'sys_code' => $institution->getSys_code(), | ||
'label' => array( | ||
'de' => $institution->getLabel_de(), | ||
'fr' => $institution->getLabel_fr(), | ||
'it' => $institution->getLabel_it(), | ||
'en' => $institution->getLabel_en() | ||
), | ||
'name' => array( | ||
'de' => $institution->getName_de(), | ||
'fr' => $institution->getName_fr(), | ||
'it' => $institution->getName_it(), | ||
'en' => $institution->getName_en() | ||
), | ||
'url' => array( | ||
'de' => $institution->getUrl_de(), | ||
'fr' => $institution->getUrl_fr(), | ||
'it' => $institution->getUrl_it(), | ||
'en' => $institution->getUrl_en() | ||
), | ||
'address' => $institution->getAddress(), | ||
'zip' => $institution->getZip(), | ||
'city' => $institution->getCity(), | ||
'country' => $institution->getCountry(), | ||
'canton' => $institution->getCanton(), | ||
'website' => $institution->getWebsite(), | ||
'email' => $institution->getEmail(), | ||
'phone' => $institution->getPhone(), | ||
'skype' => $institution->getSkype(), | ||
'facebook' => $institution->getFacebook(), | ||
'coordinates' => $institution->getCoordinates(), | ||
'isil' => $institution->getIsil(), | ||
'notes' => $institution->getNotes(), | ||
'backlink' => $this->getBackLink($groupCode,$institution->getBib_code(),array()) | ||
|
||
]]; | ||
|
||
} | ||
|
||
/** | ||
* Get grouped institution data | ||
* | ||
* @return Array | ||
*/ | ||
protected function getJsonPayloadData() | ||
{ | ||
$data = array(); | ||
$groups = $this->getGroups(); | ||
//$extractInstitutionMethod = $this->getOption('all') == true ? 'extractAllInstitutionData' : 'extractInstitutionData'; | ||
//the whole information should always be delivered to the client | ||
$extractInstitutionMethod = 'extractAllInstitutionData'; | ||
|
||
|
||
foreach ($groups as $group) { | ||
|
||
$repositoryForExportDefined = $this->configLinkedRepositories->LINKED_DATA_REPOSITORIES->offsetGet($group->code); | ||
if (isset($repositoryForExportDefined) && $repositoryForExportDefined ) { | ||
$groupData = array( | ||
'group' => $this->extractGroupData($group), | ||
'institutions' => array() | ||
); | ||
|
||
$institutions = $this->getGroupInstitutions($group); | ||
|
||
foreach ($institutions as $institution) { | ||
$groupData['institutions'][] = $this->$extractInstitutionMethod($institution,$group->code); | ||
} | ||
|
||
$data[] = $groupData; | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
return $data; | ||
} | ||
|
||
/** | ||
* @override | ||
* @return void | ||
*/ | ||
public function init() | ||
{ | ||
|
||
//http://localhost/libadmin/api/semanticweb/green.json?option[all]=true | ||
//http://www.cambridgesemantics.com/semantic-university/getting-started | ||
//documentation | ||
//http://code.ohloh.net/project?pid=jZRKcGNwZOo&cid=9cCNLmy7F0s&fp=291221&mp=&projSelected=true | ||
parent::init(); | ||
|
||
$config = $this->getServiceLocator()->get('config'); | ||
$reader = new Ini(); | ||
$this->configLinkedRepositories = new Config($reader->fromFile($config['libadmin']['linkedswissbibconfig'])); | ||
|
||
} | ||
|
||
|
||
} | ||
|
||
|
102 changes: 102 additions & 0 deletions
102
module/Libadmin/src/Libadmin/Services/View/FormetaModel.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
<?php | ||
|
||
namespace Libadmin\Services\View; | ||
|
||
use Traversable; | ||
use Zend\View\Model\ViewModel; | ||
use Zend\Stdlib\ArrayUtils; | ||
use Zend\Json\Json; | ||
|
||
class FormetaModel extends ViewModel | ||
{ | ||
|
||
/** | ||
* Formeta is usually terminal | ||
* | ||
* @var bool | ||
*/ | ||
protected $terminate = true; | ||
|
||
|
||
/** | ||
* Serialize to JSON | ||
* | ||
* @return string | ||
*/ | ||
public function serialize() | ||
{ | ||
$variables = $this->getVariables(); | ||
if ($variables instanceof Traversable) { | ||
$variables = ArrayUtils::iteratorToArray($variables); | ||
} | ||
|
||
//return Json::encode($variables); | ||
|
||
$formetaString = null; | ||
|
||
foreach ($variables['data'] as $groupContainer) { | ||
//$groupString = ""; | ||
$groupString = $groupContainer['group']['code'] . ' {'; | ||
foreach ($groupContainer['group'] as $groupKey => $groupValue) { | ||
if (!is_array($groupValue)) { | ||
//$groupString .= ' \'' . $groupKey . '\' : \'' . preg_replace(array('/\'/i'),array('\\'),$groupValue) . ' \','; | ||
$groupString .= ' \'' . $groupKey . '\' : \'' . preg_replace(array('/\'/i','/\\\\V/i','/\\\\E/i','/d\\\\a/i','/d\\\\i/i'), | ||
array('\\\'','E','d a','d\''),$groupValue) . ' \','; | ||
} else { | ||
$groupString .= $this->serializeEntity($groupKey,$groupValue) ; | ||
} | ||
|
||
} | ||
$formetaString .= $groupString; | ||
|
||
|
||
$groupString = 'institutions {'; | ||
|
||
foreach ($groupContainer['institutions'] as $institutionsContainer) { | ||
foreach ($institutionsContainer as $instKey => $instValue) { | ||
if (!is_array($instValue)) { | ||
|
||
//$groupString .= ' \'' . $instKey . '\' : \'' . preg_replace(array('/\'/i'),array('\\'),$instValue) . ' \','; | ||
$groupString .= ' \'' . $instKey . '\' : \'' . preg_replace(array('/\'/i','/\\\\V/i','/\\\\E/i','/d\\\\a/i','/d\\\\i/i'), | ||
array('\\\'','V','E','d a','d\''),$instValue) . '\','; | ||
} else { | ||
|
||
$groupString .= ' ' . $this->serializeEntity($instKey, $instValue) ; | ||
|
||
} | ||
} | ||
} | ||
$formetaString .= $groupString; | ||
|
||
$formetaString .= '} '; // schliesse Institutions | ||
$formetaString .= '}, '; | ||
} | ||
|
||
return $formetaString; | ||
|
||
} | ||
|
||
|
||
private function serializeEntity ($key, array $entity) { | ||
|
||
$localString = ' ' . $key . ' {'; | ||
|
||
foreach ($entity as $entityKey => $entityValue) | ||
{ | ||
if (!is_array($entityValue)) { | ||
//$localString .= '\'' . $entityKey . '\' : \'' . preg_replace(array('/\'/i'),array('\\'),$entityValue) . ' \','; | ||
$localString .= '\'' . $entityKey . '\' : \'' . preg_replace(array('/\'/i','/\\\\V/i','/\\\\E/i','/d\\\\a/i','/d\\\\i/i'), | ||
array('\\\'','V','E','d a','d\''),$entityValue) . '\','; | ||
} else { | ||
//$localString .= ' {' . $this->serializeEntity($entityKey,$entityValue) . ' }, '; | ||
$localString .= ' ' . $this->serializeEntity($entityKey,$entityValue) . ', '; | ||
} | ||
//if (!is_array($groupLiteral)) | ||
} | ||
|
||
$localString .= '}, '; | ||
|
||
return $localString; | ||
|
||
} | ||
} |
Oops, something went wrong.