Skip to content

Commit

Permalink
various fixes for translation and default admin mappe
Browse files Browse the repository at this point in the history
  • Loading branch information
Floby committed Sep 18, 2012
1 parent a151a25 commit bb48d22
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 7 deletions.
1 change: 1 addition & 0 deletions configs/module.ini
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ highlight.mappers.default.cover.pixelOnEmpty = 1
;
; the class to instanciate
highlight.crawlers.default.className = "Highlight_Model_Crawler_Default";
highlight.crawlers.default.useFilters = true

; each key of the config defines a model it has to crawl
; the table config define which table it has to crawl
Expand Down
37 changes: 31 additions & 6 deletions models/Controller/AdminHighlightController.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,20 +247,45 @@ public function getAction()
)));
$this->view->autoCompleteForm = $form;

$this->view->highlightMapper = $this->_getHighlightMapper();
$this->view->highlightMapper = $this->getMapper();

$this->render('admin-highlight/get', true, true);
}

/**
* gets a mapper for the highlights item we want to display.
* returns the mapper to be used upon listing of the highlight
* @return Highlight_Model_Mapper_Interface
*/
protected function _getHighlightMapper()
public function getMapper()
{
// return default mapper for now
return Highlight_Model_FieldMapper_Factory::get('default');
// maybe there was a crawler parameter in the url
// we can try and find it from config.
if($this->_getParam('mapper', false)) {
$mapperName = $this->_getParam('mapper');
$mapper = Highlight_Model_Mapper_Factory::get($mapperName);
}

// maybe the container is a named container and has a mapper in its config
if($container = $this->_getContainer()) {
if(!empty($container->name)) {
$name = $container->name;
$mapperName = Centurion_Config_Manager::get(sprintf('highlight.named_highlights.%s.mapper', $name));
if($mapperName) {
$mapper = Highlight_Model_FieldMapper_Factory::get($mapperName);
}
}
}

// if everything else fails, get default mapper
if(empty($mapper)) {
$mapper = Highlight_Model_FieldMapper_Factory::get('default');
}

// some mappers may need the container we are talking about
//$mapper->setContainer($this->_getContainer());
return $mapper;
}

public function addAction()
{
$form = $this->_getAutocompleteForm();
Expand Down
8 changes: 8 additions & 0 deletions models/Crawler/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ public function __construct(array $params)
{
unset($params['className']);

$this->_useFilters = true;
if(isset($params['useFilters'])) {
$this->_useFilters = $params['useFilters'];
}
unset($params['useFilters']);

if(!isset($params['models']) || empty($params['models'])) {
throw new InvalidArgumentException('No models defined for this crawler');
}
Expand All @@ -35,7 +41,9 @@ public function crawl(array $params=null)
$fields = (array) $model['fields'];
$limit = (isset($model['limit']) && is_numeric($model['limit'])) ? $model['limit'] : 0;

Centurion_Db_Table_Abstract::setFiltersStatus($this->_useFilters);
$res = array_merge($res, $this->crawlTable($table, $fields, $params['terms'], $limit));
Centurion_Db_Table_Abstract::restoreFiltersStatus();
}
return $res;
}
Expand Down
7 changes: 6 additions & 1 deletion models/FieldMapper/Default.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ function __construct($params)
continue;
}

$this->_pixelOnEmpty = $params['cover']['pixelOnEmpty'] > 0;
if(isset($params['cover']) && isset($params['cover']['pixelOnEmpty'])) {
$this->_pixelOnEmpty = $params['cover']['pixelOnEmpty'] > 0;
}
else {
$this->_pixelOnEmpty = false;
}

$this->_fieldMap[$field] = $fields;
}
Expand Down

0 comments on commit bb48d22

Please sign in to comment.