Skip to content

Instantly share code, notes, and snippets.

View KaiCMueller's full-sized avatar

Kai Müller KaiCMueller

View GitHub Profile
@KaiCMueller
KaiCMueller / getCalendarYearWeek.php
Last active July 16, 2020 14:42
Get year and week number as 6 digit integer from any DateTime object including fix for in between the years
<?php
/**
* @param \DateTime $dateTime
*
* @return int - e.g. 202001
*/
protected function getCalendarYearWeek(DateTime $dateTime): int
{
$week = $dateTime->format('W');
@KaiCMueller
KaiCMueller / WorkingDaysCalculator.php
Created April 6, 2020 12:53
Calculation of next working day date
class WorkingDaysCalculator
{
const SUNDAY = 0;
const SATURDAY = 6;
/**
* Get next working day date
*
* @param \DateTime $baseDate - default now
* @param int $additionalWorkingDays - default 0
@KaiCMueller
KaiCMueller / TablePrefixEventListener.php
Created February 21, 2020 09:06
Symfony: Add an automatic table prefix with Doctrine
<?php
namespace App\EventListener;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
class TablePrefixEventListener
{
/**
@KaiCMueller
KaiCMueller / TablePrefixEventListener.php
Created February 21, 2020 08:56
Symfony: Add an automatic table prefix with Doctrine
<?php
namespace App\EventListener;
use Doctrine\ORM\Event\LoadClassMetadataEventArgs;
use Doctrine\ORM\Mapping\ClassMetadataInfo;
class TablePrefixEventListener
{
/**
@KaiCMueller
KaiCMueller / doctrine_order_by_null_values_first.php
Created September 16, 2019 12:27
Doctrine: Order by NULL values first
<?php
$queryBuilder
->addSelect("(CASE WHEN entity.placedDate IS NULL THEN 1 ELSE 0 END) AS HIDDEN PLACED")
->orderBy('PLACED', 'DESC')
->addOrderBy('entity.placedDate', 'DESC');
@KaiCMueller
KaiCMueller / index.js
Last active March 20, 2019 11:58
Cordova app which loads a website in full screen and opens external links in system browser
var appUrl = 'https://www.my-website.com';
var app = {
currentUrl: appUrl,
initialize: function() {
document.addEventListener('deviceready', this.onDeviceReady.bind(this), false);
},
@KaiCMueller
KaiCMueller / menu.html.twig
Created December 12, 2018 16:27
EasyAdmin: Active entity menu items
{% macro render_menu_item(item, translation_domain) %}
{% if item.type == 'divider' %}
{{ item.label|trans(domain = translation_domain) }}
{% else %}
{% set menu_params = { menuIndex: item.menu_index, submenuIndex: item.submenu_index } %}
{% set path =
item.type == 'link' ? item.url :
item.type == 'route' ? path(item.route, item.params) :
item.type == 'entity' ? path('easyadmin', { entity: item.entity, action: 'list' }|merge(menu_params)|merge(item.params)) :
item.type == 'empty' ? '#' : ''
@KaiCMueller
KaiCMueller / paginator.html.twig
Created August 27, 2018 15:10
Adding page numbers to EasyAdmin list views
{% trans_default_domain 'EasyAdminBundle' %}
{% set _paginator_request_parameters = _request_parameters|merge({'referer': null}) %}
{% if paginator.haveToPaginate %}
<div class="list-pagination">
<div class="row">
<div class="col-sm-3 hidden-xs list-pagination-counter">
{{ 'paginator.counter'|trans({ '%start%': paginator.currentPageOffsetStart, '%end%': paginator.currentPageOffsetEnd, '%results%': paginator.nbResults})|raw }}
</div>
@KaiCMueller
KaiCMueller / layout.html.twig
Last active July 3, 2018 11:35
Extending the EasyAdmin core template
{# this template is located in templates/bundles/EasyAdminBundle/default/layout.html.twig #}
{# pay attention to the "!" in front of the bundle name which tells symfony to use the core template #}
{% extends '@!EasyAdmin/default/layout.html.twig' %}
{% block head_javascript %}
{{ parent() }}
{% block application_javascript %}{% endblock application_javascript %}
{% endblock head_javascript %}
@KaiCMueller
KaiCMueller / doctrine_migrations.yaml
Last active November 28, 2023 07:13
Doctrine Migrations Template
doctrine_migrations:
dir_name: "%kernel.project_dir%/src/Migrations"
namespace: "App\\Migrations"
custom_template: "%kernel.project_dir%/src/Migrations/migration.tpl"