@@ -14,7 +14,7 @@ component extends="app.Controllers.Controller" {
1414
1515 function blog () {
1616 blogs = getAllBlogs ();
17-
17+ blogCategoryMap = buildBlogCategoryMap ( blogs );
1818 }
1919
2020 // Function to edit a blog post
@@ -159,16 +159,24 @@ component extends="app.Controllers.Controller" {
159159 select = " id,Content,isPublished,commentParentId,createdat,authorId,blogId,slug,FullName,title" ,
160160 include = " User, Blog" ,
161161 order = " createdAt DESC" );
162- }
162+ parentCommentMap = buildParentCommentMap (comments );
163+ }
163164
164165 function viewComments (){
165166 id = params .id ;
166167 comments = model (" comment" ).findbyKey ( key = " #id #" ,
167168 select = " id,Content,isPublished,commentParentId,createdat,authorId,blogId,slug,FullName,title" ,
168169 include = " User, Blog"
169170 );
171+ parentCommentContent = " " ;
172+ if (isObject (comments ) && val (comments .commentParentId ) > 0 ) {
173+ var parentComment = model (" comment" ).findByKey (key = val (comments .commentParentId ), select = " content" );
174+ if (isObject (parentComment )) {
175+ parentCommentContent = parentComment .content ;
176+ }
177+ }
170178 renderPartial (partial = " partials/commentView" );
171- }
179+ }
172180
173181 function blogApprove () {
174182 try {
@@ -195,12 +203,19 @@ component extends="app.Controllers.Controller" {
195203 }
196204
197205 function blogBulkApprove (){
206+ if (! structKeyExists (params , " selectedBlogIds" ) || ! isArray (params .selectedBlogIds ) || arrayLen (params .selectedBlogIds ) == 0 ) {
207+ blogs = getAllBlogs ();
208+ blogCategoryMap = buildBlogCategoryMap (blogs );
209+ renderPartial (partial = " partials/blogs" );
210+ return ;
211+ }
198212 try {
199213 for (blogId in params .selectedBlogIds ) {
200214 var message = blogApproval (blogId );
201215 }
202216 success = " Blogs are approved successfully!" ;
203217 blogs = getAllBlogs ();
218+ blogCategoryMap = buildBlogCategoryMap (blogs );
204219 renderPartial (partial = " partials/blogs" );
205220 } catch (e ) {
206221 cfheader (statusCode = 500 );
@@ -227,12 +242,19 @@ component extends="app.Controllers.Controller" {
227242 }
228243
229244 function blogBulkReject (){
245+ if (! structKeyExists (params , " selectedBlogIds" ) || ! isArray (params .selectedBlogIds ) || arrayLen (params .selectedBlogIds ) == 0 ) {
246+ blogs = getAllBlogs ();
247+ blogCategoryMap = buildBlogCategoryMap (blogs );
248+ renderPartial (partial = " partials/blogs" );
249+ return ;
250+ }
230251 try {
231252 for (blogId in params .selectedBlogIds ) {
232253 var message = blogReject (blogId );
233254 }
234255 success = " Blogs are rejected successfully!" ;
235256 blogs = getAllBlogs ();
257+ blogCategoryMap = buildBlogCategoryMap (blogs );
236258 renderPartial (partial = " partials/blogs" );
237259 } catch (e ) {
238260 cfheader (statusCode = 500 );
@@ -281,7 +303,7 @@ component extends="app.Controllers.Controller" {
281303 var blog = model (" Blog" ).findByKey (blogData .id );
282304 var user = model (" user" ).findByKey (blog .createdby );
283305
284- if (! isNull (blog )) {
306+ if (isObject (blog )) {
285307 if (blog .status == " Approved" ){
286308 if (len (trim (publishDate ))){
287309 blog .publishedAt = parseDateTime (publishDate );
@@ -346,7 +368,7 @@ component extends="app.Controllers.Controller" {
346368 function unpublishComment (){
347369 try {
348370 var comment = model (" comment" ).findbyKey (key = " #params .id #" );
349- if (! isNull (comment )){
371+ if (isObject (comment )){
350372 comment .isPublished = false ;
351373 if (comment .save ()){
352374 renderText (' <span class="badge bg-danger">Hidden</span>' );
@@ -548,6 +570,43 @@ component extends="app.Controllers.Controller" {
548570 : (structKeyExists (form , name ) ? form [name ] : defaultValue );
549571 }
550572
573+ private struct function buildBlogCategoryMap (required query blogs ) {
574+ var map = {};
575+ var blogIds = valueList (arguments .blogs .id );
576+ if (! len (blogIds )) return map ;
577+ var allCategories = model (" BlogCategory" ).findAll (
578+ select = " blogId,name" ,
579+ where = " blogId IN (#blogIds #)" ,
580+ include = " Blog,Category"
581+ );
582+ for (var row in allCategories ) {
583+ if (! structKeyExists (map , row .blogId )) {
584+ map [row .blogId ] = [];
585+ }
586+ arrayAppend (map [row .blogId ], row .name );
587+ }
588+ return map ;
589+ }
590+
591+ private struct function buildParentCommentMap (required query comments ) {
592+ var map = {};
593+ var parentIds = [];
594+ for (var row in arguments .comments ) {
595+ if (val (row .commentParentId ) > 0 ) {
596+ arrayAppend (parentIds , val (row .commentParentId ));
597+ }
598+ }
599+ if (! arrayLen (parentIds )) return map ;
600+ var parentComments = model (" comment" ).findAll (
601+ select = " id,content" ,
602+ where = " id IN (#arrayToList (parentIds ) #)"
603+ );
604+ for (var pc in parentComments ) {
605+ map [pc .id ] = pc .content ;
606+ }
607+ return map ;
608+ }
609+
551610 public function getAllBlogs () {
552611 return model (" Blog" ).findAll (
553612 include = " User, PostStatus, PostType" ,
@@ -575,7 +634,7 @@ component extends="app.Controllers.Controller" {
575634 function publishComment (id ){
576635 var comment = model (" comment" ).findbyKey (key = " #id #" , include = " Blog" );
577636 var user = model (" user" ).findByKey (comment .authorId );
578- if (! isNull (comment )){
637+ if (isObject (comment )){
579638 comment .isPublished = true ;
580639 if (comment .save ()){
581640 siteurl = urlFor (route = " blog-detail" ,slug = comment .blog .slug ,onlyPath = false );
@@ -616,8 +675,8 @@ component extends="app.Controllers.Controller" {
616675 var blog = model (" Blog" ).findByKey (id );
617676 var user = model (" user" ).findByKey (blog .createdby );
618677
619- if (! isNull (blog )) {
620-
678+ if (isObject (blog )) {
679+
621680 blog .status = " Approved" ; // approved
622681 if (blog .save ()) {
623682 return {
@@ -643,8 +702,8 @@ component extends="app.Controllers.Controller" {
643702 var blog = model (" Blog" ).findByKey (id );
644703 var user = model (" user" ).findByKey (blog .createdby );
645704
646- if (! isNull (blog )) {
647-
705+ if (isObject (blog )) {
706+
648707 blog .status = " Rejected" ; // reject
649708 blog .publishedAt = " " ;
650709 if (blog .save ()) {
0 commit comments