function setObjUserPermission($user, $obj, $canWrite) { $obj_perm = ObjectUserPermissions::findOne(array('conditions' => "rel_object_id = " . $obj->getId() . " AND rel_object_manager = '" . $obj->getObjectManagerName() . "' AND user_id = " . $user->getId())); if ($obj_perm) { $obj_perm->setColumnValue('can_write', $canWrite); } else { $obj_perm = new ObjectUserPermission(); $obj_perm->setFromAttributes(array('rel_object_id' => $obj->getId(), 'rel_object_manager' => $obj->getObjectManagerName(), 'user_id' => $user->getId(), 'can_read' => 1, 'can_write' => $canWrite)); } try { DB::beginWork(); $obj_perm->save(); DB::commit(); } catch (Exception $e) { DB::rollback(); flash_error($e->getMessage()); ajx_current("empty"); } }
/** * Check whether an ObjectUserPermission * * @param ObjectUserPermission $perm * @param unknown_type $access_level */ function has_access_level(ObjectUserPermission $perm, $access_level) { switch ($access_level) { case ACCESS_LEVEL_READ: return $perm->hasReadPermission(); break; case ACCESS_LEVEL_WRITE: return $perm->hasWritePermission(); break; } return false; }
function giveAccessToObject(ProjectDataObject $object) { $ou = new ObjectUserPermission(); $ou->setObjectId($object->getId()); $ou->setObjectManager($object->getObjectManagerName()); $ou->setUserId($this->getId()); $ou->setReadPermission(true); $ou->setWritePermission(false); $ou->save(); }