示例#1
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     $values = array();
     $icons = array();
     if (!empty($this->varValue)) {
         $files = \FilesModel::findMultipleByUuids((array) $this->varValue);
         $this->renderList($values, $icons, $files, $this->isGallery || $this->isDownloads);
         $icons = $this->applySorting($icons);
     }
     $template = new ContaoBackendViewTemplate($this->subTemplate);
     $buffer = $template->setTranslator($this->getEnvironment()->getTranslator())->set('name', $this->strName)->set('id', $this->strId)->set('value', implode(',', array_map('String::binToUuid', $values)))->set('hasOrder', $this->orderField != '' && is_array($this->orderFieldValue))->set('icons', $icons)->set('isGallery', $this->isGallery)->set('orderId', $this->orderId)->set('link', $this->generateLink($values))->parse();
     if (!\Environment::get('isAjaxRequest')) {
         $buffer = '<div>' . $buffer . '</div>';
     }
     return $buffer;
 }
示例#2
0
 /**
  * Create a new instance of ContaoBackendViewTemplate with the template file of the given name.
  *
  * @param string $strTemplate Name of the template to create.
  *
  * @return ContaoBackendViewTemplate
  */
 protected function getTemplate($strTemplate)
 {
     $template = new ContaoBackendViewTemplate($strTemplate);
     $template->setTranslator($this->getEnvironment()->getTranslator());
     return $template;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function generate()
 {
     $values = array();
     $icons = array();
     if (!empty($this->varValue)) {
         $files = \FilesModel::findMultipleByUuids((array) $this->varValue);
         $this->renderList($icons, $files, $this->isGallery || $this->isDownloads);
         $icons = $this->applySorting($icons);
         // PHP 7 compatibility, see https://github.com/contao/core-bundle/issues/309
         if (version_compare(VERSION . '.' . BUILD, '3.5.5', '>=')) {
             $mapFunc = 'StringUtil::binToUuid';
         } else {
             $mapFunc = 'String::binToUuid';
         }
         foreach ($files as $model) {
             $values[] = call_user_func($mapFunc, $model->uuid);
         }
     }
     $template = new ContaoBackendViewTemplate($this->subTemplate);
     $buffer = $template->setTranslator($this->getEnvironment()->getTranslator())->set('name', $this->strName)->set('id', $this->strId)->set('value', implode(',', $values))->set('hasOrder', $this->orderField != '' && is_array($this->orderFieldValue))->set('icons', $icons)->set('isGallery', $this->isGallery)->set('orderId', $this->orderId)->set('link', $this->generateLink($values))->parse();
     if (!\Environment::get('isAjaxRequest')) {
         $buffer = '<div>' . $buffer . '</div>';
     }
     return $buffer;
 }
示例#4
0
 /**
  * Generate the tree view for a given collection.
  *
  * @param CollectionInterface $objCollection The collection to iterate over.
  *
  * @param string              $treeClass     The class to use for the tree.
  *
  * @return string
  */
 protected function generateTreeView($objCollection, $treeClass)
 {
     $arrHtml = array();
     foreach ($objCollection as $objModel) {
         /** @var ModelInterface $objModel */
         $strToggleID = $objModel->getProviderName() . '_' . $treeClass . '_' . $objModel->getId();
         $arrHtml[] = $this->parseModel($objModel, $strToggleID);
         if ($objModel->getMeta($objModel::HAS_CHILDREN) && $objModel->getMeta($objModel::SHOW_CHILDREN)) {
             $template = new ContaoBackendViewTemplate('widget_treepicker_child');
             $subHtml = '';
             foreach ($objModel->getMeta($objModel::CHILD_COLLECTIONS) as $objCollection) {
                 $subHtml .= $this->generateTreeView($objCollection, $treeClass);
             }
             $template->setTranslator($this->getEnvironment()->getTranslator())->set('objParentModel', $objModel)->set('strToggleID', $strToggleID)->set('strHTML', $subHtml)->set('strTable', $objModel->getProviderName());
             $arrHtml[] = $template->parse();
         }
     }
     return implode("\n", $arrHtml);
 }