コード例 #1
0
ファイル: index.php プロジェクト: mdb-webdev/bike
<?php

require_once dirname(dirname(__FILE__)) . '/cms/identify.php';
require_once __DIR__ . '/queriesds.php';
// other datasources
br()->importLib('GenericDataSource');
$libraryQueries = new BrGenericDataSource('savedQueries');
$libraryQueries->on('select', function ($dataSource, $row) {
    $result = array();
    $path = br()->config()->get('libraryQueriesPath');
    try {
        $fileName = $path . 'library.json';
        $queries = array();
        if (file_exists($fileName)) {
            if ($data = br()->fs()->loadFromFile($fileName)) {
                if ($resultsArray = json_decode($data, true)) {
                    foreach ($resultsArray as $row) {
                        $row['rowid'] = md5($row['name']);
                        $result[] = $row;
                    }
                }
            }
        }
    } catch (Exception $e) {
        //throw new Exception('To be able to save queries folder "' . $path . '" must be writeable');
    }
    if (!$result) {
        $result = array();
    }
    return $result;
});
コード例 #2
0
ファイル: BrDataSource.php プロジェクト: jagermesh/bright
 function __construct($dbEntity, $options = array())
 {
     $this->dbEntity = $dbEntity;
     parent::__construct($options);
 }
コード例 #3
0
ファイル: queriesds.php プロジェクト: mdb-webdev/bike
<?php

br()->importLib('GenericDataSource');
$queriesDataSource = new BrGenericDataSource('query');
$queriesDataSource->on('insert', function ($dataSource, $row) {
    if ($sql = br($row, 'sql')) {
        $normalizedQuery = trim(preg_replace('#/[*].*?[*]/#', '', preg_replace("#[\n\r]]#", '', $sql)));
        $row['isSelect'] = preg_match('#^[ ]*?SELECT#i', $normalizedQuery) > 0;
        $row['isLimited'] = !$row['isSelect'] || preg_match('#(^[ ]*?SELECT.*?COUNT.*?[(].*?FROM|LIMIT[ ]*?[0-9]+)#ism', $normalizedQuery) > 0;
        $hash = md5(json_encode($row));
        br()->session()->set($hash, $row);
        return array('hash' => $hash, 'isSelect' => $row['isSelect'], 'isLimited' => $row['isLimited']);
    }
    throw new Exception('Empty SQL');
});
$queriesDataSource->on('select', function ($dataSource, $filter, $transient, $options) {
    if (!br()->db()) {
        throw new Exception('Oops, database not configured. Check About section, please.');
    }
    try {
        if ($hash = br($filter, 'hash')) {
            if ($filter = br()->session()->get($hash)) {
                if ($sql = br($filter, 'sql')) {
                    $sql = rtrim(trim($sql), ';');
                    $isSelect = $filter['isSelect'];
                    $header = array();
                    $result = array();
                    if ($isSelect) {
                        if (br($options, 'result') == 'count') {
                            $result = br()->db()->getRowsAmount($sql);
                        } else {