text stringlengths 0 234 |
|---|
-- Now, simulate a user that logs in and publishes the comment. |
AWA.Tests.Helpers.Users.Login (Context, Sec_Ctx, "test-add-comment@test.com"); |
declare |
Comment_Manager : constant Comment_Module_Access := Get_Comment_Module; |
User : constant AWA.Users.Models.User_Ref := Context.Get_User; |
Comment : AWA.Comments.Beans.Comment_Bean; |
begin |
T.Assert (Comment_Manager /= null, "There is no comment module"); |
Comment_Manager.Publish_Comment ("logged-user", Id, AWA.Comments.Models.COMMENT_PUBLISHED, |
Comment); |
T.Assert (not Comment.Is_Null, "Comment bean is null"); |
T.List_Comments (User.Get_Id, After); |
Function Definition: function Get is new AWA.Modules.Get (Setting_Module, Setting_Module_Access, NAME); |
Function Body: begin |
return Get; |
end Get_Setting_Module; |
-- ------------------------------ |
-- Load the setting value for the current user. |
-- Return the default value if there is no such setting. |
-- ------------------------------ |
procedure Load (Name : in String; |
Default : in String; |
Value : out Ada.Strings.Unbounded.Unbounded_String) is |
Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current; |
User : constant AWA.Users.Models.User_Ref := Ctx.Get_User; |
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); |
Query : ADO.Queries.Context; |
Setting : AWA.Settings.Models.User_Setting_Ref; |
Found : Boolean; |
begin |
Query.Set_Join ("INNER JOIN awa_setting AS a ON o.setting_id = a.id "); |
Query.Set_Filter ("a.name = :name AND o.user_id = :user"); |
Query.Bind_Param ("name", Name); |
Query.Bind_Param ("user", User.Get_Id); |
Setting.Find (DB, Query, Found); |
if not Found then |
Value := Ada.Strings.Unbounded.To_Unbounded_String (Default); |
else |
Value := Setting.Get_Value; |
end if; |
end Load; |
-- Save the setting value for the current user. |
procedure Save (Name : in String; |
Value : in String) is |
Ctx : constant Services.Contexts.Service_Context_Access := AWA.Services.Contexts.Current; |
User : constant AWA.Users.Models.User_Ref := Ctx.Get_User; |
DB : ADO.Sessions.Master_Session := AWA.Services.Contexts.Get_Master_Session (Ctx); |
Setting : AWA.Settings.Models.User_Setting_Ref; |
Query : ADO.Queries.Context; |
Found : Boolean; |
begin |
Ctx.Start; |
Query.Set_Join ("INNER JOIN awa_setting AS a ON o.setting_id = a.id "); |
Query.Set_Filter ("a.name = :name AND o.user_id = :user"); |
Query.Bind_Param ("name", Name); |
Query.Bind_Param ("user", User.Get_Id); |
Setting.Find (DB, Query, Found); |
if not Found then |
declare |
Setting_Def : AWA.Settings.Models.Setting_Ref; |
begin |
Query.Clear; |
Query.Set_Filter ("o.name = :name"); |
Query.Bind_Param ("name", Name); |
Setting_Def.Find (DB, Query, Found); |
if not Found then |
Setting_Def.Set_Name (Name); |
Setting_Def.Save (DB); |
end if; |
Setting.Set_Setting (Setting_Def); |
Function Definition: procedure Free is new Ada.Unchecked_Deallocation (Object => Setting_Data, |
Function Body: Name => Setting_Data_Access); |
use Ada.Strings.Unbounded; |
protected body Settings is |
procedure Get (Name : in String; |
Default : in String; |
Value : out Ada.Strings.Unbounded.Unbounded_String) is |
Item : Setting_Data_Access := First; |
Previous : Setting_Data_Access := null; |
begin |
while Item /= null loop |
if Item.Name = Name then |
Value := Item.Value; |
if Previous /= null then |
Previous.Next_Setting := Item.Next_Setting; |
First := Item; |
end if; |
return; |
end if; |
Previous := Item; |
Item := Item.Next_Setting; |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.