File indexing completed on 2025-05-04 05:29:11
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_ActivityLog extends Default_Model_DbTable_ActivityLog 0024 { 0025 0026 const PROJECT_CREATED = 0; 0027 const PROJECT_UPDATED = 1; 0028 const PROJECT_DELETED = 2; 0029 const PROJECT_STOPPED = 3; 0030 const PROJECT_STARTED = 4; 0031 const PROJECT_EDITED = 7; 0032 const PROJECT_PUBLISHED = 8; 0033 const PROJECT_UNPUBLISHED = 9; 0034 const PROJECT_ITEM_CREATED = 10; 0035 const PROJECT_ITEM_UPDATED = 11; 0036 const PROJECT_ITEM_DELETED = 12; 0037 const PROJECT_ITEM_STOPPED = 13; 0038 const PROJECT_ITEM_STARTED = 14; 0039 const PROJECT_ITEM_EDITED = 17; 0040 const PROJECT_ITEM_PUBLISHED = 18; 0041 const PROJECT_ITEM_UNPUBLISHED = 19; 0042 const PROJECT_PLINGED = 20; 0043 const PROJECT_DISPLINGED = 21; 0044 const PROJECT_ITEM_PLINGED = 30; 0045 const PROJECT_ITEM_DISPLINGED = 31; 0046 const PROJECT_COMMENT_CREATED = 40; 0047 const PROJECT_COMMENT_UPDATED = 41; 0048 const PROJECT_COMMENT_DELETED = 42; 0049 const PROJECT_COMMENT_REPLY = 43; 0050 const PROJECT_FOLLOWED = 50; 0051 const PROJECT_UNFOLLOWED = 51; 0052 const PROJECT_SHARED = 52; 0053 const PROJECT_PLINGED_2 = 53; 0054 const PROJECT_DISPLINGED_2 = 54; 0055 const PROJECT_RATED_HIGHER = 60; 0056 const PROJECT_RATED_LOWER = 61; 0057 const PROJECT_FILES_CREATED = 200; 0058 const PROJECT_FILES_UPDATED = 210; 0059 const PROJECT_FILES_DELETED = 220; 0060 const PROJECT_LICENSE_CHANGED = 70; 0061 const MEMBER_JOINED = 100; 0062 const MEMBER_UPDATED = 101; 0063 const MEMBER_DELETED = 102; 0064 const MEMBER_EDITED = 107; 0065 const MEMBER_FOLLOWED = 150; 0066 const MEMBER_UNFOLLOWED = 151; 0067 const MEMBER_SHARED = 152; 0068 0069 const BACKEND_LOGIN = 302; 0070 const BACKEND_LOGOUT = 304; 0071 const BACKEND_PROJECT_DELETE = 310; 0072 const BACKEND_PROJECT_FEATURE = 312; 0073 const BACKEND_PROJECT_GHNS_EXCLUDED = 314; 0074 const BACKEND_PROJECT_CAT_CHANGE = 316; 0075 const BACKEND_PROJECT_PLING_EXCLUDED = 318; 0076 const BACKEND_USER_PLING_EXCLUDED = 319; 0077 const BACKEND_USER_DELETE = 320; 0078 const BACKEND_USER_UNDELETE = 321; 0079 const BACKEND_PROJECT_DANGEROUS = 322; 0080 const BACKEND_PROJECT_DEPREACTED = 323; 0081 0082 //internal system logs 0083 const MEMBER_EMAIL_CONFIRMED = 401; 0084 const MEMBER_EMAIL_CHANGED = 402; 0085 const MEMBER_PAYPAL_CHANGED = 410; 0086 0087 0088 protected static $referenceType = array( 0089 0 => 'project', 0090 1 => 'project', 0091 2 => 'project', 0092 3 => 'project', 0093 4 => 'project', 0094 7 => 'project', 0095 8 => 'project', 0096 9 => 'project', 0097 10 => 'update', 0098 11 => 'update', 0099 12 => 'update', 0100 13 => 'update', 0101 14 => 'update', 0102 17 => 'update', 0103 18 => 'update', 0104 19 => 'update', 0105 20 => 'pling', 0106 30 => 'pling', 0107 40 => 'comment', 0108 41 => 'comment', 0109 42 => 'comment', 0110 43 => 'comment', 0111 50 => 'project', 0112 51 => 'project', 0113 52 => 'project', 0114 53 => 'project', 0115 54 => 'project', 0116 60 => 'project', 0117 61 => 'project', 0118 70 => 'project', 0119 100 => 'member', 0120 101 => 'member', 0121 102 => 'member', 0122 104 => 'undefined', 0123 107 => 'member', 0124 108 => 'undefined', 0125 109 => 'undefined', 0126 150 => 'member', 0127 151 => 'member', 0128 152 => 'member', 0129 200 => 'project', 0130 210 => 'project', 0131 220 => 'project', 0132 302 => 'backend', 0133 304 => 'backend', 0134 310 => 'backend', 0135 312 => 'backend', 0136 314 => 'backend', 0137 316 => 'backend', 0138 318 => 'backend', 0139 319 => 'backend', 0140 320 => 'backend', 0141 321 => 'backend', 0142 322 => 'backend', 0143 323 => 'backend', 0144 401 => 'member', 0145 402 => 'member_email', 0146 410 => 'member' 0147 ); 0148 0149 /** 0150 * @param int $objectId 0151 * @param int $projectId 0152 * @param int $userId 0153 * @param int $activity_type_id 0154 * @param array $data array with ([type_id], [pid], description, title, image_small) 0155 * 0156 * @throws Zend_Exception 0157 */ 0158 public static function logActivity($objectId, $projectId, $userId, $activity_type_id, $data = array()) 0159 { 0160 // cutting description text if necessary 0161 if (isset($data['description'])) { 0162 $object_text = (strlen($data['description']) < 150) 0163 ? $data['description'] : mb_substr($data['description'], 0, 145, 'UTF-8') . ' ... '; 0164 } 0165 0166 $newEntry = array( 0167 'member_id' => $userId, 0168 'project_id' => $projectId, 0169 'object_id' => $objectId, 0170 'object_ref' => self::$referenceType[$activity_type_id], 0171 'object_title' => isset($data['title']) ? $data['title'] : null, 0172 'object_text' => isset($object_text) ? $object_text : null, 0173 'object_img' => false === empty($data['image_small']) ? $data['image_small'] : null, 0174 'activity_type' => $activity_type_id 0175 ); 0176 0177 $sql = " 0178 INSERT INTO `activity_log` 0179 SET `member_id` = :member_id, 0180 `project_id` = :project_id, 0181 `object_id` = :object_id, 0182 `object_ref` = :object_ref, 0183 `object_title` = :object_title, 0184 `object_text` = :object_text, 0185 `object_img` = :object_img, 0186 `activity_type_id` = :activity_type 0187 ; 0188 "; 0189 0190 try { 0191 Zend_Db_Table::getDefaultAdapter()->query($sql, $newEntry); 0192 } catch (Exception $e) { 0193 Zend_Registry::get('logger')->err(__METHOD__ . ' - ERROR write activity log - ' . print_r($e, true)); 0194 } 0195 } 0196 0197 0198 /** 0199 * @param int $objectId 0200 * @param int $userId 0201 * @param int $activity_type_id 0202 * @param array|mixed $data 0203 * 0204 * @throws Zend_Exception 0205 */ 0206 public function writeActivityLog($objectId, $userId, $activity_type_id, $data) 0207 { 0208 $projectId = $objectId; 0209 0210 //is it an item? 0211 if (isset($data['type_id']) && $data['type_id'] == Default_Model_Project::PROJECT_TYPE_UPDATE) { 0212 $projectId = $data['pid']; 0213 } 0214 $object_text = 0215 (strlen($data['description']) < 150) ? $data['description'] : mb_substr($data['description'], 0, 145, 'UTF-8') . ' ... '; 0216 0217 $newLog = array( 0218 'member_id' => $userId, 0219 'project_id' => $projectId, 0220 'object_id' => $objectId, 0221 'object_ref' => self::$referenceType[$activity_type_id], 0222 'object_title' => $data['title'], 0223 'object_text' => $object_text, 0224 'object_img' => $data['image_small'], 0225 'activity_type_id' => $activity_type_id 0226 ); 0227 0228 try { 0229 $this->insert($newLog); 0230 } catch (Exception $e) { 0231 Zend_Registry::get('logger')->err(__METHOD__ . ' - ERROR write activity log - ' . print_r($e, true)); 0232 } 0233 } 0234 0235 }