Added a moon phase display
Signed-off-by: Gergely Polonkai <polesz@w00d5t0ck.info>
@ -58,3 +58,8 @@
|
|||||||
background-color: transparent;
|
background-color: transparent;
|
||||||
color: #c4d3ff;
|
color: #c4d3ff;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#moonphase {
|
||||||
|
float: right;
|
||||||
|
width: 30px;
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.6 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 10 KiB |
After Width: | Height: | Size: 1.2 KiB |
After Width: | Height: | Size: 11 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 12 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 13 KiB |
After Width: | Height: | Size: 1.3 KiB |
After Width: | Height: | Size: 14 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 15 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
After Width: | Height: | Size: 16 KiB |
After Width: | Height: | Size: 1.5 KiB |
@ -52,6 +52,9 @@
|
|||||||
<button type="submit">Keresés</button>
|
<button type="submit">Keresés</button>
|
||||||
</div>
|
</div>
|
||||||
#}
|
#}
|
||||||
|
<div id="moonphase">
|
||||||
|
<img src="{{ asset('bundles/kekrozsakfront/images/moonphase/' ~ moonphase.phaseNum ~ '_small.png') }}" alt="{{ moonphase.percent }}" />
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div id="top-line-padding"></div>
|
<div id="top-line-padding"></div>
|
||||||
</div>
|
</div>
|
||||||
|
62
src/KekRozsak/FrontBundle/Twig/TwigMoonphaseExtension.php
Normal file
@ -0,0 +1,62 @@
|
|||||||
|
<?php
|
||||||
|
namespace KekRozsak\FrontBundle\Twig;
|
||||||
|
|
||||||
|
use Symfony\Component\DependencyInjection\ContainerInterface;
|
||||||
|
use JMS\DiExtraBundle\Annotation as DI;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @DI\Service
|
||||||
|
* @DI\Tag("twig.extension")
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class TwigMoonphaseExtension extends \Twig_Extension
|
||||||
|
{
|
||||||
|
const SYNODIC = 29.53058867;
|
||||||
|
const SECPERDAY = 86400.0;
|
||||||
|
|
||||||
|
private $container;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @DI\InjectParams({
|
||||||
|
* "container" = @DI\Inject("service_container")
|
||||||
|
* })
|
||||||
|
* @param \Symfony\Component\DependencyInjection\ContainerInterface $container
|
||||||
|
*/
|
||||||
|
public function __construct(ContainerInterface $container)
|
||||||
|
{
|
||||||
|
$this->container = $container;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getGlobals()
|
||||||
|
{
|
||||||
|
$globals = parent::getGlobals();
|
||||||
|
|
||||||
|
$gds = new \DateTime('now');
|
||||||
|
|
||||||
|
$baseDate = new \DateTime();
|
||||||
|
$baseDate->setTimezone(new \DateTimeZone('UTC'));
|
||||||
|
$baseDate->setDate(2005, 4, 8);
|
||||||
|
$baseDate->setTime(8, 48, 0);
|
||||||
|
|
||||||
|
$diff = abs($gds->getTimestamp() - $baseDate->getTimestamp());
|
||||||
|
$origPhasePercent = $diff / (self::SYNODIC * self::SECPERDAY);
|
||||||
|
$phasePercent = fmod(($origPhasePercent) * 100.0, 100.0);
|
||||||
|
if ($phasePercent < 0) {
|
||||||
|
$phasePercent += 100;
|
||||||
|
}
|
||||||
|
$phase = round($phasePercent * 0.279);
|
||||||
|
$realPercent = (50.0 - abs($phasePercent - 50.0)) * 2.0;
|
||||||
|
|
||||||
|
$globals['moonphase'] = array(
|
||||||
|
'phaseNum' => $phase,
|
||||||
|
'percent' => $realPercent,
|
||||||
|
);
|
||||||
|
|
||||||
|
return $globals;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return 'twig_moonphase';
|
||||||
|
}
|
||||||
|
}
|