summaryrefslogtreecommitdiff
path: root/app/Core/User/Avatar
diff options
context:
space:
mode:
authorFrederic Guillot <fred@kanboard.net>2016-03-18 23:06:32 -0400
committerFrederic Guillot <fred@kanboard.net>2016-03-18 23:06:32 -0400
commitfa86542f90774d7a7d8f3e81ee35821ca25b7fd4 (patch)
treee6dd027dc827b18e07536414cf4fb86321763060 /app/Core/User/Avatar
parentc4c200b530e0585fafadce41f75e383ec0ff057e (diff)
Added pluggable Avatar providers
Diffstat (limited to 'app/Core/User/Avatar')
-rw-r--r--app/Core/User/Avatar/AvatarManager.php62
-rw-r--r--app/Core/User/Avatar/AvatarProviderInterface.php30
2 files changed, 92 insertions, 0 deletions
diff --git a/app/Core/User/Avatar/AvatarManager.php b/app/Core/User/Avatar/AvatarManager.php
new file mode 100644
index 00000000..4b0c5298
--- /dev/null
+++ b/app/Core/User/Avatar/AvatarManager.php
@@ -0,0 +1,62 @@
+<?php
+
+namespace Kanboard\Core\User\Avatar;
+
+/**
+ * Avatar Manager
+ *
+ * @package user
+ * @author Frederic Guillot
+ */
+class AvatarManager
+{
+ /**
+ * Providers
+ *
+ * @access private
+ * @var AvatarProviderInterface[]
+ */
+ private $providers = array();
+
+ /**
+ * Register a new Avatar provider
+ *
+ * @access public
+ * @param AvatarProviderInterface $provider
+ * @return $this
+ */
+ public function register(AvatarProviderInterface $provider)
+ {
+ $this->providers[] = $provider;
+ return $this;
+ }
+
+ /**
+ * Render avatar html element
+ *
+ * @access public
+ * @param string $user_id
+ * @param string $username
+ * @param string $name
+ * @param string $email
+ * @param int $size
+ * @return string
+ */
+ public function render($user_id, $username, $name, $email, $size)
+ {
+ $user = array(
+ 'id' => $user_id,
+ 'username' => $username,
+ 'name' => $name,
+ 'email' => $email,
+ );
+
+ foreach ($this->providers as $provider) {
+ if ($provider->isActive($user)) {
+ return $provider->render($user, $size);
+ }
+ }
+
+ return '';
+ }
+}
diff --git a/app/Core/User/Avatar/AvatarProviderInterface.php b/app/Core/User/Avatar/AvatarProviderInterface.php
new file mode 100644
index 00000000..e0375d26
--- /dev/null
+++ b/app/Core/User/Avatar/AvatarProviderInterface.php
@@ -0,0 +1,30 @@
+<?php
+
+namespace Kanboard\Core\User\Avatar;
+
+/**
+ * Avatar Provider Interface
+ *
+ * @package user
+ * @author Frederic Guillot
+ */
+interface AvatarProviderInterface
+{
+ /**
+ * Render avatar html
+ *
+ * @access public
+ * @param array $user
+ * @param int $size
+ */
+ public function render(array $user, $size);
+
+ /**
+ * Determine if the provider is active
+ *
+ * @access public
+ * @param array $user
+ * @return boolean
+ */
+ public function isActive(array $user);
+}