public static function buildIndexIfNeeded()
 {
     $application = ActiveRecordModel::getApplication();
     $localesToTestForReindexAll = array();
     $locCount = array();
     foreach (array_unique(array($application->getLocaleCode(), $application->getDefaultLanguageCode())) as $localeCode) {
         $count = self::getSearchableItemCount($localeCode);
         if ($count == 0) {
             $localesToTestForReindexAll[] = $localeCode;
         }
     }
     if (count($localesToTestForReindexAll) > 0) {
         $sc = new SearchableConfigurationIndexing($application->getConfig(), $application, $localesToTestForReindexAll);
         $sc->buildIndex(null);
     }
 }
Example #2
0
 public function getSelectFilter($searchTerm)
 {
     // create initial index
     if (0 && !SearchableItem::getRecordCount()) {
         $app = ActiveRecordModel::getApplication();
         $sc = new SearchableConfigurationIndexing($app->getConfig(), $app);
         $sc->buildIndex(null);
     }
     $c = new ARExpressionHandle($this->getWeighedSearchCondition(array('value' => 1), $searchTerm));
     $app = ActiveRecordModel::getApplication();
     $f = new ARSelectFilter(new MoreThanCond($c, 0));
     $f->mergeCondition(new OrChainCondition(array(eq(f('SearchableItem.locale'), $app->getDefaultLanguageCode()), eq(f('SearchableItem.locale'), $app->getLocaleCode()), isnull(f('SearchableItem.locale')))));
     $f->setOrder(f('SearchableItem.sort'), 'DESC');
     $f->setOrder($c, 'DESC');
     return $f;
 }
Example #3
0
 /**
  * @role update
  */
 public function save()
 {
     $values = $this->config->getSettingsBySection($this->request->get('id'));
     $validation = $this->getValidationRules($values);
     $validator = $this->buildValidator($values, $validation);
     if (!$validator->isValid()) {
         return new JSONResponse(array('errors' => $validator->getErrorList()), 'failure', $this->translate('_could_note_save_section'));
     } else {
         $languages = $this->application->getLanguageArray();
         $defLang = $this->application->getDefaultLanguageCode();
         $this->config->setAutoSave(false);
         $data = array();
         foreach ($values as $key => $value) {
             if ($this->config->isMultiLingual($key) && 'string' == $value['type'] || 'longtext' == $value['type']) {
                 $this->config->setValueByLang($key, $defLang, $this->request->get($key));
                 foreach ($languages as $lang) {
                     $this->config->setValueByLang($key, $lang, $this->request->get($key . '_' . $lang));
                 }
             } else {
                 if ('image' == $value['type']) {
                     $file = 'upload/' . $key . '-' . $_FILES[$key]['name'];
                     $path = ClassLoader::getRealPath('public.') . $file;
                     if (@move_uploaded_file($_FILES[$key]['tmp_name'], $path)) {
                         $this->config->set($key, $file);
                     }
                 } else {
                     $this->config->set($key, $this->request->get($key, 'bool' == $value['type'] ? 0 : ''));
                 }
             }
             $data[$key] = $this->config->get($key);
         }
         $this->config->save();
         $this->config->setAutoSave(true);
         ClassLoader::import('application.model.searchable.index.SearchableConfigurationIndexing');
         SearchableConfigurationIndexing::buildIndexIfNeeded();
         $sc = new SearchableConfigurationIndexing($this->config, $this->application);
         $sc->buildIndex($this->request->get('id'));
         return new JSONResponse($data, 'success', $this->translate('_save_conf'));
     }
 }