PageRenderTime 26ms CodeModel.GetById 15ms RepoModel.GetById 0ms app.codeStats 0ms

/CMSWebParts/SmartSearch/SearchResults.ascx.cs

https://bitbucket.org/kudutest2/kenticogit
C# | 698 lines | 488 code | 93 blank | 117 comment | 5 complexity | 47249abbd73f5dae2a417bd8840e1581 MD5 | raw file
  1. using System;
  2. using System.Web;
  3. using System.Web.UI;
  4. using CMS.GlobalHelper;
  5. using CMS.Controls;
  6. using CMS.PortalControls;
  7. public partial class CMSWebParts_SmartSearch_SearchResults : CMSAbstractWebPart
  8. {
  9. #region "Webpart properties"
  10. /// <summary>
  11. /// Gets or sets sorting of search.
  12. /// </summary>
  13. public string SearchSort
  14. {
  15. get
  16. {
  17. return ValidationHelper.GetString(GetValue("SearchSort"), srchResults.SearchSort);
  18. }
  19. set
  20. {
  21. SetValue("SearchSort", value);
  22. srchResults.SearchSort = value;
  23. }
  24. }
  25. /// <summary>
  26. /// Gets or sets sorting of search.
  27. /// </summary>
  28. public string SearchCondition
  29. {
  30. get
  31. {
  32. return ValidationHelper.GetString(GetValue("SearchCondition"), srchResults.SearchCondition);
  33. }
  34. set
  35. {
  36. SetValue("SearchCondition", value);
  37. srchResults.SearchCondition = value;
  38. }
  39. }
  40. /// <summary>
  41. /// Gets or sets indexes.
  42. /// </summary>
  43. public string Indexes
  44. {
  45. get
  46. {
  47. return ValidationHelper.GetString(GetValue("Indexes"), srchResults.Indexes);
  48. }
  49. set
  50. {
  51. SetValue("Indexes", value);
  52. srchResults.Indexes = value;
  53. }
  54. }
  55. /// <summary>
  56. /// Gets or sets path.
  57. /// </summary>
  58. public string Path
  59. {
  60. get
  61. {
  62. return ValidationHelper.GetString(GetValue("Path"), srchResults.Path);
  63. }
  64. set
  65. {
  66. SetValue("Path", value);
  67. srchResults.Path = value;
  68. }
  69. }
  70. /// <summary>
  71. /// Gets or sets document types.
  72. /// </summary>
  73. public string DocumentTypes
  74. {
  75. get
  76. {
  77. return ValidationHelper.GetString(GetValue("DocumentTypes"), srchResults.DocumentTypes);
  78. }
  79. set
  80. {
  81. SetValue("DocumentTypes", value);
  82. srchResults.DocumentTypes = value;
  83. }
  84. }
  85. /// <summary>
  86. /// Gets or sets check permissions.
  87. /// </summary>
  88. public bool CheckPermissions
  89. {
  90. get
  91. {
  92. return ValidationHelper.GetBoolean(GetValue("CheckPermissions"), srchResults.CheckPermissions);
  93. }
  94. set
  95. {
  96. SetValue("CheckPermissions", value);
  97. srchResults.CheckPermissions = false;
  98. }
  99. }
  100. /// <summary>
  101. /// Gets or sets search option.
  102. /// </summary>
  103. public CMS.SiteProvider.SearchOptionsEnum SearchOptions
  104. {
  105. get
  106. {
  107. return CMS.SiteProvider.SearchHelper.GetSearchOptionsEnum(ValidationHelper.GetString(GetValue("SearchOptions"), CMS.SiteProvider.SearchHelper.GetSearchOptionsString(srchResults.SearchOptions)));
  108. }
  109. set
  110. {
  111. SetValue("SearchOptions", CMS.SiteProvider.SearchHelper.GetSearchOptionsString(value));
  112. srchResults.SearchOptions = value;
  113. }
  114. }
  115. /// <summary>
  116. /// Gets or sets transformation name.
  117. /// </summary>
  118. public string TransformationName
  119. {
  120. get
  121. {
  122. return ValidationHelper.GetString(GetValue("TransformationName"), srchResults.TransformationName);
  123. }
  124. set
  125. {
  126. SetValue("TransformationName", value);
  127. srchResults.TransformationName = value;
  128. }
  129. }
  130. /// <summary>
  131. /// Gets or sets culture code.
  132. /// </summary>
  133. public string CultureCode
  134. {
  135. get
  136. {
  137. return ValidationHelper.GetString(GetValue("CultureCode"), srchResults.CultureCode);
  138. }
  139. set
  140. {
  141. SetValue("CultureCode", value);
  142. srchResults.CultureCode = value;
  143. }
  144. }
  145. /// <summary>
  146. /// Gets or sets combine with default culture.
  147. /// </summary>
  148. public bool CombineWithDefaultCulture
  149. {
  150. get
  151. {
  152. return ValidationHelper.GetBoolean(GetValue("CombineWithDefaultCulture"), srchResults.CombineWithDefaultCulture);
  153. }
  154. set
  155. {
  156. SetValue("CombineWithDefaultCulture", value);
  157. srchResults.CombineWithDefaultCulture = value;
  158. }
  159. }
  160. /// <summary>
  161. /// Gets or sets search in attachments.
  162. /// </summary>
  163. public bool SearchInAttachments
  164. {
  165. get
  166. {
  167. return ValidationHelper.GetBoolean(GetValue("SearchInAttachments"), srchResults.SearchInAttachments);
  168. }
  169. set
  170. {
  171. SetValue("SearchInAttachments", value);
  172. srchResults.SearchInAttachments = value;
  173. }
  174. }
  175. /// <summary>
  176. /// Gets or sets attachments where.
  177. /// </summary>
  178. public string AttachmentsWhere
  179. {
  180. get
  181. {
  182. return ValidationHelper.GetString(GetValue("AttachmentsWhere"), srchResults.AttachmentsWhere);
  183. }
  184. set
  185. {
  186. SetValue("AttachmentsWhere", value);
  187. srchResults.AttachmentsWhere = value;
  188. }
  189. }
  190. /// <summary>
  191. /// Gets or sets attachment order by.
  192. /// </summary>
  193. public string AttachmentsOrderBy
  194. {
  195. get
  196. {
  197. return ValidationHelper.GetString(GetValue("AttachmentsOrderBy"), srchResults.AttachmentsOrderBy);
  198. }
  199. set
  200. {
  201. SetValue("AttachmentsOrderBy", value);
  202. srchResults.AttachmentsOrderBy = value;
  203. }
  204. }
  205. /// <summary>
  206. /// Gets or sets results text.
  207. /// </summary>
  208. public string NoResultsText
  209. {
  210. get
  211. {
  212. return ValidationHelper.GetString(GetValue("NoResultsText"), srchResults.NoResultsText);
  213. }
  214. set
  215. {
  216. SetValue("NoResultsText", value);
  217. srchResults.NoResultsText = value;
  218. }
  219. }
  220. /// <summary>
  221. /// Gets or sets the maximal displayed results.
  222. /// </summary>
  223. public int MaxResults
  224. {
  225. get
  226. {
  227. return ValidationHelper.GetInteger(this.GetValue("MaxResults"), srchResults.MaxResults);
  228. }
  229. set
  230. {
  231. this.SetValue("MaxResults", value);
  232. srchResults.MaxResults = value;
  233. }
  234. }
  235. #endregion
  236. #region "UniPager properties"
  237. /// <summary>
  238. /// Gets or sets page size.
  239. /// </summary>
  240. public int PageSize
  241. {
  242. get
  243. {
  244. return ValidationHelper.GetInteger(GetValue("PageSize"), srchResults.PageSize);
  245. }
  246. set
  247. {
  248. SetValue("PageSize", value);
  249. srchResults.PageSize = value;
  250. }
  251. }
  252. /// <summary>
  253. /// Gets or sets search option.
  254. /// </summary>
  255. public string PagingMode
  256. {
  257. get
  258. {
  259. return ValidationHelper.GetString(GetValue("PagingMode"), srchResults.PagingMode.ToString());
  260. }
  261. set
  262. {
  263. SetValue("PagingMode", value);
  264. srchResults.PagingMode = UniPagerMode.Querystring;
  265. if (value == "postback")
  266. {
  267. srchResults.PagingMode = UniPagerMode.PostBack;
  268. }
  269. }
  270. }
  271. /// <summary>
  272. /// Gets or sets query string key.
  273. /// </summary>
  274. public string QueryStringKey
  275. {
  276. get
  277. {
  278. return ValidationHelper.GetString(GetValue("QueryStringKey"), srchResults.QueryStringKey);
  279. }
  280. set
  281. {
  282. SetValue("QueryStringKey", value);
  283. srchResults.QueryStringKey = value;
  284. }
  285. }
  286. /// <summary>
  287. /// Gets or sets group size.
  288. /// </summary>
  289. public int GroupSize
  290. {
  291. get
  292. {
  293. return ValidationHelper.GetInteger(GetValue("GroupSize"), srchResults.PageSize);
  294. }
  295. set
  296. {
  297. SetValue("GroupSize", value);
  298. srchResults.PageSize = value;
  299. }
  300. }
  301. /// <summary>
  302. /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view.
  303. /// </summary>
  304. public bool DisplayFirstLastAutomatically
  305. {
  306. get
  307. {
  308. return ValidationHelper.GetBoolean(GetValue("DisplayFirstLastAutomatically"), srchResults.DisplayFirstLastAutomatically);
  309. }
  310. set
  311. {
  312. SetValue("DisplayFirstLastAutomatically", value);
  313. srchResults.DisplayFirstLastAutomatically = value;
  314. }
  315. }
  316. /// <summary>
  317. /// Gets or sets the value that indicates whether first and last item template are displayed dynamically based on current view.
  318. /// </summary>
  319. public bool DisplayPreviousNextAutomatically
  320. {
  321. get
  322. {
  323. return ValidationHelper.GetBoolean(GetValue("DisplayPreviousNextAutomatically"), srchResults.DisplayPreviousNextAutomatically);
  324. }
  325. set
  326. {
  327. SetValue("DisplayPreviousNextAutomatically", value);
  328. srchResults.DisplayPreviousNextAutomatically = value;
  329. }
  330. }
  331. /// <summary>
  332. /// Gets or sets the value that indicates whether pager should be hidden for single page.
  333. /// </summary>
  334. public bool HidePagerForSinglePage
  335. {
  336. get
  337. {
  338. return ValidationHelper.GetBoolean(GetValue("HidePagerForSinglePage"), srchResults.HidePagerForSinglePage);
  339. }
  340. set
  341. {
  342. SetValue("HidePagerForSinglePage", value);
  343. srchResults.HidePagerForSinglePage = value;
  344. }
  345. }
  346. /// <summary>
  347. /// Gets or sets the max. pages.
  348. /// </summary>
  349. public int MaxPages
  350. {
  351. get
  352. {
  353. return ValidationHelper.GetInteger(GetValue("MaxPages"), srchResults.MaxPages);
  354. }
  355. set
  356. {
  357. SetValue("MaxPages", value);
  358. srchResults.MaxPages = value;
  359. }
  360. }
  361. #endregion
  362. #region "UniPager Template properties"
  363. /// <summary>
  364. /// Gets or sets the pages template.
  365. /// </summary>
  366. public string PagesTemplate
  367. {
  368. get
  369. {
  370. return ValidationHelper.GetString(GetValue("Pages"), srchResults.PagesTemplateName);
  371. }
  372. set
  373. {
  374. SetValue("Pages", value);
  375. srchResults.PagesTemplateName = value;
  376. }
  377. }
  378. /// <summary>
  379. /// Gets or sets the current page template.
  380. /// </summary>
  381. public string CurrentPageTemplate
  382. {
  383. get
  384. {
  385. return ValidationHelper.GetString(GetValue("CurrentPage"), srchResults.CurrentPageTemplateName);
  386. }
  387. set
  388. {
  389. SetValue("CurrentPage", value);
  390. srchResults.CurrentPageTemplateName = value;
  391. }
  392. }
  393. /// <summary>
  394. /// Gets or sets the separator template.
  395. /// </summary>
  396. public string SeparatorTemplate
  397. {
  398. get
  399. {
  400. return ValidationHelper.GetString(GetValue("PageSeparator"), srchResults.SeparatorTemplateName);
  401. }
  402. set
  403. {
  404. SetValue("PageSeparator", value);
  405. srchResults.SeparatorTemplateName = value;
  406. }
  407. }
  408. /// <summary>
  409. /// Gets or sets the first page template.
  410. /// </summary>
  411. public string FirstPageTemplate
  412. {
  413. get
  414. {
  415. return ValidationHelper.GetString(GetValue("FirstPage"), srchResults.FirstPageTemplateName);
  416. }
  417. set
  418. {
  419. SetValue("FirstPage", value);
  420. srchResults.FirstPageTemplateName = value;
  421. }
  422. }
  423. /// <summary>
  424. /// Gets or sets the last page template.
  425. /// </summary>
  426. public string LastPageTemplate
  427. {
  428. get
  429. {
  430. return ValidationHelper.GetString(GetValue("LastPage"), srchResults.LastPageTemplateName);
  431. }
  432. set
  433. {
  434. SetValue("LastPage", value);
  435. srchResults.LastPageTemplateName = value;
  436. }
  437. }
  438. /// <summary>
  439. /// Gets or sets the previous page template.
  440. /// </summary>
  441. public string PreviousPageTemplate
  442. {
  443. get
  444. {
  445. return ValidationHelper.GetString(GetValue("PreviousPage"), srchResults.PreviousPageTemplateName);
  446. }
  447. set
  448. {
  449. SetValue("PreviousPage", value);
  450. srchResults.PreviousPageTemplateName = value;
  451. }
  452. }
  453. /// <summary>
  454. /// Gets or sets the next page template.
  455. /// </summary>
  456. public string NextPageTemplate
  457. {
  458. get
  459. {
  460. return ValidationHelper.GetString(GetValue("NextPage"), srchResults.NextPageTemplateName);
  461. }
  462. set
  463. {
  464. SetValue("NextPage", value);
  465. srchResults.NextPageTemplateName = value;
  466. }
  467. }
  468. /// <summary>
  469. /// Gets or sets the previous group template.
  470. /// </summary>
  471. public string PreviousGroupTemplate
  472. {
  473. get
  474. {
  475. return ValidationHelper.GetString(GetValue("PreviousGroup"), srchResults.PreviousGroupTemplateName);
  476. }
  477. set
  478. {
  479. SetValue("PreviousGroup", value);
  480. srchResults.NextPageTemplateName = value;
  481. }
  482. }
  483. /// <summary>
  484. /// Gets or sets the next group template.
  485. /// </summary>
  486. public string NextGroupTemplate
  487. {
  488. get
  489. {
  490. return ValidationHelper.GetString(GetValue("NextGroup"), srchResults.NextGroupTemplateName);
  491. }
  492. set
  493. {
  494. SetValue("NextGroup", value);
  495. srchResults.NextGroupTemplateName = value;
  496. }
  497. }
  498. /// <summary>
  499. /// Gets or sets the layout template.
  500. /// </summary>
  501. public string LayoutTemplate
  502. {
  503. get
  504. {
  505. return ValidationHelper.GetString(GetValue("PagerLayout"), srchResults.LayoutTemplateName);
  506. }
  507. set
  508. {
  509. SetValue("PagerLayout", value);
  510. srchResults.LayoutTemplateName = value;
  511. }
  512. }
  513. #endregion
  514. #region "Events"
  515. /// <summary>
  516. /// On init event.
  517. /// </summary>
  518. /// <param name="e">Params</param>
  519. protected override void OnInit(EventArgs e)
  520. {
  521. srchResults.FilterID = ValidationHelper.GetString(GetValue("WebPartControlID"), ClientID);
  522. srchResults.LoadData();
  523. base.OnInit(e);
  524. }
  525. /// <summary>
  526. /// Content loaded event handler.
  527. /// </summary>
  528. public override void OnContentLoaded()
  529. {
  530. base.OnContentLoaded();
  531. SetupControl();
  532. }
  533. #endregion
  534. #region "Methods"
  535. /// <summary>
  536. /// Initializes the control properties.
  537. /// </summary>
  538. protected void SetupControl()
  539. {
  540. if (StopProcessing)
  541. {
  542. srchResults.StopProcessing = true;
  543. }
  544. else
  545. {
  546. // Get unipage mode
  547. UniPagerMode mode = UniPagerMode.Querystring;
  548. if (PagingMode == "postback")
  549. {
  550. mode = UniPagerMode.PostBack;
  551. }
  552. // Search properties
  553. srchResults.SearchSort = SearchSort;
  554. srchResults.SearchCondition = SearchCondition;
  555. srchResults.Indexes = Indexes;
  556. srchResults.Path = Path;
  557. srchResults.DocumentTypes = DocumentTypes;
  558. srchResults.CheckPermissions = CheckPermissions;
  559. srchResults.SearchOptions = SearchOptions;
  560. srchResults.TransformationName = TransformationName;
  561. srchResults.CultureCode = CultureCode;
  562. srchResults.CombineWithDefaultCulture = CombineWithDefaultCulture;
  563. srchResults.SearchInAttachments = SearchInAttachments;
  564. srchResults.AttachmentsOrderBy = AttachmentsOrderBy;
  565. srchResults.AttachmentsWhere = AttachmentsWhere;
  566. srchResults.NoResultsText = NoResultsText;
  567. // UniPager properties
  568. srchResults.PageSize = PageSize;
  569. srchResults.GroupSize = GroupSize;
  570. srchResults.QueryStringKey = QueryStringKey;
  571. srchResults.DisplayFirstLastAutomatically = DisplayFirstLastAutomatically;
  572. srchResults.DisplayPreviousNextAutomatically = DisplayPreviousNextAutomatically;
  573. srchResults.HidePagerForSinglePage = HidePagerForSinglePage;
  574. srchResults.PagingMode = mode;
  575. srchResults.MaxPages = MaxPages;
  576. srchResults.MaxResults = this.MaxResults;
  577. // Unipager template properties
  578. srchResults.PagesTemplateName = PagesTemplate;
  579. srchResults.CurrentPageTemplateName = CurrentPageTemplate;
  580. srchResults.SeparatorTemplateName = SeparatorTemplate;
  581. srchResults.FirstPageTemplateName = FirstPageTemplate;
  582. srchResults.LastPageTemplateName = LastPageTemplate;
  583. srchResults.PreviousPageTemplateName = PreviousPageTemplate;
  584. srchResults.NextPageTemplateName = NextPageTemplate;
  585. srchResults.PreviousGroupTemplateName = PreviousGroupTemplate;
  586. srchResults.NextGroupTemplateName = NextGroupTemplate;
  587. srchResults.LayoutTemplateName = LayoutTemplate;
  588. // Events
  589. srchResults.OnSearchCompleted += srchResults_OnSearchCompleted;
  590. }
  591. }
  592. protected void srchResults_OnSearchCompleted(bool visible)
  593. {
  594. Visible = visible;
  595. }
  596. /// <summary>
  597. /// Reloads data.
  598. /// </summary>
  599. public override void ReloadData()
  600. {
  601. SetupControl();
  602. base.ReloadData();
  603. }
  604. #endregion
  605. }