Skip to content

Instantly share code, notes, and snippets.

View iron-viper's full-sized avatar
🏠
Working from home

iron-viper

🏠
Working from home
View GitHub Profile
/*
* XSS filter
*
* This was built from numerous sources
* (thanks all, sorry I didn't track to credit you)
*
* It was tested against *most* exploits here: http://ha.ckers.org/xss.html
* WARNING: Some weren't tested!!!
* Those include the Actionscript and SSI samples, or any newer than Jan 2011
*
// Generate migration file
s doctrine:migrations:generate
// Применить миграцию up
s doctrine:migrations:execute YYYYMMDDHHMMSS --up
// Откатить миграцию down
s doctrine:migrations:execute YYYYMMDDHHMMSS --down
@iron-viper
iron-viper / transaction.php
Last active August 29, 2015 14:27 — forked from datacow-com/transaction.php
How to make transactions in Doctrine 2 using Symfony 2
<?php
// Snippet for Symfony 2 application that uses Doctrine 2 to handle transactions
// It uses the names of the objects/doctrine repositories from the Beta 4 Manual of Symfony 2.
// Get the entity manager
$em = $this->getDoctrine()->getEntityManager();
// suspend auto-commit
$em->getConnection()->beginTransaction();
// Возвращает ассоциативный массив если запос удался.
// Если не удался - пустой массив
// Если возникла ошибка - Ексепшен
->getArrayResult()
// Выполняет запрос созданные в билдере
// В случае выполнения запорса - возвращает int 'n', где n = количеству выполненных запросов
// В случае НЕ выполнения запорса - возвращает int '0'
// В случае ошибки - возывает Ексепшен
->execute()
/** PHP function **/
function array_to_tree(array $array, $parent_id = 0)
{
$array = array_combine(array_column ($array, 'id'), array_values($array));
foreach ($array as $k => &$v) {
if (isset($array[$v['parent_id']])) {
$array[$v['parent_id']]['children'][$k] = &$v;
}
@iron-viper
iron-viper / getchildren
Created April 9, 2016 08:18 — forked from avknor/getchildren
Doctrine2 get all the child records from adjacency list.
public function getSubOrgsForTranspnakl(Entity $topitem)
{
$childrenArray = array();
$iterate = true;
$listOfParents = array();
$listOfParents = array_push($listOfParents, $topitem);
while ($iterate){
$q = $this
->createQueryBuilder('o')
<?php
/**
* Class for working with wood Adjacency List
* see down sql 'show create table'
*
* @author Alexander Kapliy <[email protected]>
*/
class AdjacencyList {
protected $tbl;
<?php
$tree = [
[
"id" => "1",
"name" => "test 1",
"parent" => null,
"_children" => [
[
"id" => "1.1",
php app/console doctrine:fixtures:load --append --no-debug --fixtures=/path/to/fixture1
$dateNow = "04/28/2016";
$timestamp = strtotime($dateNow);
$currDayOfWeek = date("w", $timestamp);
$startDayOflastWeekT = strtotime(-($currDayOfWeek + 7) . " days", $timestamp);
$startDayOflastWeek = date("m/d/Y", $startDayOflastWeekT);
$endDayOflastWeekT = strtotime("+ 6 days", $startDayOflastWeekT);
$endDayOflastWeek = date("m/d/Y", $endDayOflastWeekT);
$startDayOfMiddleWeekT = strtotime("+ 7 days", $startDayOflastWeekT);