CWIS Developer Documentation
SavedSearchFactory.php
Go to the documentation of this file.
1 <?PHP
2 
3 #
4 # FILE: SavedSearchFactory.php
5 #
6 # Part of the Collection Workflow Integration System
7 # Copyright 2009 Edward Almasy and Internet Scout
8 # http://scout.wisc.edu
9 #
10 
15 
16  # ---- PUBLIC INTERFACE --------------------------------------------------
17 
18  # object constructor
19  public function __construct()
20  {
21  # set up item factory base class
22  $this->ItemFactory("SavedSearch", "SavedSearches", "SearchId", "SearchName");
23  }
24 
25  public function GetSearchesForUser($UserId)
26  {
27  # start with empty list of searches
28  $Searches = array();
29 
30  # retrieve all IDs for user
31  $this->DB->Query("SELECT SearchId FROM SavedSearches WHERE UserId = '"
32  .intval($UserId)."'");
33  $SearchIds = $this->DB->FetchColumn("SearchId");
34 
35  # for each search ID
36  foreach ($SearchIds as $SearchId)
37  {
38  # add search to list
39  $Searches[$SearchId] = new SavedSearch($SearchId);
40  }
41 
42  # return list of searches to caller
43  return $Searches;
44  }
45 
46  # retrieve all searches that should be run according to frequency and last run time
48  {
49  # start with empty list of searches
50  $Searches = array();
51 
52  # retrieve searches with frequency/time values that indicate need to be run
53  $this->DB->Query("SELECT SearchId FROM SavedSearches"
54  ." WHERE ((Frequency = ".SavedSearch::SEARCHFREQ_HOURLY.")"
55  ." AND (DateLastRun < '"
56  .date("Y-m-d H:i:s", (strtotime("1 hour ago") + 15))."'))"
57  ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_DAILY.")"
58  ." AND (DateLastRun < '"
59  .date("Y-m-d H:i:s", (strtotime("1 day ago") + 15))."'))"
60  ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_WEEKLY.")"
61  ." AND (DateLastRun < '"
62  .date("Y-m-d H:i:s", (strtotime("1 week ago") + 15))."'))"
63  ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_BIWEEKLY.")"
64  ." AND (DateLastRun < '"
65  .date("Y-m-d H:i:s", (strtotime("2 weeks ago") + 15))."'))"
66  ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_MONTHLY.")"
67  ." AND (DateLastRun < '"
68  .date("Y-m-d H:i:s", (strtotime("1 month ago") + 15))."'))"
69  ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_QUARTERLY.")"
70  ." AND (DateLastRun < '"
71  .date("Y-m-d H:i:s", (strtotime("3 months ago") + 15))."'))"
72  ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_YEARLY.")"
73  ." AND (DateLastRun < '"
74  .date("Y-m-d H:i:s", (strtotime("1 year ago") + 15))."'))");
75  $SearchIds = $this->DB->FetchColumn("SearchId");
76 
77  # for each search ID
78  foreach ($SearchIds as $SearchId)
79  {
80  # add search to list
81  $Searches[$SearchId] = new SavedSearch($SearchId);
82  }
83 
84  # return list of searches to caller
85  return $Searches;
86  }
87 
88  function GetSearchCount()
89  {
90  return $this->DB->Query(
91  "SELECT COUNT(*) AS SearchCount FROM SavedSearches", "SearchCount");
92  }
93 
94  function GetSearchUserCount()
95  {
96  return $this->DB->Query(
97  "SELECT COUNT(DISTINCT UserId) AS UserCount FROM SavedSearches",
98  "UserCount");
99  }
100 
101 
102  # ---- PRIVATE INTERFACE -------------------------------------------------
103 
104 }
105 
106 
107 ?>