define('application/models/relatedcontent', [
'rofl/models/api/abstract',
'rofl/lib/utils',
'application/models/configuration',
'antie/runtimecontext'
], function (
Abstract,
Utils,
ApiConfig,
RuntimeContext
) {
'use strict';
var application = RuntimeContext.getCurrentApplication(),
broadcastReference;
return Abstract.extend({
/**
* Initialises the model.
*
* @param {Object} data - The data.
*/
init: function (data) {
var startTime = new Date(application.getDate().getTime() - 1000 * 60 * 60 * 24 * 7), // 7 days ago
endTime = new Date(application.getDate().getTime() + 1000 * 60 * 60 * 24 * 5); // 5 days ahead
require(['application/models/broadcast'], function (
Broadcast
) {
broadcastReference = Broadcast;
});
startTime.setHours(0);
startTime.setMinutes(0);
startTime.setSeconds(0);
startTime.setMilliseconds(0);
endTime.setHours(0);
endTime.setMinutes(0);
endTime.setSeconds(0);
endTime.setMilliseconds(0);
this._title = data.getTitle() || '';
this._endpoint = '101/1.2.0/A/nld/smarttv/kpn'
+ '/TRAY/SEARCH/PROGRAM?'
+ 'filter_seriesId=' + data.getSeriesId()
+ '&filter_channelIds=' + data.getChannelId()
+ '&filter_isTvPremiere=true'
+ '&filter_startTime=' + startTime.getTime()
+ '&filter_endTime=' + endTime.getTime()
+ '&outputFormat=EXTENDED'
+ '&sortOrder=desc';
},
/**
* Resolves the endpoint.
*
* @returns {Object} - The endpoint.
*/
resolveEndpoint: function () {
return this._endpoint;
},
/**
* Validates the response.
*
* @param {Object} response - The response.
* @returns {boolean} Response.
*/
validateResponse: function (response) {
return response.resultCode === ApiConfig.RESPONSE_CODES.OK;
},
/**
* Transforms the response.
*
* @param {Object} response - The response.
* @returns {Array} - The formatted related items.
*/
transformFrom: function (response) {
var results = Utils.getNested(response, 'resultObj', 'containers'),
formatted = [];
Utils.each(results, function (result) {
formatted.push(new broadcastReference(result));
});
return formatted;
}
});
});