|
| 1 | +#region Copyright and License |
| 2 | + |
| 3 | +// Copyright (c) Islington Council 2010-2013 |
| 4 | +// Author: Oli Sharpe (oli@gometa.co.uk) |
| 5 | +// |
| 6 | +// This file is part of the Work Box Framework. |
| 7 | +// |
| 8 | +// The Work Box Framework is free software: you can redistribute it and/or |
| 9 | +// modify it under the terms of the GNU Lesser General Public License as |
| 10 | +// published by the Free Software Foundation, either version 2.1 of the |
| 11 | +// License, or (at your option) any later version. |
| 12 | +// |
| 13 | +// The Work Box Framework is distributed in the hope that it will be |
| 14 | +// useful, but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | +// GNU Lesser General Public License for more details. |
| 17 | +// |
| 18 | +// You should have received a copy of the GNU Lesser General Public License |
| 19 | +// along with Foobar. If not, see <http://www.gnu.org/licenses/>. |
| 20 | + |
| 21 | +#endregion |
| 22 | + |
| 23 | +using System; |
| 24 | +using System.Collections.Generic; |
| 25 | +using System.Linq; |
| 26 | +using System.Text; |
| 27 | +using Microsoft.SharePoint; |
| 28 | +using WorkBoxFramework; |
| 29 | + |
| 30 | +namespace WBFWebParts |
| 31 | +{ |
| 32 | + internal class WBFWebPartsUtils |
| 33 | + { |
| 34 | + |
| 35 | + internal static bool InDMZ(SPContext context) |
| 36 | + { |
| 37 | + return false; |
| 38 | + } |
| 39 | + |
| 40 | + |
| 41 | + internal static bool OnIzziOrPublicWeb(SPContext context) |
| 42 | + { |
| 43 | + string[] izziOrPublicWeb = { "sp.izzi", "collection.izzi", "izzi", "collection", "teststagingweb", "stagingweb", "liveweb", "www.islington.gov.uk" }; |
| 44 | + |
| 45 | + if (izziOrPublicWeb.Contains(context.Site.HostName)) |
| 46 | + { |
| 47 | + return true; |
| 48 | + } |
| 49 | + else |
| 50 | + { |
| 51 | + return false; |
| 52 | + } |
| 53 | + |
| 54 | + } |
| 55 | + |
| 56 | + internal static String GetPublicLibraryURL(SPContext context) |
| 57 | + { |
| 58 | + WBFarm farm = WBFarm.Local; |
| 59 | + |
| 60 | + string[] internalSites = { "sp.izzi", "collection.izzi", "izzi", "collection" }; |
| 61 | + string[] publicSites = { "teststagingweb", "stagingweb", "liveweb", "www.islington.gov.uk" }; |
| 62 | + |
| 63 | + if (OnPublicSite(context)) |
| 64 | + { |
| 65 | + WBLogging.Debug("On a public site"); |
| 66 | + |
| 67 | + if (publicSites.Contains(context.Site.HostName)) |
| 68 | + { |
| 69 | + return "http://" + context.Site.HostName + "/publicrecords/library/"; |
| 70 | + } |
| 71 | + else |
| 72 | + { |
| 73 | + if (InDMZ(context)) |
| 74 | + { |
| 75 | + return "http://www.islington.gov.uk/publicrecords/library/"; |
| 76 | + } |
| 77 | + else |
| 78 | + { |
| 79 | + return farm.PublicRecordsLibraryUrl; |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + else |
| 84 | + { |
| 85 | + WBLogging.Debug("Not on a public site"); |
| 86 | + return farm.ProtectedRecordsLibraryUrl; |
| 87 | + } |
| 88 | + } |
| 89 | + |
| 90 | + |
| 91 | + internal static String GetExtranetLibraryURL(SPContext context) |
| 92 | + { |
| 93 | + WBFarm farm = WBFarm.Local; |
| 94 | + |
| 95 | + if (InDMZ(context)) |
| 96 | + { |
| 97 | + WBLogging.Debug("In DMZ"); |
| 98 | + |
| 99 | + return "http://extranets.islington.gov.uk/records/library"; |
| 100 | + } |
| 101 | + else |
| 102 | + { |
| 103 | + return "http://stagingextranets/records/library"; |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + |
| 108 | + internal static bool OnPublicSite(SPContext context) |
| 109 | + { |
| 110 | +// string [] publicSites = { "teststagingweb", "stagingweb", "liveweb", "www.islington.gov.uk" }; |
| 111 | + |
| 112 | + string[] internalSites = { "sp.izzi", "collection.izzi" , "izzi", "collection" }; |
| 113 | + |
| 114 | + return (!internalSites.Contains(context.Site.HostName)); |
| 115 | + } |
| 116 | + |
| 117 | + |
| 118 | + |
| 119 | + internal static SPListItem GetRecord(SPSite site, SPWeb web, SPList library, String zone, String recordID) |
| 120 | + { |
| 121 | + WBQuery query = new WBQuery(); |
| 122 | + |
| 123 | + WBQueryClause recordIDClause = new WBQueryClause(WBColumn.RecordID, WBQueryClause.Comparators.Equals, recordID); |
| 124 | + query.AddClause(recordIDClause); |
| 125 | + |
| 126 | + WBQueryClause isLiveClause = new WBQueryClause(WBColumn.LiveOrArchived, WBQueryClause.Comparators.Equals, WBColumn.LIVE_OR_ARCHIVED__LIVE); |
| 127 | + query.AddClause(isLiveClause); |
| 128 | + |
| 129 | + query.AddViewColumn(WBColumn.Name); |
| 130 | + query.AddViewColumn(WBColumn.Title); |
| 131 | + query.AddViewColumn(WBColumn.FileSize); |
| 132 | + query.AddViewColumn(WBColumn.FileTypeIcon); |
| 133 | + query.AddViewColumn(WBColumn.FileType); |
| 134 | + query.AddViewColumn(WBColumn.TitleOrName); |
| 135 | + query.AddViewColumn(WBColumn.DisplayFileSize); |
| 136 | + query.AddViewColumn(WBColumn.EncodedAbsoluteURL); |
| 137 | + //query.AddViewColumn(WBColumn.FunctionalArea); |
| 138 | + //query.AddViewColumn(WBColumn.OwningTeam); |
| 139 | + query.AddViewColumn(WBColumn.ReferenceDate); |
| 140 | + query.AddViewColumn(WBColumn.SourceID); |
| 141 | + |
| 142 | + SPListItemCollection items = library.WBxGetItems(site, query); |
| 143 | + |
| 144 | + if (items.Count < 1) |
| 145 | + { |
| 146 | + WBLogging.Debug("Couldn't find the document with Record ID = " + recordID); |
| 147 | + return null; |
| 148 | + } |
| 149 | + else |
| 150 | + { |
| 151 | + |
| 152 | + if (items.Count > 1) WBUtils.shouldThrowError("Found " + items.Count + " items that matched the query for Record ID: " + recordID); |
| 153 | + |
| 154 | + return items[0]; |
| 155 | + } |
| 156 | + } |
| 157 | + |
| 158 | + |
| 159 | + } |
| 160 | +} |
0 commit comments