Created
September 6, 2017 07:58
-
-
Save Opencontent/9dd9c88b1e91c4a041ffbf8980010940 to your computer and use it in GitHub Desktop.
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
<?php | |
use Opencontent\Opendata\Api\Values\ExtraData; | |
use Opencontent\Opendata\Api\Values\ExtraDataProviderInterface; | |
class ezfIndexAccountInfo implements ezfIndexPlugin, ExtraDataProviderInterface | |
{ | |
/** | |
* @param eZContentObject $contentObject | |
* @param eZSolrDoc[] $docList | |
*/ | |
public function modify(eZContentObject $contentObject, &$docList) | |
{ | |
try { | |
$user = eZUser::fetch($contentObject->ID); | |
if ($user instanceof eZUser) { | |
$availableLanguages = $contentObject->currentVersion()->translationList(false, false); | |
foreach ($availableLanguages as $languageCode) { | |
$docList[$languageCode]->addField('extra_login_count_si', $user->loginCount()); | |
$docList[$languageCode]->addField('extra_last_visit_si', $user->lastVisit()); | |
} | |
} | |
} catch (Exception $e) { | |
eZDebug::writeError($e->getMessage(), __METHOD__); | |
} | |
} | |
public function setExtraDataFromContentObject(eZContentObject $object, ExtraData $extraData) | |
{ | |
try { | |
$user = eZUser::fetch($contentObject->ID); | |
if ($user instanceof eZUser) { | |
$availableLanguages = $contentObject->currentVersion()->translationList(false, false); | |
foreach ($availableLanguages as $languageCode) { | |
$extraData->set('login_count', $user->loginCount(), $languageCode); | |
$extraData->set('last_visit', $user->lastVisit(), $languageCode); | |
} | |
} | |
} catch (Exception $e) { | |
eZDebug::writeError($e->getMessage(), __METHOD__); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment