Query PHP Class Code Examples

This page contains top rated real world PHP examples of class Query extracted from open source projects. You can rate examples to help us improve the quality of examples

Example #1
Show file File: Kat.php Project: DeathByPenguin/gush
0
 /**
  * TODO: fix issue with single files in torrent
  * @param unknown $torrentId
  * @return multitype:multitype:NULL Ambigous <unknown>
  */
 private function getFileListing($data)
 {
     $dom = new Query($data);
     $results = $dom->execute('#torrent_files tr');
     $row = array();
     foreach ($results as $parentElement) {
         if ($parentElement->hasAttribute('class') && $parentElement->getAttribute('class') == 'innerFolder') {
             continue;
         }
         $newHTML = $this->nodeToHTML($parentElement);
         $subDom = new Query($newHTML);
         $subResults = $subDom->execute('td');
         $parts = array();
         foreach ($subResults as $subResult) {
             foreach ($subResult->childNodes as $childNode) {
                 $tmpHTML = str_replace(array("\t", "\n"), '', trim($this->nodeToHTML($childNode)));
                 if ($tmpHTML || $tmpHTML === '0') {
                     $parts[] = $tmpHTML;
                 }
             }
         }
         if (count($parts)) {
             $row[] = $parts;
         }
     }
     $output = array();
     foreach ($row as $file) {
         $output[] = array('filename' => $file[2], 'size' => $this->cleanString($file[3] . ' ' . $file[4]));
     }
     return $output;
 }
Example #2
Show file File: delete.php Project: godboko/modules
0
/**
 * Publications Module
 *
 * @package modules
 * @subpackage publications module
 * @category Third Party Xaraya Module
 * @version 2.0.0
 * @copyright (C) 2011 Netspan AG
 * @license GPL {@link http://www.gnu.org/licenses/gpl.html}
 * @author Marc Lutolf <mfl@netspan.ch>
 */
function publications_adminapi_delete($args)
{
    // Get arguments from argument array
    extract($args);
    // Argument check
    if (!isset($itemid)) {
        $msg = xarML('Invalid #(1) for #(2) function #(3)() in module #(4)', 'publication ID', 'admin', 'delete', 'Publications');
        throw new BadParameterException(null, $msg);
    }
    $ids = !is_array($itemid) ? explode(',', $itemid) : $itemid;
    if (!isset($deletetype)) {
        $deletetype = 0;
    }
    sys::import('xaraya.structures.query');
    $table = xarDB::getTables();
    switch ($deletetype) {
        case 0:
        default:
            $q = new Query('UPDATE', $table['publications']);
            $q->addfield('state', 0);
            break;
        case 10:
            $q = new Query('DELETE', $table['publications']);
            break;
    }
    $q->in('id', $ids);
    if (!$q->run()) {
        return false;
    }
    return true;
}
Example #3
Show file File: characteristics.php Project: RogerGee/abet1
0
function create_characteristic($level, $shortName, $description, $programSpecifier)
{
    if (is_null($level) || $level == "") {
        page_fail_on_field(BAD_REQUEST, 'level', 'must be non-empty');
    }
    if (is_null($shortName) || $shortName == "") {
        page_fail_on_field(BAD_REQUEST, 'short_name', 'must be non-empty');
    }
    if (is_null($description) || $description == "") {
        page_fail_on_field(BAD_REQUEST, 'description', 'must be non-empty');
    }
    $info = array('table' => 'abet_characteristic', 'fields' => array('level', 'short_name', 'description'), 'values' => array(array("s:{$level}", "s:{$shortName}", "s:{$description}")));
    if (!is_null($programSpecifier) && $programSpecifier != "") {
        $info['fields'][] = 'program_specifier';
        $info['values'][0][] = "s:{$programSpecifier}";
    }
    list($code, $json) = Query::perform_transaction(function (&$rollback) use($info) {
        $insert = new Query(new QueryBuilder(INSERT_QUERY, $info));
        if (!$insert->validate_update()) {
            $rollback = true;
            return array(SERVER_ERROR, "{\"success\":false}");
        }
        $query = new Query(new QueryBuilder(SELECT_QUERY, array('tables' => array('abet_characteristic' => array('id', 'level', 'short_name', 'description', 'program_specifier')), 'where' => 'abet_characteristic.id = LAST_INSERT_ID()')));
        if ($query->is_empty()) {
            $rollback = true;
            return array(SERVER_ERROR, "{\"success\":false}");
        }
        return array(OKAY, json_encode($query->get_row_assoc()));
    });
    http_response_code($code);
    return $json;
}
Example #4
Show file File: Piratebay.php Project: DeathByPenguin/gush
0
 private function getFileListing($torrentId)
 {
     $url = 'http://thepiratebay.la/ajax_details_filelist.php?id=' . $torrentId;
     $data = $this->retreiveData($url, self::FORMAT_PLAIN);
     $dom = new Query($data);
     $results = $dom->execute('tr');
     $row = array();
     foreach ($results as $parentElement) {
         $newHTML = $this->nodeToHTML($parentElement);
         $subDom = new Query($newHTML);
         $subResults = $subDom->execute('td');
         $parts = array();
         foreach ($subResults as $subResult) {
             foreach ($subResult->childNodes as $childNode) {
                 $tmpHTML = str_replace(array("\t", "\n"), '', trim($this->nodeToHTML($childNode)));
                 if ($tmpHTML || $tmpHTML === '0') {
                     $parts[] = $tmpHTML;
                 }
             }
         }
         if (count($parts)) {
             $row[] = $parts;
         }
     }
     $output = array();
     foreach ($row as $file) {
         $output[] = array('filename' => $file[0], 'size' => $this->convertFileSize($file[1]));
     }
     return $output;
 }
