Guest User

Untitled

a guest
May 22nd, 2018
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.32 KB | None | 0 0
  1. {
  2. title:"Test Banner 4",
  3. url:"http://localhost:8888/banners/test-banner-4",
  4. jsonUrl:"http://localhost:8888/api/banners/17",
  5. content:"Test.",
  6. page-categories:[
  7. {
  8. label:"ADSL",
  9. value:"adsl",
  10. selected:true
  11. },
  12. {
  13. label:"Fibre",
  14. value:"fibre",
  15. selected:true
  16. }
  17. ],
  18. campaignId:"sHKJJK",
  19. targetUrl:"http://xyx.xaws.co.za",
  20. image1:"//xyx.xaws.co.za/dev/images/banners/banner-lg.png",
  21. image2:"//xyx.xaws.co.za/dev/images/banners/banner-md.png",
  22. image3:"//xyx.xaws.co.za/dev/images/banners/banner-sm.png",
  23. date_published:"2018-05-22T14:06:05+02:00",
  24. date_modified:"2018-05-22T14:06:05+02:00"
  25. }
  26.  
  27. 'api/banners' => function () {
  28. Craft::$app->response->headers->set('Access-Control-Allow-Origin', '*');
  29. $target = Craft::$app->request->getQueryParam('target');
  30. $campaign = Craft::$app->request->getQueryParam('campaign');
  31. return [
  32. 'elementType' => Entry::class,
  33. 'criteria' => [
  34. 'section' => 'banners',
  35. 'bannerPageCategories' => $target,
  36. 'campaignId' => $campaign
  37. ],
  38. 'transformer' => function (Entry $entry) {
  39. $image1 = $entry->image1->first();
  40. $image2 = $entry->image2->first();
  41. $image3 = $entry->image3->first();
  42.  
  43. return [
  44. 'title' => $entry->title,
  45. 'url' => $entry->url,
  46. 'jsonUrl' => UrlHelper::url("api/banners/{$entry->id}"),
  47. 'content' => $entry->htmlcontent,
  48. 'page-categories' => $entry->bannerPageCategories,
  49. 'campaignId' => $entry->campaignId,
  50. 'targetUrl' => $entry->targetUrl,
  51. 'image1' => $image1 ? $image1->url : null,
  52. 'image2' => $image2 ? $image2->url : null,
  53. 'image3' => $image3 ? $image3->url : null,
  54. 'date_published' => $entry->postDate->format(DateTime::ATOM),
  55. 'date_modified' => $entry->dateUpdated->format(DateTime::ATOM),
  56. ];
  57. },
  58. ];
  59. },
  60.  
  61. ['and', '*adsl*', '*fibre*']
  62.  
  63. ['or', '*adsl*', '*fibre*']
  64.  
  65. 'bannerPageCategories' => "*{$target}*"
Add Comment
Please, Sign In to add comment