コード例 #1
0
ファイル: index.php プロジェクト: naujasdizainas/forkcms
 /**
  * Load the datagrid
  */
 private function loadDataGrid()
 {
     // init vars
     $langWidth = 80 / count($this->filter['language']);
     // get all the translations for the selected languages
     $translations = BackendLocaleModel::getTranslations($this->filter['application'], $this->filter['module'], $this->filter['type'], $this->filter['language'], $this->filter['name'], $this->filter['value']);
     // create datagrids
     $this->dgLabels = new BackendDataGridArray(isset($translations['lbl']) ? $translations['lbl'] : array());
     $this->dgMessages = new BackendDataGridArray(isset($translations['msg']) ? $translations['msg'] : array());
     $this->dgErrors = new BackendDataGridArray(isset($translations['err']) ? $translations['err'] : array());
     $this->dgActions = new BackendDataGridArray(isset($translations['act']) ? $translations['act'] : array());
     // put the datagrids (references) in an array so we can loop them
     $dataGrids = array('lbl' => &$this->dgLabels, 'msg' => &$this->dgMessages, 'err' => &$this->dgErrors, 'act' => &$this->dgActions);
     // loop the datagrids (as references)
     foreach ($dataGrids as $type => &$dataGrid) {
         // set sorting
         $dataGrid->setSortingColumns(array('module', 'name'), 'name');
         // disable paging
         $dataGrid->setPaging(false);
         // set header label for reference code
         $dataGrid->setHeaderLabels(array('name' => SpoonFilter::ucfirst(BL::lbl('ReferenceCode'))));
         // set column attributes for each language
         foreach ($this->filter['language'] as $lang) {
             // add a class for the inline edit
             $dataGrid->setColumnAttributes($lang, array('class' => 'translationValue'));
             // add attributes, so the inline editing has all the needed data
             $dataGrid->setColumnAttributes($lang, array('data-id' => '{language: \'' . $lang . '\', application: \'' . $this->filter['application'] . '\', module: \'[module]\', name: \'[name]\', type: \'' . $type . '\'}'));
             // escape the double quotes
             $dataGrid->setColumnFunction(array('SpoonFilter', 'htmlentities'), array('[' . $lang . ']', null, ENT_QUOTES), $lang, true);
             if ($type == 'act') {
                 $dataGrid->setColumnFunction('urldecode', array('[' . $lang . ']'), $lang, true);
             }
             // set header labels
             $dataGrid->setHeaderLabels(array($lang => SpoonFilter::ucfirst(BL::getMessage(strtoupper($lang)))));
             // set column attributes
             $dataGrid->setColumnAttributes($lang, array('style' => 'width: ' . $langWidth . '%'));
             // hide translation_id column (only if only one language is selected because the key doesn't exist if more than 1 language is selected)
             if (count($this->filter['language']) == 1) {
                 $dataGrid->setColumnHidden('translation_id');
             }
             // only 1 language selected?
             if (count($this->filter['language']) == 1) {
                 // check if this action is allowed
                 if (BackendAuthentication::isAllowedAction('edit')) {
                     // add edit button
                     $dataGrid->addColumn('edit', null, BL::lbl('Edit'), BackendModel::createURLForAction('edit', null, null, null) . '&id=[translation_id]' . $this->filterQuery);
                 }
                 // check if this action is allowed
                 if (BackendAuthentication::isAllowedAction('add')) {
                     // add copy button
                     $dataGrid->addColumnAction('copy', null, BL::lbl('Copy'), BackendModel::createURLForAction('add', null, null) . '&id=[translation_id]' . $this->filterQuery, array('class' => 'button icon iconCopy linkButton'));
                 }
             }
         }
     }
 }