Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fix model implementation

  • Loading branch information...
commit 50c1ea783ca207f0260edaf12bad2088b8d9dc5e 1 parent cbac73d
@bladeofsteel authored
View
13 src/ZfcUser/Model/Mapper/UserActivation.php
@@ -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);
-}
View
60 src/ZfcUser/Model/Mapper/UserActivationZendDb.php
@@ -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;
- }
-}
View
201 src/ZfcUser/Model/UserActivation.php
@@ -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;
+ }
}
View
276 src/ZfcUser/Model/UserActivationBase.php
@@ -1,276 +0,0 @@
-<?php
-
-namespace ZfcUser\Model;
-
-use DateTime,
- ZfcBase\Model\ModelAbstract;
-
-class UserActivationBase extends ModelAbstract implements UserActivation
-{
- /**
- * @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()
- {
- return $this->id;
- }
-
- /**
- * Set id.
- *
- * @param int $id the value to be set
- * @return UserActivation
- */
- public function setId($id)
- {
- $this->id = (int) $id;
- return $this;
- }
-
- /**
- * Get userId.
- *
- * @return int userId
- */
- public function getUserId()
- {
- return $this->userId;
- }
-
- /**
- * Set userId.
- *
- * @param int $userId the value to be set
- * @return UserActivation
- */
- public function setUserId($userId)
- {
- $this->userId = (int) $userId;
- return $this;
- }
-
- /**
- * Get token.
- *
- * @return string
- */
- public function getToken()
- {
- return $this->token;
- }
-
- /**
- * Set token.
- *
- * @param string $token the value to be set
- * @return UserActivation
- */
- public function setToken($token)
- {
- $this->token = $token;
- return $this;
- }
-
- /**
- * Get requestTime.
- *
- * @return \DateTime registerTime
- */
- public function getRequestTime()
- {
- return $this->requestTime;
- }
-
- /**
- * Set requestTime.
- *
- * @param string|\DateTime $requestTime the value to be set
- * @return UserActivation
- */
- 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()
- {
- return $this->validTo;
- }
-
- /**
- * Set validTo.
- *
- * @param string|\DateTime $validTo the value to be set
- * @return UserActivation
- */
- public function setValidTo($validTo)
- {
- if ($validTo instanceof \DateTime) {
- $this->validTo = $validTo;
- } else {
- $this->validTo = new \DateTime($validTo);
- }
- return $this;
- }
-
- /**
- * Get requestIp.
- *
- * @TODO: Map custom IP field type with inet_pton() and inet_ntop()
- * @param bool $long
- * @return string|int
- */
- 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
- */
- public function setRequestIp($requestIp)
- {
- $this->requestIp = ip2long($requestIp);
- return $this;
- }
-
- /**
- * Get confirmTime.
- *
- * @return \DateTime registerTime
- */
- public function getConfirmTime()
- {
- return $this->confirmTime;
- }
-
- /**
- * Set confirmTime.
- *
- * @param string|\DateTime $confirmTime the value to be set
- * @return UserActivation
- */
- public function setConfirmTime($confirmTime)
- {
- if ($confirmTime instanceof \DateTime) {
- $this->confirmTime = $confirmTime;
- } else {
- $this->confirmTime = new \DateTime($confirmTime);
- }
- return $this;
- }
-
- /**
- * Get confirmIp.
- *
- * @TODO: Map custom IP field type with inet_pton() and inet_ntop()
- * @param bool $long
- * @return string|int
- */
- 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
- */
- public function setConfirmIp($confirmIp)
- {
- $this->confirmIp = ip2long($confirmIp);
- return $this;
- }
-
- /**
- * Get active.
- *
- * @return bool active
- */
- public function getActive()
- {
- return $this->active;
- }
-
- /**
- * Set active.
- *
- * @param bool $active the value to be set
- * @return UserActivation
- */
- public function setActive($active)
- {
- $this->active = $active;
- return $this;
- }
-}
View
163 src/ZfcUser/Model/UserActivationInterface.php
@@ -0,0 +1,163 @@
+<?php
+
+namespace ZfcUser\Model;
+
+interface UserActivationInterface
+{
+ /**
+ * Get id.
+ *
+ * @return int id
+ */
+ public function getId();
+
+ /**
+ * Set id.
+ *
+ * @param int $id the value to be set
+ * @return UserActivationInterface
+ */
+ public function setId($id);
+
+ /**
+ * Get userId.
+ *
+ * @return int userId
+ */
+ public function getUserId();
+
+ /**
+ * Set userId.
+ *
+ * @param int $userId the value to be set
+ * @return UserActivationInterface
+ */
+ public function setUserId($userId);
+
+ /**
+ * Get token.
+ *
+ * @return string
+ */
+ public function getToken();
+
+ /**
+ * Set token.
+ *
+ * @param string $token the value to be set
+ * @return UserActivationInterface
+ */
+ public function setToken($token);
+
+ /**
+ * Get requestTime.
+ *
+ * @return \DateTime registerTime
+ */
+ public function getRequestTime();
+
+ /**
+ * Set requestTime.
+ *
+ * @param string|\DateTime $requestTime the value to be set
+ * @return UserActivationInterface
+ */
+ public function setRequestTime($requestTime);
+
+ /**
+ * Get validTo.
+ *
+ * @return \DateTime validTo
+ */
+ public function getValidTo();
+
+ /**
+ * Set validTo.
+ *
+ * @param string|\DateTime $validTo the value to be set
+ * @return UserActivationInterface
+ */
+ public function setValidTo($validTo);
+
+ /**
+ * Get requestIp.
+ *
+ * @TODO: Map custom IP field type with inet_pton() and inet_ntop()
+ * @param bool $long
+ * @return string|int
+ */
+ public function getRequestIp($long = false);
+
+ /**
+ * Set requestIp.
+ *
+ * @TODO: Map custom IP field type with inet_pton() and inet_ntop()
+ * @param string $requestIp the value to be set
+ * @return UserActivationInterface
+ */
+ public function setRequestIp($requestIp);
+
+ /**
+ * Get confirmTime.
+ *
+ * @return \DateTime registerTime
+ */
+ public function getConfirmTime();
+
+ /**
+ * Set confirmTime.
+ *
+ * @param string|\DateTime $confirmTime the value to be set
+ * @return UserActivationInterface
+ */
+ public function setConfirmTime($confirmTime);
+
+ /**
+ * Get confirmIp.
+ *
+ * @TODO: Map custom IP field type with inet_pton() and inet_ntop()
+ * @param bool $long
+ * @return string|int
+ */
+ public function getConfirmIp($long = false);
+
+ /**
+ * Set confirmIp.
+ *
+ * @TODO: Map custom IP field type with inet_pton() and inet_ntop()
+ * @param string $confirmIp the value to be set
+ * @return UserActivationInterface
+ */
+ public function setConfirmIp($confirmIp);
+
+ /**
+ * Get active.
+ *
+ * @return bool active
+ */
+ public function getActive();
+
+ /**
+ * Set active.
+ *
+ * @param bool $active the value to be set
+ * @return UserActivationInterface
+ */
+ 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
+ */
+ public static function fromArray($array);
+}
View
65 src/ZfcUser/Model/UserActivationMapper.php
@@ -0,0 +1,65 @@
+<?php
+
+namespace ZfcUser\Model\Mapper;
+
+use ZfcBase\Mapper\DbMapperAbstract,
+ ZfcUser\Module as ZfcUser,
+ ZfcUser\Model\UserActivationInterface,
+ ZfcUser\Model\UserActivationMapperInterface,
+ ArrayObject;
+
+class UserActivationMapper extends DbMapperAbstract implements UserActivationMapperInterface
+{
+ protected $tableName = 'user_activation';
+ protected $emailField = 'email';
+ protected $tokenField = 'token';
+ protected $idField = 'id';
+
+ public function persist(UserActivationInterface $userActivation)
+ {
+ $data = new ArrayObject($userActivation->toArray()); // or perhaps pass it by reference?
+ $this->events()->trigger(__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(__FUNCTION__ . '.pre', $this, array('query' => $sql));
+ $row = $db->fetchRow($sql);
+ $userActivationModelClass = ZfcUser::getOption('user_activation_model_class');
+ $userActivation = $userActivationModelClass::fromArray($row);
+ $this->events()->trigger(__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(__FUNCTION__ . '.pre', $this, array('query' => $sql));
+ $row = $db->fetchRow($sql);
+ $userActivationModelClass = ZfcUser::getOption('user_activation_model_class');
+ $userActivation = $userActivationModelClass::fromArray($row);
+ $this->events()->trigger(__FUNCTION__ . '.post', $this,
+ array('userActivation' => $userActivation, 'row' => $row));
+ return $userActivation;
+ }
+}
View
13 src/ZfcUser/Model/UserActivationMapperInterface.php
@@ -0,0 +1,13 @@
+<?php
+namespace ZfcUser\Model;
+
+use ZfcUser\Model\UserActivationInterface;
+
+interface UserActivationMapperInterface
+{
+ public function persist(UserActivationInterface $userActivation);
+
+ public function findByEmail($email);
+
+ public function findByToken($token);
+}
View
7 src/ZfcUser/Service/User.php
@@ -9,6 +9,7 @@
Zend\Mail\Message as MailMessage,
DateTime,
ZfcUser\Util\Password,
+ ZfcUser\Model\UserActivationMapperInterface,
ZfcUser\Model\UserMapperInterface,
ZfcUser\Model\UserMetaMapperInterface,
ZfcUser\Module as ZfcUser,
@@ -28,7 +29,7 @@ class User extends EventProvider
protected $userMetaMapper;
/**
- * @var UserActivationMapper
+ * @var UserActivationMapperInterface
*/
protected $userActivationMapper;
@@ -194,10 +195,10 @@ public function setUserMetaMapper(UserMetaMapperInterface $userMetaMapper)
/**
* setUserActivationMapper
*
- * @param UserActivationMapper $userActivationMapper
+ * @param UserActivationMapperInterface $userActivationMapper
* @return User
*/
- public function setUserActivationMapper(UserActivationMapper $userActivationMapper)
+ public function setUserActivationMapper(UserActivationMapperInterface $userActivationMapper)
{
$this->userActivationMapper = $userActivationMapper;
return $this;
Please sign in to comment.
Something went wrong with that request. Please try again.