PageRenderTime 44ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/from_1.2.2-1.3/components/model/dataaccess/CommentGateway.cfc

https://bitbucket.org/asfusion/mango-updates
ColdFusion CFScript | 196 lines | 156 code | 40 blank | 0 comment | 0 complexity | 1642840c6438acacb1e1ad9355417cf4 MD5 | raw file
  1. <cfcomponent name="comment" hint="Gateway for comment">
  2. <!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  3. <cffunction name="init" output="false" returntype="any" hint="instantiates an object of this class" access="public">
  4. <cfargument name="datasource" required="true" type="struct">
  5. <cfset variables.datasource = arguments.datasource />
  6. <cfset variables.dsn = arguments.datasource.name />
  7. <cfset variables.prefix = arguments.datasource.tablePrefix />
  8. <cfset variables.username = arguments.datasource.username />
  9. <cfset variables.password = arguments.datasource.password />
  10. <cfreturn this />
  11. </cffunction>
  12. <!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  13. <cffunction name="getByID" output="false" hint="Gets a query with only one record corresponding tor ID" access="public" returntype="query">
  14. <cfargument name="id" required="true" type="string" hint="Primary key"/>
  15. <cfargument name="adminMode" required="false" default="false" type="boolean" hint="Whether to include non-approved comments"/>
  16. <cfset var q_comment = "" />
  17. <cfquery name="q_comment" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
  18. SELECT comment.*, entry.title as entry_title,
  19. <!--- getting the id is redundant, but with this we can distinguish between a page and a post --->
  20. post.id as post_id
  21. FROM #variables.prefix#comment as comment
  22. LEFT OUTER JOIN #variables.prefix#entry as entry ON comment.entry_id = entry.id
  23. LEFT OUTER JOIN #variables.prefix#post as post ON comment.entry_id = post.id
  24. WHERE comment.id = <cfqueryparam value="#arguments.id#" cfsqltype="CF_SQL_VARCHAR" maxlength="35"/>
  25. <cfif NOT adminMode>
  26. AND comment.approved = 1
  27. </cfif>
  28. </cfquery>
  29. <cfreturn q_comment />
  30. </cffunction>
  31. <!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  32. <cffunction name="getRecent" output="false" hint="Gets all the records" access="public" returntype="query">
  33. <cfargument name="count" required="false" default="-1" type="numeric" hint=""/>
  34. <cfargument name="adminMode" required="false" default="false" type="boolean" hint="Whether to include non-approved comments"/>
  35. <cfset var q_comment = "" />
  36. <cfquery name="q_comment" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#" maxRows="#arguments.count#">
  37. SELECT comment.*, entry.title as entry_title,
  38. <!--- getting the id is redundant, but with this we can distinguish between a page and a post --->
  39. post.id as post_id
  40. FROM #variables.prefix#comment as comment
  41. LEFT OUTER JOIN #variables.prefix#entry as entry ON comment.entry_id = entry.id
  42. LEFT OUTER JOIN #variables.prefix#post as post ON comment.entry_id = post.id
  43. <cfif NOT adminMode>
  44. WHERE comment.approved = 1
  45. AND entry.status = 'published'
  46. </cfif>
  47. ORDER BY created_on desc
  48. </cfquery>
  49. <cfreturn q_comment />
  50. </cffunction>
  51. <!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  52. <cffunction name="getByPost" output="false" access="public" returntype="query">
  53. <cfargument name="entry_id" required="true" type="string" hint="Entry"/>
  54. <cfargument name="adminMode" required="false" default="false" type="boolean" hint="Whether to include non-approved comments"/>
  55. <cfset var q_comment = "" />
  56. <cfquery name="q_comment" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
  57. SELECT
  58. comment.*, entry.title as entry_title,
  59. <!--- getting the id is redundant, but with this we can distinguish between a page and a post --->
  60. post.id as post_id
  61. FROM #variables.prefix#comment as comment
  62. LEFT OUTER JOIN #variables.prefix#entry as entry ON comment.entry_id = entry.id
  63. LEFT OUTER JOIN #variables.prefix#post as post ON comment.entry_id = post.id
  64. WHERE comment.entry_id = <cfqueryparam value="#arguments.entry_id#" cfsqltype="cf_sql_varchar"/>
  65. <cfif NOT adminMode>
  66. AND comment.approved = 1
  67. </cfif>
  68. ORDER BY created_on
  69. </cfquery>
  70. <cfreturn q_comment />
  71. </cffunction>
  72. <!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  73. <cffunction name="getCount" output="false" hint="Gets the number of comments" access="public" returntype="numeric">
  74. <cfargument name="blogid" type="string" required="false" default="default" />
  75. <cfargument name="adminMode" required="false" default="false" type="boolean" hint="Whether to include drafts and future posts"/>
  76. <cfset var q_getCount = "" />
  77. <cfquery name="q_getCount" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
  78. SELECT count(comment.id) as total
  79. FROM #variables.prefix#comment as comment
  80. LEFT OUTER JOIN #variables.prefix#entry as entry ON comment.entry_id = entry.id
  81. WHERE entry.blog_id = <cfqueryparam value="#arguments.blogid#" cfsqltype="cf_sql_varchar"/>
  82. <cfif NOT adminMode>
  83. AND comment.approved = 1
  84. </cfif>
  85. </cfquery>
  86. <cfreturn q_getCount.total />
  87. </cffunction>
  88. <!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  89. <cffunction name="getBycreated_on" output="false" access="public" returntype="query">
  90. <cfargument name="created_on" required="true" hint="Date"/>
  91. <cfargument name="adminMode" required="false" default="false" type="boolean" hint="Whether to include non-approved comments"/>
  92. <cfset var q_comment = "" />
  93. <cfquery name="q_comment" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
  94. SELECT
  95. #variables.prefix#comment.*, #variables.prefix#entry.title as entry_title
  96. FROM #variables.prefix#comment
  97. LEFT OUTER JOIN #variables.prefix#entry ON #variables.prefix#comment.entry_id = #variables.prefix#entry.id
  98. WHERE created_on = <cfqueryparam value="#arguments.created_on#" cfsqltype="CF_SQL_DATETIME"/>
  99. <cfif NOT adminMode>
  100. AND #variables.prefix#comment.approved = 1
  101. </cfif>
  102. </cfquery>
  103. <cfreturn q_comment />
  104. </cffunction>
  105. <!--- ::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  106. <cffunction name="getByApproved" output="false" access="public" returntype="query">
  107. <cfargument name="approved" required="true" type="boolean" default="true" hint="Approved?"/>
  108. <cfset var q_comment = "" />
  109. <cfquery name="q_comment" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
  110. SELECT
  111. comment.*, entry.title as entry_title,
  112. <!--- getting the id is redundant, but with this we can distinguish between a page and a post --->
  113. post.id as post_id
  114. FROM #variables.prefix#comment as comment
  115. LEFT OUTER JOIN #variables.prefix#entry as entry ON comment.entry_id = entry.id
  116. LEFT OUTER JOIN #variables.prefix#post as post ON comment.entry_id = post.id
  117. WHERE approved = <cfqueryparam value="#arguments.approved#" cfsqltype="CF_SQL_BIT"/>
  118. </cfquery>
  119. <cfreturn q_comment />
  120. </cffunction>
  121. <!--- :::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::: --->
  122. <cffunction name="search" output="false" hint="Search for comments matching the criteria" access="public" returntype="query">
  123. <cfargument name="entry_id" required="false" type="string" hint="Entry"/>
  124. <cfargument name="created_since" required="false" hint="Date"/>
  125. <cfargument name="approved" required="false" type="boolean" hint="Approved?"/>
  126. <cfargument name="content" required="false" type="string" hint="Content to match (exact match)"/>
  127. <cfargument name="creator_email" required="false" type="string" hint="Email to match (exact match)"/>
  128. <cfset var q_search = "" />
  129. <cfquery name="q_search" datasource="#variables.dsn#" username="#variables.username#" password="#variables.password#">
  130. SELECT comment.*, entry.title as entry_title,
  131. <!--- getting the id is redundant, but with this we can distinguish between a page and a post --->
  132. post.id as post_id
  133. FROM #variables.prefix#comment as comment
  134. LEFT OUTER JOIN #variables.prefix#entry as entry ON comment.entry_id = entry.id
  135. LEFT OUTER JOIN #variables.prefix#post as post ON comment.entry_id = post.id
  136. WHERE 0=0
  137. <cfif structkeyexists(arguments,"created_since") AND isDate(arguments.created_since)>
  138. AND comment.created_on >= <cfqueryparam value="#created_since#" cfsqltype="cf_sql_date" />
  139. </cfif>
  140. <cfif structkeyexists(arguments,"approved")>
  141. AND comment.approved = <cfqueryparam value="#arguments.approved#" cfsqltype="CF_SQL_BIT"/>
  142. </cfif>
  143. <cfif structkeyexists(arguments,"entry_id")>
  144. AND comment.entry_id = <cfqueryparam value="#arguments.entry_id#" cfsqltype="cf_sql_varchar"/>
  145. </cfif>
  146. <cfif structkeyexists(arguments,"content")>
  147. AND comment.content LIKE <cfqueryparam value="#arguments.content#" cfsqltype="cf_sql_longvarchar" />
  148. </cfif>
  149. <cfif structkeyexists(arguments,"creator_email")>
  150. AND comment.creator_email = <cfqueryparam value="#arguments.creator_email#" cfsqltype="cf_sql_varchar" />
  151. </cfif>
  152. ORDER BY created_on
  153. </cfquery>
  154. <cfreturn q_search />
  155. </cffunction>
  156. </cfcomponent>