Skip to content

Instantly share code, notes, and snippets.

View davialexandre's full-sized avatar

Davi Alexandre davialexandre

View GitHub Profile
<?php
if($aposta->aposta_time1 == $jogo->placar_time1 && $aposta->aposta_time2 == $jogo->placar_time2) {
$pontos[$aposta->id]['pontos'][] = CategoriaPonto::ACERTO_PLACAR;
} else {
if($jogo->empatou() && $aposta->aposta_time1 == $aposta->aposta_time2) {
$pontos[$aposta->id]['pontos'][] = CategoriaPonto::ACERTO_EMPATE;
} else if($aposta->vencedor == $jogo->vencedor) {
$pontos[$aposta->id]['pontos'][] = CategoriaPonto::ACERTO_VENCEDOR;
if($aposta->aposta_time1 == $jogo->placar_time1 || $aposta->aposta_time2 == $jogo->placar_time2) {
@davialexandre
davialexandre / gist:1003157
Created June 1, 2011 19:58
Dependent dropdown sample
<div class="row">
<?php echo $form->labelEx($model,'ficha'); ?>
<?php echo $form->dropDownList($model,'ficha',
CHtml::listData($fichas, 'id', 'name'),
array(
'ajax' => array(
'type'=>'POST',
'url'=>CController::createUrl('movimentos/AtivosPorFicha'),
'update'=>'#Movimentos_id_servico',
),
<?php
$fichas = Movimentos::model()->PegaFichas();
$servicos = array();
if(isset($_POST['Model'])) {
$model->attributes = $_POST['Model'];
...
}
if(isset($model->ficha)) {
@davialexandre
davialexandre / AttributesBakcupBehavior.php
Created January 5, 2012 14:51
A simple behavior to store the original loaded activerecord values and use it to check if any was changed
<?php
class AttributesBackupBehavior extends CActiveRecordBehavior {
private $old_attributes;
public function afterFind($event) {
parent::afterFind($event);
foreach($this->owner->attributes as $name => $value) {
$this->old_attributes[$name] = $value;
@davialexandre
davialexandre / gist:2721369
Created May 17, 2012 20:23
Function to get weeks for a given month
<?php
function getWeeksForMonth($year, $month) {
$weeks = array();
$weekday_of_first_day = date('w', strtotime("$year-$month-1"));
$last_day_of_first_week = 6 - $weekday_of_first_day + 1;
$weeks[] = array("$year-$month-1", "$year-$month-$last_day_of_first_week");
$last_day_of_month = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$day = $last_day_of_first_week;
@davialexandre
davialexandre / class.Encrypt.php
Created July 2, 2012 02:23
Security lvl Blonde
<?php
class Encrypt
{
function Encrypt()
{
$this->word = "";
}
function bytexor($a,$b,$l)
{
@davialexandre
davialexandre / gerador-cpf.sh
Created October 5, 2012 22:49
Script bash gerador de CPF
#!/bin/bash
SOMA=0
for i in {10..2}
do
NUMERO=$((`cat /dev/urandom|od -N1 -An -i` % 9))
CPF=$CPF$NUMERO
SOMA=$(($SOMA+($NUMERO*$i)))
done
RESTO=$(($SOMA%11))
if [ $RESTO -lt 2 ]
@davialexandre
davialexandre / relations.php
Created October 19, 2012 18:01
Relations - exemplos
<?php
class Os extends CActiveRecord {
public function relations() {
return array(
'cliente' => array(self::BELONGS_TO, 'Cliente', 'id_cliente'),
);
}
}
@davialexandre
davialexandre / gist:3921652
Created October 20, 2012 01:48
Exemplo de customização de filtros no CGridView
<?php $this->widget('zii.widgets.grid.CGridView', array(
'columns'=>array(
array(
'name' => 'pesquisa',
'value' => '$data->pesquisa',
'header' => 'Termo',
),
array(
'name' => 'data_cadastro',
'value' => 'Yii::app()->dateFormatter->formatDatetime(strtotime($data->data_cadastro), "short", "short")',
@davialexandre
davialexandre / DefaultController.php
Created November 5, 2012 17:53
Exemplo de um controller dentro de um módulo com Login
<?php
class DefaultController extends CController
{
public $defaultAction = 'login';
public function actionLogin() {
$this->layout = 'login';
$model = new AdminLoginForm;
if(isset($_POST['AdminLoginForm'])) {