Example #5
Show file File: DatabaseResult.class.php Project: Superbeest/Core
0
 /**
  * Creates a new database resultset. This function is automatically called by the database and should not
  * be called directly.
  * @param \MySQLi The link to the database system
  * @param \System\Db\Query The query
  * @param \System\Db\Database The database issueing the request
  */
 public function __construct(\MySQLi $databaseLink, \System\Db\Query $query, \System\Db\Database $database)
 {
     $this->databaseLink = $databaseLink;
     $this->requestIssuer = $database;
     $this->query = $query;
     //increase its own querycounter
     self::$queryCount++;
     $timer = new \System\Calendar\Timer();
     $timer->start();
     $actualQuery = $query->getQuery();
     if (!($this->results = $databaseLink->query($actualQuery))) {
         throw new \System\Error\Exception\DatabaseQueryException('Query: ' . $actualQuery . ' - ' . $databaseLink->error);
     }
     /**
      * If there is a query that wants to execute the amount of found rows, we store this amount in the own vector.
      * Do note that this query gets logged before the actual query, because of the stackframe buildup. The actual execution order is correct
      */
     if (strpos($actualQuery, 'SQL_CALC_FOUND_ROWS') !== false) {
         $query = new \System\Db\Query($database, 'SELECT FOUND_ROWS() AS amount');
         $this->totalAmount = $database->queryScalar($query)->first();
     } else {
         $this->totalAmount = $this->count();
     }
     $timer->stop();
     $this->duration = $timer->getDuration();
     self::$totalQueryTime += $this->duration;
     if (round($timer->getDuration()) >= self::SLOW_QUERY_TIME) {
         $event = new \System\Event\Event\OnSlowMySQLQueryEvent();
         $event->setQuery($query);
         $event->setDuration($this->duration);
         $event->raise($this);
     }
     $this->rewind();
 }
Example #6
Show file File: QueryCombination.class.php Project: onphp-framework/onphp-framework
0
 public function __construct(Query $left, Query $right, $logic)
 {
     $this->left = $left;
     $this->right = $right;
     $this->logic = $logic;
     $this->order = new OrderChain();
 }
Example #7
Show file File: GeoDistanceRangeTest.php Project: makeandship/wordpress-fantastic-elasticsearch
0
 /**
  * @group functional
  */
 public function testGeoPoint()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('point' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('point', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('point', 30, 40);
     $type->addDocument($doc2);
     $index->optimize();
     $index->refresh();
     // Only one point should be in radius
     $query = new Query();
     $geoQuery = new GeoDistanceRange('point', array('lat' => 30, 'lon' => 40), array('from' => '0km', 'to' => '2km'));
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoQuery);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $geoQuery = new GeoDistanceRange('point', array('lat' => 30, 'lon' => 40), array('gte' => '0km', 'lte' => '4000km'));
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoQuery);
     $index->refresh();
     $this->assertEquals(2, $type->search($query)->count());
 }
