SavedSearchFactory.php
Go to the documentation of this file.00001 <?PHP
00002
00003 #
00004 # FILE: SavedSearchFactory.php
00005 #
00006 # Part of the Collection Workflow Integration System
00007 # Copyright 2009 Edward Almasy and Internet Scout
00008 # http://scout.wisc.edu
00009 #
00010
00014 class SavedSearchFactory extends ItemFactory {
00015
00016 # ---- PUBLIC INTERFACE --------------------------------------------------
00017
00018 # object constructor
00019 public function __construct()
00020 {
00021 # set up item factory base class
00022 $this->ItemFactory("SavedSearch", "SavedSearches", "SearchId", "SearchName");
00023 }
00024
00025 public function GetSearchesForUser($UserId)
00026 {
00027 # start with empty list of searches
00028 $Searches = array();
00029
00030 # retrieve all IDs for user
00031 $this->DB->Query("SELECT SearchId FROM SavedSearches WHERE UserId = '"
00032 .intval($UserId)."'");
00033 $SearchIds = $this->DB->FetchColumn("SearchId");
00034
00035 # for each search ID
00036 foreach ($SearchIds as $SearchId)
00037 {
00038 # add search to list
00039 $Searches[$SearchId] = new SavedSearch($SearchId);
00040 }
00041
00042 # return list of searches to caller
00043 return $Searches;
00044 }
00045
00046 # retrieve all searches that should be run according to frequency and last run time
00047 function GetSearchesDueToRun()
00048 {
00049 # start with empty list of searches
00050 $Searches = array();
00051
00052 # retrieve searches with frequency/time values that indicate need to be run
00053 $this->DB->Query("SELECT SearchId FROM SavedSearches"
00054 ." WHERE ((Frequency = ".SavedSearch::SEARCHFREQ_HOURLY.")"
00055 ." AND (DateLastRun < '"
00056 .date("Y-m-d H:i:s", (strtotime("1 hour ago") + 15))."'))"
00057 ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_DAILY.")"
00058 ." AND (DateLastRun < '"
00059 .date("Y-m-d H:i:s", (strtotime("1 day ago") + 15))."'))"
00060 ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_WEEKLY.")"
00061 ." AND (DateLastRun < '"
00062 .date("Y-m-d H:i:s", (strtotime("1 week ago") + 15))."'))"
00063 ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_BIWEEKLY.")"
00064 ." AND (DateLastRun < '"
00065 .date("Y-m-d H:i:s", (strtotime("2 weeks ago") + 15))."'))"
00066 ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_MONTHLY.")"
00067 ." AND (DateLastRun < '"
00068 .date("Y-m-d H:i:s", (strtotime("1 month ago") + 15))."'))"
00069 ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_QUARTERLY.")"
00070 ." AND (DateLastRun < '"
00071 .date("Y-m-d H:i:s", (strtotime("3 months ago") + 15))."'))"
00072 ." OR ((Frequency = ".SavedSearch::SEARCHFREQ_YEARLY.")"
00073 ." AND (DateLastRun < '"
00074 .date("Y-m-d H:i:s", (strtotime("1 year ago") + 15))."'))");
00075 $SearchIds = $this->DB->FetchColumn("SearchId");
00076
00077 # for each search ID
00078 foreach ($SearchIds as $SearchId)
00079 {
00080 # add search to list
00081 $Searches[$SearchId] = new SavedSearch($SearchId);
00082 }
00083
00084 # return list of searches to caller
00085 return $Searches;
00086 }
00087
00088 function GetSearchCount()
00089 {
00090 return $this->DB->Query(
00091 "SELECT COUNT(*) AS SearchCount FROM SavedSearches", "SearchCount");
00092 }
00093
00094 function GetSearchUserCount()
00095 {
00096 return $this->DB->Query(
00097 "SELECT COUNT(DISTINCT UserId) AS UserCount FROM SavedSearches",
00098 "UserCount");
00099 }
00100
00101
00102 # ---- PRIVATE INTERFACE -------------------------------------------------
00103
00104 }
00105
00106
00107 ?>