SproutCMS

This is the code documentation for the SproutCMS project

source of /sprout/Helpers/DisplayConditions/Platform/DeviceCategory.php

  1. <?php
  2. /*
  3.  * Copyright (C) 2017 Karmabunny Pty Ltd.
  4.  *
  5.  * This file is a part of SproutCMS.
  6.  *
  7.  * SproutCMS is free software: you can redistribute it and/or modify it under the terms
  8.  * of the GNU General Public License as published by the Free Software Foundation, either
  9.  * version 2 of the License, or (at your option) any later version.
  10.  *
  11.  * For more information, visit <http://getsproutcms.com>.
  12.  */
  13.  
  14. namespace Sprout\Helpers\DisplayConditions\Platform;
  15.  
  16. use Sprout\Helpers\DisplayConditions\DisplayConditionEnum;
  17. use Sprout\Helpers\UserAgent;
  18.  
  19.  
  20. /**
  21.  * Display condtion for device category - desktop, mobile, tablet
  22.  */
  23. class DeviceCategory extends DisplayConditionEnum
  24. {
  25.  
  26. /**
  27.   * Return the available values for dropdowns
  28.   *
  29.   * @return array Key is internal value (e.g. 'desktop') and value is the label (e.g. 'Desktop')
  30.   */
  31. public function getParamValues()
  32. {
  33. return [
  34. 'Desktop' => 'Desktop',
  35. 'Tablet' => 'Tablet',
  36. 'Mobile' => 'Mobile',
  37. ];
  38. }
  39.  
  40.  
  41. /**
  42.   * Return the current value of the variable
  43.   * This is compared against the params returned by {@see DisplayCondition::getParamValues}
  44.   *
  45.   * @param array $env Environment, such as page id etc
  46.   * @return string
  47.   */
  48. protected function getCurrentValue(array $env)
  49. {
  50. $info = UserAgent::getInfo();
  51. return @$info['device_category'];
  52. }
  53.  
  54. }
  55.