File indexing completed on 2025-05-04 05:29:12
0001 <?php 0002 0003 /** 0004 * ocs-webserver 0005 * 0006 * Copyright 2016 by pling GmbH. 0007 * 0008 * This file is part of ocs-webserver. 0009 * 0010 * This program is free software: you can redistribute it and/or modify 0011 * it under the terms of the GNU Affero General Public License as 0012 * published by the Free Software Foundation, either version 3 of the 0013 * License, or (at your option) any later version. 0014 * 0015 * This program is distributed in the hope that it will be useful, 0016 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0017 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0018 * GNU Affero General Public License for more details. 0019 * 0020 * You should have received a copy of the GNU Affero General Public License 0021 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0022 **/ 0023 class Default_Model_Avatar 0024 { 0025 const AVATAR_DEFAULT_URL = 'default-profile.png'; 0026 0027 /** 0028 * @param string $emailHash 0029 * @param string $username 0030 * @param int $size 0031 * @return string|null 0032 * @throws Zend_Exception 0033 */ 0034 public function getAvatarUrl($emailHash, $username = null, $size = 200) 0035 { 0036 if (false === empty($emailHash)) { 0037 return $this->getAvatarForEmailHash($emailHash, $size); 0038 } 0039 0040 if (false === empty($username)) { 0041 return $this->getAvatarForUsername($username, $size); 0042 } 0043 0044 return self::getAvatarImageUrl($size); 0045 } 0046 0047 /** 0048 * @param string $email_hash 0049 * @param int $size 0050 * @return string|null 0051 * @throws Zend_Exception 0052 */ 0053 public function getAvatarForEmailHash($email_hash, $size) 0054 { 0055 if (empty($email_hash)) { 0056 return self::getAvatarImageUrl($size); 0057 } 0058 0059 $memberTable = new Default_Model_Member(); 0060 $member = $memberTable->findMemberForMailHash($email_hash, false); 0061 0062 if (empty($member)) { 0063 Zend_Registry::get('logger')->warn(__METHOD__ . ' - no member found for email_hash: ' . $email_hash); 0064 return self::getAvatarImageUrl($size); 0065 } 0066 0067 $imgUrl = self::getAvatarImageUrl($size, $member['profile_image_url']); 0068 0069 return $imgUrl; 0070 } 0071 0072 /** 0073 * @param int $size 0074 * @param string $profile_image_url 0075 * @return string|null 0076 */ 0077 public static function getAvatarImageUrl($size, $profile_image_url = self::AVATAR_DEFAULT_URL) 0078 { 0079 $helperImage = new Default_View_Helper_Image(); 0080 $imgUrl = $helperImage->Image($profile_image_url, array('width' => $size, 'height' => $size)); 0081 0082 return $imgUrl; 0083 } 0084 0085 /** 0086 * @param string $username 0087 * @param int $width 0088 * @return string|null 0089 * @throws Zend_Exception 0090 */ 0091 public function getAvatarForUsername($username, $width) 0092 { 0093 if (empty($username)) { 0094 return self::getAvatarImageUrl($width); 0095 } 0096 0097 $members = new Default_Model_Member(); 0098 $member = $members->findUsername($username, Default_Model_Member::CASE_INSENSITIVE, array(), false); 0099 if (empty($member)) { 0100 Zend_Registry::get('logger')->warn(__METHOD__ . ' - no member_id found for username: ' . $username); 0101 return self::getAvatarImageUrl($width); 0102 } 0103 0104 return self::getAvatarImageUrl($width, $member[0]['profile_image_url']); 0105 } 0106 0107 }