Skip to content

Commit

Permalink
Add limit to number of post per user in the theme.
Browse files Browse the repository at this point in the history
This limit is hard coded to 1 on the template file.
  • Loading branch information
TurboGit committed Sep 20, 2013
1 parent 12400b8 commit 8096fe3
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 3 deletions.
7 changes: 6 additions & 1 deletion web/src/v2p-callbacks-page.adb
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Vision2Pixels --
-- --
-- Copyright (C) 2007-2012 --
-- Copyright (C) 2007-2013 --
-- Pascal Obry - Olivier Ramonat --
-- --
-- This library is free software; you can redistribute it and/or modify --
Expand Down Expand Up @@ -689,6 +689,11 @@ package body V2P.Callbacks.Page is
Templates.Assoc
(Template_Defs.Page_Forum_New_Photo_Entry.OPEN_THEME,
Database.Themes.Current_Stage = Database.Themes.Open));
Templates.Insert
(Translations,
Templates.Assoc
(Template_Defs.Page_Forum_New_Photo_Entry.NB_THEME_USER_POST,
Database.Themes.Get_Nb_User_Post (Login)));
Templates.Insert
(Translations,
Templates.Assoc
Expand Down
34 changes: 34 additions & 0 deletions web/src/v2p-database-themes.adb
Expand Up @@ -338,6 +338,40 @@ package body V2P.Database.Themes is
return Set;
end Get_Current_Status;

----------------------
-- Get_Nb_User_Post --
----------------------

function Get_Nb_User_Post (Login : in String) return Natural is
use type Templates.Tag;

DBH : constant TLS_DBH_Access := TLS_DBH_Access (DBH_TLS.Reference);
SQL : constant String :=
"SELECT COUNT(*) "
& "FROM themes_photos, user_post, post "
& "WHERE user_post.user_login=" & Q (Login)
& " AND user_post.post_id = post.id"
& " AND themes_photos.photo_id=post.photo_id"
& " AND themes_photos.theme_id=" & I (Current_Theme);
Iter : DB.Iterator'Class := DB_Handle.Get_Iterator;
Line : DB.String_Vectors.Vector;
Count : Natural := 0;
begin
Connect (DBH);

DBH.Handle.Prepare_Select (Iter, SQL);

if Iter.More then
Iter.Get_Line (Line);
Count := Natural'Value (DB.String_Vectors.Element (Line, 1));
Line.Clear;
end if;

Iter.End_Select;

return Count;
end Get_Nb_User_Post;

-------------------------
-- Get_Selected_Photos --
-------------------------
Expand Down
6 changes: 5 additions & 1 deletion web/src/v2p-database-themes.ads
@@ -1,7 +1,7 @@
------------------------------------------------------------------------------
-- Vision2Pixels --
-- --
-- Copyright (C) 2012 --
-- Copyright (C) 2012-2013 --
-- Pascal Obry - Olivier Ramonat --
-- --
-- This library is free software; you can redistribute it and/or modify --
Expand Down Expand Up @@ -71,4 +71,8 @@ package V2P.Database.Themes is
procedure Next_Stage;
-- Move current theme to next stage, does nothing if this is no stage open

function Get_Nb_User_Post (Login : in String) return Natural;
-- Returns the number of post in the current running theme for the given
-- user.

end V2P.Database.Themes;
2 changes: 1 addition & 1 deletion web/templates/page_forum_new_photo_entry.thtml
Expand Up @@ -36,7 +36,7 @@
<label for="new_entry_name_input">@_BABEL_POST_NAME_@</label>
<input name="NAME" id="pfnpe_new_entry_name_input" type="entry" value=""/>
</p>
@@IF@@ @_OPEN_THEME_@
@@IF@@ @_OPEN_THEME_@ AND @_NB_THEME_USER_POST_@ < 1
<p id="pfnpe_for_theme">
<label for="for_theme_check">@_BABEL_FOR_THEME_@</label>
<input name="@_SET_THEME_@" id="pfnpe_for_theme_check"
Expand Down
4 changes: 4 additions & 0 deletions web/templates/page_new.thtml
Expand Up @@ -10,6 +10,10 @@
rapports d'erreur ou des demandes de fonctionnalités. Le site ne peut
évoluer sans vous.</p>

<h1>Version 3.6 (septembre 2013)</h1>

<p>Vérifie qu'une seule image par utilisateur est affectée au thème.</p>

<h1>Version 3.5.3 (juin 2013)</h1>

<p>Corrige un problème de vote pour le thème.</p>
Expand Down

0 comments on commit 8096fe3

Please sign in to comment.