-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathFeed.xxm
95 lines (92 loc) · 3.01 KB
/
Feed.xxm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
[[@xxmSession,DataLank,fCommon,Variants]][[!var
id,rw,i:integer;
c,cat,lbl:string;
ur:Variant;
db:TDataConnection;
qr:TQueryResult;
hl:array of record
id:integer;
hl:boolean;
end;
]][[
id:=Context['id'].AsInteger;
case Context['x'].AsInteger of
1://update
begin
db:=Session.Connection;
db.BeginTrans;
try
lbl:=Context['label'].Value;
cat:=Context['category'].Value;
if cat='---' then cat:=Context['categoryNew'].Value;
c:=CheckColor(Context['color'].Value);
rw:=Context['readwidth'].AsInteger;
if Context['autounread0'].Value='' then
ur:=Null
else
case Context['autounread1'].AsInteger of
0:ur:=Context['autounread0'].AsInteger;//hours
1:ur:=Context['autounread0'].AsInteger*24;//days
2:ur:=Context['autounread0'].AsInteger*24*7;//weeks
end;
db.Execute('update "Subscription" set'+
' category=$1,label=$2,color=$3,readwidth=$4,autounread=$5'+
' where id=$6 and user_id=$7',[cat,lbl,c,rw,ur,id,Session.UserID]);
qr:=TQueryResult.Create(Session.Connection,
'select H.*, HLS.id as hlsid'+
' from "HotList" H'+
' left outer join "HotListSubscription" HLS on HLS.hotlist_id=H.id and HLS.subscription_id=$2'+
' where H.user_id=$1'+
' order by lower(H.label)',[Session.UserID,id]);
try
i:=0;
SetLength(hl,qr.Count);
while qr.Read do
begin
hl[i].id:=qr.GetInt('id');
hl[i].hl:=not qr.IsNull('hlsid');
inc(i);
end;
finally
qr.Free;
end;
for i:=0 to Length(hl)-1 do
if hl[i].hl then
begin
if Context['hl'+IntToStr(hl[i].id)].AsInteger=0 then
db.Execute('delete from "HotListSubscription" where hotlist_id=$1 and subscription_id=$2',[hl[i].id,id]);
end
else
begin
if Context['hl'+IntToStr(hl[i].id)].AsInteger=1 then
db.Execute('insert into "HotListSubscription" (hotlist_id,subscription_id) values ($1,$2)',[hl[i].id,id]);
end;
db.CommitTrans;
except
db.RollbackTrans;
raise;
end;
Context.Redirect('Feeds.xxm',true);
end;
2://remove
begin
db:=Session.Connection;
db.BeginTrans;
try
db.Execute('delete from "UserPost" where subscription_id in '+
'(select id from "Subscription" where id=$1 and user_id=$2)',[id,Session.UserID]);
db.Execute('delete from "HotListSubscription" where subscription_id in '+
'(select id from "Subscription" where id=$1 and user_id=$2)',[id,Session.UserID]);
db.Execute('delete from "SubCount" where subscription_id in '+
'(select id from "Subscription" where id=$1 and user_id=$2)',[id,Session.UserID]);
db.Execute('delete from "Subscription" where id=$1 and user_id=$2',[id,Session.UserID]);
db.CommitTrans;
except
db.RollbackTrans;
raise;
end;
Context.Redirect('Feeds.xxm',true);
end
else
raise Exception.Create('Unknown action');
end;