Skip to content

Instantly share code, notes, and snippets.

View fatorx's full-sized avatar
💭
Learning and learning.

Fabio de Souza fatorx

💭
Learning and learning.
View GitHub Profile
<?php
namespace Imoveis\Entity;
use Doctrine\ORM\Mapping as ORM;
use Zend\Stdlib\Hydrator;
/**
* Bairros
*
@fatorx
fatorx / gist:7870874
Last active December 30, 2015 18:59
Doctrine - entidades relacionadas
- Entidades Relacionadas
Inserir a anotação | fetch="EAGER" | no item de relacionamento,
para carregar automaticamente o objeto.
Ex:
/**
* @ORM\OneToMany(targetEntity="Clientes\Entity\PedidosItens", mappedBy="pedido", fetch="EAGER")
*/
private $itens;
@fatorx
fatorx / gist:8099313
Created December 23, 2013 15:48
ZF2 - Pegar um campo de um elemento Collection na view
<?php
$formCampos = $form->get('fieldset_princpal');
$collectionElement = $formCampos->get('collection_element');
?>
<?php $campoTipo = $collectionElement->getFieldsets()[0]->getElements()['nomeCampo']; ?>
@fatorx
fatorx / gist:8107429
Last active January 1, 2016 06:49
Somar dias a uma data (via objeto DateTime)
<?php
$dataOperacao = '2013-12-23 15:16:17';
$format = 'Y-m-d H:i:s';
$date = DateTime::createFromFormat($format, $dataOperacao);
$date->add(new DateInterval('P365D'));
echo $date->format('Y-m-d') . "\n";
/**
* lê-se os argumentos de DateInterval da seguinte forma: periodo de 365 dias (period of 365 days)
<?php
// Onde $this->em recebe o EntityManager
$sql = 'SELECT id,titulo FROM posts';
$stmt = $this->em->getConnection()->prepare($sqlSlug);
$stmt->bindValue(1, $slugPost);
try {
$stmt->execute();
<?php
// use para classe doctrine
use Doctrine\ORM\Query\ResultSetMappingBuilder;
// código no método de consulta
$sql = " SELECT p.* " .
" FROM posts p ".
" INNER JOIN post_categories_has_posts pcp ON pcp.posts_id = p.id ".
@fatorx
fatorx / gist:9196485
Last active August 29, 2015 13:56
Controller Test - get variables defined for ViewModel
<?php
public function testIfSetsVariablesInRequestABudgetAction()
{
$this->createMocks(); // create mocks for services
$this->dispatch('/en/contact/request-a-budget');
$this->assertResponseStatusCode(200);
$viewManager = $this->getApplicationServiceLocator()->get('ViewManager');
$variables = $viewManager->getViewModel()->getChildren()[0]->getVariables();
Script para testar SDK do Facebook:
1 - Baixar SDK e importar para o Eclipse
2 - Nos projetos de exemplo, excluir a pasta libs
3 - Em propriedades -> Android, incluir o Facebook como uma lib
Link de referência:
http://stackoverflow.com/questions/20399836/friendpickersample-installation-failed-due-to-invalid-apk-file-friendpickersa
@fatorx
fatorx / gist:2d1c53b5eec5175214a7
Last active August 29, 2015 14:17
Focus in canvas element (HTML5)
// With Jquery
$(function() {
$("#canvas").click(); // simulate click in canvas element
});
// Or pure javascript
window.onload = function() {
var canvasElm = document.getElementById('canvas');
canvasElm.setAttribute('tabindex','0');
canvasElm.focus();
@fatorx
fatorx / InvertRecyclerView
Last active September 21, 2018 17:37
Para inverter a ordem dos itens de um recycler view, para ficar parecido com o formato de mensagens do WhatsApp
recyclerView = (RecyclerView) findViewById(R.id.rvMessagesList);
LinearLayoutManager linearLayoutManager = new LinearLayoutManager(MessageThreadActivity.this);
linearLayoutManager.setStackFromEnd(true);
linearLayoutManager.setReverseLayout(false);
recyclerView.setLayoutManager(linearLayoutManager);