Last active
March 16, 2017 10:11
-
-
Save EmilioNicolas/7f422092a9b20fb7862f02fc8e594e1f to your computer and use it in GitHub Desktop.
Ejercicio revisión de código Erasmusu
This file contains hidden or 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 | |
class UserLoginService | |
{ | |
protected $notis; | |
public function execute($request) | |
{ | |
$email = $request->getEmail(); | |
$password = $request->getPassword(); | |
$autenticated = AuthService::autenticate( | |
$email, | |
$password | |
); | |
if ($autenticated) { | |
$userRepo = new UserRepository(); | |
$user = $userRepo->findByEmail($email); | |
$this->notis = $user->getNotifications(); | |
if (!$user->isBlocked()) { | |
$mail = new Zend_Mail(); | |
$mail->setTo($email); | |
$mail->setBody('Sesión iniciada'); | |
$email->send(); | |
Events:trigger( | |
'user.logged', | |
array('user_id' => $user->getId()) | |
); | |
} else { | |
throw new AuthException('User is blocked'); | |
} | |
} else { | |
throw new AuthException(); | |
} | |
} | |
public function getNotifications() | |
{ | |
return $this->notis; | |
} | |
} |
This file contains hidden or 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 | |
interface Figure | |
{ | |
public function getName(); | |
public function getPosition(); | |
public function rotate($degrees); | |
public function jump(); | |
public function walk(); | |
} | |
class Person implements Figure | |
{ | |
protected $acceleration = 1; | |
protected $color; | |
protected $name; | |
public function __construct($name, $position, $color) | |
{ | |
$this->setName($name); | |
$this->setPosition($position); | |
$this->color = $color; | |
} | |
public function changeColor($color) | |
{ | |
$this->color = $color; | |
} | |
public function jump() | |
{ | |
$x = $position->getX(); | |
$x += $someWeirdNumber /* + some weird math */; | |
$position->setX($x); | |
} | |
public function rotate($degrees) | |
{ | |
$position->rotate($degrees); | |
} | |
public function walk() | |
{ | |
$position->move($this->acceleration); | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
public function setPosition($position) | |
{ | |
$this->position = $position; | |
} | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
} | |
class Tree implements Figure | |
{ | |
protected $name; | |
public function __construct($name, $position) | |
{ | |
$this->setName($name); | |
$this->setPosition($position); | |
} | |
public function jump() | |
{ | |
return; | |
} | |
public function walk() | |
{ | |
return; | |
} | |
public function rotate() | |
{ | |
$position->rotate($degrees); | |
} | |
public function getName() | |
{ | |
return $this->name; | |
} | |
public function setPosition($position) | |
{ | |
$this->position = $position; | |
} | |
public function setName($name) | |
{ | |
$this->name = $name; | |
} | |
} | |
class Main | |
{ | |
protected $figures = array(); | |
public static function game() | |
{ | |
$figures[] = new Person(); | |
$figures[] = new Tree(); | |
GameScreen::init('800', '600'); | |
} | |
public function draw() | |
{ | |
foreach ($this->figures as $figure) { | |
if (Game::detectKeyJump()) { | |
$figure->jump(); | |
} | |
$x = $figure->getPosition()->getX(); | |
$y = $figure->getPosition()->getY(); | |
$name = $figure->getName(); | |
GameScreen::put($x, $y, $name); | |
if ($figure->getPosition()->getX() | |
> GameScreen::getWith() | |
) { | |
$figure->changeColor(new RedColor()); | |
} | |
} | |
} | |
} |
This file contains hidden or 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 | |
// Breath deepdly... | |
// Las funciones que no estén implementadas suponlas en la propia clase o en la padre. | |
abstract class ItemController extends AbstractController // que a su vez hereda de Zend_Controller_Action | |
{ | |
const NEWACTION_STATUS_SAVED = 1; // indica que se ha hecho un POST y que está todo OK | |
const NEWACTION_STATUS_INVALID = 2; // indica que se ha hecho POST pero que hay errores en el formulario de ítem. | |
const NEWACTION_STATUS_NO_POST = 3; // indica que se ha hecho un GET. | |
protected $status; | |
protected $item; | |
/* | |
* Acción abstracta para creación de diversos tipos de items. | |
* Las clases hijas heredarán y añadirán funcionalidad a este método | |
* para crear ítems de diferentes tipos. | |
*/ | |
public function newItem() | |
{ | |
$this->view->inyectJS('erasmusu.Uploader.init()'); | |
if ( !($this->view->form instanceof Erasmusu_Form_AbstractItem) ) { | |
return; | |
} | |
$itemDraftId = $this->view->form->item_draft_id !== null | |
? $this->view->form->item_draft_id->getValue() | |
: null; | |
switch ($this->status) { | |
case self::NEWACTION_STATUS_SAVED: | |
$this->itemTextCopyQueue($this->item); | |
if($this->view->form->getActionType() == 'NEW'){ | |
$this->autoCheckAndNotify($this->item); | |
} else { | |
$this->autoCheck($this->item); | |
} | |
$photosAdded = $this->addPhotosToItem( | |
$this->item, | |
$itemDraftId | |
); | |
$mustSave = $this->item->deleteTextTempImages(); | |
if ($photosAdded || $mustSave) { | |
$this->mapper->save($this->item); | |
} | |
$this->sendContestEmail(); | |
if ($this->item instanceof Erasmusu_Model_Item_ForumPost) { | |
$this->_redirect($this->redirect); | |
} | |
// Si es ficha, redirigimos al listado de pisos de la ciudad. | |
elseif ($this->item instanceof Erasmusu_Model_Item_Card) { | |
$url = $this->view->link(array( | |
'controller' => 'flat', | |
'action' => 'location', | |
'values' => $this->item->getLocation()->getInterfaceUrl(), | |
)); | |
$this->_redirect($url); | |
} | |
else { | |
if ($this->item->hasInterface()) { | |
$url = $this->view->link( | |
$this->item->getUrl(), | |
null, | |
array( | |
'lang' => $this->item->getLanguage()->getCode() | |
) | |
); | |
$this->_redirect($url); | |
} else { | |
$this->_redirect($this->view->link('warn/interface')); | |
} | |
} | |
break; | |
case self::NEWACTION_STATUS_INVALID: | |
$photos = array(); | |
if($this->view->form->getActionType() == 'UPDATE'){ | |
$photos = $this->parsePhotoList( | |
$this->item->getPhotoList() | |
); | |
} | |
$this->redirectIfDuplicate(); | |
$photos = array_merge( | |
$photos, | |
$this->getTempPhotos($itemDraftId) | |
); | |
$this->view->form->setPhotos($photos); | |
$this->view->form->setItem($this->item); | |
break; | |
case self::NEWACTION_STATUS_NO_POST: | |
default: | |
if($this->view->form->item_draft_id !== null){ | |
$hash = md5("{$this->profileId}-review-".time()); | |
$this->view->form->item_draft_id->setValue($hash); | |
$this->view->form->ssid->setValue(session_id()); | |
if($this->view->form->getActionType() == 'UPDATE'){ | |
$this->view->form->setPhotos( | |
$this->parsePhotoList( | |
$this->item->getPhotoList() | |
) | |
); | |
} | |
$this->view->form->setItem($this->item); | |
} | |
break; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment