예제 #1
0
 /**
  * Prepare object for iteration
  *
  * @param modTemplate $template
  * @return array
  */
 public function prepareRow(modTemplate $template)
 {
     $templateArray = $template->toArray();
     $templateArray['access'] = $template->get('tmplvarid');
     $templateArray['access'] = empty($templateArray['access']) ? false : true;
     unset($templateArray['content']);
     return $templateArray;
 }
예제 #2
0
 public function process($properties = null, $content = null)
 {
     $this->_process($properties, $content);
     if (!$this->_processed) {
         return parent::process($properties, $content);
     }
     return $this->_output;
 }
예제 #3
0
 /**
  * Prepare the element and get the static openTo path if needed
  *
  * @return void|string
  */
 public function prepareElement()
 {
     $this->templateArray['openTo'] = '/';
     if (!empty($this->templateArray['static'])) {
         $file = $this->template->get('static_file');
         $this->templateArray['openTo'] = dirname($file) . '/';
     }
     return $this->templateArray['openTo'];
 }
예제 #4
0
 /**
  * Process this page, load the resource, and present its values
  * @return void
  */
 public function process()
 {
     $this->setPlaceholders($this->resource->toArray());
     $this->template = $this->resource->getOne('Template');
     if ($this->template) {
         $this->setPlaceholder('template', $this->template->get('templatename'));
     }
     $contentType = $this->resource->getOne('ContentType');
     if ($contentType) {
         $this->setPlaceholder('content_type', $contentType->get('name'));
     }
     $this->getContent();
     $this->getResourceFields();
     $this->getResourceSettings();
     if ($this->template) {
         $this->getTemplateVariables();
     }
 }
예제 #5
0
 public static function listTemplateVars(modTemplate &$template, array $sort = array('name' => 'ASC'), $limit = 0, $offset = 0, array $conditions = array())
 {
     $result = array('collection' => array(), 'total' => 0);
     $c = $template->xpdo->newQuery('modTemplateVar');
     $result['total'] = $template->xpdo->getCount('modTemplateVar', $c);
     $c->select($template->xpdo->getSelectColumns('modTemplateVar', 'modTemplateVar'));
     $c->leftJoin('modTemplateVarTemplate', 'modTemplateVarTemplate', array("modTemplateVarTemplate.tmplvarid = modTemplateVar.id", 'modTemplateVarTemplate.templateid' => $template->get('id')));
     $c->leftJoin('modCategory', 'Category');
     if (!empty($conditions)) {
         $c->where($conditions);
     }
     $c->select(array("CASE modTemplateVarTemplate.tmplvarid WHEN NULL THEN 0 ELSE 1 END AS access", "ISNULL(modTemplateVarTemplate.rank, 0) AS tv_rank", 'category_name' => 'Category.category'));
     foreach ($sort as $sortKey => $sortDir) {
         $c->sortby($sortKey, $sortDir);
     }
     if ($limit > 0) {
         $c->limit($limit, $offset);
     }
     $result['collection'] = $template->xpdo->getCollection('modTemplateVar', $c);
     return $result;
 }
예제 #6
0
 /**
  * Get all the Template Variables for this Resource
  * @return void
  */
 public function getTemplateVariables()
 {
     $tvObjs = $this->template->getTemplateVars();
     $tvs = array();
     $categories = array();
     /** @var modTemplateVar $tv */
     foreach ($tvObjs as $tv) {
         if ($tv instanceof modTemplateVar) {
             $tvArray = $tv->toArray();
             if (!empty($categories[$tvArray['category']])) {
                 $tvs[$categories[$tvArray['category']]][] = $tv;
             } else {
                 if ($tvArray['category'] == 0) {
                     $tvs[$this->modx->lexicon('uncategorized')][] = $tv;
                 } else {
                     $cat = $tv->getOne('Category');
                     if ($cat instanceof modCategory) {
                         $categories[$tvArray['category']] = $cat->get('category');
                         $tvs[$categories[$tvArray['category']]][] = $tv;
                     }
                 }
             }
         }
     }
     $list = array();
     if (count($tvs) > 0) {
         $this->modx->loadClass('hmTvInputRenderer', $this->hm->config['classesPath'], true, true);
         $renderer = new hmTvInputRenderer($this->hm);
         foreach ($tvs as $categoryName => $categoryTemplateVariables) {
             $tvList = array();
             /** @var modTemplateVar $tv */
             foreach ($categoryTemplateVariables as $tv) {
                 $tvList[] = $renderer->render($tv->get('display'), $tv);
             }
             $list[] = $this->hm->getTpl('fields/tvs/category', array('name' => $categoryName, 'collapsed' => !isset($notFirst) && count($tvs != 1) ? 'data-collapsed="false"' : 'data-collapsed="true"', 'tvs' => implode("\n", $tvList)));
             // This makes sure the first section is opened if there are > 1 sections
             $notFirst = true;
         }
         unset($notFirst);
     }
     $this->setPlaceholder('tvs', implode("\n", $list));
 }
예제 #7
0
 /**
  * @param string $expected
  * @param array $properties
  * @param null|string $content
  * @dataProvider providerProcess
  */
 public function testProcess($expected, array $properties = array(), $content = null)
 {
     $result = $this->template->process($properties, $content);
     $this->assertEquals($expected, $result);
 }