fix(smartblock): fixed getTracklist method
This commit is contained in:
parent
6ae2de57f2
commit
efdca547fc
1 changed files with 39 additions and 5 deletions
|
@ -10,6 +10,7 @@ use App\Models\SmartBlockContent;
|
|||
use App\Models\SmartBlockCriteria;
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use http\Exception\BadMethodCallException;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Collection;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
@ -30,7 +31,7 @@ class SmartBlockController extends Controller
|
|||
}
|
||||
|
||||
return SmartBlock::searchFilter($request)
|
||||
->with(['creator', 'content', 'criteria'])
|
||||
->with(['creator', 'tracks', 'tracks.file', 'criteria'])
|
||||
->paginate($pagination)
|
||||
->toJson();
|
||||
}
|
||||
|
@ -91,6 +92,7 @@ class SmartBlockController extends Controller
|
|||
]);
|
||||
|
||||
$this->saveCriteria($dbSmartBlock, $criteria);
|
||||
//ToDo: save content
|
||||
|
||||
return $dbSmartBlock->with(['criteria', 'content'])->get()->toJson();
|
||||
}
|
||||
|
@ -126,9 +128,41 @@ class SmartBlockController extends Controller
|
|||
* @return mixed json string
|
||||
* @throws \DateMalformedIntervalStringException
|
||||
*/
|
||||
public function getTrackList(int $block_id, int $instance_id = null) {
|
||||
$smartBlock = SmartBlock::whereId($block_id)->first();
|
||||
$criteria = $smartBlock->criteria;
|
||||
public function getTrackList(int $block_id, Request $request) {
|
||||
if ($block_id === 0 && count($request->criteria) === 0) {
|
||||
throw new BadMethodCallException('If block_id is 0 criteria array must be passed as parameter');
|
||||
}
|
||||
|
||||
if ($block_id > 0) {
|
||||
$smartBlock = SmartBlock::whereId($block_id)->first();
|
||||
$criteria = $smartBlock->criteria;
|
||||
} else {
|
||||
$criteria = new \Illuminate\Database\Eloquent\Collection();
|
||||
foreach($request->criteria as $key => $criterion) {
|
||||
$criteria->push(new SmartBlockCriteria($criterion));
|
||||
}
|
||||
$criteria->push(new SmartBlockCriteria([
|
||||
'criteria' => 'limit',
|
||||
'modifier' => $request->limit['type'],
|
||||
'value' => $request->limit['quantity'],
|
||||
]));
|
||||
$criteria->push(new SmartBlockCriteria([
|
||||
'criteria' => 'repeat_tracks',
|
||||
'modifier' => 'N/A',
|
||||
'value' => intval($request->repeat_tracks),
|
||||
]));
|
||||
$criteria->push(new SmartBlockCriteria([
|
||||
'criteria' => 'overflow_tracks',
|
||||
'modifier' => 'N/A',
|
||||
'value' => intval($request->overflow_tracks),
|
||||
]));
|
||||
$criteria->push(new SmartBlockCriteria([
|
||||
'criteria' => 'sort',
|
||||
'modifier' => 'N/A',
|
||||
'value' => $request->sort
|
||||
]));
|
||||
}
|
||||
//dd($criteria);
|
||||
$files = File::smartBlockFilter($criteria)->get();
|
||||
|
||||
return $this->criteriaLimit($criteria, $files);
|
||||
|
@ -159,7 +193,7 @@ class SmartBlockController extends Controller
|
|||
$list = collect();
|
||||
foreach ($files as $file) {
|
||||
$fileLength = new LengthFormatter($file->length);
|
||||
$totLengthFromToday->add(DateInterval::createFromDateString($fileLength->toSeconds().' seconds'));
|
||||
$totLengthFromToday->add(DateInterval::createFromDateString(round($fileLength->toSeconds()).' seconds'));
|
||||
if ($totLengthFromToday < $intervalFromToday) {
|
||||
$list->push($file);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue