Skip to content

Commit 339636e

Browse files
committed
Working =D
1 parent 10c4df1 commit 339636e

File tree

2 files changed

+16
-16
lines changed

2 files changed

+16
-16
lines changed

BricksetSnippet.api.php

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,9 @@
33
class BricksetSnippetAPI extends ApiBase {
44

55
public function execute() {
6-
$id = $this->getMain()->getVal('id');
7-
$name = $this->getMain()->getVal('name');
6+
$set = $this->getMain()->getVal('set');
87

9-
$title = BricksetSnippet::getTitle( $id, $name );
10-
11-
$title = Title::newFromText( '7965 Millennium Falcon' );
8+
$title = BricksetSnippet::getTitle( $set );
129

1310
if ( $title ) {
1411

@@ -34,11 +31,7 @@ public function getDescription() {
3431

3532
public function getAllowedParams() {
3633
return array(
37-
'id' => array (
38-
ApiBase::PARAM_TYPE => 'string',
39-
ApiBase::PARAM_REQUIRED => true
40-
),
41-
'name' => array (
34+
'set' => array (
4235
ApiBase::PARAM_TYPE => 'string',
4336
ApiBase::PARAM_REQUIRED => true
4437
),
@@ -47,14 +40,13 @@ public function getAllowedParams() {
4740

4841
public function getParamDescription() {
4942
return array(
50-
'id' => 'The ID of the set to return',
51-
'name' => 'The name of the set to return'
43+
'set' => 'The set to search for',
5244
);
5345
}
5446

5547
public function getExamples() {
5648
return array(
57-
'api.php?action=bricksetsnippet&id=4346&name=Robo_Pod&format=xml' => 'Get the description for 4346 Robo Pod'
49+
'api.php?action=bricksetsnippet&set=7965-1:%20Millennium%20Falcon' => 'Get the description for 7965-1: Millennium Falcon'
5850
);
5951
}
6052
}

BricksetSnippet.body.php

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,19 @@ static function parseText( $text ) {
3535
/**
3636
* Get the title object for the given search data, or false if none found
3737
*
38-
* @param String $id: id of article to find
39-
* @param String $name: name of article to find
38+
* @param String $search: article to search for
4039
* @return Title|boolean: title if found OR false if none found
4140
*/
42-
static function getTitle( $id, $name ) {
41+
static function getTitle( $search ) {
4342

43+
$engine = SearchEngine::create();
44+
$results = $engine->searchTitle( $search );
45+
46+
if ( $results->numRows() ) {
47+
$result = $results->next();
48+
return $result->getTitle();
49+
} else {
50+
return false;
51+
}
4452
}
4553
}

0 commit comments

Comments
 (0)