Permalink
Browse files

Fix model implementation

  • Loading branch information...
1 parent cbac73d commit 50c1ea783ca207f0260edaf12bad2088b8d9dc5e @bladeofsteel committed Mar 31, 2012
@@ -1,13 +0,0 @@
-<?php
-namespace ZfcUser\Model\Mapper;
-
-use ZfcUser\Model\UserActivation as UserActivationModel;
-
-interface UserActivation
-{
- public function persist(UserActivationModel $userActivation);
-
- public function findByEmail($email);
-
- public function findByToken($token);
-}
@@ -1,60 +0,0 @@
-<?php
-
-namespace ZfcUser\Model\Mapper;
-
-use ZfcBase\Mapper\DbMapperAbstract,
-ZfcUser\Module as ZfcUser,
-ZfcUser\Model\UserActivation as UserActivationModel,
-ZfcUser\Model\Mapper\UserActivation as UserActivationMapper,
-ArrayObject;
-
-class UserActivationZendDb extends DbMapperAbstract implements UserActivationMapper
-{
- protected $tableName = 'user_activation';
- protected $emailField = 'email';
- protected $tokenField = 'token';
- protected $idField = 'id';
-
- public function persist(UserActivationModel $userActivation)
- {
- $data = new ArrayObject($userActivation->toArray()); // or perhaps pass it by reference?
- $this->events()->trigger('UserActivationMapper::' . __FUNCTION__ . '.pre', $this, array('data' => $data, 'userActivation' => $userActivation));
- $db = $this->getWriteAdapter();
- if ($userActivation->getId() > 0) {
- $db->update($this->getTableName(), (array) $data, $db->quoteInto($this->idField.' = ?', $userActivation->getId()));
- } else {
- $db->insert($this->getTableName(), (array) $data);
- $userActivationId = $db->lastInsertId();
- $userActivation->setId($userActivationId);
- }
- return $userActivation;
- }
-
- public function findByEmail($email)
- {
- $db = $this->getReadAdapter();
- $sql = $db->select()
- ->from($this->getTableName())
- ->where($this->emailField. ' = ?', $email);
- $this->events()->trigger('UserActivationMapper::' . __FUNCTION__ . '.pre', $this, array('query' => $sql));
- $row = $db->fetchRow($sql);
- $userActivationModelClass = ZfcUser::getOption('user_activation_model_class');
- $userActivation = $userActivationModelClass::fromArray($row);
- $this->events()->trigger('UserActivationMapper::' . __FUNCTION__ . '.post', $this, array('userActivation' => $userActivation, 'row' => $row));
- return $userActivation;
- }
-
- public function findByToken($token)
- {
- $db = $this->getReadAdapter();
- $sql = $db->select()
- ->from($this->getTableName())
- ->where($this->tokenField. ' = ?', $token);
- $this->events()->trigger('UserActivationMapper::' . __FUNCTION__ . '.pre', $this, array('query' => $sql));
- $row = $db->fetchRow($sql);
- $userActivationModelClass = ZfcUser::getOption('user_activation_model_class');
- $userActivation = $userActivationModelClass::fromArray($row);
- $this->events()->trigger('UserActivationMapper::' . __FUNCTION__ . '.post', $this, array('userActivation' => $userActivation, 'row' => $row));
- return $userActivation;
- }
-}
@@ -2,82 +2,173 @@
namespace ZfcUser\Model;
-interface UserActivation
+use DateTime,
+ ZfcBase\Model\ModelAbstract;
+
+class UserActivation extends ModelAbstract implements UserActivationInterface
{
+ /**
+ * @var int
+ */
+ protected $id;
+
+ /**
+ * @var int
+ */
+ protected $userId;
+
+ /**
+ * @var string
+ */
+ protected $token;
+
+ /**
+ * @var \DateTime
+ */
+ protected $requestTime;
+
+ /**
+ * @var \DateTime
+ */
+ protected $validTo;
+
+ /**
+ * @var int
+ */
+ protected $requestIp;
+
+ /**
+ * @var \DateTime
+ */
+ protected $confirmTime;
+
+ /**
+ * @var int
+ */
+ protected $confirmIp;
+
+ /**
+ * @var bool
+ */
+ protected $active;
+
/**
* Get id.
*
* @return int id
*/
- public function getId();
+ public function getId()
+ {
+ return $this->id;
+ }
/**
* Set id.
*
* @param int $id the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setId($id);
+ public function setId($id)
+ {
+ $this->id = (int) $id;
+ return $this;
+ }
/**
* Get userId.
*
* @return int userId
*/
- public function getUserId();
+ public function getUserId()
+ {
+ return $this->userId;
+ }
/**
* Set userId.
*
* @param int $userId the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setUserId($userId);
+ public function setUserId($userId)
+ {
+ $this->userId = (int) $userId;
+ return $this;
+ }
/**
* Get token.
*
* @return string
*/
- public function getToken();
+ public function getToken()
+ {
+ return $this->token;
+ }
/**
* Set token.
*
* @param string $token the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setToken($token);
+ public function setToken($token)
+ {
+ $this->token = $token;
+ return $this;
+ }
/**
* Get requestTime.
*
* @return \DateTime registerTime
*/
- public function getRequestTime();
+ public function getRequestTime()
+ {
+ return $this->requestTime;
+ }
/**
* Set requestTime.
*
* @param string|\DateTime $requestTime the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setRequestTime($requestTime);
+ public function setRequestTime($requestTime)
+ {
+ if ($requestTime instanceof \DateTime) {
+ $this->requestTime = $requestTime;
+ } else {
+ $this->requestTime = new \DateTime($requestTime);
+ }
+ return $this;
+ }
/**
* Get validTo.
*
* @return \DateTime validTo
*/
- public function getValidTo();
+ public function getValidTo()
+ {
+ return $this->validTo;
+ }
/**
* Set validTo.
*
* @param string|\DateTime $validTo the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setValidTo($validTo);
+ public function setValidTo($validTo)
+ {
+ if ($validTo instanceof \DateTime) {
+ $this->validTo = $validTo;
+ } else {
+ $this->validTo = new \DateTime($validTo);
+ }
+ return $this;
+ }
/**
* Get requestIp.
@@ -86,31 +177,52 @@ public function setValidTo($validTo);
* @param bool $long
* @return string|int
*/
- public function getRequestIp($long = false);
+ public function getRequestIp($long = false)
+ {
+ if (true === $long) {
+ return $this->requestIp;
+ }
+ return long2ip($this->requestIp);
+ }
/**
* Set requestIp.
*
* @TODO: Map custom IP field type with inet_pton() and inet_ntop()
* @param string $requestIp the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setRequestIp($requestIp);
+ public function setRequestIp($requestIp)
+ {
+ $this->requestIp = ip2long($requestIp);
+ return $this;
+ }
/**
* Get confirmTime.
*
* @return \DateTime registerTime
*/
- public function getConfirmTime();
+ public function getConfirmTime()
+ {
+ return $this->confirmTime;
+ }
/**
* Set confirmTime.
*
* @param string|\DateTime $confirmTime the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setConfirmTime($confirmTime);
+ public function setConfirmTime($confirmTime)
+ {
+ if ($confirmTime instanceof \DateTime) {
+ $this->confirmTime = $confirmTime;
+ } else {
+ $this->confirmTime = new \DateTime($confirmTime);
+ }
+ return $this;
+ }
/**
* Get confirmIp.
@@ -119,45 +231,46 @@ public function setConfirmTime($confirmTime);
* @param bool $long
* @return string|int
*/
- public function getConfirmIp($long = false);
+ public function getConfirmIp($long = false)
+ {
+ if (true === $long) {
+ return $this->confirmIp;
+ }
+ return long2ip($this->confirmIp);
+ }
/**
* Set confirmIp.
*
* @TODO: Map custom IP field type with inet_pton() and inet_ntop()
* @param string $confirmIp the value to be set
- * @return UserActivation
+ * @return UserActivationInterface
*/
- public function setConfirmIp($confirmIp);
+ public function setConfirmIp($confirmIp)
+ {
+ $this->confirmIp = ip2long($confirmIp);
+ return $this;
+ }
/**
* Get active.
*
* @return bool active
*/
- public function getActive();
+ public function getActive()
+ {
+ return $this->active;
+ }
/**
* Set active.
*
* @param bool $active the value to be set
- * @return UserActivation
- */
- public function setActive($active);
-
- /**
- * Convert the model to an array
- *
- * @return array
- */
- public function toArray();
-
- /**
- * Convert an array into a model instance
- *
- * @param array $array
- * @static
- * @return User
+ * @return UserActivationInterface
*/
- public static function fromArray($array);
+ public function setActive($active)
+ {
+ $this->active = $active;
+ return $this;
+ }
}
Oops, something went wrong.

0 comments on commit 50c1ea7

Please sign in to comment.