Ejemplo n.º 1
0
    public function getJQGridGridData($filters, $options = array())
    {
        if (isset($options['idName'])) {
            $pk = $options['idName'];
        } else {
            $pk = DBC::getPrimaryKey($this->table);
            if (count($pk) == 1) {
                $pk = $pk[0];
            }
        }
        $params = self::getJQGridPagerParams($this->getTotal($filters));
        $result = array('columns' => array(), 'page' => $params['page'], 'rows' => array(), 'total' => $params['pages'], 'records' => $params['total']);
        //提供兩種覆蓋SQL的方式: 覆蓋整個SQL或覆蓋部分條件
        $options = array_merge(array('SQL_SELECT' => property_exists(get_class($this), 'fields') ? implode(',', $this->fields) : '*', 'SQL_FROM' => $this->table, 'SQL_WHERE' => $filters, 'SQL_ORDERBY' => $params['sidx'] . ' ' . $params['sord'], 'SQL_LIMIT' => $params['start'] . ', ' . $params['limit']), $options);
        //若其中的參數為陣列,則視為call_user_func_array的參數
        if (is_array($options['SQL_ORDERBY'])) {
            $options['SQL_ORDERBY'] = call_user_func_array($options['SQL_ORDERBY'], array($params['sidx'], $params['sord']));
        }
        $sql = isset($options['SQL']) ? $options['SQL'] : '
			SELECT ' . $options['SQL_SELECT'] . '
			FROM ' . $options['SQL_FROM'] . '
			WHERE ' . $options['SQL_WHERE'] . '
			ORDER BY ' . $options['SQL_ORDERBY'] . '
			LIMIT ' . $options['SQL_LIMIT'] . '
		';
        $query = DBC::query($sql);
        $func = array('self', 'buildID');
        while ($d = $query->fetchAssoc()) {
            if (isset($options['sanitize']) && is_array($options['sanitize'])) {
                $d = call_user_func_array($options['sanitize'], array($d));
            }
            //var_export(array($pk, $d, $this->separator));
            if (!$result['columns']) {
                $result['columns'] = array_keys($d);
            }
            $result['rows'][] = array_values($d);
            //			$result['rows'][] = array(
            //					'id' => is_array($pk) ? call_user_func_array($func, array($pk, $d, $this->separator)) : $d[$pk],
            //					'cell' => array_values($d)
            //			);
        }
        return $result;
    }
Ejemplo n.º 2
0
 public function __construct($tablename, $pks = array())
 {
     $this->tablename = $tablename;
     //抓取表格資料
     $tmpPKs = DBC::getPrimaryKey($this->tablename);
     foreach ($tmpPKs as $keyname) {
         $this->pk[$keyname] = null;
     }
     if (!is_array($pks)) {
         return;
     }
     $this->setPrimaryKeys($pks);
 }