Commit 0655b2f7 authored by Sigrid Suski's avatar Sigrid Suski
Browse files

(#) Search suggest for pre-defined fields checked the key instead of the value (Issue #127)

parent 504b515e
......@@ -41,6 +41,7 @@ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
(#) Calling TinyMCE editor with parameters fails (Issue #126)
(#) Some toolbar buttons not visible in iframes (e.g. Download field licenses configuration)
(#) Entries sorting order by 'least popular first' didn't work
(#) Search suggest for pre-defined fields checked the key instead of the value (Issue #127)
### 1.4.8 (14 September 2018)
......
......@@ -140,7 +140,7 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$path = SPConfig::unserialize( $this->_fData->options );
$subFields = $this->travelDependencyPath( $path, $params );
$selected = $path[ 1 ];
$hiddenValue = str_replace( '"', "'", json_encode( (object)$path ) );
$hiddenValue = str_replace( '"', "'", json_encode( (object) $path ) );
}
$field = "<div class=\"spFieldSelect\">" . SPHtml_Input::select( $this->nid, $this->getValues(), $selected, $this->multi, $params );
// $field = SPHtml_Input::select( $this->nid, $this->getValues(), $selected, $this->multi, $params );
......@@ -161,7 +161,7 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$values = [];
if ( $this->dependency ) {
SPFactory::header()
->addJsFile( 'opt.field_select' );
->addJsFile( 'opt.field_select' );
$options = json_decode( FileSystem::Read( SOBI_PATH . '/etc/fields/select-list/definitions/' . ( str_replace( '.xml', '.json', $this->dependencyDefinition ) ) ), true );
if ( isset( $options[ 'translation' ] ) ) {
SPLang::load( $options[ 'translation' ] );
......@@ -219,7 +219,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$o = $db->loadObjectList();
$db->select( [ 'sValue', 'language', 'sKey' ], 'spdb_language', [ 'fid' => $this->fid, 'oType' => 'field_option' ] );
$l = $db->loadObjectList();
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_GET_FIELD_POSITION_DB_ERR', $x->getMessage() ), SPC::ERROR, 500, __LINE__, __FILE__ );
}
static $lang, $defLang = null;
......@@ -284,21 +285,21 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
/* @var SPdb $db */
$db =& SPFactory::db();
$table = $db->join(
[
[ 'table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid' ],
[ 'table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid' ],
[ 'table' => 'spdb_language', 'as' => 'ldata', 'key' => [ 'sdata.optValue', 'ldata.sKey' ] ],
]
[
[ 'table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid' ],
[ 'table' => 'spdb_field_data', 'as' => 'fdata', 'key' => 'fid' ],
[ 'table' => 'spdb_language', 'as' => 'ldata', 'key' => [ 'sdata.optValue', 'ldata.sKey' ] ],
]
);
try {
//$order = $this->checkCopy() ? 'scopy.desc' : 'scopy.asc';
$order = $this->checkCopy() ? 'scopy.asc' : 'scopy.desc';
$where = [
'sdata.fid' => $this->id,
'sdata.sid' => $sid,
'fdata.sid' => $sid,
'ldata.oType' => 'field_option',
'ldata.fid' => $this->id
'sdata.fid' => $this->id,
'sdata.sid' => $sid,
'fdata.sid' => $sid,
'ldata.oType' => 'field_option',
'ldata.fid' => $this->id,
];
if ( $this->dependency ) {
$where[ 'ldata.sKey' ] = $rawData;
......@@ -321,7 +322,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$fullData->baseData = isset( $data->sValue ) ? $data->sValue : null;
$fData = isset( $data->sValue ) ? $data->sValue : null;
}
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_GET_SELECTED_OPTIONS', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -378,6 +380,7 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
}
}
$this->path = $path;
return $path;
}
/* check if such option exist at all */
......@@ -491,15 +494,16 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$params[ 'baseData' ] = $element;
}
}
$params[ 'copy' ] = ( int )!( $entry->get( 'approved' ) );
$params[ 'copy' ] = ( int ) !( $entry->get( 'approved' ) );
if ( Sobi::My( 'id' ) == $entry->get( 'owner' ) ) {
--$this->editLimit;
}
$params[ 'editLimit' ] = $this->editLimit;
try {
SPFactory::db()
->insertUpdate( 'spdb_field_data', $params );
} catch ( SPException $x ) {
->insertUpdate( 'spdb_field_data', $params );
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_SAVE_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
$selectedOption = null;
......@@ -513,7 +517,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
/* delete old selected values */
try {
SPFactory::db()->delete( 'spdb_field_option_selected', [ 'fid' => $this->fid, 'sid' => $entry->get( 'id' ), 'copy' => $params[ 'copy' ] ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
......@@ -522,7 +527,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
if ( $selectedOption ) {
SPFactory::db()->insertArray( 'spdb_field_option_selected', $options );
}
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_SAVE_SELECTED_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -576,7 +582,7 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$params[ 'updatedIP' ] = $IP;
$params[ 'copy' ] = 0;
$params[ 'baseData' ] = null;
$params[ 'copy' ] = ( int )!( $entry->get( 'approved' ) );
$params[ 'copy' ] = ( int ) !( $entry->get( 'approved' ) );
if ( Sobi::My( 'id' ) == $entry->get( 'owner' ) ) {
--$this->editLimit;
}
......@@ -586,7 +592,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
/* save it */
try {
$db->insertUpdate( 'spdb_field_data', $params );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_SAVE_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
foreach ( $data as $selected ) {
......@@ -598,14 +605,16 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
/* delete old selected values */
try {
$db->delete( 'spdb_field_option_selected', [ 'fid' => $this->fid, 'sid' => $entry->get( 'id' ), 'copy' => $params[ 'copy' ] ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
/* insert new selected value */
try {
$db->insertArray( 'spdb_field_option_selected', $options );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_SAVE_SELECTED_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -613,7 +622,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
if ( !( $entry->get( 'approved' ) ) ) {
try {
$db->update( 'spdb_field_option_selected', [ 'copy' => 1 ], [ 'fid' => $this->fid, 'sid' => $entry->get( 'id' ) ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_UPDATE_PREVIOUS_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -621,7 +631,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
/* delete old selected values */
try {
$db->delete( 'spdb_field_option_selected', [ 'fid' => $this->fid, 'sid' => $entry->get( 'id' ) ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( __CLASS__, SPLang::e( 'CANNOT_DELETE_PREVIOUS_DATA', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -636,6 +647,7 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
* @param string $oPrefix
* @param string $eOrder
* @param string $eDir
*
* @return bool
*/
public static function sortBy( &$tables, &$conditions, &$oPrefix, &$eOrder, $eDir )
......@@ -643,14 +655,14 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
/* @var SPdb $db */
$db =& SPFactory::db();
$tables = $db->join(
[
[ 'table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid' ],
[ 'table' => 'spdb_object', 'as' => 'spo', 'key' => [ 'sdata.sid', 'spo.id' ] ],
[ 'table' => 'spdb_field_data', 'as' => 'fdata', 'key' => [ 'fdata.fid', 'sdata.fid' ] ],
[ 'table' => 'spdb_field', 'as' => 'fdef', 'key' => [ 'fdef.fid', 'sdata.fid' ] ],
[ 'table' => 'spdb_language', 'as' => 'ldata', 'key' => [ 'sdata.optValue', 'ldata.sKey' ] ],
[ 'table' => 'spdb_relations', 'as' => 'sprl', 'key' => [ 'spo.id', 'sprl.id' ] ],
]
[
[ 'table' => 'spdb_field_option_selected', 'as' => 'sdata', 'key' => 'fid' ],
[ 'table' => 'spdb_object', 'as' => 'spo', 'key' => [ 'sdata.sid', 'spo.id' ] ],
[ 'table' => 'spdb_field_data', 'as' => 'fdata', 'key' => [ 'fdata.fid', 'sdata.fid' ] ],
[ 'table' => 'spdb_field', 'as' => 'fdef', 'key' => [ 'fdef.fid', 'sdata.fid' ] ],
[ 'table' => 'spdb_language', 'as' => 'ldata', 'key' => [ 'sdata.optValue', 'ldata.sKey' ] ],
[ 'table' => 'spdb_relations', 'as' => 'sprl', 'key' => [ 'spo.id', 'sprl.id' ] ],
]
);
$oPrefix = 'spo.';
$conditions[ 'spo.oType' ] = 'entry';
......@@ -672,7 +684,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
try {
$db->delete( 'spdb_field_option_selected', [ 'sid' => $sid, 'copy' => '0', 'fid' => $this->fid ] );
$db->update( 'spdb_field_option_selected', [ 'copy' => '0' ], [ 'sid' => $sid, 'copy' => '1', 'fid' => $this->fid ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::ERROR, 500, __LINE__, __FILE__ );
}
}
......@@ -714,12 +727,12 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
}
if ( $this->dependency ) {
SPFactory::header()
->addJsFile( 'opt.field_select' );
->addJsFile( 'opt.field_select' );
$request = json_decode( Sobi::Clean( Input::String( $this->nid . '_path' ) ), true );
$params[ 'class' ] .= ' ctrl-dependency-field';
$hidden = $this->travelDependencyPath( $request, $params );
$this->_selected = isset( $request[ 1 ] ) ? $request[ 1 ] : null;
$hiddenValue = str_replace( '"', "&quot;", json_encode( (object)$request ) );
$hiddenValue = str_replace( '"', "&quot;", json_encode( (object) $request ) );
$hidden .= SPHtml_Input::hidden( $this->nid . '_path', $hiddenValue, null, [ 'data' => [ 'selected' => '', 'section' => Sobi::Section() ] ] );
$params[ 'data' ] = [ 'order' => '1' ];
}
......@@ -737,8 +750,9 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
parent::rejectChanges( $sid );
try {
SPFactory::db()
->delete( 'spdb_field_option_selected', [ 'sid' => $sid, 'fid' => $this->fid, 'copy' => '1', ] );
} catch ( SPException $x ) {
->delete( 'spdb_field_option_selected', [ 'sid' => $sid, 'fid' => $this->fid, 'copy' => '1', ] );
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
......@@ -752,8 +766,9 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
parent::deleteData( $sid );
try {
SPFactory::db()
->delete( 'spdb_field_option_selected', [ 'sid' => $sid, 'fid' => $this->fid ] );
} catch ( SPException $x ) {
->delete( 'spdb_field_option_selected', [ 'sid' => $sid, 'fid' => $this->fid ] );
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -766,13 +781,15 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$db =& SPFactory::db();
try {
$db->delete( 'spdb_field_option_selected', [ 'fid' => $this->fid ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
try {
$db->delete( 'spdb_field_option', [ 'fid' => $this->fid ] );
$db->delete( 'spdb_language', [ 'oType' => 'field_option', 'fid' => $this->id ] );
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'DB_REPORTS_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
......@@ -806,7 +823,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
}
}
}
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_SEARCH_DB_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
......@@ -825,25 +843,24 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
if ( ( $this->dependency ) ) {
return parent::searchSuggest( $data, $section, $startWith );
}
/* @var SPdb $db */
// $db =& SPFactory::db();
$terms = [];
$data = $startWith ? "{$data}%" : "%{$data}%";
try {
$fids = SPFactory::db()
->dselect( 'sKey', 'spdb_language', [ 'oType' => 'field_option', 'fid' => $this->fid, 'sValue' => $data ] )
->loadResultArray();
->dselect( [ 'sKey', 'sValue' ], 'spdb_language', [ 'oType' => 'field_option', 'fid' => $this->fid, 'sValue' => $data ] )
->loadAssocList();
if ( count( $fids ) ) {
foreach ( $fids as $opt ) {
$c = SPFactory::db()
->dselect( 'COUNT(*)', 'spdb_field_option_selected', [ 'copy' => '0', 'fid' => $this->fid, 'optValue' => $opt ] )
->loadResult();
->dselect( 'COUNT(*)', 'spdb_field_option_selected', [ 'copy' => '0', 'fid' => $this->fid, 'optValue' => $opt['sKey'] ] )
->loadResult();
if ( $c ) {
$terms[] = $opt;
$terms[] = $opt[ 'sValue' ];
}
}
}
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_SEARCH_DB_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
......@@ -885,9 +902,10 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
}
else {
$cids = $db->loadResultArray();
if ($this->searchOperator === 'and') {
if ( $this->searchOperator === 'and' ) {
$results = array_intersect( $results, $cids );
} else {
}
else {
$results = array_merge( $results, $cids );
}
}
......@@ -896,13 +914,15 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
}
else {
$sids = $db
->select( 'sid', 'spdb_field_option_selected', [ 'copy' => '0', 'fid' => $this->fid, 'optValue' => $request ] )
->loadResultArray();
->select( 'sid', 'spdb_field_option_selected', [ 'copy' => '0', 'fid' => $this->fid, 'optValue' => $request ] )
->loadResultArray();
}
} catch ( SPException $x ) {
}
catch ( SPException $x ) {
Sobi::Error( $this->name(), SPLang::e( 'CANNOT_SEARCH_DB_ERR', $x->getMessage() ), SPC::WARNING, 0, __LINE__, __FILE__ );
}
}
return $sids;
}
......@@ -984,8 +1004,8 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$path = json_decode( Sobi::Clean( Input::String( 'path' ) ), true );
$values = $this->loadDependencyDefinition( $path );
SPFactory::mainframe()
->cleanBuffer()
->customHeader();
->cleanBuffer()
->customHeader();
exit( json_encode( [ 'options' => $values, 'path' => ( json_encode( $path ) ) ] ) );
}
......@@ -1060,17 +1080,17 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
if ( isset( $opt[ 'options' ] ) && is_array( $opt[ 'options' ] ) ) {
foreach ( $opt[ 'options' ] as $sub ) {
$_options[] = [
'_complex' => 1,
'_data' => $sub[ 'label' ],
'_attributes' => [ 'group' => $opt[ 'id' ], 'selected' => $selected == $sub[ 'id' ] ? 'true' : 'false', 'id' => $sub[ 'id' ], 'position' => $sub[ 'position' ] ]
'_complex' => 1,
'_data' => $sub[ 'label' ],
'_attributes' => [ 'group' => $opt[ 'id' ], 'selected' => $selected == $sub[ 'id' ] ? 'true' : 'false', 'id' => $sub[ 'id' ], 'position' => $sub[ 'position' ] ],
];
}
}
else {
$_options[] = [
'_complex' => 1,
'_data' => $opt[ 'label' ],
'_attributes' => [ 'selected' => $selected == $opt[ 'id' ] ? 'true' : 'false', 'id' => $opt[ 'id' ], 'position' => $opt[ 'position' ] ]
'_complex' => 1,
'_data' => $opt[ 'label' ],
'_attributes' => [ 'selected' => $selected == $opt[ 'id' ] ? 'true' : 'false', 'id' => $opt[ 'id' ], 'position' => $opt[ 'position' ] ],
];
}
}
......@@ -1078,13 +1098,13 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
$this->cleanCss();
return [
'_complex' => 1,
'_data' => $data,
'_attributes' => [
'class' => $this->cssClass,
'selected' => $this->getRaw()
],
'_options' => $_options,
'_complex' => 1,
'_data' => $data,
'_attributes' => [
'class' => $this->cssClass,
'selected' => $this->getRaw(),
],
'_options' => $_options,
];
}
......@@ -1130,12 +1150,12 @@ class SPField_Select extends SPFieldType implements SPFieldInterface
protected function saveSelectLabel( &$attr )
{
$data = [
'key' => $this->nid . '-select-label',
'value' => $attr[ 'selectLabel' ],
'type' => 'field_select',
'fid' => $this->fid,
'id' => Sobi::Section(),
'section' => Sobi::Section()
'key' => $this->nid . '-select-label',
'value' => $attr[ 'selectLabel' ],
'type' => 'field_select',
'fid' => $this->fid,
'id' => Sobi::Section(),
'section' => Sobi::Section(),
];
SPLang::saveValues( $data );
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment