Newscoop\Entity\Repository\TemplateRepository::getTemplate PHP Method

getTemplate() public method

Get template for given key
public getTemplate ( string $key ) : Template
$key string
return Newscoop\Entity\Template
    public function getTemplate($key)
    {
        $key = $this->formatKey($key);
        $template = $this->findOneBy(array('key' => $key));
        if (empty($template)) {
            $template = new Template($key);
            $em = $this->getEntityManager();
            $em->persist($template);
            $em->flush();
        }
        return $template;
    }

Usage Example

Esempio n. 1
0
 /**
  * Fetch item metadata
  *
  * @param string $key
  * @return object
  */
 public function fetchMetadata($key)
 {
     $item = $this->storage->getItem($key);
     $metadata = array('key' => $item->getKey(), 'name' => $item->getName(), 'type' => $item->getType(), 'realpath' => $this->storage->getRealpath($key));
     if (!$item->isDir()) {
         $metadata += array('size' => $item->getSize(), 'ctime' => $item->getChangeTime());
         if ($metadata['type'] == 'tpl') {
             $template = $this->repository->getTemplate($key, false);
             // get the resource for the template id
             $resource = $this->syncResServ->findByPathOrId(rtrim($this->theme->getPath(), "/") . "/" . ltrim($key, "/"));
             /* @var $resource Newscoop\Entity\Resource */
             $metadata += array('id' => is_object($resource) ? $resource->getId() : $template->getId(), 'ttl' => $template->getCacheLifetime());
         }
     }
     return (object) $metadata;
 }
All Usage Examples Of Newscoop\Entity\Repository\TemplateRepository::getTemplate