2010-01-12 01:04:11 +00:00
|
|
|
|
using System;
|
|
|
|
|
using System.Collections.Generic;
|
2010-01-07 01:06:17 +00:00
|
|
|
|
using System.Linq;
|
2010-01-26 01:08:58 +00:00
|
|
|
|
using Orchard.ContentManagement.Records;
|
2010-02-22 20:36:50 -08:00
|
|
|
|
using Orchard.Pages.Controllers;
|
2010-01-07 01:06:17 +00:00
|
|
|
|
using Orchard.Pages.Models;
|
|
|
|
|
using Orchard.Core.Common.Records;
|
|
|
|
|
using Orchard.ContentManagement;
|
2010-01-25 03:44:51 +00:00
|
|
|
|
using Orchard.Tasks.Scheduling;
|
2010-01-07 01:06:17 +00:00
|
|
|
|
|
|
|
|
|
namespace Orchard.Pages.Services {
|
|
|
|
|
public class PageService : IPageService {
|
|
|
|
|
private readonly IContentManager _contentManager;
|
2010-01-25 03:44:51 +00:00
|
|
|
|
private readonly IPublishingTaskManager _publishingTaskManager;
|
2010-01-26 01:08:58 +00:00
|
|
|
|
private readonly ISlugConstraint _slugConstraint;
|
2010-01-07 01:06:17 +00:00
|
|
|
|
|
2010-01-26 01:08:58 +00:00
|
|
|
|
public PageService(IContentManager contentManager, IPublishingTaskManager publishingTaskManager, ISlugConstraint slugConstraint) {
|
2010-01-07 01:06:17 +00:00
|
|
|
|
_contentManager = contentManager;
|
2010-01-25 03:44:51 +00:00
|
|
|
|
_publishingTaskManager = publishingTaskManager;
|
2010-01-26 01:08:58 +00:00
|
|
|
|
_slugConstraint = slugConstraint;
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Page> Get() {
|
2010-01-08 21:07:35 +00:00
|
|
|
|
return Get(PageStatus.All);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public IEnumerable<Page> Get(PageStatus status) {
|
|
|
|
|
switch (status) {
|
|
|
|
|
case PageStatus.All:
|
2010-01-26 01:08:58 +00:00
|
|
|
|
return _contentManager.Query<Page>(VersionOptions.Latest).List();
|
2010-01-08 21:07:35 +00:00
|
|
|
|
case PageStatus.Published:
|
2010-01-26 01:08:58 +00:00
|
|
|
|
return _contentManager.Query<Page>(VersionOptions.Published).List();
|
2010-01-08 21:07:35 +00:00
|
|
|
|
case PageStatus.Offline:
|
2010-01-26 01:08:58 +00:00
|
|
|
|
return _contentManager.Query<Page>(VersionOptions.Latest).Where<ContentPartVersionRecord>(ci => !ci.ContentItemVersionRecord.Published).List();
|
2010-01-08 21:07:35 +00:00
|
|
|
|
default:
|
2010-01-26 01:08:58 +00:00
|
|
|
|
return Enumerable.Empty<Page>();
|
2010-01-08 21:07:35 +00:00
|
|
|
|
}
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-21 21:59:57 +00:00
|
|
|
|
public Page Get(int id) {
|
|
|
|
|
return _contentManager.Get<Page>(id);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 01:06:17 +00:00
|
|
|
|
public Page Get(string slug) {
|
2010-01-13 23:51:07 +00:00
|
|
|
|
return
|
2010-02-22 20:36:50 -08:00
|
|
|
|
_contentManager.Query(PageDriver.ContentType.Name).Join<RoutableRecord>().Where(rr => rr.Slug == slug).List().FirstOrDefault
|
2010-01-13 23:51:07 +00:00
|
|
|
|
().As<Page>();
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-08 21:07:35 +00:00
|
|
|
|
public Page GetLatest(int id) {
|
|
|
|
|
return _contentManager.Get<Page>(id, VersionOptions.Latest);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-10 11:18:28 +00:00
|
|
|
|
public Page GetLatest(string slug) {
|
2010-01-13 23:51:07 +00:00
|
|
|
|
return
|
2010-02-22 20:36:50 -08:00
|
|
|
|
_contentManager.Query(VersionOptions.Latest, PageDriver.ContentType.Name).Join<RoutableRecord>().Where(rr => rr.Slug == slug)
|
2010-01-13 23:51:07 +00:00
|
|
|
|
.Slice(0, 1).FirstOrDefault().As<Page>();
|
2010-01-10 11:18:28 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-20 01:19:16 +00:00
|
|
|
|
public Page GetPageOrDraft(int id) {
|
|
|
|
|
return _contentManager.GetDraftRequired<Page>(id);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-10 11:18:28 +00:00
|
|
|
|
public Page GetPageOrDraft(string slug) {
|
|
|
|
|
Page page = GetLatest(slug);
|
2010-01-07 23:12:46 +00:00
|
|
|
|
return _contentManager.GetDraftRequired<Page>(page.Id);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-07 01:06:17 +00:00
|
|
|
|
public void Delete(Page page) {
|
2010-01-25 03:44:51 +00:00
|
|
|
|
_publishingTaskManager.DeleteTasks(page.ContentItem);
|
2010-01-07 23:12:46 +00:00
|
|
|
|
_contentManager.Remove(page.ContentItem);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void Publish(Page page) {
|
2010-01-25 03:44:51 +00:00
|
|
|
|
_publishingTaskManager.DeleteTasks(page.ContentItem);
|
2010-01-07 23:12:46 +00:00
|
|
|
|
_contentManager.Publish(page.ContentItem);
|
2010-01-26 01:08:58 +00:00
|
|
|
|
_slugConstraint.AddPublishedSlug(page.Slug);
|
2010-01-12 01:04:11 +00:00
|
|
|
|
}
|
|
|
|
|
|
2010-01-25 03:44:51 +00:00
|
|
|
|
public void Publish(Page page, DateTime scheduledPublishUtc) {
|
|
|
|
|
_publishingTaskManager.Publish(page.ContentItem, scheduledPublishUtc);
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
2010-01-08 22:49:16 +00:00
|
|
|
|
|
|
|
|
|
public void Unpublish(Page page) {
|
2010-01-12 01:04:11 +00:00
|
|
|
|
_contentManager.Unpublish(page.ContentItem);
|
2010-01-26 01:08:58 +00:00
|
|
|
|
_slugConstraint.RemovePublishedSlug(page.Slug);
|
2010-01-08 22:49:16 +00:00
|
|
|
|
}
|
2010-01-25 03:44:51 +00:00
|
|
|
|
|
|
|
|
|
public DateTime? GetScheduledPublishUtc(Page page) {
|
|
|
|
|
var task = _publishingTaskManager.GetPublishTask(page.ContentItem);
|
|
|
|
|
return (task == null ? null : task.ScheduledUtc);
|
|
|
|
|
}
|
2010-01-07 01:06:17 +00:00
|
|
|
|
}
|
|
|
|
|
}
|