Skip to content

Instantly share code, notes, and snippets.

@ModernTimes
ModernTimes / LazySaverBehavior
Created September 4, 2012 00:26
LazySaverBehavior: prevents save() command from being executed if no attributes have changed
<?php
Yii::import('ext.AttributesBackupBehavior');
/**
* Prevent save() command from being executed if no attributes have changed
* The AttributesBackupBehavior class is available here:
* http://www.yiiframework.com/extension/attributesbackupbehavior/
*/
@ModernTimes
ModernTimes / ListBehavior.php
Created September 4, 2012 00:17
ListBehavior: makes AR models behave like CLists
<?php
/**
* Based on CList:
* @author Qiang Xue <qiang.xue@gmail.com>
* @link http://www.yiiframework.com/doc/api/1.1/CList
* @copyright Copyright &copy; 2008-2011 Yii Software LLC
* @license http://www.yiiframework.com/license/
*/
/**
@ModernTimes
ModernTimes / Lottery.php
Created August 16, 2012 07:28
Lottery: simulates unfair/weighted die rolls
/**
* Beware: Returns a winner even if the collective drop chance is below 100%.
* If that behavior is undesired, add some logic in getWinner to prevent it.
*/
class Lottery {
/**
* list of entries in the lottery. Elements are of the form
* array('participant' => (mixed),
* 'lots' => (float)),