/** * {@inheritDoc} */ public function setSocialCache($cache) { $this->__initializer__ && $this->__initializer__->__invoke($this, 'setSocialCache', array($cache)); return parent::setSocialCache($cache); }
/** * Get the user's social profile data from cache or integrations if indicated * * @param \Mautic\LeadBundle\Entity\Lead $lead * @param array $fields * @param bool $refresh * @param string $specificIntegration * @param bool $persistLead * @param bool $returnSettings * * @return array */ public function getUserProfiles($lead, $fields = array(), $refresh = false, $specificIntegration = null, $persistLead = true, $returnSettings = false) { $socialCache = $lead->getSocialCache(); $featureSettings = array(); if ($refresh) { //regenerate from integrations $now = new DateTimeHelper(); //check to see if there are social profiles activated $socialIntegrations = $this->getIntegrationObjects($specificIntegration, array('public_profile', 'public_activity')); /* @var \MauticPlugin\MauticSocialBundle\Integration\SocialIntegration $sn */ foreach ($socialIntegrations as $integration => $sn) { $settings = $sn->getIntegrationSettings(); $features = $settings->getSupportedFeatures(); $identifierField = $this->getUserIdentifierField($sn, $fields); if ($returnSettings) { $featureSettings[$integration] = $settings->getFeatureSettings(); } if ($identifierField && $settings->isPublished()) { $profile = !isset($socialCache[$integration]) ? array() : $socialCache[$integration]; //clear the cache unset($profile['profile'], $profile['activity']); if (in_array('public_profile', $features) && $sn->isAuthorized()) { $sn->getUserData($identifierField, $profile); } if (in_array('public_activity', $features) && $sn->isAuthorized()) { $sn->getPublicActivity($identifierField, $profile); } if (!empty($profile['profile']) || !empty($profile['activity'])) { if (!isset($socialCache[$integration])) { $socialCache[$integration] = array(); } $socialCache[$integration]['profile'] = !empty($profile['profile']) ? $profile['profile'] : array(); $socialCache[$integration]['activity'] = !empty($profile['activity']) ? $profile['activity'] : array(); $socialCache[$integration]['lastRefresh'] = $now->toUtcString(); } } elseif (isset($socialCache[$integration])) { //integration is now not applicable unset($socialCache[$integration]); } } if ($persistLead && !empty($socialCache)) { $lead->setSocialCache($socialCache); $this->factory->getEntityManager()->getRepository('MauticLeadBundle:Lead')->saveEntity($lead); } } elseif ($returnSettings) { $socialIntegrations = $this->getIntegrationObjects($specificIntegration, array('public_profile', 'public_activity')); foreach ($socialIntegrations as $integration => $sn) { $settings = $sn->getIntegrationSettings(); $featureSettings[$integration] = $settings->getFeatureSettings(); } } if ($specificIntegration) { return $returnSettings ? array(array($specificIntegration => $socialCache[$specificIntegration]), $featureSettings) : array($specificIntegration => $socialCache[$specificIntegration]); } return $returnSettings ? array($socialCache, $featureSettings) : $socialCache; }