示例#1
0
 /**
  * Get the cache-value
  *
  * @param string $type
  *
  * @return Cache
  */
 public function getCache()
 {
     $caches = $this->usergroup->getCaches();
     $myCache = null;
     foreach ($caches as $cache) {
         if ($this->type != $cache->getType()) {
             continue;
         }
         $myCache = $cache;
         break;
     }
     if (!$myCache) {
         $myCache = $this->serviceManager->get('Phpug\\Entity\\Cache');
         $myCache->setType($this->type);
         $this->usergroup->caches->add($myCache);
         $myCache->setGroup($this->usergroup);
     }
     $config = $this->serviceManager->get('config');
     $cacheLifeTime = $config['phpug']['entity']['cache'][$this->type]['cacheLifeTime'];
     $cacheLifeTime = new \DateInterval($cacheLifeTime);
     if ($myCache->getLastChangeDate()->add($cacheLifeTime) < new \DateTime() || trim($myCache->getCache()) == '') {
         $value = $this->populator->populate($this->usergroup, $this->serviceManager);
         if ($value) {
             $myCache->setCache($value);
         }
         $myCache->setLastChangeDate(new DateTime());
         $myCache = $this->makePersistent($myCache);
     }
     return $myCache;
 }
示例#2
0
 /**
  * Do the actual Cache-Popularion
  *
  * @param Usergroup $usergroup
  * @param ServiceLocatorInterface $serviceManager
  *
  * @return String
  */
 public function populate(Usergroup $usergroup, ServiceLocatorInterface $serviceManager)
 {
     try {
         $geocoder = $serviceManager->get('Phpug\\Service\\Geocoder');
         $geocode = $geocoder->reverse($usergroup->getLatitude(), $usergroup->getLongitude());
         return $geocode->getCountryCode();
     } catch (\Exception $e) {
         //
     }
     return '';
 }
 /**
  * Assert that the users social nick is associated with this group
  *
  * @param Acl $acl
  * @param RoleInterface $role
  * @param ResourceInterface $resource
  * @param string $privilege
  *
  * @return boolean
  */
 public function assert(Acl $acl, RoleInterface $role = null, ResourceInterface $resource = null, $privilege = null)
 {
     if (!$this->user) {
         return false;
     }
     if (!$this->group) {
         return false;
     }
     $service = strtolower($this->user->getService());
     $uid = strtolower($this->user->getDisplayName());
     foreach ($this->group->getContacts() as $contact) {
         if (strtolower($contact->getServiceName()) !== $service) {
             continue;
         }
         if (strtolower($contact->name) !== $uid) {
             continue;
         }
         return true;
     }
     return false;
 }
 protected function sendNotification(Usergroup $usergroup)
 {
     $message = $this->getServiceLocator()->get('Phpug\\Service\\UsergroupMessage');
     $message->setBody(sprintf($message->getBody(), $usergroup->getName(), $usergroup->getShortname()));
     $message->setSubject(sprintf($message->getSubject(), $usergroup->getName()));
     $transport = $this->getServiceLocator()->get('Phpug\\Service\\Transport');
     $transport->send($message);
     return $this;
 }