Author: allyb
Date: 2010-01-14 15:12:20 +0100 (Thu, 14 Jan 2010)
New Revision: 26632
Modified:
plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserCredentialPeer.php
Log:
Added 2 new methods for working with extra credentials - addExtraCredential and
removeExtraCredential to sfEasyAuthUserBase
Modified: plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
===================================================================
--- plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
2010-01-14 14:11:55 UTC (rev 26631)
+++ plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserBase.php
2010-01-14 14:12:20 UTC (rev 26632)
@@ -50,9 +50,58 @@
}
/**
+ * Adds an extra credential for this user
+ *
+ * @param string $credential The name of a credential to add, e.g.
'superAdmin'
+ * @param int $profileId An ID of a profile to associate with this
credential (optional)
+ */
+ public function addExtraCredential($credential, $profileId=null)
+ {
+ // if the user doesn't already have the credential, add a new one
+ if (!in_array($credential, $this->getExtraCredentials()))
+ {
+ $extraCredential = new sfEasyAuthUserCredential();
+ $extraCredential->setCredential($credential);
+
+ if ($profileId !== null)
+ {
+ $extraCredential->setProfileId($profileId);
+ }
+
+ $extraCredential->setUserId($this->getId());
+
+ // if we can save the new object, set a flag so we know the user has
extra credentials
+ if ($extraCredential->save())
+ {
+ $this->setHasExtraCredentials(true);
+ $this->save();
+ }
+ }
+ }
+
+ /**
+ * Removes an extra credential from a user account
+ *
+ * @param string $credential The name of a credential to remove
+ */
+ public function removeExtraCredential($credential)
+ {
+ if ($extraCredential =
sfEasyAuthUserCredentialPeer::retrieveByUserIdAndName($this->getId(),
$credential))
+ {
+ $extraCredential->delete();
+
+ if (count($this->getExtraCredentials()) === 0)
+ {
+ $this->setHasExtraCredentials(false);
+ $this->save();
+ }
+ }
+ }
+
+ /**
* Gets extra credentials for a user
*
- * @return array
+ * @return array An array of string credential names
*/
protected function getExtraCredentials()
{
Modified:
plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserCredentialPeer.php
===================================================================
--- plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserCredentialPeer.php
2010-01-14 14:11:55 UTC (rev 26631)
+++ plugins/sfEasyAuthPlugin/trunk/lib/model/sfEasyAuthUserCredentialPeer.php
2010-01-14 14:12:20 UTC (rev 26632)
@@ -24,5 +24,21 @@
}
return $credentials;
- }
+ }
+
+ /**
+ * Retrieves an sfEasyAuthUserCredential object by user ID and credential
name
+ *
+ * @param int $userId An easy auth user ID
+ * @param string $credentialName The name of a credential, e.g. 'editor'
+ * @return array|null
+ */
+ public static function retrieveByUserIdAndName($userId, $credentialName)
+ {
+ $c = new Criteria();
+ $c->add(self::USER_ID, $userId);
+ $c->add(self::CREDENTIAL, $credentialName);
+
+ return self::doSelect($c);
+ }
}
--
You received this message because you are subscribed to the Google Groups
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/symfony-svn?hl=en.