Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
JaJuMa committed Nov 27, 2023
0 parents commit e2d3b32
Show file tree
Hide file tree
Showing 20 changed files with 1,169 additions and 0 deletions.
71 changes: 71 additions & 0 deletions Block/PowerToys/Weather.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Block\PowerToys;
use Jajuma\PowerToys\Block\PowerToys\Dashboard;
use Magento\Framework\View\Element\Template\Context;
use Jajuma\PotWeather\Helper\WeatherConfig;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\Locale\Resolver;

class Weather extends Dashboard
{
private $weatherConfig;

private $storeManager;

private $store;

public function __construct(
WeatherConfig $weatherConfig,
StoreManagerInterface $storeManager,
Resolver $store,
Context $context,
array $data = []
) {
$this->weatherConfig = $weatherConfig;
$this->storeManager = $storeManager;
$this->store = $store;
parent::__construct($context, $data);
}

public function isEnable(): bool
{
$storeId = $this->storeManager->getStore()->getId();
return $this->weatherConfig->isEnable($storeId);
}

public function getWeatherTypeLocation()
{
$storeId = $this->storeManager->getStore()->getId();
return $this->weatherConfig->getWeatherTypeLocation($storeId);
}
public function getWeatherAddress()
{
$storeId = $this->storeManager->getStore()->getId();
return $this->weatherConfig->getWeatherAddress($storeId);
}
public function getWeatherSkin()
{
$storeId = $this->storeManager->getStore()->getId();
return $this->weatherConfig->getWeatherSkin($storeId);
}
public function getWeatherUnits()
{
$storeId = $this->storeManager->getStore()->getId();
return $this->weatherConfig->getWeatherUnits($storeId);
}
public function getWeatherLocation()
{
$storeId = $this->storeManager->getStore()->getId();
return $this->weatherConfig->getWeatherLocation($storeId);
}

public function getLocaleCode()
{
return $this->store->getLocale();
}
}
49 changes: 49 additions & 0 deletions Block/System/Config/AddressSugguest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023-present JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Block\System\Config;
use Magento\Backend\Block\Template\Context;
use Magento\Config\Block\System\Config\Form\Field;
use Magento\Framework\Data\Form\Element\AbstractElement;
class AddressSugguest extends Field
{
/**
* @var string
*/
protected $_template = 'Jajuma_PotWeather::system/config/suggestion.phtml';
/**
* @param Context $context
* @param array $data
*/
public function __construct(
Context $context,
array $data = []
) {
parent::__construct($context, $data);
}
/**
* Remove scope label
*
* @param AbstractElement $element
* @return string
*/
public function render(AbstractElement $element)
{
//$element->unsScope()->unsCanUseWebsiteValue()->unsCanUseDefaultValue();
return parent::render($element);
}
/**
* Return element html
*
* @param AbstractElement $element
* @return string
*/
protected function _getElementHtml(AbstractElement $element)
{
return $this->_toHtml();
}

}
46 changes: 46 additions & 0 deletions Controller/Adminhtml/Weather/Address.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Controller\Adminhtml\Weather;

use Magento\Framework\View\Result\PageFactory;
use Magento\Backend\App\Action;
use Magento\Framework\HTTP\Client\Curl;

