public function __actionIndex()
 {
     $checked = @array_keys($_POST['items']);
     if (is_array($checked) and !empty($checked)) {
         switch ($_POST['with-selected']) {
             case 'delete':
                 foreach ($checked as $section_id) {
                     $this->__setContext($section_id);
                     // ignore if no index is set for a selected section
                     if (is_null($this->_index)) {
                         continue;
                     }
                     SearchIndex::deleteIndexBySection($section_id);
                     unset($this->_indexes[$section_id]);
                     SearchIndex::saveIndexes($this->_indexes);
                 }
                 redirect("{$this->_uri}/indexes/");
                 break;
             case 're-index':
                 foreach ($checked as $section_id) {
                     SearchIndex::deleteIndexBySection($section_id);
                 }
                 redirect("{$this->_uri}/indexes/?section=" . join(',', $checked));
                 break;
         }
     }
 }
Exemplo n.º 2
0
 public function __viewIndex()
 {
     $this->setPageType('table');
     $this->setTitle(__('Symphony') . ' – ' . __('Search Indexes'));
     $this->appendSubheading(__('Indexes'));
     $this->Form->appendChild(new XMLElement('p', __('Configure how each of your sections are indexed. Choose which field text values to index, which entries to index, and the weighting of the section in search results.'), array('class' => 'intro')));
     $this->addElementToHead(new XMLElement('script', "Symphony.Context.add('search_index', " . json_encode(Symphony::Configuration()->get('search_index')) . ")", array('type' => 'text/javascript')), 99);
     $this->addStylesheetToHead(URL . '/extensions/search_index/assets/search_index.css', 'screen', 100);
     $this->addScriptToHead(URL . '/extensions/search_index/assets/search_index.js', 101);
     $tableHead = array();
     $tableBody = array();
     $tableHead[] = array(__('Section'), 'col');
     $tableHead[] = array(__('Fields'), 'col');
     $tableHead[] = array(__('Weighting'), 'col');
     $tableHead[] = array(__('Index Size'), 'col');
     if (!is_array($this->_sections) or empty($this->_sections)) {
         $tableBody = array(Widget::TableRow(array(Widget::TableData(__('None Found.'), 'inactive', null, count($tableHead)))));
     } else {
         $re_index = explode(',', $_GET['section']);
         foreach ($this->_sections as $section) {
             $index = NULL;
             if (isset($this->_indexes[$section->get('id')])) {
                 $index = $this->_indexes[$section->get('id')];
             }
             $col_name = Widget::TableData(Widget::Anchor($section->get('name'), "{$this->_uri}/indexes/edit/{$section->get('id')}/"));
             if ($index) {
                 $col_name->appendChild(Widget::Input("items[{$section->get('id')}]", null, 'checkbox'));
             }
             if ($index && isset($index['fields']) && count($index['fields'] > 0)) {
                 $section_fields = $section->fetchFields();
                 $fields = $this->_indexes[$section->get('id')]['fields'];
                 $fields_list = '';
                 foreach ($section_fields as $section_field) {
                     if (in_array($section_field->get('element_name'), array_values($fields))) {
                         $fields_list .= $section_field->get('label') . ', ';
                     }
                 }
                 $fields_list = trim($fields_list, ', ');
                 $col_fields = Widget::TableData($fields_list);
             } else {
                 $col_fields = Widget::TableData(__('None'), 'inactive');
             }
             if ($index) {
                 if ($index['weighting'] == '') {
                     $index['weighting'] = 2;
                 }
                 $col_weighting = Widget::TableData($this->_weightings[$index['weighting']]);
             } else {
                 $col_weighting = Widget::TableData(__('None'), 'inactive');
             }
             $count_data = null;
             $count_class = null;
             if (isset($_GET['section']) && in_array($section->get('id'), $re_index) && in_array($section->get('id'), array_keys($this->_indexes))) {
                 SearchIndex::deleteIndexBySection($section->get('id'));
                 $count_data = '<span class="to-re-index" id="section-' . $section->get('id') . '">' . __('Waiting to re-index...') . '</span>';
             } else {
                 if (isset($this->_indexes[$section->get('id')])) {
                     $count = Symphony::Database()->fetchCol('count', sprintf("SELECT COUNT(entry_id) as `count` FROM tbl_search_index WHERE `section_id`='%d'", $section->get('id')));
                     $count_data = $count[0] . ' ' . ((int) $count[0] == 1 ? __('entry') : __('entries'));
                 } else {
                     $count_data = __('No index');
                     $count_class = 'inactive';
                 }
             }
             $col_count = Widget::TableData($count_data, $count_class . ' count-column');
             $tableBody[] = Widget::TableRow(array($col_name, $col_fields, $col_weighting, $col_count), 'section-' . $section->get('id'));
         }
     }
     $table = Widget::Table(Widget::TableHead($tableHead), NULL, Widget::TableBody($tableBody), 'selectable', null, array('role' => 'directory', 'aria-labelledby' => 'symphony-subheading', 'data-interactive' => 'data-interactive'));
     $this->Form->appendChild($table);
     $actions = new XMLElement('div');
     $actions->setAttribute('class', 'actions');
     $options = array(array(null, false, __('With Selected...')), array('re-index', false, __('Re-index Entries')), array('delete', false, __('Delete')));
     $actions->appendChild(Widget::Apply($options));
     $this->Form->appendChild($actions);
 }