32 public function __construct(
DbManager $dbManager, Logger $logger)
35 $this->logger = $logger;
38 public function isAccessible($uploadId, $groupId)
40 $perm = $this->
dbManager->getSingleRow(
'SELECT perm FROM perm_upload WHERE upload_fk=$1 AND group_fk=$2',
41 array($uploadId, $groupId), __METHOD__.
'.group_perm');
50 $uploadPub = $this->
dbManager->getSingleRow(
'SELECT public_perm FROM upload WHERE upload_pk=$1 AND public_perm>$2',
52 return !empty($uploadPub);
55 public function isEditable($uploadId, $groupId)
61 $perm = $this->
dbManager->getSingleRow(
'SELECT perm FROM perm_upload WHERE upload_fk=$1 AND group_fk=$2',
62 array($uploadId, $groupId), __METHOD__);
66 public function makeAccessibleToGroup($uploadId, $groupId, $perm=null)
71 $this->
dbManager->getSingleRow(
"INSERT INTO perm_upload (perm, upload_fk, group_fk) " 72 .
" VALUES($1,$2,$3)",
73 array($perm, $uploadId, $groupId), __METHOD__);
76 public function makeAccessibleToAllGroupsOf($uploadId, $userId, $perm=null)
82 $this->
dbManager->getSingleRow(
"INSERT INTO perm_upload (group_fk, perm, upload_fk) 83 SELECT DISTINCT(gum.group_fk), $perm perm, $uploadId upload_fk 84 FROM group_user_member gum 85 LEFT JOIN perm_upload ON perm_upload.group_fk=gum.group_fk 86 AND upload_fk=$uploadId 87 WHERE perm_upload IS NULL AND gum.user_fk=$userId",
88 array(), __METHOD__.
'.insert');
92 public function updatePermissionId($permId, $permLevel)
94 if (empty($permLevel)) {
95 $this->
dbManager->getSingleRow(
'DELETE FROM perm_upload WHERE perm_upload_pk=$1',
97 __METHOD__ .
'.delete');
99 $this->
dbManager->getSingleRow(
'UPDATE perm_upload SET perm=$2 WHERE perm_upload_pk=$1',
100 array($permId, $permLevel),
101 __METHOD__ .
'.update');
105 public function insertPermission($uploadId, $groupId, $permLevel)
107 $this->
dbManager->getSingleRow(
"DELETE FROM perm_upload WHERE upload_fk=$1 AND group_fk=$2",
108 array($uploadId,$groupId),
109 __METHOD__.
'.avoid_doublet');
113 $this->
dbManager->insertTableRow(
'perm_upload', array(
'perm'=>$permLevel,
'upload_fk'=>$uploadId,
'group_fk'=>$groupId));
116 public function setPublicPermission($uploadId, $permLevel)
118 $this->
dbManager->getSingleRow(
'UPDATE upload SET public_perm=$2 WHERE upload_pk=$1', array($uploadId, $permLevel));
121 public function getPublicPermission($uploadId)
123 $row = $this->
dbManager->getSingleRow(
'SELECT public_perm FROM upload WHERE upload_pk=$1 LIMIT 1',array($uploadId),__METHOD__);
124 return $row[
'public_perm'];
127 public function getPermissionGroups($uploadId)
129 $this->
dbManager->prepare($stmt=__METHOD__,
130 "SELECT perm_upload_pk, perm, group_pk, group_name 131 FROM groups, perm_upload 132 WHERE group_fk=group_pk AND upload_fk=$1 133 ORDER BY group_name");
134 $res = $this->
dbManager->execute($stmt, array($uploadId));
136 while ($row=$this->
dbManager->fetchArray($res)) {
137 $groupMap[$row[
'group_pk']] = $row;
#define PLUGIN_DB_ADMIN
Plugin requires admin level permission on DB.
fo_dbManager * dbManager
fo_dbManager object