Example #8
Show file File: GeoPolygonTest.php Project: makeandship/wordpress-fantastic-elasticsearch
0
 /**
  * @group functional
  */
 public function testGeoPoint()
 {
     $index = $this->_createIndex();
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('location' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('location', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('location', 30, 40);
     $type->addDocument($doc2);
     $index->refresh();
     // Only one point should be in polygon
     $query = new Query();
     $points = array(array(16, 16), array(16, 20), array(20, 20), array(20, 16), array(16, 16));
     $geoFilter = new GeoPolygon('location', $points);
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $points = array(array(16, 16), array(16, 40), array(40, 40), array(40, 16), array(16, 16));
     $geoFilter = new GeoPolygon('location', $points);
     $query = new Query(new MatchAll());
     $query->setPostFilter($geoFilter);
     $this->assertEquals(2, $type->search($query)->count());
 }
Example #9
Show file File: GeoDistanceTest.php Project: viz/wordpress-fantastic-elasticsearch
0
 public function testGeoPoint()
 {
     $client = $this->_getClient();
     $index = $client->getIndex('test');
     $index->create(array(), true);
     $type = $index->getType('test');
     // Set mapping
     $type->setMapping(array('point' => array('type' => 'geo_point')));
     // Add doc 1
     $doc1 = new Document(1, array('name' => 'ruflin'));
     $doc1->addGeoPoint('point', 17, 19);
     $type->addDocument($doc1);
     // Add doc 2
     $doc2 = new Document(2, array('name' => 'ruflin'));
     $doc2->addGeoPoint('point', 30, 40);
     $type->addDocument($doc2);
     $index->optimize();
     $index->refresh();
     // Only one point should be in radius
     $query = new Query();
     $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '1km');
     $query = new Query(new MatchAll());
     $query->setFilter($geoFilter);
     $this->assertEquals(1, $type->search($query)->count());
     // Both points should be inside
     $query = new Query();
     $geoFilter = new GeoDistance('point', array('lat' => 30, 'lon' => 40), '40000km');
     $query = new Query(new MatchAll());
     $query->setFilter($geoFilter);
     $index->refresh();
     $this->assertEquals(2, $type->search($query)->count());
 }
Example #10
Show file File: EagerLoaderTest.php Project: alexunique0519/Blog_Cakephp_association
0
 /**
  * Tests that default fields for associations are added to the select clause when
  * none is specified
  *
  * @return void
  */
 public function testContainToFieldsDefault()
 {
     $contains = ['clients' => ['orders']];
     $query = new Query($this->connection, $this->table);
     $query->select()->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name', 'clients__id' => 'clients.id', 'clients__phone' => 'clients.phone', 'orders__id' => 'orders.id', 'orders__total' => 'orders.total', 'orders__placed' => 'orders.placed'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
     $contains['clients']['fields'] = ['name'];
     $query = new Query($this->connection, $this->table);
     $query->select('foo.id')->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__name' => 'clients.name'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
     $contains['clients']['fields'] = [];
     $contains['clients']['orders']['fields'] = false;
     $query = new Query($this->connection, $this->table);
     $query->select()->contain($contains)->sql();
     $select = $query->clause('select');
     $expected = ['foo__id' => 'foo.id', 'clients__id' => 'clients.id', 'clients__name' => 'clients.name', 'clients__phone' => 'clients.phone'];
     $expected = $this->_quoteArray($expected);
     $this->assertEquals($expected, $select);
 }
Example #11
Show file File: MoreLikeThisTest.php Project: makeandship/wordpress-fantastic-elasticsearch
0
 /**
  * @group functional
  */
 public function testSearchByDocument()
 {
     $client = $this->_getClient(array('persistent' => false));
     $index = $client->getIndex('elastica_test');
     $index->create(array('index' => array('number_of_shards' => 1, 'number_of_replicas' => 0)), true);
     $type = new Type($index, 'mlt_test');
     $type->addDocuments(array(new Document(1, array('visible' => true, 'name' => 'bruce wayne batman')), new Document(2, array('visible' => true, 'name' => 'bruce wayne')), new Document(3, array('visible' => false, 'name' => 'bruce wayne')), new Document(4, array('visible' => true, 'name' => 'batman')), new Document(5, array('visible' => false, 'name' => 'batman')), new Document(6, array('visible' => true, 'name' => 'superman')), new Document(7, array('visible' => true, 'name' => 'spiderman'))));
     $index->refresh();
     $doc = $type->getDocument(1);
     // Return all similar from id
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query($mltQuery);
     $resultSet = $type->search($query);
     $this->assertEquals(4, $resultSet->count());
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query\BoolQuery();
     $query->addMust($mltQuery);
     $this->hideDeprecated();
     // Return just the visible similar from id
     $filter = new Query\BoolQuery();
     $filterTerm = new Query\Term();
     $filterTerm->setTerm('visible', true);
     $filter->addMust($filterTerm);
     $query->addFilter($filter);
     $this->showDeprecated();
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
     // Return all similar from source
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setMinimumShouldMatch(90);
     $mltQuery->setLike($type->getDocument(1)->setId(''));
     $query = new Query($mltQuery);
     $resultSet = $type->search($query);
     $this->assertEquals(1, $resultSet->count());
     // Legacy test with filter
     $mltQuery = new MoreLikeThis();
     $mltQuery->setMinTermFrequency(1);
     $mltQuery->setMinDocFrequency(1);
     $mltQuery->setLike($doc);
     $query = new Query\BoolQuery();
     $query->addMust($mltQuery);
     $this->hideDeprecated();
     // Return just the visible similar
     $filter = new BoolFilter();
     $filterTerm = new Term();
     $filterTerm->setTerm('visible', true);
     $filter->addMust($filterTerm);
     $query->addFilter($filter);
     $this->showDeprecated();
     $resultSet = $type->search($query);
     $this->assertEquals(2, $resultSet->count());
 }
Example #12
Show file File: SearchTest.php Project: bungkoko/Elastica
0
 /**
  * @group functional
  */
 public function testGlobalSearchTypeSearchWithKeys()
 {
     $type = $this->_createType();
     $index = $type->getIndex();
     $client = $index->getClient();
     $multiSearch = new MultiSearch($client);
     $search1 = new Search($client);
     $search1->addIndex($index)->addType($type);
     $query1 = new Query();
     $termQuery1 = new Term();
     $termQuery1->setTerm('username', 'farrelley');
     $query1->setQuery($termQuery1);
     $query1->setSize(2);
     $search1->setQuery($query1);
     $multiSearch->addSearch($search1);
     $this->assertCount(1, $multiSearch->getSearches());
     $search2 = new Search($client);
     $search2->addIndex($index)->addType($type);
     $query2 = new Query();
     $termQuery2 = new Term();
     $termQuery2->setTerm('username', 'bunny');
     $query2->setQuery($termQuery2);
     $query2->setSize(3);
     $search2->setQuery($query2);
     $multiSearch->addSearch($search2);
     $multiSearch->setSearchType(Search::OPTION_SEARCH_TYPE_COUNT);
     $multiResultSet = $multiSearch->search();
     $this->assertInstanceOf('Elastica\\Multi\\ResultSet', $multiResultSet);
     $this->assertCount(2, $multiResultSet);
     $this->assertInstanceOf('Elastica\\Response', $multiResultSet->getResponse());
     $resultSets = $multiResultSet->getResultSets();
     $this->assertInternalType('array', $resultSets);
     $this->assertArrayHasKey(0, $resultSets);
     $this->assertInstanceOf('Elastica\\ResultSet', $resultSets[0]);
     $this->assertCount(0, $resultSets[0]);
     $this->assertSame($query1, $resultSets[0]->getQuery());
     $this->assertEquals(3, $resultSets[0]->getTotalHits());
     $this->assertArrayHasKey(1, $resultSets);
     $this->assertInstanceOf('Elastica\\ResultSet', $resultSets[1]);
     $this->assertCount(0, $resultSets[1]);
     $this->assertSame($query2, $resultSets[1]->getQuery());
     $this->assertEquals(6, $resultSets[1]->getTotalHits());
     $search1->setOption(Search::OPTION_SEARCH_TYPE, Search::OPTION_SEARCH_TYPE_QUERY_AND_FETCH);
     $multiResultSet = $multiSearch->search();
     $this->assertInstanceOf('Elastica\\Multi\\ResultSet', $multiResultSet);
     $this->assertCount(2, $multiResultSet);
     $this->assertInstanceOf('Elastica\\Response', $multiResultSet->getResponse());
     $resultSets = $multiResultSet->getResultSets();
     $this->assertInternalType('array', $resultSets);
     $this->assertArrayHasKey(0, $resultSets);
     $this->assertInstanceOf('Elastica\\ResultSet', $resultSets[0]);
     $this->assertCount(2, $resultSets[0]);
     $this->assertSame($query1, $resultSets[0]->getQuery());
     $this->assertEquals(3, $resultSets[0]->getTotalHits());
     $this->assertArrayHasKey(1, $resultSets);
     $this->assertInstanceOf('Elastica\\ResultSet', $resultSets[1]);
     $this->assertCount(0, $resultSets[1]);
     $this->assertSame($query2, $resultSets[1]->getQuery());
     $this->assertEquals(6, $resultSets[1]->getTotalHits());
 }
Example #13
Show file File: BelongsToMany.php Project: maxmirazh33/analogue
0
 /**
  * Add the constraints for a relationship count query.
  *
  * @param  \Analogue\ORM\Query  $query
  * @param  \Analogue\ORM\Query  $parent
  * @return \Analogue\ORM\Query
  */
 public function getRelationCountQuery(Query $query, Query $parent)
 {
     if ($parent->getQuery()->from == $query->getQuery()->from) {
         return $this->getRelationCountQueryForSelfJoin($query, $parent);
     }
     $this->setJoin($query);
     return parent::getRelationCountQuery($query, $parent);
 }
Example #14
Show file File: BeforeSearchEventTest.php Project: Maksold/platform
0
 public function testEvent()
 {
     $query = new Query();
     $event = new BeforeSearchEvent($query);
     $this->assertEquals($query, $event->getQuery());
     $anotherQuery = new Query();
     $anotherQuery->from('test');
     $event->setQuery($anotherQuery);
     $this->assertEquals($anotherQuery, $event->getQuery());
 }
Example #15
Show file File: ExploreController.php Project: rocketyang/iisns
0
 /**
  * Lists all ExploreRecommend models.
  * @return mixed
  */
 public function actionIndex()
 {
     $query = new Query();
     $query->select('id, summary, created_at, title, username, user_id')->from('{{%explore_recommend}}')->where(['category' => 'post'])->orderBy('id DESC');
     $pages = new \yii\data\Pagination(['totalCount' => $query->count()]);
     $posts = $query->offset($pages->offset)->limit($pages->limit)->all();
     $forums = new Query();
     $forums = $forums->select('f.forum_name, f.forum_url, f.forum_desc, f.forum_icon, e.id')->from('{{%forum}} as f')->join('LEFT JOIN', '{{%explore_recommend}} as e', 'e.table_id=f.id')->where(['e.category' => 'forum'])->orderBy('e.id DESC')->all();
     $albums = new Query();
     $albums = $albums->select('id, table_id')->from('{{%explore_recommend}}')->where(['category' => 'album'])->orderBy('id DESC')->all();
     return $this->render('index', ['posts' => $posts, 'pages' => $pages, 'forums' => $forums, 'albums' => $albums]);
 }
Example #16
Show file File: QueryBuilderTest.php Project: glcode/yii2-2.0.3-annotated
0
 /**
  * This test contains three select queries connected with UNION and UNION ALL constructions.
  * It could be useful to use "phpunit --group=db --filter testBuildUnion" command for run it.
  */
 public function testBuildUnion()
 {
     $expectedQuerySql = $this->replaceQuotes("(SELECT `id` FROM `TotalExample` `t1` WHERE (w > 0) AND (x < 2)) UNION ( SELECT `id` FROM `TotalTotalExample` `t2` WHERE w > 5 ) UNION ALL ( SELECT `id` FROM `TotalTotalExample` `t3` WHERE w = 3 )");
     $query = new Query();
     $secondQuery = new Query();
     $secondQuery->select('id')->from('TotalTotalExample t2')->where('w > 5');
     $thirdQuery = new Query();
     $thirdQuery->select('id')->from('TotalTotalExample t3')->where('w = 3');
     $query->select('id')->from('TotalExample t1')->where(['and', 'w > 0', 'x < 2'])->union($secondQuery)->union($thirdQuery, TRUE);
     list($actualQuerySql, $queryParams) = $this->getQueryBuilder()->build($query);
     $this->assertEquals($expectedQuerySql, $actualQuerySql);
     $this->assertEquals([], $queryParams);
 }