Created
July 4, 2012 04:22
-
-
Save Sigmus/3045292 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
abstract class Badge { | |
public $nome; | |
public $pontos; | |
abstract public function conforms(); | |
private function __construct() {} | |
public function beforeConforms() {} | |
public function exists() | |
{ | |
$criteria = new CDbCriteria; | |
$criteria->condition = 'id_usuario=:id_usuario AND nome=:nome'; | |
$criteria->params = array( | |
':id_usuario'=> $this->id_usuario, | |
':nome'=> $this->nome | |
); | |
return Conquista::model()->find($criteria) != null; | |
} | |
public function create() | |
{ | |
$conquista = new Conquista(); | |
$conquista->id_usuario = $this->id_usuario; | |
$conquista->nome = $this->nome;; | |
$conquista->save(false); | |
} | |
private static function _factory($classes, $id_usuario, $id_comentario=0) | |
{ | |
foreach ($classes as $className) { | |
$badge = new $className; | |
$badge->id_usuario = $id_usuario; | |
$badge->usuario = Usuario::model()->findByPk($id_usuario); | |
$badge->id_comentario = $id_comentario; | |
$badge->beforeConforms(); | |
if ( $badge->conforms() and !$badge->exists() ) { | |
$badge->create(); | |
Ranking::somarPontos($id_usuario, $badge->pontos); | |
} | |
} | |
} | |
public static function factoryVisita($id_usuario) | |
{ | |
self::_factory(array('VisitaBadge'), $id_usuario); | |
} | |
public static function factoryPost($id_usuario) | |
{ | |
self::_factory(array('AssiduoBadge'), $id_usuario); | |
} | |
public static function factoryComentario($id_usuario, $id_comentario) | |
{ | |
self::_factory(array( | |
'QuantidadeComentarioBadge', | |
'QuantidadeLikeComentarioBadge', | |
'QuantidadeLikeComentarioUnicoBadge' | |
), $id_usuario, $id_comentario); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment