getLang = Lang::default('ZN\Language\GridDefaultLanguage') ::select('ViewObjects:mlgrid'); } /** * Set URL * * @param string $url = NULL * * @return Grid */ public function url(?string $url = NULL) { $this->url = $url; } /** * Set Limit * * @param int $limit = NULL * * @return Grid */ public function limit(?int $limit = NULL) { $this->limit = $limit; } /** * Creates table * * @param mixed $app = NULL * * @return string */ public function create($app = NULL) : string { $searchWord = ''; if( Method::post() ) { $keyword = Method::post('ML_UPDATE_KEYWORD_HIDDEN'); $languages = explode(',', Method::post('ML_LANGUAGES')); $words = Method::post('ML_UPDATE_WORDS'); // SEARCH if( Method::post('ML_SEARCH_SUBMIT') ) { $searchWord = Method::post('ML_SEARCH'); } // ADD LANGUAGE if( Method::post('ML_ADD_ALL_LANGUAGE_SUBMIT') ) { (new Insert)->do(Method::post('ML_ADD_LANGUAGE'), 'example', 'Example'); } // ALL DELETE if( Method::post('ML_ALL_DELETE_SUBMIT') ) { $allDelete = Method::post('ML_ALL_DELETE_HIDDEN'); (new Delete)->all($allDelete); } // ADD if( Method::post('ML_ADD_KEYWORD_SUBMIT') ) { $addWords = Method::post('ML_ADD_WORDS'); $addKeyword = Method::post('ML_ADD_KEYWORD'); if( is_numeric($addKeyword) ) { $addKeyword = 'Wrong Keyword! Only String.'; } if( ! empty($languages) ) foreach( $languages as $key => $lang ) { (new Insert)->do($lang, $addKeyword, $addWords[$key]); } } // UPDATE if( Method::post('ML_UPDATE_KEYWORD_SUBMIT') ) { if( ! empty($languages) ) foreach( $languages as $key => $lang ) { (new Update)->do($lang, $keyword, $words[$key]); } } // DELETE if( Method::post('ML_DELETE_SUBMIT') ) { if( ! empty($languages) ) foreach( $languages as $key => $lang ) { (new Delete)->do($lang, $keyword); } } } $config = $this->gridConfig; $attributes = $config['attributes']; $pagcon = $config['pagination']; $title = $this->getLang['ml:titleLabel']; $confirmMessage = $this->getLang['ml:confirmLabel']; $process = $this->getLang['ml:processLabel']; $keywords = $this->getLang['ml:keywordsLabel']; $confirmBox = ' onsubmit="return confirm(\''.$confirmMessage.'\');"'; $data = (new Select)->all($app); $languageCount = count($data); $formClass = Singleton::class('ZN\Hypertext\Form'); $table = $this->_styleElement(); $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $words = []; $formObjects = ''; $languages = implode(',', $arrayKeys = array_keys($data)); $mlLanguages = (string) $formClass->hidden('ML_LANGUAGES', $languages); foreach( $data as $lang => $values ) { $upperLang = strtoupper($lang); $table .= ''; $table .= ''; $table .= ''; foreach( $values as $key => $val ) { $words[$key][$lang] = $val; } $formObjects .= ''; } $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= ''; $table .= $formObjects; $table .= ''; $table .= ''; $table .= ''; $limit = $this->limit; $start = (int) URI::segment(-1); $totalRows = count($words); $index = 1; if( ! empty($searchWord) ) { $newWords = []; foreach( $words as $key => $val ) { if( stristr($key, $searchWord) ) { $newWords[$key] = $val; // @codeCoverageIgnore } else { $newValues = []; foreach( $val as $k => $v ) { if( stristr($v, $searchWord) ) { $newValues = array_merge($newValues, $val); // @codeCoverageIgnore } } if( ! empty($newValues) ) { $newWords[$key] = $newValues; // @codeCoverageIgnore } } } $words = $newWords; } if( empty($searchWord) ) { $words = array_slice($words, $start, $limit); } foreach( $words as $key => $val ) { $table .= ''; $table .= ''; $table .= ''; $table .= ''; foreach( $arrayKeys as $i ) { $table .= ''; } $table .= ''; $table .= ''; $table .= ''; } if( empty($this->url) ) { $paginationUrl = CURRENT_CFPATH; } else { $paginationUrl = $this->url; } if( empty($searchWord) ) { $pagination = Singleton::class('ZN\Pagination\Paginator') ->style($pagcon['style']) ->css($pagcon['class']) ->start($start) ->totalRows($totalRows) ->limit($limit) ->url($paginationUrl) ->create(); } else { $pagination = NULL; } if( ! empty($pagination) && ! empty($totalRows) ) { $table .= ''; // @codeCoverageIgnore } $table .= ''; $table .= '
'.$title.'
S/L'; $table .= '
'; $table .= $formClass->attr($attributes['textbox'])->placeholder($this->getLang['ml:searchPlaceHolder'])->text('ML_SEARCH'); $table .= $formClass->attr($attributes['add'])->submit('ML_SEARCH_SUBMIT', $this->getLang['ml:searchButton']); $table .= $formClass->attr($attributes['textbox'])->placeholder($this->getLang['ml:addLanguagePlaceHolder'])->text('ML_ADD_LANGUAGE'); $table .= $formClass->attr($attributes['add'])->submit('ML_ADD_ALL_LANGUAGE_SUBMIT', $this->getLang['ml:addButton']).'
#'.$keywords.'
'.$upperLang.$formClass->hidden('ML_ALL_DELETE_HIDDEN', $lang).$formClass->attr($attributes['delete'])->submit('ML_ALL_DELETE_SUBMIT', $this->getLang['ml:deleteButton']).''.$formClass->attr($attributes['textbox'])->placeholder($upperLang)->text('ML_ADD_WORDS[]').''.$process.'
N'.$mlLanguages.$formClass->attr($attributes['textbox'])->placeholder($this->getLang['ml:keywordPlaceHolder'])->text('ML_ADD_KEYWORD').''.$formClass->attr($attributes['add'])->submit('ML_ADD_KEYWORD_SUBMIT', $this->getLang['ml:addButton']).' '.$formClass->attr($attributes['clear'])->reset('ML_ADD_KEYWORD_RESET', $this->getLang['ml:clearButton']).'
'.$index++.''.$formClass->hidden('ML_UPDATE_KEYWORD_HIDDEN', $key).$key.''.$formClass->attr($attributes['textbox'])->text('ML_UPDATE_WORDS[]', ( ! empty($val[$i]) ? $val[$i] : '' )).''.$mlLanguages.$formClass->attr($attributes['update'])->submit('ML_UPDATE_KEYWORD_SUBMIT', $this->getLang['ml:updateButton']); $table .= ' '; $table .= $formClass->attr($attributes['delete'])->submit('ML_DELETE_SUBMIT', $this->getLang['ml:deleteButton']).'
P'.$pagination.'
'; return $table; } /** * Protected Style Element */ protected function _styleElement() { $styleElementConfig = $this->gridConfig['styleElement'] ?? NULL; // @codeCoverageIgnoreStart if( ! empty($styleElementConfig) ) { $attributes = ''; $sheet = Singleton::class('ZN\Hypertext\Sheet'); $style = Singleton::class('ZN\Hypertext\Style'); foreach( $styleElementConfig as $selector => $attr ) { $attributes .= $sheet->selector($selector)->attr($attr)->create(); } return $style->open().$attributes.$style->close(); } // @codeCoverageIgnoreEnd return NULL; } }