protected function getModelCategories() { $retval = array(); $error = error_reporting(0); $i18n = sfContext::getInstance()->getI18N(); error_reporting($error); if ($i18n) { $i18n = $this->getSearch()->getContext()->getI18N(); $i18n->setMessageSource(null, $this->getSearch()->getParameter('culture')); } // see: http://www.nabble.com/Lucene-and-n:m-t4449653s16154.html#a12695579 foreach (parent::getModelCategories() as $category) { if (preg_match('/^%(.*)%$/', $category, $matches)) { $category = $matches[1]; $getter = 'get' . $category; if (!is_callable(array($this->getModel(), $getter))) { throw new sfLuceneIndexerException(sprintf('%s->%s() cannot be called', $this->getModelName(), $getter)); } $getterValue = $this->getModel()->{$getter}(); if (is_object($getterValue) && method_exists($getterValue, '__toString')) { $getterValue = $getterValue->__toString(); } elseif (!is_scalar($getterValue)) { if (is_object($getterValue)) { throw new sfLuceneIndexerException('Category value returned is an object, but could not be casted to a string (add a __toString() method to fix this).'); } else { throw new sfLuceneIndexerException('Category value returned is not a string (got a ' . gettype($value) . ' ) and could not be transformed into a string.'); } } $retval[] = $getterValue; } else { $retval[] = $i18n ? $i18n->__($category) : $category; } } return $retval; }
/** * Returns an array of all the categories that this model is configured for */ protected function getModelCategories() { $retval = array(); // change i18n to this culture if (sfConfig::get('sf_i18n')) { $i18n = $this->getSearch()->getContext()->getI18N(); $i18n->setMessageSource(null, $this->getSearch()->getParameter('culture')); } // see: http://www.nabble.com/Lucene-and-n:m-t4449653s16154.html#a12695579 foreach (parent::getModelCategories() as $category) { // if category fits into syntax "%XXX%" then we must replace it with ->getXXX() on the model if (substr($category, 0, 1) == '%' && substr($category, -1, 1) == '%') { $category = substr($category, 1, -1); $getter = 'get' . sfInflector::camelize($category); $getterValue = $this->getModel()->{$getter}(); // attempt to convert value to string if (is_object($getterValue) && method_exists($getterValue, '__toString')) { $getterValue = $getterValue->__toString(); } elseif (!is_scalar($getterValue)) { throw new sfLuceneIndexerException('Category value returned is not a string (got a ' . gettype($getterValue) . ') and could not be transformed into a string.'); } // store value for returning. as the value comes the model, it is already // configured for i18n $retval[] = $getterValue; } else { // value did not come from model, so store it using i18n if possible if (isset($i18n) && $i18n) { $retval[] = $i18n->__($category); } else { $retval[] = $category; } } } return $retval; }