1<?php 2/* 3 * Copyright Intermesh BV. 4 * 5 * This file is part of Group-Office. You should have received a copy of the 6 * Group-Office license along with Group-Office. See the file /LICENSE.TXT 7 * 8 * If you have questions write an e-mail to info@intermesh.nl 9 * 10 */ 11 12/** 13 * 14 * The Group model 15 * 16 * @version $Id: Group.php 7607 2011-08-04 13:41:42Z mschering $ 17 * @copyright Copyright Intermesh BV. 18 * @author Wesley Smits <wsmits@intermesh.nl> 19 * @package GO.base.model 20 * 21 * @property int $aclId 22 * @property int $groupId 23 * @property int $level {@see Acl::READ_PERMISSION etc} 24 */ 25 26namespace GO\Base\Model; 27 28use GO; 29use GO\Base\Db\ActiveRecord; 30use go\core\App; 31use go\core\jmap\Entity; 32use go\core\orm\Property; 33use go\core\orm\StateManager; 34use GO\Log\Model\Log; 35 36 37class AclUsersGroups extends ActiveRecord { 38 39 /** 40 * Returns a static model of itself 41 * 42 * @param String $className 43 * @return AclUsersGroups 44 */ 45 public static function model($className=__CLASS__) 46 { 47 return parent::model($className); 48 } 49 50 public function tableName() { 51 return 'core_acl_group'; 52 } 53 54 /** 55 * The ACL record itself never has an ACL field so always return false 56 * @return boolean 57 */ 58 public function aclField() { 59 return false; 60 } 61 62 public function primaryKey() { 63 return array('aclId','groupId'); 64 } 65 66 67 public function relations() { 68 return array('aclItem'=>array( 69 "type"=>self::BELONGS_TO, 70 "model"=>"GO\Base\Model\Acl", 71 "field"=>'aclId' 72 )); 73 } 74 75 protected function afterDelete() { 76 77 if($this->aclItem){ 78 $this->aclItem->touch(); 79 } 80 81 if(!Entity::$trackChanges){ 82 return true; 83 } 84 85 $success = App::get()->getDbConnection() 86 ->update('core_acl_group_changes', 87 [ 88 'revokeModSeq' => \go\core\model\Acl::entityType()->nextModSeq() 89 ], 90 [ 91 'aclId' => $this->aclId, 92 'groupId' => $this->groupId, 93 'revokeModSeq' => null 94 ] 95 )->execute(); 96 97 if(!$success) { 98 return false; 99 } 100 101 return parent::afterDelete(); 102 } 103 104 105 106 protected function afterSave($wasNew) { 107 if($this->aclItem){ 108 //Add log message for activitylog here 109 if(GO::modules()->isInstalled("log")){ 110 Log::create("acl", $this->aclItem->usedIn,$this->aclItem->className(),$this->aclItem->id); 111 } 112 113 $this->aclItem->touch(); 114 } 115 116 if(!Entity::$trackChanges){ 117 return true; 118 } 119 120 $success = App::get()->getDbConnection() 121 ->insert('core_acl_group_changes', 122 [ 123 'aclId' => $this->aclId, 124 'groupId' => $this->groupId, 125 'grantModSeq' => \go\core\model\Acl::entityType()->nextModSeq() 126 ] 127 )->execute(); 128 if(!$success) { 129 return false; 130 } 131 132 return parent::afterSave($wasNew); 133 } 134} 135