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"); } }