forked from unacms/una
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
34 changed files
with
1,101 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,109 @@ | ||
<?php defined('BX_DOL') or die('hack attempt'); | ||
/** | ||
* Copyright (c) UNA, Inc - https://una.io | ||
* MIT License - https://opensource.org/licenses/MIT | ||
* | ||
* @defgroup UnaCore UNA Core | ||
* @{ | ||
*/ | ||
|
||
class BxDolSearchExtended extends BxDolFactory implements iBxDolFactoryObject | ||
{ | ||
public static $SEARCHABLE_TYPES = array( | ||
'text', 'textarea', 'number', | ||
'datepicker', 'date_time', 'datetime', | ||
'select', 'radio_set', | ||
'checkbox', 'switcher' | ||
); | ||
|
||
public static $TYPE_TO_TYPE_SEARCH = array( | ||
'text' => array('text'), | ||
'textarea' => array('text'), | ||
'number' => array('text'), | ||
'text_auto' => array('text_auto'), | ||
'select' => array('checkbox_set', 'select_multiple', 'select'), | ||
'radio_set' => array('checkbox_set', 'select_multiple', 'select'), | ||
'checkbox' => array('checkbox', 'switcher'), | ||
'switcher' => array('checkbox', 'switcher'), | ||
); | ||
|
||
public static $TYPE_TO_OPERATOR = array( | ||
'text' => array('like'), | ||
'textarea' => array('like'), | ||
'number' => array('='), | ||
'text_auto' => array('in'), | ||
'select' => array('in'), | ||
'radio_set' => array('in'), | ||
'checkbox' => array('='), | ||
'switcher' => array('='), | ||
); | ||
|
||
protected $_oDb; | ||
|
||
protected $_sObject; | ||
protected $_aObject; | ||
|
||
|
||
/** | ||
* Constructor | ||
* @param $aObject array of search options | ||
*/ | ||
protected function __construct($aObject) | ||
{ | ||
parent::__construct(); | ||
|
||
$this->_oDb = new BxDolSearchExtendedQuery($this->_aObject); | ||
|
||
$this->_sObject = $aObject['object']; | ||
$this->_aObject = $aObject; | ||
} | ||
|
||
/** | ||
* Get editor object instance by object name | ||
* @param $sObject object name | ||
* @return object instance or false on error | ||
*/ | ||
static public function getObjectInstance($sObject, $oTemplate = false) | ||
{ | ||
if(isset($GLOBALS['bxDolClasses']['BxDolSearchExtended!' . $sObject])) | ||
return $GLOBALS['bxDolClasses']['BxDolSearchExtended!' . $sObject]; | ||
|
||
$aObject = BxDolSearchExtendedQuery::getSearchObject($sObject); | ||
if(!$aObject || !is_array($aObject)) | ||
return false; | ||
|
||
$sClass = 'BxTemplSearchExtended'; | ||
if(!empty($aObject['class_name'])) { | ||
$sClass = $aObject['class_name']; | ||
if(!empty($aObject['class_file'])) | ||
require_once(BX_DIRECTORY_PATH_ROOT . $aObject['class_file']); | ||
} | ||
|
||
$o = new $sClass($aObject, $oTemplate); | ||
return ($GLOBALS['bxDolClasses']['BxDolSearchExtended!' . $sObject] = $o); | ||
} | ||
|
||
static public function actionGetAuthors() | ||
{ | ||
$aResult = BxDolService::call('system', 'profiles_search', array(bx_get('term')), 'TemplServiceProfiles'); | ||
|
||
header('Content-Type:text/javascript; charset=utf-8'); | ||
echo json_encode($aResult); | ||
} | ||
|
||
public function isEnabled() | ||
{ | ||
return isset($this->_aObject['active']) && (int)$this->_aObject['active'] != 0; | ||
} | ||
|
||
public function reset() | ||
{ | ||
if($this->_oDb->deleteFields(array('object' => $this->_sObject)) === false) | ||
return false; | ||
|
||
$this->_aObject['fields'] = BxDolSearchExtendedQuery::getSearchFields($this->_aObject); | ||
return true; | ||
} | ||
} | ||
|
||
/** @} */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
<?php defined('BX_DOL') or die('hack attempt'); | ||
/** | ||
* Copyright (c) UNA, Inc - https://una.io | ||
* MIT License - https://opensource.org/licenses/MIT | ||
* | ||
* @defgroup UnaCore UNA Core | ||
* @{ | ||
*/ | ||
|
||
class BxDolSearchExtendedQuery extends BxDolDb | ||
{ | ||
protected static $TYPES_SET = array ( | ||
'select_multiple' => 1, | ||
'checkbox_set' => 1, | ||
); | ||
|
||
public function __construct($aObject = array()) | ||
{ | ||
parent::__construct(); | ||
} | ||
|
||
static public function getSearchObject($sObject) | ||
{ | ||
$oDb = BxDolDb::getInstance(); | ||
|
||
$sQuery = $oDb->prepare("SELECT * FROM `sys_objects_search_extended` WHERE `object` = ?", $sObject); | ||
|
||
$aObject = $oDb->getRow($sQuery); | ||
if(!$aObject || !is_array($aObject)) | ||
return false; | ||
|
||
$aObject['fields'] = self::getSearchFields($aObject); | ||
return $aObject; | ||
} | ||
|
||
static public function getSearchFields($aObject) | ||
{ | ||
$oDb = BxDolDb::getInstance(); | ||
|
||
$sQueryFields = "SELECT * FROM `sys_search_extended_fields` WHERE `object` = :object ORDER BY `order`"; | ||
$aQueryFieldsBindings = array('object' => $aObject['object']); | ||
$aFields = $oDb->getAll($sQueryFields, $aQueryFieldsBindings); | ||
|
||
//--- Get fields | ||
if(empty($aFields) || !is_array($aFields)) { | ||
$aFields = BxDolContentInfo::getObjectInstance($aObject['object_content_info'])->getSearchableFieldsExtended(); | ||
if(empty($aFields) || !is_array($aFields)) | ||
return array(); | ||
|
||
$iOrder = 0; | ||
foreach($aFields as $sField => $aField) | ||
$oDb->query("INSERT INTO `sys_search_extended_fields`(`object`, `name`, `type`, `caption`, `values`, `search_type`, `search_operator`, `active`, `order`) VALUES(:object, :name, :type, :caption, :values, :search_type, :search_operator, '1', :order)", array( | ||
'object' => $aObject['object'], | ||
'name' => $sField, | ||
'type' => $aField['type'], | ||
'caption' => $aField['caption'], | ||
'values' => $aField['values'], | ||
'search_type' => reset(BxDolSearchExtended::$TYPE_TO_TYPE_SEARCH[$aField['type']]), | ||
'search_operator' => reset(BxDolSearchExtended::$TYPE_TO_OPERATOR[$aField['type']]), | ||
'order' => $iOrder++ | ||
)); | ||
|
||
$aFields = $oDb->getAll($sQueryFields, $aQueryFieldsBindings); | ||
} | ||
|
||
//--- Process fields | ||
foreach ($aFields as $iIndex => $aField) { | ||
//--- Process field Values | ||
if(!empty($aField['values'])) { | ||
if(strncmp(BX_DATA_LISTS_KEY_PREFIX, $aField['values'], 2) === 0) { | ||
$sList = trim($aField['values'], BX_DATA_LISTS_KEY_PREFIX . ' '); | ||
$aFields[$iIndex] = array_merge($aField, array( | ||
'values' => BxDolFormQuery::getDataItems($sList, isset(self::$TYPES_SET[$aField['search_type']])), | ||
'values_list_name' => $sList, | ||
)); | ||
} | ||
else | ||
$aFields[$iIndex]['values'] = unserialize($aField['values']); | ||
} | ||
} | ||
|
||
return $aFields; | ||
} | ||
|
||
public function deleteFields($aWhere) | ||
{ | ||
if(empty($aWhere)) | ||
return false; | ||
|
||
return $this->query("DELETE FROM `sys_search_extended_fields` WHERE " . $this->arrayToSQL($aWhere, ' AND ')); | ||
} | ||
} | ||
|
||
/** @} */ |
Oops, something went wrong.