Skip to content

Commit fffa4b1

Browse files
committed
major improvements with content type builder
1 parent fa8b683 commit fffa4b1

File tree

2 files changed

+44
-19
lines changed

2 files changed

+44
-19
lines changed

src/Darryldecode/Backend/Components/ContentBuilder/Commands/QueryContentsCommand.php

Lines changed: 41 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -179,23 +179,20 @@ protected function query($contentType, $content)
179179
// check if terms are provided so we can include it in query conditions
180180
if( !is_null($this->terms) && ($this->terms != '') )
181181
{
182-
// if terms is in array format, the request probably don't contain "terms" query string
183-
// because an empty [] is set to it as default when it is not provided
184-
if( !is_array($this->terms) )
182+
$tax = $this->extractTerms($this->terms);
183+
184+
if(count($tax) > 0)
185185
{
186-
$q->whereHas('terms', function ($q)
186+
foreach($tax as $k => $v)
187187
{
188-
$terms = $this->extractTerms($this->terms);
189-
190-
if( count($terms) > 1 )
191-
{
192-
$q->whereIn('slug', $terms);
193-
}
194-
elseif( count($terms) == 1 )
188+
$q->whereHas('terms', function ($q) use ($k, $v)
195189
{
196-
$q->where('slug', $terms[0]);
197-
}
198-
});
190+
$q->whereHas('taxonomy', function ($q) use ($k)
191+
{
192+
$q->where('taxonomy', $k);
193+
})->whereIn('slug',$v);
194+
});
195+
}
199196
}
200197
}
201198

@@ -224,7 +221,17 @@ protected function query($contentType, $content)
224221

225222
/**
226223
* Just extracts the terms from param
227-
* Ex. terms=term1:term2:term3 to array(term1,term2,term3)
224+
*
225+
* Example.
226+
*
227+
* from:
228+
* terms=:Size|small:Color|blue:Availability|yes:Size|medium
229+
* to:
230+
* array(
231+
* Size => array('small','medium'),
232+
* Color => array('blue'),
233+
* Availability => array('yes'),
234+
* )
228235
*
229236
* @param $terms
230237
* @return array
@@ -233,6 +240,24 @@ private function extractTerms($terms)
233240
{
234241
if( is_array($terms) ) return $terms;
235242

236-
return explode(':',$terms);
243+
$t = array();
244+
245+
$terms = explode(':', trim($terms,':'));
246+
247+
foreach($terms as $tx)
248+
{
249+
$x = explode('|',$tx);
250+
251+
if( array_key_exists($x[0], $t) )
252+
{
253+
array_push($t[$x[0]],$x[1]);
254+
}
255+
else
256+
{
257+
$t[$x[0]] = array($x[1]);
258+
}
259+
}
260+
261+
return $t;
237262
}
238263
}

src/Darryldecode/Backend/Public/backend/cb/app/contents/controller.contents.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -397,10 +397,10 @@ angular.module('cb.group').controller('ContentsController', ['$scope','$timeout'
397397

398398
// extracts selected terms use in filter
399399
function extractTermsFromSelectedFilterObjects(selected) {
400-
var arr = [];
400+
var taxString = '';
401401
angular.forEach(selected, function(term,i) {
402-
arr.push(term.slug);
402+
taxString += ':'+term.taxonomy.taxonomy+'|'+term.slug+'';
403403
});
404-
return arr.join(':');
404+
return taxString;
405405
}
406406
}]);

0 commit comments

Comments
 (0)