Skip to content

Instantly share code, notes, and snippets.

@Opencontent
Created September 6, 2017 07:58
Show Gist options
  • Save Opencontent/9dd9c88b1e91c4a041ffbf8980010940 to your computer and use it in GitHub Desktop.
Save Opencontent/9dd9c88b1e91c4a041ffbf8980010940 to your computer and use it in GitHub Desktop.
<?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