Se añaden busquedas avanzadas
git-svn-id: https://192.168.0.254/svn/Proyectos.Incam_PROFIND_Web/trunk@79 3fe1ab16-cfe0-e34b-8c9f-7d8c168d430d
This commit is contained in:
parent
5c52cdb53d
commit
52fef1f348
@ -27,6 +27,9 @@ class SearchController extends Controller {
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('nombre', CHtml::encode($candidato->nombre), 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('apellidos', CHtml::encode($candidato->apellidos), 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('n_identificacion', CHtml::encode($candidato->n_identificacion), 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('email', CHtml::encode($candidato->email), 'utf-8'));
|
||||
$doc->addField(Zend_Search_Lucene_Field::Text('estado', CHtml::encode($candidato->estado->descripcion), 'utf-8'));
|
||||
|
||||
echo "\tAdding: " . $candidato->id . "\n";
|
||||
$index->addDocument($doc);
|
||||
}
|
||||
@ -35,28 +38,55 @@ class SearchController extends Controller {
|
||||
}
|
||||
|
||||
public function actionSearch() {
|
||||
Yii::trace('Búsqueda', 'application.controllers.SearchController');
|
||||
|
||||
$term = '';
|
||||
$results = array();
|
||||
|
||||
if (($term = Yii::app()->getRequest()->getParam('q', null)) !== null) {
|
||||
if (str_word_count($term) == 1) $term .= '*';
|
||||
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
|
||||
|
||||
try {
|
||||
$results = $index->find($term);
|
||||
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
|
||||
} catch (Exception $e) {
|
||||
if ($e instanceof Zend_Search_Lucene_Exception) {
|
||||
Yii::app()->user->setFlash('error', Yii::t('profind', 'Indique un término de búsqueda de al menos 3 caracteres'));
|
||||
$query = NULL;
|
||||
|
||||
$formulario = new FormularioSearch;
|
||||
|
||||
if (isset($_POST['FormularioSearch'])) {
|
||||
$formulario->attributes = $_POST['FormularioSearch'];
|
||||
if ($formulario->validate()) {
|
||||
foreach ($formulario->attributes as $nombre => $valor) {
|
||||
if (strlen($valor) > 0) {
|
||||
if (strlen($term) > 0)
|
||||
$term .= ' AND ';
|
||||
|
||||
if (in_array($nombre, array('estado'))) {
|
||||
$antes = '"';
|
||||
$despues = '"';
|
||||
} else {
|
||||
$antes = '';
|
||||
$despues = '*';
|
||||
}
|
||||
$term .= $nombre . ':' . $antes . $valor . $despues;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$pages = new CPagination(count($results));
|
||||
$currentPage = Yii::app()->getRequest()->getQuery('page', 1);
|
||||
$pages->pageSize = 10;
|
||||
|
||||
$this->render('search', compact('results', 'term', 'query', 'pages', 'currentPage'));
|
||||
} elseif (($term = Yii::app()->getRequest()->getParam('keyword', null)) !== null) {
|
||||
if (str_word_count($term, 0) < 2)
|
||||
$term .= '*';
|
||||
} else
|
||||
throw new CHttpException(400, Yii::t('profind', 'Petición no válida'));
|
||||
|
||||
$index = new Zend_Search_Lucene(Yii::getPathOfAlias('application.' . $this->_indexFiles));
|
||||
|
||||
try {
|
||||
$results = $index->find($term);
|
||||
$query = Zend_Search_Lucene_Search_QueryParser::parse($term);
|
||||
} catch (Exception $e) {
|
||||
if ($e instanceof Zend_Search_Lucene_Exception) {
|
||||
Yii::app()->user->setFlash('error', Yii::t('profind', 'Indique un término de búsqueda de al menos 3 caracteres'));
|
||||
}
|
||||
}
|
||||
|
||||
$pages = new CPagination(count($results));
|
||||
$currentPage = Yii::app()->getRequest()->getQuery('page', 1);
|
||||
$pages->pageSize = 10;
|
||||
|
||||
$this->render('search', compact('formulario', 'results', 'term', 'query', 'pages', 'currentPage'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -7,7 +7,7 @@ class SearchBlock extends CPortlet {
|
||||
|
||||
protected function renderContent() {
|
||||
echo CHtml::beginForm(array('search/search'), 'get', array('class' => 'input-append'));
|
||||
echo CHtml::textField('q', '', array(
|
||||
echo CHtml::textField('keyword', '', array(
|
||||
'placeholder' => Yii::t('profind', 'Buscar...'),
|
||||
'class' => 'search_query input-medium')
|
||||
);?>
|
||||
|
||||
@ -51,8 +51,14 @@ class Candidato extends CActiveRecord {
|
||||
public $ficheroFotografia;
|
||||
public $fotografia;
|
||||
public $descripcionEstado;
|
||||
public $salario_ini_search;
|
||||
public $salario_fin_search;
|
||||
public $idiomas_search;
|
||||
public $titulaciones_search;
|
||||
public $perfiles_search;
|
||||
|
||||
private $_nombreCompleto;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
@ -141,6 +147,8 @@ class Candidato extends CActiveRecord {
|
||||
// Please remove those attributes that should not be searched.
|
||||
array('id, id_estado, estado, descripcionEstado, nombre, apellidos, nombreCompleto,
|
||||
n_identificacion, email, telefono_fijo,
|
||||
salario_ini_search, salario_fin_search, idiomas_search, titulaciones_search,
|
||||
perfiles_search,
|
||||
telefono_movil, sexo, fecha_nacimiento, lugar_nacimiento,
|
||||
localidad, carnet_conducir, vehiculo_propio,
|
||||
observaciones, salario_minimo, salario_maximo, procedencia,
|
||||
@ -243,10 +251,11 @@ class Candidato extends CActiveRecord {
|
||||
// should not be searched.
|
||||
|
||||
$criteria = new CDbCriteria;
|
||||
$criteria->with = array();
|
||||
|
||||
if ($this->descripcionEstado) {
|
||||
$criteria->together = true;
|
||||
$criteria->with = array('estado');
|
||||
array_push($criteria->with, 'estado');
|
||||
$criteria->compare('estado.id', $this->id_estado, true);
|
||||
$criteria->compare('estado.descripcion', $this->descripcionEstado, true);
|
||||
}
|
||||
@ -291,7 +300,50 @@ class Candidato extends CActiveRecord {
|
||||
$criteria->compare('t.modified_time', $this->modified_time, true);
|
||||
$criteria->compare('t.deleted_time', $this->deleted_time, true);
|
||||
|
||||
if ($this->salario_ini_search != '')
|
||||
$criteria->addCondition(('t.salario_minimo >='. $this->salario_ini_search));
|
||||
if ($this->salario_fin_search != '')
|
||||
$criteria->addCondition(('t.salario_minimo <='. $this->salario_fin_search));
|
||||
|
||||
if (($this->idiomas_search != '') && ($this->idiomas_search[0] != '')){
|
||||
$criteria->together = true;
|
||||
array_push($criteria->with, 'idiomas');
|
||||
$cadena = '';
|
||||
foreach ($this->idiomas_search as $idioma_search){
|
||||
if ($cadena != '')
|
||||
$cadena = $cadena . ',';
|
||||
$cadena = $cadena . "'" . $idioma_search . "'";
|
||||
}
|
||||
$criteria->addCondition(('idiomas.idioma in ('. $cadena . ')'));
|
||||
}
|
||||
|
||||
if (($this->titulaciones_search != '') && ($this->titulaciones_search[0] != '')){
|
||||
$criteria->together = true;
|
||||
array_push($criteria->with, 'titulaciones');
|
||||
$cadena = '';
|
||||
foreach ($this->titulaciones_search as $titulacion_search){
|
||||
if ($cadena != '')
|
||||
$cadena = $cadena . ',';
|
||||
$cadena = $cadena . "'" . $titulacion_search . "'";
|
||||
}
|
||||
$criteria->addCondition(('titulaciones.titulacion in ('. $cadena . ')'));
|
||||
}
|
||||
|
||||
if (($this->perfiles_search != '') && ($this->perfiles_search[0] != '')){
|
||||
$criteria->together = true;
|
||||
array_push($criteria->with, 'capacidadesProfesionales');
|
||||
$cadena = '';
|
||||
foreach ($this->perfiles_search as $perfil_search){
|
||||
if ($cadena != '')
|
||||
$cadena = $cadena . ',';
|
||||
$cadena = $cadena . "'" . $perfil_search . "'";
|
||||
}
|
||||
$criteria->addCondition(('capacidadesProfesionales.id_capacidad in ('. $cadena . ')'));
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
$sort = new CSort();
|
||||
$sort->modelClass = 'Candidato';
|
||||
$sort->attributes = array(
|
||||
|
||||
@ -72,6 +72,8 @@ class CandidatoDocumento extends CActiveRecord {
|
||||
array('id_candidato', 'numerical', 'integerOnly' => true),
|
||||
array('titulo, nombre_fichero', 'length', 'max' => 255),
|
||||
array('titulo, nombre_fichero, fecha', 'safe'),
|
||||
|
||||
// array('fecha', 'date', 'format' => 'dd/mm/yyyy'),
|
||||
|
||||
array('ficheroDocumento', 'file',
|
||||
//'types' => 'pdf, doc, docx, txt, odt',
|
||||
@ -132,7 +134,18 @@ class CandidatoDocumento extends CActiveRecord {
|
||||
));
|
||||
}
|
||||
|
||||
protected function beforeSave() {
|
||||
// $this->fecha = date('Y-m-d', CDateTimeParser::parse($this->fecha, Yii::app()->locale->dateFormat));
|
||||
return parent::beforeSave();
|
||||
}
|
||||
|
||||
protected function afterFind() {
|
||||
// $this->fecha = Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($this->fecha, 'yyyy-MM-dd'), 'medium', null);
|
||||
return parent::afterFind();
|
||||
}
|
||||
|
||||
protected function afterSave() {
|
||||
// $this->fecha = Yii::app()->dateFormatter->formatDateTime(CDateTimeParser::parse($this->fecha, 'yyyy-MM-dd'), 'medium', null);
|
||||
if ($this->isNewRecord)
|
||||
$this->guardarFicheroDocumento();
|
||||
return parent::afterSave();
|
||||
@ -145,7 +158,7 @@ class CandidatoDocumento extends CActiveRecord {
|
||||
|
||||
protected function afterConstruct() {
|
||||
// Valores por defecto
|
||||
$this->fecha = date('Y-m-d H:i:s', time());
|
||||
// $this->fecha = date('yyyy-mm-dd', time());
|
||||
return parent::afterConstruct();
|
||||
}
|
||||
|
||||
|
||||
@ -1704,7 +1704,7 @@ label, input, button, select, textarea, select, textarea, input[type="text"], in
|
||||
}
|
||||
|
||||
.sidebar_filters {
|
||||
padding:30px 30px 20px;
|
||||
padding:0 30px 20px;
|
||||
}
|
||||
|
||||
.sidebar_filters h3 {
|
||||
|
||||
@ -34,7 +34,7 @@ Yii::app()->clientScript->registerScript('js_datepicker', $js_datepicker, CClien
|
||||
'model' => $documento,
|
||||
'attribute' => "[$i]fecha",
|
||||
'language' => 'es',
|
||||
'options' => array('showAnim' => 'fold', 'dateFormat' => 'dd/mm/yy'),
|
||||
'options' => array('showAnim' => 'fold', 'dateFormat' => 'dd/mm/yyyy'),
|
||||
'htmlOptions' => array('class' => 'span12'),
|
||||
));
|
||||
?>
|
||||
@ -77,7 +77,7 @@ Yii::app()->clientScript->registerScript('js_datepicker', $js_datepicker, CClien
|
||||
<td>
|
||||
<?php $this->widget('zii.widgets.jui.CJuiDatePicker', array(
|
||||
'name' => 'CandidatoDocumento[{0}][fecha]',
|
||||
'value' => date('dd/mm/yy', time()),
|
||||
'value' => date('d/m/Y', time()),
|
||||
'language' => 'es',
|
||||
'options' => array('showAnim' => 'fold', 'dateFormat' => 'dd/mm/yy'),
|
||||
'htmlOptions' => array('class' => 'span12 datepicker'),
|
||||
|
||||
@ -190,6 +190,22 @@ $form = $this->beginWidget('CActiveForm', array(
|
||||
<legend><?php echo Yii::t('profind', 'Disponibilidad'); ?></legend>
|
||||
<div class="row-fluid formSep">
|
||||
<div class="span6">
|
||||
<div class="sepH_b">
|
||||
<label class="control-label"><?php echo Yii::t('profind', 'estado'); ?></label>
|
||||
<div class="controls">
|
||||
<?php
|
||||
$lista = CHtml::listData(EstadoCandidato::model()->findAll(),'id', 'descripcion');
|
||||
echo $form->dropDownList(
|
||||
$candidato,
|
||||
'id_estado',
|
||||
$lista,
|
||||
array(
|
||||
'class'=>'mf',
|
||||
));
|
||||
?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="sepH_b">
|
||||
<label class="control-label"><?php echo Yii::t('profind', '...de incorporación'); ?></label>
|
||||
<div class="controls">
|
||||
|
||||
@ -14,7 +14,7 @@ $columnas = array(
|
||||
),
|
||||
array(
|
||||
'type' => 'html',
|
||||
'name' => 'descripcionEstado',
|
||||
'name' => 'id_estado',
|
||||
'value' => 'CHtml::encode($data->estado->descripcion);',
|
||||
'filter' => CHtml::listData(EstadoCandidato::model()->findAll(), 'id', 'descripcion'),
|
||||
'headerHtmlOptions' => array(
|
||||
@ -59,9 +59,6 @@ $columnas = array(
|
||||
),
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
$gridView = $this->widget('zii.widgets.grid.CGridView', array(
|
||||
'id' => 'candidato-grid',
|
||||
'dataProvider' => $candidatos->search(),
|
||||
@ -81,8 +78,18 @@ $gridView = $this->widget('zii.widgets.grid.CGridView', array(
|
||||
'hiddenPageCssClass' => 'disabled',
|
||||
),
|
||||
), true);
|
||||
|
||||
|
||||
Yii::app()->clientScript->registerScript('search', "
|
||||
$('.search-button').click(function(){
|
||||
$('.search-form').toggle();
|
||||
return false;
|
||||
});
|
||||
");
|
||||
?>
|
||||
|
||||
|
||||
|
||||
<div class="row-fluid">
|
||||
<div class="span12">
|
||||
<h3 class="heading"><?php echo Yii::t('profind', 'BD Candidatos'); ?></h3>
|
||||
@ -93,14 +100,29 @@ $gridView = $this->widget('zii.widgets.grid.CGridView', array(
|
||||
$this->createUrl('create'),
|
||||
array('class' => 'btn')
|
||||
); ?>
|
||||
<?php echo CHtml::link(CHtml::tag('i', array('class' => 'icon-filter'), '') . ' ' . Yii::t('profind', 'Filtro'), '',
|
||||
<?php
|
||||
// echo CHtml::link(CHtml::tag('i', array('class' => 'icon-filter'), '') . ' ' . Yii::t('profind', 'Filtro'), '',
|
||||
// array(
|
||||
// 'onclick' => '$("tr.filters").toggle(); $(this).toggleClass("active");',
|
||||
// 'class' => 'btn active')
|
||||
// );
|
||||
?>
|
||||
<?php echo CHtml::link(Yii::t('profind', 'Búsqueda avanzada'), '#',
|
||||
array(
|
||||
'onclick' => '$("tr.filters").toggle(); $(this).toggleClass("active");',
|
||||
'class' => 'btn active')
|
||||
); ?>
|
||||
'onclick' => '$(".search-form").toggle(); $(this).toggleClass("active");$("tr.filters").toggle();',
|
||||
'class' => 'btn')
|
||||
); ?>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="search-form" style="display:none">
|
||||
<?php
|
||||
$this->renderPartial('_search',array(
|
||||
'model'=>$candidatos,
|
||||
)); ?>
|
||||
</div><!-- search-form -->
|
||||
|
||||
<?php echo $gridView; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -1,11 +1,14 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $this SearchController
|
||||
*/
|
||||
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('profind', 'Resultados de la búsqueda');
|
||||
$this->breadcrumbs = array(
|
||||
Yii::t('profind', 'Resultados de la búsqueda')
|
||||
);
|
||||
/**
|
||||
* @var $this SearchController
|
||||
*/
|
||||
$this->pageTitle = Yii::app()->name . ' - ' . Yii::t('profind', 'Resultados de la búsqueda');
|
||||
$this->breadcrumbs = array(
|
||||
Yii::t('profind', 'Resultados de la búsqueda')
|
||||
);
|
||||
|
||||
// Sidebar
|
||||
// echo $this->renderPartial('//sidebars/_search', array('formulario' => $formulario));
|
||||
|
||||
?>
|
||||
|
||||
@ -16,7 +19,7 @@ $this->breadcrumbs = array(
|
||||
|
||||
<div class="row-fluid search_page">
|
||||
<div class="span12">
|
||||
<h3 class="heading"><small><?php echo Yii::t('profind', 'Resultados de búsqueda para'); ?></small> <?php echo CHtml::encode($term); ?></h3>
|
||||
<h3 class="heading"><?php echo Yii::t('profind', 'Resultados de la búsqueda'); ?></h3>
|
||||
|
||||
<?php if ($results) : ?>
|
||||
<div class="well clearfix">
|
||||
@ -39,7 +42,9 @@ $this->breadcrumbs = array(
|
||||
?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<pre>
|
||||
<?php print_r($term); ?>
|
||||
</pre>
|
||||
<div class="search_panel clearfix">
|
||||
<?php if (!empty($results)): ?>
|
||||
<?php for($i = ($inicio - 1); $i < $final; $i++) : ?>
|
||||
@ -55,7 +60,8 @@ $this->breadcrumbs = array(
|
||||
<h4>
|
||||
<?php
|
||||
echo CHtml::link(
|
||||
$query->highlightMatches(CHtml::encode($candidato->nombreCompleto)),
|
||||
//$query->htmlFragmentHighlightMatches(CHtml::encode($candidato->nombreCompleto)),
|
||||
CHtml::encode($candidato->nombreCompleto),
|
||||
array('candidato/update', 'id' => $candidato->id),
|
||||
array('class' => 'sepV_a')
|
||||
);
|
||||
@ -63,6 +69,13 @@ $this->breadcrumbs = array(
|
||||
<span class="label label-info"><?php echo $candidato->estado->descripcion; ?></span>
|
||||
</h4>
|
||||
<p class="sepH_b item_description">
|
||||
<!-- email -->
|
||||
<?php $text = ''; //CHtml::encode($query->htmlFragmentHighlightMatches(CHtml::encode($results[$i]->email))); ?>
|
||||
<?php if ($text != CHtml::encode($results[$i]->email)) : ?>
|
||||
<strong>Email:</strong>
|
||||
<?php echo CHtml::link($text, CHtml::encode($results[$i]->email)); ?>
|
||||
<?php endif; ?>
|
||||
</h4>
|
||||
|
||||
|
||||
</p>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user