The resources can be from the database or from the file system so whenever checking resources for equality use the path property.
Inheritance: extends AbstractEntity
Example #1
0
 public function __construct($p_templateIdOrName = null, $p_themePath = null)
 {
     $this->m_properties = array();
     $this->m_customProperties['name'] = 'getValue';
     $this->m_customProperties['identifier'] = 'getId';
     $this->m_customProperties['type'] = 'getTemplateType';
     $this->m_customProperties['defined'] = 'defined';
     $this->m_customProperties['theme_dir'] = 'getThemeDir';
     $this->_map = array("frontPage" => "issue", "errorPage" => "default", "sectionPage" => "section", "issuePage" => "issue", "articlePage" => "article");
     if ((is_string($p_templateIdOrName) || is_int($p_templateIdOrName)) && !empty($p_templateIdOrName)) {
         $filePath = is_numeric($p_templateIdOrName) ? $p_templateIdOrName : $p_themePath . $p_templateIdOrName;
         $resourceId = new ResourceId('template_engine/metaclasses/MetaTemplate');
         /* @var $syncResourceService ISyncResourceService */
         $syncResourceService = $resourceId->getService(ISyncResourceService::NAME);
         $this->m_dbObject = $syncResourceService->findByPathOrId($filePath);
         if (is_null($this->m_dbObject)) {
             $pathRsc = new Resource();
             $pathRsc->setName('buildPage');
             $filePath = CS_PATH_TEMPLATES . DIR_SEP . $p_themePath . $p_templateIdOrName;
             if (!is_numeric($p_templateIdOrName) && !is_null($p_themePath) && file_exists($filePath)) {
                 $pathRsc->setPath($p_themePath . $p_templateIdOrName);
                 $this->m_dbObject = $syncResourceService->getSynchronized($pathRsc);
             } else {
                 $this->m_dbObject = $pathRsc;
             }
         }
     }
 }
 function getThemePath($themePath)
 {
     Validation::notEmpty($themePath, 'themePath');
     $pathRsc = new Resource();
     $pathRsc->setName(self::THEME_PATH_RSC_NAME);
     $pathRsc->setPath($themePath);
     return $this->getSynchronized($pathRsc);
 }
 /**
  * Sets the URI path and query values based on given parameters.
  *
  * @param array   $p_params
  *                           An array of valid URL parameters
  * @param boolean $p_preview
  *                           If true, will keep the preview parameters in the URL
  *
  * @return void
  */
 protected function buildURI(array &$p_params = array(), $p_preview = false)
 {
     if ($this->isValidCache()) {
         return;
     }
     $parameter = count($p_params) > 0 ? strtolower(array_shift($p_params)) : null;
     switch ($parameter) {
         case 'language':
         case 'publication':
             $this->m_buildPath = $this->getURILanguage();
             if ($p_preview) {
                 $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters);
             } else {
                 $this->m_buildQueryArray = array();
             }
             $p_params = array();
             break;
         case 'issue':
             $this->m_buildPath = $this->getURIIssue();
             if ($p_preview) {
                 $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters);
             } else {
                 $this->m_buildQueryArray = array();
             }
             $p_params = array();
             break;
         case 'section':
             $this->m_buildPath = $this->getURISection();
             if ($p_preview) {
                 $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters);
             } else {
                 $this->m_buildQueryArray = array();
             }
             $p_params = array();
             break;
         case 'article':
             $this->m_buildPath = $this->getURIArticle();
             if ($p_preview) {
                 $this->m_buildQueryArray = $this->getQueryArray(CampURI::$m_previewParameters);
             } else {
                 $this->m_buildQueryArray = array();
             }
             $p_params = array();
             break;
         case 'template':
         case 'id':
             $option = isset($p_params[0]) ? array_shift($p_params) : null;
             if (is_null($option)) {
                 break;
             }
             if (is_null($this->_themePath)) {
                 $themesService = \Zend_Registry::get('container')->getService('newscoop_newscoop.themes_service');
                 $this->_themePath = $themesService->getThemePath();
             }
             $pathRsc = new Resource();
             $pathRsc->setName('buildPage');
             $pathRsc->setPath($this->_themePath . $option);
             $resourceId = new ResourceId('template_engine/classes/CampURIShortNames');
             $pathRsc = $resourceId->getService(ISyncResourceService::NAME)->getSynchronized($pathRsc);
             if (!is_null($pathRsc) && $pathRsc->exists()) {
                 $this->m_buildQueryArray[CampRequest::TEMPLATE_ID] = $pathRsc->getId();
             }
             break;
         default:
             if (!empty($parameter)) {
                 array_unshift($p_params, $parameter);
                 $count = count($p_params);
                 parent::buildURI($p_params, $p_preview);
                 if (count($p_params) == $count) {
                     array_shift($p_params);
                 }
             }
     }
     if (count($p_params) > 0) {
         $this->buildURI($p_params);
     }
     if (!is_null($this->m_language) && $this->m_language->defined() && is_null($this->m_buildPath)) {
         $this->m_buildPath = '/' . $this->m_language->code . '/';
         if (!is_null($this->m_issue) && $this->m_issue->defined()) {
             $this->m_buildPath .= $this->m_issue->url_name . '/';
             if (!is_null($this->m_section) && $this->m_section->defined()) {
                 $this->m_buildPath .= $this->m_section->url_name . '/';
                 if (!is_null($this->m_article) && $this->m_article->defined()) {
                     $this->m_buildPath = $this->getURIArticle();
                 }
             }
         }
     }
     if (is_null($this->m_buildQuery)) {
         $this->m_buildQuery = CampURI::QueryArrayToString($this->m_buildQueryArray);
     }
     $this->validateCache(true);
 }
 public function it_gets_theme_path(OutputSettingsIssue $issueOutput, Resource $resource)
 {
     $resource->getPath()->willReturn('publication_1/theme_1/');
     $issueOutput->getThemePath()->willReturn($resource);
     $this->getThemePath()->shouldReturn('publication_1/theme_1/');
 }
