summaryrefslogtreecommitdiff
path: root/www/wiki/extensions/SemanticMediaWiki/src/QueryFactory.php
blob: ca0a36dd165e20878aceae09b7520469424b9af6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
<?php

namespace SMW;

use SMW\Query\DescriptionFactory;
use SMW\Query\Language\Description;
use SMW\Query\Parser as QueryParser;
use SMW\Query\Parser\DescriptionProcessor;
use SMW\Query\Parser\LegacyParser;
use SMW\Query\Parser\Tokenizer;
use SMW\Query\PrintRequestFactory;
use SMW\Query\ProfileAnnotatorFactory;
use SMW\Query\QueryCreator;
use SMW\Query\QueryToken;
use SMWQuery as Query;
use SMWQueryResult as QueryResult;

/**
 * @license GNU GPL v2+
 * @since 2.4
 *
 * @author mwjames
 */
class QueryFactory {

	/**
	 * @since 2.5
	 *
	 * @return ProfileAnnotatorFactory
	 */
	public function newProfileAnnotatorFactory() {
		return new ProfileAnnotatorFactory();
	}

	/**
	 * @since 2.4
	 *
	 * @param Description $description
	 * @param integer|false $context
	 *
	 * @return Query
	 */
	public function newQuery( Description $description, $context = false ) {
		return new Query( $description, $context );
	}

	/**
	 * @since 2.4
	 *
	 * @return DescriptionFactory
	 */
	public function newDescriptionFactory() {
		return new DescriptionFactory();
	}

	/**
	 * @since 2.4
	 *
	 * @return PrintRequestFactory
	 */
	public function newPrintRequestFactory() {
		return new PrintRequestFactory();
	}

	/**
	 * @since 2.4
	 *
	 * @return RequestOptions
	 */
	public function newRequestOptions() {
		return new RequestOptions();
	}

	/**
	 * @since 2.4
	 *
	 * @param string $string
	 * @param integer $condition
	 * @param boolean $isDisjunctiveCondition
	 *
	 * @return StringCondition
	 */
	public function newStringCondition( $string, $condition, $isDisjunctiveCondition = false ) {
		return new StringCondition( $string, $condition, $isDisjunctiveCondition );
	}

	/**
	 * @since 2.4
	 *
	 * @param integer|boolean $queryFeatures
	 *
	 * @return QueryParser
	 */
	public function newQueryParser( $queryFeatures = false ) {
		return $this->newLegacyQueryParser( $queryFeatures );
	}

	/**
	 * @since 3.0
	 *
	 * @param integer|boolean $queryFeatures
	 *
	 * @return QueryParser
	 */
	public function newLegacyQueryParser( $queryFeatures = false ) {

		if ( $queryFeatures === false ) {
			$queryFeatures = Applicationfactory::getInstance()->getSettings()->get( 'smwgQFeatures' );
		}

		return new LegacyParser(
			new DescriptionProcessor( $queryFeatures ),
			new Tokenizer(),
			new QueryToken()
		);
	}

	/**
	 * @since 2.5
	 *
	 * @param Store $store
	 * @param Query $query
	 * @param DIWikiPage[]|[] $results = array()
	 * @param boolean $continue
	 *
	 * @return QueryResult
	 */
	public function newQueryResult( Store $store, Query $query, $results = [], $continue = false ) {

		$queryResult =  new QueryResult(
			$query->getDescription()->getPrintrequests(),
			$query,
			$results,
			$store,
			$continue
		);

		return $queryResult;
	}

}