class Address extends \Magento\Backend\App\Action
{
protected $_pageFactory;

private $curl;

public function __construct(
Action\Context $context,
PageFactory $pageFactory,
Curl $curl
) {
$this->curl = $curl;
parent::__construct($context);
}

public function execute()
{
$nameSearch = $this->getRequest()->getParam('name');
if (!$nameSearch) return false;
$url = 'https://weather-services.tomorrow.io/backend/v1/cities?name=' . rawurlencode($nameSearch);
// define options
$optArray = array(
CURLOPT_URL => $url,
CURLOPT_RETURNTRANSFER => true
);
// apply those options
$this->curl->setOptions($optArray);
$this->curl->get($url);
// execute request and get response
$result = $this->curl->getBody();
//$result = json_decode($result, true);
return $this->getResponse()->setBody($result);
}
}
96 changes: 96 additions & 0 deletions Helper/WeatherConfig.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Helper;
use Magento\Store\Model\ScopeInterface;
use Magento\Store\Model\StoreManagerInterface;
use Magento\Framework\App\Helper\AbstractHelper;
use Jajuma\PotWeather\Model\Config\Source\Location\Type;
/**
* Class Data
* @package Jajuma\PotWeather\Helper
*/
class WeatherConfig extends AbstractHelper
{
public const WEATHER_ENABLED = 'power_toys/weather/is_enabled';
public const WEATHER_TYPE = 'power_toys/weather/type_location';
public const WEATHER_ADDRESS = 'power_toys/weather/address_id';
public const WEATHER_SKIN = 'power_toys/weather/skin';
public const WEATHER_UNITS = 'power_toys/weather/units';

/**
* @param null $store
* @return bool
*/
public function isEnable($store = null)
{
return (int) $this->scopeConfig->getValue(
self::WEATHER_ENABLED,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param null $store
* @return bool
*/
public function getWeatherTypeLocation($store = null)
{
return (int) $this->scopeConfig->getValue(
self::WEATHER_TYPE,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param null $store
* @return bool
*/
public function getWeatherLocation($store = null)
{
if ($this->getWeatherTypeLocation() == Type::LOCATION_TYPE_DYNAMIC) {
return '';
} else {
return $this->getWeatherAddress($store);
}
}
/**
* @param null $store
* @return bool
*/
public function getWeatherAddress($store = null)
{
return $this->scopeConfig->getValue(
self::WEATHER_ADDRESS,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param null $store
* @return bool
*/
public function getWeatherSkin($store = null)
{
return $this->scopeConfig->getValue(
self::WEATHER_SKIN,
ScopeInterface::SCOPE_STORE,
$store
);
}
/**
* @param null $store
* @return bool
*/
public function getWeatherUnits($store = null)
{
return $this->scopeConfig->getValue(
self::WEATHER_UNITS,
ScopeInterface::SCOPE_STORE,
$store
);
}
}
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2023 JaJuMa

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions Model/Config/Source/Location/Type.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Model\Config\Source\Location;
/**
* @api
* @since 100.0.2
*/
class Type implements \Magento\Framework\Option\ArrayInterface
{
public const LOCATION_TYPE_DYNAMIC = 1;
public const LOCATION_TYPE_FIXED = 0;
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [['value' => self::LOCATION_TYPE_DYNAMIC, 'label' => __('Dynamic')], ['value' => self::LOCATION_TYPE_FIXED, 'label' => __('Fixed')]];
}
/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [self::LOCATION_TYPE_FIXED => __('Fixed'), self::LOCATION_TYPE_DYNAMIC => __('Dynamic')];
}
}
34 changes: 34 additions & 0 deletions Model/Config/Source/Skin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Model\Config\Source;
/**
* @api
* @since 100.0.2
*/
class Skin implements \Magento\Framework\Option\ArrayInterface
{
public const WEATHER_SKIN_LIGHT = 'light';
public const WEATHER_SKIN_DARK = 'dark';
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [['value' => self::WEATHER_SKIN_LIGHT, 'label' => __('Light')], ['value' => self::WEATHER_SKIN_DARK, 'label' => __('Dark')]];
}
/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [self::WEATHER_SKIN_LIGHT => __('Light'), self::WEATHER_SKIN_DARK => __('Dark')];
}
}
34 changes: 34 additions & 0 deletions Model/Config/Source/Units.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php
/**
* @author JaJuMa GmbH <info@jajuma.de>
* @copyright Copyright (c) 2023 JaJuMa GmbH <https://www.jajuma.de>. All rights reserved.
* @license http://opensource.org/licenses/mit-license.php MIT License
*/
namespace Jajuma\PotWeather\Model\Config\Source;
/**
* @api
* @since 100.0.2
*/
class Units implements \Magento\Framework\Option\ArrayInterface
{
public const WEATHER_METRIC = 'metric';
public const WEATHER_IMPERIAL = 'imperial';
/**
* Options getter
*
* @return array
*/
public function toOptionArray()
{
return [['value' => self::WEATHER_METRIC, 'label' => __('Metric C°')], ['value' => self::WEATHER_IMPERIAL, 'label' => __('Imperial F°')]];
}
/**
* Get options in "key-value" format
*
* @return array
*/
public function toArray()
{
return [self::WEATHER_METRIC => __('Metric C°'), self::WEATHER_IMPERIAL => __('Imperial F°')];
}
}
Loading

0 comments on commit e2d3b32

Please sign in to comment.