File indexing completed on 2024-12-15 05:21:36
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 Application_Model_DbTable_MemberEmail extends Local_Model_Table 0024 { 0025 0026 const EMAIL_DELETED = 1; 0027 const EMAIL_NOT_DELETED = 0; 0028 0029 const EMAIL_PRIMARY = 1; 0030 const EMAIL_NOT_PRIMARY = 0; 0031 0032 protected $_name = "member_email"; 0033 0034 protected $_keyColumnsForRow = array('email_id'); 0035 0036 protected $_key = 'email_id'; 0037 0038 protected $_defaultValues = array( 0039 'email_member_id' => 0, 0040 'email_address' => null, 0041 'email_primary' => 0, 0042 'email_deleted' => 0, 0043 'email_created' => null, 0044 'email_checked' => null 0045 ); 0046 0047 /** 0048 * @param int $email_id 0049 * 0050 * @return int 0051 * @throws Zend_Db_Statement_Exception 0052 */ 0053 public function setChecked($email_id) 0054 { 0055 $sql = "UPDATE `{$this->_name}` SET `email_checked` = NOW() WHERE `{$this->_key}` = :emailId"; 0056 $stmnt = $this->_db->query($sql, array('emailId' => $email_id)); 0057 0058 return $stmnt->rowCount(); 0059 } 0060 0061 /** 0062 * @param int $email_id 0063 * 0064 * @return int 0065 * @throws Zend_Db_Statement_Exception 0066 */ 0067 public function setPrimary($email_id) 0068 { 0069 $sql = "UPDATE `{$this->_name}` SET `email_primary` = 1 WHERE `{$this->_key}` = :emailId"; 0070 $stmnt = $this->_db->query($sql, array('emailId' => $email_id)); 0071 0072 return $stmnt->rowCount(); 0073 } 0074 0075 /** 0076 * @param int $member_id 0077 * 0078 * @return int 0079 * @throws Zend_Db_Statement_Exception 0080 * @throws Zend_Exception 0081 */ 0082 public function setDeletedByMember($member_id) 0083 { 0084 0085 $sql = "SELECT `email_id` FROM `member_email` WHERE `email_member_id` = :member_id AND `email_deleted` = 0"; 0086 $emailsForDelete = $this->_db->fetchAll($sql, array( 0087 'member_id' => $member_id 0088 )); 0089 foreach ($emailsForDelete as $item) { 0090 $this->setDeleted($member_id, $item['email_id']); 0091 } 0092 0093 $sql = "UPDATE `{$this->_name}` SET `email_deleted` = 1 WHERE `email_member_id` = :memberId"; 0094 $stmnt = $this->_db->query($sql, array('memberId' => $member_id)); 0095 0096 return $stmnt->rowCount(); 0097 } 0098 0099 /** 0100 * @param int $member_id 0101 * @param int $identifer 0102 * 0103 * @return int 0104 * @throws Zend_Db_Statement_Exception 0105 * @throws Zend_Exception 0106 */ 0107 public function setDeleted($member_id, $identifer) 0108 { 0109 $memberLog = new Application_Model_MemberDeactivationLog(); 0110 $memberLog->logMemberEmailAsDeleted($member_id, $identifer); 0111 0112 return $this->delete($identifer); 0113 } 0114 0115 /** 0116 * @param int $email_id 0117 * 0118 * @return int|void 0119 * @throws Zend_Db_Statement_Exception 0120 */ 0121 public function delete($email_id) 0122 { 0123 $sql = "UPDATE `{$this->_name}` SET `email_deleted` = 1 WHERE `{$this->_key}` = :emailId"; 0124 $stmnt = $this->_db->query($sql, array('emailId' => $email_id)); 0125 0126 return $stmnt->rowCount(); 0127 } 0128 0129 /** 0130 * @param $member_id 0131 * 0132 * @return void 0133 * @throws Zend_Db_Statement_Exception 0134 * @throws Zend_Exception 0135 */ 0136 public function setActivatedByMember($member_id) 0137 { 0138 $sql = "SELECT `e`.`email_id` 0139 FROM `member_email` `e` 0140 JOIN `member_deactivation_log` `l` ON `l`.`object_type_id` = 2 AND `l`.`object_id` = `e`.`email_id` AND `l`.`deactivation_id` = `e`.`email_member_id` AND `l`.`is_deleted` = 0 0141 WHERE `e`.`email_member_id` = :member_id AND `email_deleted` = 1"; 0142 $emails = $this->_db->fetchAll($sql, array( 0143 'member_id' => $member_id 0144 )); 0145 foreach ($emails as $item) { 0146 $this->setActive($member_id, $item['email_id']); 0147 } 0148 } 0149 0150 /** 0151 * @param int $member_id 0152 * @param int $identifer 0153 * 0154 * @return int 0155 * @throws Zend_Db_Statement_Exception 0156 * @throws Zend_Exception 0157 */ 0158 public function setActive($member_id, $identifer) 0159 { 0160 $memberLog = new Application_Model_MemberDeactivationLog(); 0161 $memberLog->removeLogMemberEmailAsDeleted($member_id, $identifer); 0162 0163 return $this->activate($identifer); 0164 } 0165 0166 /** 0167 * @param int $email_id 0168 * 0169 * @return int|void 0170 * @throws Zend_Db_Statement_Exception 0171 */ 0172 public function activate($email_id) 0173 { 0174 $sql = "UPDATE `{$this->_name}` SET `email_deleted` = 0 WHERE `{$this->_key}` = :emailId"; 0175 $stmnt = $this->_db->query($sql, array('emailId' => $email_id)); 0176 0177 return $stmnt->rowCount(); 0178 } 0179 0180 }