function smarty_function_column_metainfo($params, &$smarty)
{
    if (empty($params['var'])) {
        $smarty->trigger_error("assign: missing 'var' parameter");
        return;
    }
    $excludeFields = array('status');
    $dq = new dilpsQuery();
    $colinfo = $dq->getColumnMetainfo($excludeFields);
    $smarty->assign($params['var'], $colinfo);
}
function query_local_collection_overview($query, $options, $db, $db_prefix)
{
    $querystruct = transform_query($query['querypiece']);
    $dbQuery = new dilpsQuery($db, $db_prefix);
    $fields = "1 as local, {$db_prefix}collection.collectionid, {$db_prefix}collection.name";
    $joinOn = $dbQuery->buildWhere($querystruct);
    $joinOn .= " and {$db_prefix}collection.collectionid = {$db_prefix}meta.collectionid ";
    $from = "{$db_prefix}collection left join {$db_prefix}meta  on {$joinOn}";
    $where = "{$db_prefix}collection.host = 'local'";
    if (!empty($query['groupid'])) {
        // add grouptable to query
        $fields .= ", sum(if(groupid, 1, 0)) as count";
        $from .= " LEFT JOIN {$db_prefix}img_group ON {$db_prefix}img_group.imageid = {$db_prefix}meta.imageid AND {$db_prefix}img_group.collectionid = {$db_prefix}meta.collectionid";
        $from .= get_groupid_where_clause($query, $db, $db_prefix);
    } else {
        $fields .= ", count({$db_prefix}meta.id) as count";
    }
    $sql = "SELECT DISTINCT {$fields} FROM {$from} WHERE {$where}" . " group by {$db_prefix}collection.collectionid, {$db_prefix}collection.name";
    //die($sql);
    $result = array();
    $rs = $db->GetAll($sql);
    if (!$rs) {
        if ($db->ErrorNo()) {
            $result['error'] = $db->ErrorMsg();
        } else {
            $result = array();
        }
    } else {
        $result = $rs;
    }
    return $result;
}
	function queryCount($querystruct) {
        global $db, $db_prefix;
        if (is_object($querystruct)) {
            $querystruct = _stdclass2array($querystruct);    
        }
        
        // take care of empty arrays which are mysteriously turned into empty strings by the soap monster:
        if (!is_array($querystruct['connectors'])) {$querystruct['connectors'] = array();}
        if (!is_array($querystruct['phrases'])) {$querystruct['phrases'] = array();}
        
    	$dbQuery = new dilpsQuery($db, $db_prefix);
    	
       $fields = 'count(*) as count'; 
       
        //return array('result'=>array('count'=>'here'));            	         
    	$where = $dbQuery->buildWhere($querystruct)
    	         ." and {$db_prefix}meta.status = 'reviewed'";
    	$from = "{$db_prefix}meta ";
    	$sql = "SELECT DISTINCT $fields FROM $from WHERE $where";

	    if ($rs = $db->GetRow($sql)) {
	        $result = $rs;
	    } else  {
	        $result = array('error'=>$db->ErrorMsg());
        	if ($this->needsUtf8Conversion) {
            	$result = utf8_encode_recursive($result);
        	}
	    }
    	    
    	$response = array('result'=>$result);
        return $response;	
	}
function query_all_piece($fields, $value)
{
    $value = trim($value);
    $qpieces = array();
    $dq = new dilpsQuery();
    $metainfo = $dq->getColumnMetainfo();
    foreach ($fields as $field) {
        $qpieces[] = new_simple_qpiece($field, $value, 'like', $metainfo[$field]['operators'], '0', 'or');
    }
    $queryall = combine_pieces($qpieces, '');
    return $queryall;
}
Beispiel #5
0
function query_local_collection($query, $options, $db, $db_prefix)
{
    $querystruct = transform_query($query['querypiece']);
    // print_r($querystruct);
    $dbQuery = new dilpsQuery($db, $db_prefix);
    $where = $dbQuery->buildWhere($querystruct);
    $from = "{$db_prefix}meta LEFT JOIN {$db_prefix}archaeology ON {$db_prefix}archaeology.imageid = {$db_prefix}meta.imageid AND {$db_prefix}archaeology.collectionid = {$db_prefix}meta.collectionid LEFT JOIN {$db_prefix}architecture ON {$db_prefix}architecture.collectionid = {$db_prefix}meta.collectionid AND {$db_prefix}meta.imageid = {$db_prefix}architecture.imageid ";
    $fields = "{$db_prefix}meta.type as type,{$db_prefix}meta.collectionid as collectionid," . "{$db_prefix}meta.imageid as imageid,ifnull({$db_prefix}meta.name1, '') as name1,ifnull({$db_prefix}meta.name2, '') as name2," . "{$db_prefix}meta.addition as addition, {$db_prefix}meta.title as title, " . "{$db_prefix}meta.dating as dating, {$db_prefix}meta.literature as literature, " . "{$db_prefix}meta.location as location, " . "{$db_prefix}archaeology.category as category, " . "{$db_prefix}architecture.classification as classification";
    if (!empty($query['groupid'])) {
        // add grouptable to query
        $fields .= ", {$db_prefix}img_group.groupid as groupid";
        $from .= "LEFT JOIN {$db_prefix}img_group ON {$db_prefix}img_group.imageid = {$db_prefix}meta.imageid AND {$db_prefix}img_group.collectionid = {$db_prefix}meta.collectionid";
        $where .= get_groupid_where_clause($query, $db, $db_prefix);
    }
    $sql = "SELECT DISTINCT {$fields} FROM {$from} WHERE {$where}" . " ORDER BY insert_date DESC, imageid DESC";
    // die($sql);
    // $db->debug = true;
    $pagesize = $options['pagesize'];
    $page = $options['page'];
    $rs = $db->PageExecute($sql, $pagesize, $page);
    $result = array();
    if (!$rs) {
        $result['error'] = $db->ErrorMsg();
    } else {
        $result['lastpage'] = $rs->LastPageNo();
        $result['maxrecords'] = $rs->MaxRecordCount();
        $result['rs'] = array();
        while (!$rs->EOF) {
            array_walk($rs->fields, '__stripslashes');
            $result['rs'][] = $rs->fields;
            $rs->MoveNext();
        }
        $rs->Close();
        if ($page > $result['lastpage']) {
            $page = $result['lastpage'];
        }
        $result['page'] = $page;
        $result['pagesize'] = $pagesize;
    }
    return $result;
}