File indexing completed on 2025-05-04 05:29:01
0001 <?php 0002 /** 0003 * ocs-webserver 0004 * 0005 * Copyright 2016 by pling GmbH. 0006 * 0007 * This file is part of ocs-webserver. 0008 * 0009 * This program is free software: you can redistribute it and/or modify 0010 * it under the terms of the GNU Affero General Public License as 0011 * published by the Free Software Foundation, either version 3 of the 0012 * License, or (at your option) any later version. 0013 * 0014 * This program is distributed in the hope that it will be useful, 0015 * but WITHOUT ANY WARRANTY; without even the implied warranty of 0016 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0017 * GNU Affero General Public License for more details. 0018 * 0019 * You should have received a copy of the GNU Affero General Public License 0020 * along with this program. If not, see <http://www.gnu.org/licenses/>. 0021 * 0022 * Created: 12.10.2018 0023 */ 0024 0025 class Backend_Model_Group 0026 { 0027 0028 public function processEventData($data) 0029 { 0030 switch ($data['event_name']) { 0031 case 'group_create': 0032 $this->addGroup($data['name'], $data['group_id'], $data['full_path']); 0033 break; 0034 case 'user_add_to_group': 0035 $this->addUser($data['group_id'], $data['user_id'], $data['user_username'], $data['user_email'], $data['group_access']); 0036 $this->addLdapGroupMember($data['group_name'], $data['user_username'], $data['group_access'], $data['group_id'], $data['group_path']); 0037 break; 0038 default: 0039 Zend_Registry::get('logger')->info(__METHOD__ . ' - unhandled git event: ' . json_encode($data)); 0040 } 0041 } 0042 0043 public function addGroup($group_name, $group_id, $full_path) 0044 { 0045 $sql = "INSERT INTO `git_group` (`group_name`, `group_id`, `group_full_path`) VALUES (:groupName, :groupId, :fullPath)"; 0046 0047 $db = Zend_Db_Table::getDefaultAdapter(); 0048 0049 $statement = $db->query($sql, array('groupName' => $group_name, 'groupId' => $group_id, 'fullPath' => $full_path)); 0050 0051 return $statement->rowCount(); 0052 } 0053 0054 public function addUser($group_id, $user_id, $user_name, $user_email, $group_access) 0055 { 0056 $sql = "INSERT INTO `git_group_user` (`group_id`, `user_id`, `user_name`, `user_email`, `group_access`) 0057 VALUES (:groupId, :userId, :userName, :userEmail, :groupAccess)"; 0058 0059 $db = Zend_Db_Table::getDefaultAdapter(); 0060 0061 $statement = $db->query($sql, array( 0062 'groupId' => $group_id, 0063 'userId' => $user_id, 0064 'userName' => $user_name, 0065 'userEmail' => $user_email, 0066 'groupAccess' => $group_access 0067 )); 0068 0069 return $statement->rowCount(); 0070 } 0071 0072 public function addLdapGroupMember($group_name, $user_username, $group_access, $group_id, $group_path) 0073 { 0074 $modelLdap = new Default_Model_Ocs_Ldap(); 0075 $modelLdap->addGroupMember($user_username, $group_name, $group_access, $group_id, $group_path); 0076 } 0077 0078 public function addLdapGroup($name, $group_id, $full_path) 0079 { 0080 $modelLdap = new Default_Model_Ocs_Ldap(); 0081 $modelLdap->createGroup($name, $group_id, $full_path); 0082 } 0083 0084 }