View Javadoc
1   package fr.paris.lutece.plugins.newsletter.modules.htmldocs.business;
2   
3   import fr.paris.lutece.plugins.htmldocs.business.Tag;
4   import fr.paris.lutece.plugins.htmldocs.service.PublishingService;
5   import fr.paris.lutece.plugins.htmldocs.service.TagService;
6   import fr.paris.lutece.portal.business.user.AdminUser;
7   import fr.paris.lutece.portal.service.plugin.Plugin;
8   import fr.paris.lutece.portal.service.spring.SpringContextService;
9   import fr.paris.lutece.util.ReferenceList;
10  
11  import java.util.Collection;
12  import java.util.Date;
13  import java.util.List;
14  
15  /**
16   * Home for newsletter document
17   */
18  public final class NewsletterHtmlDocHome
19  {
20      private static INewsletterHtmlDocDAO _dao = SpringContextService.getBean( "newsletter-htmldocs.newsletterHtmlDocDAO" );
21  
22      /**
23       * Private constructor
24       */
25      private NewsletterHtmlDocHome( )
26      {
27      }
28  
29      /**
30       * Get a newsletter htmldocs topic from its id
31       * 
32       * @param nIdTopic
33       *            the id of the topic to get
34       * @param plugin
35       *            The plugin
36       * @return The topic, or null if no topic was found
37       */
38      public static NewsletterHtmlDoc findByPrimaryKey( int nIdTopic, Plugin plugin )
39      {
40          return _dao.findByPrimaryKey( nIdTopic, plugin );
41      }
42  
43      /**
44       * Update a newsletter htmldocs topic
45       * 
46       * @param topic
47       *            The topic to update
48       * @param plugin
49       *            The plugin
50       */
51      public static void updateDocumentTopic( NewsletterHtmlDoc topic, Plugin plugin )
52      {
53          _dao.updateDocumentTopic( topic, plugin );
54      }
55  
56      /**
57       * Remove a newsletter htmldocs topic from the database
58       * 
59       * @param nIdTopic
60       *            The id of the newsletter htmldocs topic to remove
61       * @param plugin
62       *            The plugin
63       */
64      public static void deleteDocumentTopic( int nIdTopic, Plugin plugin )
65      {
66          _dao.deleteDocumentTopic( nIdTopic, plugin );
67      }
68  
69      /**
70       * Insert a new newsletter htmldocs topic into the database
71       * 
72       * @param topic
73       *            The newsletter htmldocs topic to insert
74       * @param plugin
75       *            the plugin
76       */
77      public static void createDocumentTopic( NewsletterHtmlDoc topic, Plugin plugin )
78      {
79          _dao.createDocumentTopic( topic, plugin );
80      }
81  
82  
83      /**
84       * Fetches all the tags defined
85       * 
86       * @param user
87       *            the current user
88       * @return A list of all tags
89       */
90      public static ReferenceList getAllTag( AdminUser user )
91      {
92          ReferenceList list = new ReferenceList( );
93          Collection<Tag> listTagDisplay = TagService.getInstance( ).getAllTagDisplay( );
94  
95          for ( Tag tg : listTagDisplay )
96          {
97              list.addItem( tg.getIdTag( ), tg.getName( ) );
98          }
99  
100         return list;
101     }
102 
103     
104     /**
105      * Associate a htmldocs category to a newsletter topic
106      * 
107      * @param nTopicId
108      *            the topic identifier
109      * @param nDocumentTagId
110      *            the id of the htmldocs tag to associate
111      * @param plugin
112      *            the Plugin
113      */
114     public static void associateNewsLetterDocumentCategory( int nTopicId, int nDocumentTagId, Plugin plugin )
115     {
116         _dao.associateNewsLetterDocumentTag( nTopicId, nDocumentTagId, plugin );
117     }
118 
119     /**
120      * Removes the relationship between a list of htmldocs categories and a newsletter topic
121      * 
122      * @param nTopicId
123      *            the newsletter identifier
124      * @param plugin
125      *            the Plugin
126      */
127     public static void removeNewsLetterDocumentTags( int nTopicId, Plugin plugin )
128     {
129         _dao.deleteNewsLetterDocumentTags( nTopicId, plugin );
130     }
131 
132     /**
133      * loads the list of categories of the newsletter
134      * 
135      * @param nTopicId
136      *            the topic identifier
137      * @param plugin
138      *            the plugin
139      * @return the array of categories id
140      */
141     public static int [ ] findNewsletterTagIds( int nTopicId, Plugin plugin )
142     {
143         return _dao.selectNewsletterTagIds( nTopicId, plugin );
144     }
145 
146     /**
147      * Associate a new portlet to a newsletter topic
148      * 
149      * @param nTopicId
150      *            the topic id
151      * @param nPortletId
152      *            the portlet identifier
153      * @param plugin
154      *            the newsletter htmldocs plugin
155      */
156     public static void associateNewsLetterDocumentPortlet( int nTopicId, int nPortletId, Plugin plugin )
157     {
158         _dao.associateNewsLetterDocumentPortlet( nTopicId, nPortletId, plugin );
159     }
160 
161     /**
162      * Remove the relationship between a topic and the list of portlets
163      * 
164      * @param nTopicId
165      *            the topic id
166      * @param plugin
167      *            the newsletter htmldocs plugin
168      */
169     public static void removeNewsLetterDocumentPortlet( int nTopicId, Plugin plugin )
170     {
171         _dao.deleteNewsLetterDocumentPortlet( nTopicId, plugin );
172     }
173 
174     /**
175      * loads the list of htmldocs list portlets linked to the newsletter
176      * 
177      * @param nTopicId
178      *            the topic identifier
179      * @param plugin
180      *            the plugin
181      * @return the array of portlets id
182      */
183     public static int [ ] findNewsletterPortletsIds( int nTopicId, Plugin plugin )
184     {
185         return _dao.selectNewsletterPortletsIds( nTopicId, plugin );
186     }
187 
188     /**
189      * Get the list of id of published htmldocs associated with a given collection of portlets.
190      * 
191      * @param nPortletsIds
192      *            The list of portlet ids.
193      * @param datePublishing
194      *            TODO
195      * @param plugin
196      *            The document plugin
197      * @return The list of documents id.
198      */
199     public static List<Integer> getPublishedDocumentsIdsListByPortletIds( int [ ] nPortletsIds, Date datePublishing, Date dateEndPublishing, Plugin plugin )
200     {
201         return PublishingService.getInstance( ).getPublishedDocumentsIdsListByPortletIds( nPortletsIds, datePublishing, dateEndPublishing, plugin );
202     }
203 
204     /**
205      * Check if a template is used by a topic
206      * 
207      * @param nIdNewsletterTemplate
208      *            The id of the template
209      * @param plugin
210      *            The newsletter plugin
211      * @return True if the template is used by a topic, false otherwise
212      */
213     public static boolean findTemplate( int nIdNewsletterTemplate, Plugin plugin )
214     {
215         return _dao.findTemplate( nIdNewsletterTemplate, plugin );
216     }
217 }