Skip to content

Commit 2b8c17b

Browse files
Rohit MishraRohit Mishra
authored andcommitted
Added new method under entries and Assets class
1 parent 302cec2 commit 2b8c17b

File tree

5 files changed

+50
-21
lines changed

5 files changed

+50
-21
lines changed

src/lib/helper.php

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,22 @@ function contentstackAddBoolean($operator = '', $query = array()) {
267267
}
268268
}
269269

270+
if (!function_exists('contentstackAddParam')) {
271+
/*
272+
* AddParam
273+
* Set the locale on the Query
274+
* @param
275+
* $operator - key of the query
276+
* $query - Query object
277+
* $value - value to be set against key
278+
* @return $query
279+
* */
280+
function contentstackAddParam($key = '', $query = array(), $value = '') {
281+
$query[$key] = $value;
282+
return $query;
283+
}
284+
}
285+
270286
if (!function_exists('contentstackExistence')) {
271287
/*
272288
* existence
@@ -284,5 +300,4 @@ function contentstackExistence($operator = '', $query = array(), $key = '', $val
284300
$query[$key] = array($operator => $value);
285301
return $query;
286302
}
287-
}
288-
303+
}

src/lib/models/assets.php

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,21 @@
44
* */
55
namespace Contentstack\Stack\Assets;
66

7+
require_once __DIR__ . "/../helper.php";
78

89
use Contentstack\Stack\ContentType\Query\Query;
9-
// use Contentstack\Stack\ContentType\BaseQuery\BaseQuery;
10+
use Contentstack\Stack\ContentType\BaseQuery\BaseQuery;
1011
use Contentstack\Utility;
1112

1213

1314
require_once __DIR__.'/query.php';
14-
// require_once __DIR__."/base_query.php";
15+
require_once __DIR__."/base_query.php";
1516

1617

1718
/*
1819
* Class Assets
1920
* */
20-
class Assets {
21+
class Assets extends BaseQuery {
2122

2223
var $operation;
2324
var $assetUid = '';
@@ -34,12 +35,13 @@ class Assets {
3435
* */
3536
public function __construct($asset_uid = '', $stack = '') {
3637

37-
$this->stack = $stack;
3838
if($asset_uid == ''){
39+
$this->stack = $stack;
3940
$this->type = 'assets';
4041
}else{
41-
$this->type = 'asset';
42-
$this->assetUid = $asset_uid;
42+
$stack->type = 'asset';
43+
$this->assetUid = $asset_uid;
44+
parent::__construct($stack, $this);
4345
}
4446
}
4547

@@ -61,4 +63,7 @@ public function fetch() {
6163
$this->operation = __FUNCTION__;
6264
return \Contentstack\Utility\contentstackRequest($this, 'asset');
6365
}
64-
}
66+
67+
68+
}
69+

src/lib/models/base_query.php

Lines changed: 19 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,16 @@ public function __construct($data = '', $parent = '') {
2020
$this->queryObject->_query = array();
2121
$this->subQuery = array();
2222
}elseif ($data->type === 'asset'){
23-
$this->asset = $data;
24-
$this->queryObject = $data;
23+
$this->stack = $data;
24+
$this->queryObject = $parent;
2525
$this->queryObject->_query = array();
26-
$this->subQuery = array();
27-
}
28-
else{
26+
$this->subQuery = array();
27+
}else{
2928
$this->contentType = $data;
3029
$this->queryObject = $parent;
3130
$this->queryObject->_query = array();
32-
$this->subQuery = array();
33-
31+
$this->subQuery = array();
3432
}
35-
3633
}
3734

3835
/*
@@ -63,7 +60,7 @@ public function except($level = 'BASE', $field_uids = array()) {
6360
* @return Query
6461
* */
6562
public function only($level = 'BASE', $field_uids = array()) {
66-
$this->queryObject->_query = call_user_func('contentstackProjection', 'only', $this->queryObject->_query, $level, $field_uids);
63+
$this->queryObject->_query = call_user_func('contentstackProjection', 'only', $this->queryObject->_query, $level, $field_uids);
6764
return $this->queryObject;
6865
}
6966

@@ -233,6 +230,18 @@ public function includeOwner() {
233230
return $this->queryObject;
234231
}
235232

233+
/*
234+
* addParam
235+
* To sort the entries in addParam
236+
* @param
237+
* field_uid - field uid to be sorted
238+
* @return Query
239+
* */
240+
public function addParam($key = '', $value = '') {
241+
$this->queryObject->_query = call_user_func('contentstackAddParam', $key, $this->queryObject->_query, $value);
242+
return $this->queryObject;
243+
}
244+
236245
/*
237246
* language
238247
* To set the language code in the query
@@ -403,7 +412,5 @@ public function getQuery() {
403412
} catch(\Exception $e) {
404413
echo $e->getMessage();
405414
}
406-
}
407-
408-
415+
}
409416
}

src/lib/models/query.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class Query extends BaseQuery {
2121
* @param
2222
* */
2323
public function __construct($data = '', $type = '') {
24+
2425
$this->_query = array();
2526
$this->type = $type;
2627
parent::__construct($data, $this);

src/lib/utility.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ function wrapResult($result = '', $queryObject = '') {
256256
function contentstackRequest($queryObject = '', $type = ''){
257257
$server_output = '';
258258
if($queryObject) {
259+
\Contentstack\Utility\debug(contentstackUrl($queryObject, $type));
259260
$http = curl_init(contentstackUrl($queryObject, $type));
260261

261262
// setting the GET request

0 commit comments

Comments
 (0)