Example #5
0
 public function getNonDbResource($name, $path)
 {
     $rsc = new Resource();
     $rsc->setName($name);
     $rsc->setPath($path);
     return $rsc;
 }
 /**
  * Internal method, get the full path from an resource.
  *
  * @param Resource $resource
  * @return string
  */
 protected function getResourceFullPath(Resource $resource)
 {
     return $resource->getPath();
 }
 public function setId($id)
 {
     $this->__load();
     return parent::setId($id);
 }
 /**
  * Provides the relative path of the resource based on the provided theme path.
  * This method also checks if the resource path is compatible with the theme path
  * meaning that the resource needs to be placed in the theme.
  *
  * @param Resource $rsc
  * 		The resource to extract the relative path from, not null.
  * @param string $themePath
  * 		The theme path, not null.
  * @throws Exception
  * 		In case the resource does not belong to the theme.
  * @return string
  * 		The relative [path in regards with the theme path for the resource.
  */
 protected function getRelativePath(Resource $rsc, $themePath)
 {
     $path = $rsc->getPath();
     $lenght = strlen($themePath);
     if (strncmp($path, $themePath, $lenght) != 0) {
         throw new \Exception("The resource path '.{$path}.' is not for the provided theme path '.{$themePath}.'.");
     }
     $path = substr($path, $lenght);
     return $path;
 }
 function getPresentationImages(Theme $theme)
 {
     Validation::notEmpty($theme, self::TAG_THEME);
     $xml = $this->loadXML($this->toFullPath($theme, $this->themeConfigFileName));
     $presentResources = array();
     if ($xml != NULL) {
         $nodes = $this->getNodes($xml, self::TAG_PRESENT);
         foreach ($nodes as $node) {
             /* @var $node \SimpleXMLElement */
             $rsc = new Resource();
             try {
                 $rsc->setName($this->readAttribute($node, self::ATTR_PRESENT_NAME));
                 $rsc->setPath($theme->getPath() . $this->readAttribute($node, self::ATTR_PRESENT_SRC));
                 $presentResources[] = $rsc;
             } catch (XMLMissingAttribueException $e) {
                 $this->getErrorHandler()->error(ThemeErrors::XML_MISSING_ATTRIBUTE, $e->getAttributeName(), $node->getName());
             }
         }
     }
     return $presentResources;
 }