CWIS Developer Documentation

- Home
- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

SavedSearch.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: SavedSearch.php
4 #
5 # Part of the Collection Workflow Integration System (CWIS)
6 # Copyright 2011-2015 Edward Almasy and Internet Scout Research Group
7 # http://scout.wisc.edu/cwis/
8 #
9
10 class SavedSearch
11 {
12
13 # ---- PUBLIC INTERFACE --------------------------------------------------
14
15 # search frequency mnemonics
16 const SEARCHFREQ_NEVER = 0;
17 const SEARCHFREQ_HOURLY = 1;
18 const SEARCHFREQ_DAILY = 2;
19 const SEARCHFREQ_WEEKLY = 3;
20 const SEARCHFREQ_BIWEEKLY = 4;
21 const SEARCHFREQ_MONTHLY = 5;
22 const SEARCHFREQ_QUARTERLY = 6;
23 const SEARCHFREQ_YEARLY = 7;
24
25 # object constructor
26
34 public function __construct($SearchId, $SearchName = NULL, $UserId = NULL,
35 $Frequency = NULL, $SearchParameters = NULL)
36 {
37 # get our own database handle
38 $this->DB = new Database();
39
40 # if search ID was provided
41 if ($SearchId !== NULL)
42 {
43 # save search ID
44 $this->SearchId = intval($SearchId);
45
46 # initialize our local copies of data
47 $this->DB->Query(
48 "SELECT * FROM SavedSearches "
49 ."WHERE SearchId = ".$this->SearchId);
50
51 if ($this->DB->NumRowsSelected() == 0)
52 {
53 throw new Exception ("Specified SearchId does not exist");
54 }
55
56 $this->Record = $this->DB->FetchRow();
57
58 # get our Search Parameters
59 $this->SearchParameters = new SearchParameterSet(
60 $this->Record["SearchData"]);
61
62 # remove now redundant 'Data' from our record
63 unset ($this->Record["SearchData"]);
64
65 # update search details where provided
66 if ($SearchName)
67 {
68 $this->SearchName($SearchName);
69 }
70
71 if ($UserId)
72 {
73 $this->UserId($UserId);
74 }
75
76 if ($Frequency)
77 {
78 $this->Frequency($Frequency);
79 }
80 }
81 else
82 {
83 # add new saved search to database
84 $this->DB->Query("INSERT INTO SavedSearches"
85 ." (SearchName, UserId, Frequency) VALUES ("
86 ."'".addslashes($SearchName)."', "
87 .intval($UserId).", "
88 .intval($Frequency).")");
89
90 # retrieve and save ID of new search locally
91 $this->SearchId = $this->DB->LastInsertId();
92
93 # save frequency and user ID locally
94 $this->Record["SearchName"] = $SearchName;
95 $this->Record["UserId"] = $UserId;
96 $this->Record["Frequency"] = $Frequency;
97
98 if (!is_null($SearchParameters) && is_array($SearchParameters))
99 {
100 $Params = new SearchParameterSet();
101 $Params->SetFromLegacyArray($SearchParameters);
102 $SearchParameters = $Params;
103 }
104
105 $EndUser = new CWUser($this->UserId());
106
107 $RFactory = new ResourceFactory();
108
109 # signal event to allow modification of search parameters
110 $SignalResult = $GLOBALS["AF"]->SignalEvent(
111 "EVENT_FIELDED_SEARCH", array(
112 "SearchParameters" => $SearchParameters,
113 "User" => $EndUser,
114 "SavedSearch" => $this));
115 $this->SearchParameters($SignalResult["SearchParameters"]);
116
117 # perform search
118 $SearchEngine = new SPTSearchEngine();
119 $SearchResults = $SearchEngine->GroupedSearch(
120 $SearchParameters, 0, PHP_INT_MAX);
121
122 $NewItemIds = array_keys($SearchResults);
123
124 #Only allow resources the user can view
125 $NewItemIds = $RFactory->FilterNonViewableResources($NewItemIds, $EndUser);
126
127 # if search results were found
128 if (count($NewItemIds))
129 {
130 $this->SaveLastMatches($NewItemIds);
131 }
132 }
133 }
134
143 public function SearchGroups($NewSearchGroups = NULL)
144 {
145 if (!is_null($NewSearchGroups))
146 {
147 $Params = new SearchParameterSet();
148 $Params->SetFromLegacyArray($NewSearchGroups);
149 $this->SearchParameters($Params);
150 }
151
152 # return search parameters to caller
153 return $this->SearchParameters()->GetAsLegacyArray();
154 }
155
161 public function SearchParameters($NewParams = NULL)
162 {
163 if (!is_null($NewParams))
164 {
165 if ($NewParams instanceof SearchParameterSet)
166 {
167
168 $Data = $NewParams->Data();
169
170 $this->DB->Query(
171 "UPDATE SavedSearches SET SearchData = '". addslashes($Data)."'"
172 ." WHERE SearchId = ".$this->SearchId);
173
174 $this->SearchParameters = new SearchParameterSet($Data);
175 }
176 else
177 {
178 throw new Exception("NewParams must be a SearchParameterSet");
179 }
180 }
181
182 return clone $this->SearchParameters;
183 }
184
190 public function SearchName($NewValue = DB_NOVALUE)
191 {
192 return $this->UpdateValue("SearchName", $NewValue);
193 }
194
199 public function Id()
200 {
201 return $this->SearchId;
202 }
203
209 public function UserId($NewValue = DB_NOVALUE)
210 {
211 return $this->UpdateValue("UserId", $NewValue);
212 }
213
219 public function Frequency($NewValue = DB_NOVALUE)
220 {
221 return $this->UpdateValue("Frequency", $NewValue);
222 }
223
224
228 public function UpdateDateLastRun()
229 {
230 $this->DB->Query(
231 "UPDATE SavedSearches SET DateLastRun = NOW() "
232 ."WHERE SearchId = ".$this->SearchId);
233 }
234
240 public function DateLastRun($NewValue = DB_NOVALUE)
241 {
242 return $this->UpdateValue("DateLastRun", $NewValue);
243 }
244
249 public function SaveLastMatches($ArrayofMatchingIds)
250 {
251 $NewValue = implode(",", $ArrayofMatchingIds);
252 $this->UpdateValue("LastMatchingIds", $NewValue);
253 }
254
259 public function LastMatches()
260 {
261 return explode(",", $this->DB->Query(
262 "SELECT LastMatchingIds FROM SavedSearches "
263 ."WHERE SearchId = ".$this->SearchId, "LastMatchingIds"));
264 }
270 public function GetSearchGroupsAsUrlParameters()
271 {
272 return self::TranslateSearchGroupsToUrlParameters($this->SearchGroups());
273 }
274
312 public static function TranslateSearchGroupsToUrlParameters($SearchGroups)
313 {
314 # assume that no parameters will be found
315 $UrlPortion = "";
316
317 # for each group in parameters
318 $Schema = new MetadataSchema();
319 foreach ($SearchGroups as $GroupIndex => $Group)
320 {
321 # if group holds single parameters
322 if ($GroupIndex == "MAIN")
323 {
324 # for each field within group
325 foreach ($Group["SearchStrings"] as $FieldName => $Value)
326 {
327 # add segment to URL for this field
328 if ($FieldName == "XXXKeywordXXX")
329 {
330 $FieldId = "K";
331 }
332 else
333 {
334 $Field = $Schema->GetFieldByName($FieldName);
335 $FieldId = $Field->Id();
336 }
337 if (is_array($Value))
338 {
339 $UrlPortion .= "&F".$FieldId."=";
340 $ValueString = "";
341 foreach ($Value as $SingleValue)
342 {
343 $ValueString .= $SingleValue." ";
344 }
345 $UrlPortion .= urlencode(trim($ValueString));
346 }
347 else
348 {
349 $UrlPortion .= "&F".$FieldId."=".urlencode($Value);
350 }
351 }
352 }
353 else
354 {
355 # convert value based on field type
356 $FieldId = ($GroupIndex[0] == "X")
357 ? substr($GroupIndex, 1)
358 : $GroupIndex;
359 $Field = $Schema->GetField($FieldId);
360 $FieldName = $Field->Name();
361 $Values = self::TranslateValues($Field,
362 $Group["SearchStrings"][$FieldName],
363 "SearchGroup to Database");
364
365 # add values to URL
366 $FirstValue = TRUE;
367 foreach ($Values as $Value)
368 {
369 if ($FirstValue)
370 {
371 $FirstValue = FALSE;
372 $UrlPortion .= "&G".$FieldId."=".$Value;
373 }
374 else
375 {
376 $UrlPortion .= "-".$Value;
377 }
378 }
379 }
380 }
381
382 # trim off any leading "&"
383 if (strlen($UrlPortion)) { $UrlPortion = substr($UrlPortion, 1); }
384
385 # return URL portion to caller
386 return $UrlPortion;
387 }
388
394 public function GetSearchGroupsAsUrlParameterArray()
395 {
396 return self::TranslateSearchGroupsToUrlParameters($this->SearchGroups());
397 }
398
405 public static function TranslateSearchGroupsToUrlParameterArray($SearchGroups)
406 {
407 # assume that no parameters will be found
408 $UrlPortion = array();
409
410 # for each group in parameters
411 $Schema = new MetadataSchema();
412 foreach ($SearchGroups as $GroupIndex => $Group)
413 {
414 # if group holds single parameters
415 if ($GroupIndex == "MAIN")
416 {
417 # for each field within group
418 foreach ($Group["SearchStrings"] as $FieldName => $Value)
419 {
420 # add segment to URL for this field
421 if ($FieldName == "XXXKeywordXXX")
422 {
423 $FieldId = "K";
424 }
425 else
426 {
427 $Field = $Schema->GetFieldByName($FieldName);
428 $FieldId = $Field->Id();
429 }
430 if (is_array($Value))
431 {
432 $ValueString = "";
433 foreach ($Value as $SingleValue)
434 {
435 $ValueString .= $SingleValue." ";
436 }
437
438 $UrlPortion["F".$FieldId] = urlencode(trim($ValueString));
439 }
440 else
441 {
442 $UrlPortion["F".$FieldId] = urlencode($Value);
443 }
444 }
445 }
446 else
447 {
448 # convert value based on field type
449 $FieldId = ($GroupIndex[0] == "X")
450 ? substr($GroupIndex, 1)
451 : $GroupIndex;
452 $Field = $Schema->GetField($FieldId);
453 $FieldName = $Field->Name();
454 $Values = self::TranslateValues($Field,
455 $Group["SearchStrings"][$FieldName],
456 "SearchGroup to Database");
457 $LeadChar = ($Group["Logic"] == SearchEngine::LOGIC_AND)
458 ? "H" : "G";
459
460 # add values to URL
461 $FirstValue = TRUE;
462 foreach ($Values as $Value)
463 {
464 if ($FirstValue)
465 {
466 $FirstValue = FALSE;
467 $UrlPortion[$LeadChar.$FieldId] = $Value;
468 }
469 else
470 {
471 $UrlPortion[$LeadChar.$FieldId] .= "-".$Value;
472 }
473 }
474 }
475 }
476
477 # return URL portion to caller
478 return $UrlPortion;
479 }
480
486 public static function TranslateUrlParametersToSearchGroups($GetVars)
487 {
488 # if URL segment was passed in instead of GET var array
489 if (is_string($GetVars))
490 {
491 $GetVars = ParseQueryString($GetVars);
492 }
493
494 # start with empty list of parameters
495 $SearchGroups = array();
496
497 $Schema = new MetadataSchema();
498 $AllFields = $Schema->GetFields(NULL, NULL, TRUE);
499
500 foreach ($AllFields as $Field)
501 {
502 $FieldId = $Field->Id();
503 $FieldName = $Field->Name();
504
505 # if URL included literal value for this field
506 if (isset($GetVars["F".$FieldId]))
507 {
508 # retrieve value and add to search parameters
509 $SearchGroups["MAIN"]["SearchStrings"][$FieldName] =
510 $GetVars["F".$FieldId];
511 }
512
513 # if URL included group value for this field
514 if (isset($GetVars["G".$FieldId]))
515 {
516 # retrieve and parse out values
517 $Values = explode("-", $GetVars["G".$FieldId]);
518
519 # translate values
520 $Values = self::TranslateValues($Field, $Values,
521 "Database to SearchGroup");
522
523 # add values to searchgroups
524 $SearchGroups[$FieldId]["SearchStrings"][$FieldName] = $Values;
525 }
526
527 # if URL included group value for this field
528 if (isset($GetVars["H".$FieldId]))
529 {
530 # retrieve and parse out values
531 $Values = explode("-", $GetVars["H".$FieldId]);
532
533 # translate values
534 $Values = self::TranslateValues($Field, $Values,
535 "Database to SearchGroup");
536
537 # add values to searchgroups
538 $SearchGroups["X".$FieldId]["SearchStrings"][$FieldName] = $Values;
539 }
540 }
541
542 # if keyword pseudo-field was included in URL
543 if (isset($GetVars["FK"]))
544 {
545 # retrieve value and add to search parameters
546 $SearchGroups["MAIN"]["SearchStrings"]["XXXKeywordXXX"] = $GetVars["FK"];
547 }
548
549 # set search logic
550 foreach ($SearchGroups as $GroupIndex => $Group)
551 {
552 $SearchGroups[$GroupIndex]["Logic"] = ($GroupIndex == "MAIN")
553 ? SearchEngine::LOGIC_AND
554 : (($GroupIndex[0] == "X")
555 ? SearchEngine::LOGIC_AND : SearchEngine::LOGIC_OR);
556 }
557
558 # return parameters to caller
559 return $SearchGroups;
560 }
561
572 public function GetSearchGroupsAsTextDescription(
573 $IncludeHtml = TRUE, $StartWithBreak = TRUE, $TruncateLongWordsTo = 0)
574 {
575 return $this->SearchParameters->TextDescription(
576 $IncludeHtml, $StartWithBreak, $TruncateLongWordsTo);
577 }
578
590 public static function TranslateSearchGroupsToTextDescription($SearchGroups,
591 $IncludeHtml = TRUE, $StartWithBreak = TRUE, $TruncateLongWordsTo = 0)
592 {
593 $Schema = new MetadataSchema();
594
595 # start with empty description
596 $Descrip = "";
597
598 # set characters used to indicate literal strings
599 $LiteralStart = $IncludeHtml ? "<i>" : "\"";
600 $LiteralEnd = $IncludeHtml ? "</i>" : "\"";
601 $LiteralBreak = $IncludeHtml ? "<br>\n" : "\n";
602
603 # if this is a simple keyword search
604 if (isset($SearchGroups["MAIN"]["SearchStrings"]["XXXKeywordXXX"])
605 && (count($SearchGroups) == 1)
606 && (count($SearchGroups["MAIN"]["SearchStrings"]) == 1))
607 {
608 # just use the search string
609 $Descrip .= $LiteralStart;
610 $Descrip .= defaulthtmlentities(
611 $SearchGroups["MAIN"]["SearchStrings"]["XXXKeywordXXX"]);
612 $Descrip .= $LiteralEnd . $LiteralBreak;
613 }
614 else
615 {
616 # start description on a new line (if requested)
617 if ($StartWithBreak)
618 {
619 $Descrip .= $LiteralBreak;
620 }
621
622 # define list of phrases used to represent logical operators
623 $WordsForOperators = array(
624 "=" => "is",
625 ">" => "is greater than",
626 "<" => "is less than",
627 ">=" => "is at least",
628 "<=" => "is no more than",
629 "!" => "is not",
630 );
631
632 # for each search group
633 foreach ($SearchGroups as $GroupIndex => $Group)
634 {
635 # if group is main
636 if ($GroupIndex == "MAIN")
637 {
638 # for each field in group
639 foreach ($Group["SearchStrings"] as $FieldName => $Value)
640 {
641 # determine wording based on operator
642 preg_match("/^[=><!]+/", $Value, $Matches);
643 if (count($Matches) && isset($WordsForOperators[$Matches[0]]))
644 {
645 $Value = preg_replace("/^[=><!]+/", "", $Value);
646 $Wording = $WordsForOperators[$Matches[0]];
647 }
648 else
649 {
650 $Wording = "contains";
651 }
652
653 # if field is psuedo-field
654 if ($FieldName == "XXXKeywordXXX")
655 {
656 # add criteria for psuedo-field
657 $Descrip .= "Keyword ".$Wording." "
658 .$LiteralStart.htmlspecialchars($Value)
659 .$LiteralEnd.$LiteralBreak;
660 }
661 else
662 {
663 # if field is valid
664 $Field = $Schema->GetFieldByName($FieldName);
665 if ($Field !== NULL)
666 {
667 # add criteria for field
668 $Descrip .= $Field->GetDisplayName()." ".$Wording." "
669 .$LiteralStart.htmlspecialchars($Value)
670 .$LiteralEnd.$LiteralBreak;
671 }
672 }
673 }
674 }
675 else
676 {
677 # for each field in group
678 $LogicTerm = ($Group["Logic"] == SearchEngine::LOGIC_AND)
679 ? "and " : "or ";
680 foreach ($Group["SearchStrings"] as $FieldName => $Values)
681 {
682 # translate values
683 $Values = self::TranslateValues(
684 $FieldName, $Values, "SearchGroup to Display");
685
686 # for each value
687 $FirstValue = TRUE;
688 foreach ($Values as $Value)
689 {
690 # determine wording based on operator
691 preg_match("/^[=><!]+/", $Value, $Matches);
692 $Operator = $Matches[0];
693 $Wording = $WordsForOperators[$Operator];
694
695 # strip off operator
696 $Value = preg_replace("/^[=><!]+/", "", $Value);
697
698 # add text to description
699 if ($FirstValue)
700 {
701 $Descrip .= $FieldName." ".$Wording." "
702 .$LiteralStart.htmlspecialchars($Value)
703 .$LiteralEnd.$LiteralBreak;
704 $FirstValue = FALSE;
705 }
706 else
707 {
708 $Descrip .= ($IncludeHtml ?
709 "&nbsp;&nbsp;&nbsp;&nbsp;" : " ")
710 .$LogicTerm.$Wording." ".$LiteralStart
711 .htmlspecialchars($Value).$LiteralEnd
712 .$LiteralBreak;
713 }
714 }
715 }
716 }
717 }
718 }
719
720 # if caller requested that long words be truncated
721 if ($TruncateLongWordsTo > 4)
722 {
723 # break description into words
724 $Words = explode(" ", $Descrip);
725
726 # for each word
727 $NewDescrip = "";
728 foreach ($Words as $Word)
729 {
730 # if word is longer than specified length
731 if (strlen(strip_tags($Word)) > $TruncateLongWordsTo)
732 {
733 # truncate word and add ellipsis
734 $Word = NeatlyTruncateString($Word, $TruncateLongWordsTo - 3);
735 }
736
737 # add word to new description
738 $NewDescrip .= " ".$Word;
739 }
740
741 # set description to new description
742 $Descrip = $NewDescrip;
743 }
744
745 # return description to caller
746 return $Descrip;
747 }
748
753 public function GetSearchFieldNames()
754 {
755 return $this->SearchParameters->GetFields();
756 }
757
763 public static function TranslateSearchGroupsToSearchFieldNames($SearchGroups)
764 {
765 # start out assuming no fields are being searched
766 $FieldNames = array();
767
768 # for each search group defined
769 foreach ($SearchGroups as $GroupIndex => $Group)
770 {
771 # for each field in group
772 foreach ($Group["SearchStrings"] as $FieldName => $Values)
773 {
774 # add field name to list of fields being searched
775 $FieldNames[] = $FieldName;
776 }
777 }
778
779 # return list of fields being searched to caller
780 return $FieldNames;
781 }
782
788 public static function GetSearchFrequencyList()
789 {
790 # define list with descriptions
791 $FreqDescr = array(
792 self::SEARCHFREQ_NEVER => "Never",
793 self::SEARCHFREQ_HOURLY => "Hourly",
794 self::SEARCHFREQ_DAILY => "Daily",
795 self::SEARCHFREQ_WEEKLY => "Weekly",
796 self::SEARCHFREQ_BIWEEKLY => "Biweekly",
797 self::SEARCHFREQ_MONTHLY => "Monthly",
798 self::SEARCHFREQ_QUARTERLY => "Quarterly",
799 self::SEARCHFREQ_YEARLY => "Yearly",
800 );
801
802 # for each argument passed in
803 $Args = func_get_args();
804 foreach ($Args as $Arg)
805 {
806 # remove value from list
807 $FreqDescr = array_diff_key($FreqDescr, array($Arg => ""));
808 }
809
810 # return list to caller
811 return $FreqDescr;
812 }
813
817 public function Delete()
818 {
819 $this->DB->Query("DELETE FROM SavedSearches"
820 ." WHERE SearchId = ".intval($this->SearchId));
821 }
822
823
824 # ---- PRIVATE INTERFACE -------------------------------------------------
825
826 private $SearchId;
827 private $Record;
828 private $SearchGroups;
829
844 private static function TranslateValues($FieldOrFieldName, $Values, $TranslationType)
845 {
846 # start out assuming we won't find any values to translate
847 $ReturnValues = array();
848
849 # convert field name to field object if necessary
850 if (is_object($FieldOrFieldName))
851 {
852 $Field = $FieldOrFieldName;
853 }
854 else
855 {
856 static $Schema;
857 if (!isset($Schema)) { $Schema = new MetadataSchema(); }
858 $Field = $Schema->GetFieldByName($FieldOrFieldName);
859 }
860
861 # if incoming value is not an array
862 if (!is_array($Values))
863 {
864 # convert incoming value to an array
865 $Values = array($Values);
866 }
867
868 # for each incoming value
869 foreach ($Values as $Value)
870 {
871 switch ($TranslationType)
872 {
873 case "SearchGroup to Display":
874 # if field is Flag field
875 if ($Field->Type() == MetadataSchema::MDFTYPE_FLAG)
876 {
877 # translate value to true/false label and add leading operator
878 $ReturnValues[] = ($Value == "=1") ?
879 "=".$Field->FlagOnLabel() : "=".$Field->FlagOffLabel();
880 }
881 elseif ($Field->Name() == "Cumulative Rating")
882 {
883 # translate numeric value to stars
884 $StarStrings = array(
885 "20" => "*",
886 "40" => "**",
887 "60" => "***",
888 "80" => "****",
889 "100" => "*****",
890 );
891 preg_match("/[0-9]+$/", $Value, $Matches);
892 $Number = $Matches[0];
893 preg_match("/^[=><!]+/", $Value, $Matches);
894 $Operator = $Matches[0];
895 $ReturnValues[] = $Operator.$StarStrings[$Number];
896 }
897 else
898 {
899 # use value as is
900 $ReturnValues[] = $Value;
901 }
902 break;
903
904 case "SearchGroup to Database":
905 # strip off leading operator on value
906 $Value = preg_replace("/^[=><!]+/", "", $Value);
907
908 # look up index for value
909 if ($Field->Type() & (MetadataSchema::MDFTYPE_FLAG |
910 MetadataSchema::MDFTYPE_NUMBER))
911 {
912 # (for flag or number fields the value index is already
913 # what is used in SearchGroups)
914 if ($Value >= 0)
915 {
916 $ReturnValues[] = $Value;
917 }
918 }
919 elseif ($Field->Type() == MetadataSchema::MDFTYPE_USER)
920 {
921 # (for user fields the value index is the user ID)
922 $User = new CWUser(strval($Value));
923 if ($User)
924 {
925 $ReturnValues[] = $User->Id();
926 }
927 }
928 elseif ($Field->Type() == MetadataSchema::MDFTYPE_OPTION)
929 {
930 if (!isset($PossibleFieldValues))
931 {
932 $PossibleFieldValues = $Field->GetPossibleValues();
933 }
934 $NewValue = array_search($Value, $PossibleFieldValues);
935 if ($NewValue !== FALSE)
936 {
937 $ReturnValues[] = $NewValue;
938 }
939 }
940 else
941 {
942 $NewValue = $Field->GetIdForValue($Value);
943 if ($NewValue !== NULL)
944 {
945 $ReturnValues[] = $NewValue;
946 }
947 }
948 break;
949
950 case "Database to SearchGroup":
951 # look up value for index
952 if ($Field->Type() == MetadataSchema::MDFTYPE_FLAG)
953 {
954 # (for flag fields the value index (0 or 1) is already
955 # what is used in Database)
956 if ($Value >= 0)
957 {
958 $ReturnValues[] = "=".$Value;
959 }
960 }
961 elseif ($Field->Type() == MetadataSchema::MDFTYPE_NUMBER)
962 {
963 # (for flag fields the value index (0 or 1) is already
964 # what is used in Database)
965
966 if ($Value >= 0)
967 {
968 $ReturnValues[] = ">=".$Value;
969 }
970 }
971 elseif ($Field->Type() == MetadataSchema::MDFTYPE_USER)
972 {
973 $User = new CWUser(intval($Value));
974 if ($User)
975 {
976 $ReturnValues[] = "=".$User->Get("UserName");
977 }
978 }
979 elseif ($Field->Type() == MetadataSchema::MDFTYPE_OPTION)
980 {
981 if (!isset($PossibleFieldValues))
982 {
983 $PossibleFieldValues = $Field->GetPossibleValues();
984 }
985
986 if (isset($PossibleFieldValues[$Value]))
987 {
988 $ReturnValues[] = "=".$PossibleFieldValues[$Value];
989 }
990 }
991 else
992 {
993 $NewValue = $Field->GetValueForId($Value);
994 if ($NewValue !== NULL)
995 {
996 $ReturnValues[] = "=".$NewValue;
997 }
998 }
999 break;
1000 }
1001 }
1002
1003 # return array of translated values to caller
1004 return $ReturnValues;
1005 }
1006
1009 # utility function for updating values in database
1010
1016 private function UpdateValue($FieldName, $NewValue)
1017 {
1018 return $this->DB->UpdateValue("SavedSearches", $FieldName, $NewValue,
1019 "SearchId = ".$this->SearchId, $this->Record);
1020 }
1021
1027 public function GetSearchId()
1028 {
1029 return $this->Id();
1030 }
1031
1033 }
SavedSearch\SEARCHFREQ_WEEKLY
const SEARCHFREQ_WEEKLY
Definition: SavedSearch.php:19
SavedSearch\SEARCHFREQ_NEVER
const SEARCHFREQ_NEVER
Definition: SavedSearch.php:16
SPTSearchEngine
Definition: SPTSearchEngine.php:10
SavedSearch\TranslateUrlParametersToSearchGroups
static TranslateUrlParametersToSearchGroups($GetVars)
Translate URL parameters to legacy search group array.
Definition: SavedSearch.php:486
MetadataSchema
Metadata schema (in effect a Factory class for MetadataField).
Definition: MetadataSchema.php:13
SavedSearch\SEARCHFREQ_DAILY
const SEARCHFREQ_DAILY
Definition: SavedSearch.php:18
SearchParameterSet
Set of parameters used to perform a search.
Definition: SearchParameterSet.php:13
SavedSearch\UpdateDateLastRun
UpdateDateLastRun()
Update date this search was last run.
Definition: SavedSearch.php:228
Database
SQL database abstraction object with smart query caching.
Definition: Database.php:22
SavedSearch\GetSearchId
GetSearchId()
Get search id.
Definition: SavedSearch.php:1027
SavedSearch\Id
Id()
Get ID of search.
Definition: SavedSearch.php:199
SavedSearch\TranslateSearchGroupsToUrlParameterArray
static TranslateSearchGroupsToUrlParameterArray($SearchGroups)
Translate a search group array to an URL parameter array.
Definition: SavedSearch.php:405
MetadataSchema\MDFTYPE_NUMBER
const MDFTYPE_NUMBER
Definition: MetadataSchema.php:23
SavedSearch\SEARCHFREQ_QUARTERLY
const SEARCHFREQ_QUARTERLY
Definition: SavedSearch.php:22
MetadataSchema\MDFTYPE_OPTION
const MDFTYPE_OPTION
Definition: MetadataSchema.php:29
SavedSearch\UserId
UserId($NewValue=DB_NOVALUE)
Get/set user ID.
Definition: SavedSearch.php:209
SearchEngine\LOGIC_OR
const LOGIC_OR
Definition: SearchEngine.php:20
MetadataSchema\MDFTYPE_FLAG
const MDFTYPE_FLAG
Definition: MetadataSchema.php:26
SavedSearch\Frequency
Frequency($NewValue=DB_NOVALUE)
Get/set search frequency.
Definition: SavedSearch.php:219
SavedSearch\SEARCHFREQ_YEARLY
const SEARCHFREQ_YEARLY
Definition: SavedSearch.php:23
SavedSearch\SEARCHFREQ_HOURLY
const SEARCHFREQ_HOURLY
Definition: SavedSearch.php:17
SearchEngine\LOGIC_AND
const LOGIC_AND
Definition: SearchEngine.php:19
SavedSearch\SEARCHFREQ_BIWEEKLY
const SEARCHFREQ_BIWEEKLY
Definition: SavedSearch.php:20
PHP
PHP
Definition: RSSClient--Test.php:12
SavedSearch\TranslateSearchGroupsToTextDescription
static TranslateSearchGroupsToTextDescription($SearchGroups, $IncludeHtml=TRUE, $StartWithBreak=TRUE, $TruncateLongWordsTo=0)
Translate search group array into multi-line string describing search criteria.
Definition: SavedSearch.php:590
DB_NOVALUE
const DB_NOVALUE
Definition: Database.php:1706
SavedSearch\DateLastRun
DateLastRun($NewValue=DB_NOVALUE)
Get/set the date this search was last run.
Definition: SavedSearch.php:240
SavedSearch\SEARCHFREQ_MONTHLY
const SEARCHFREQ_MONTHLY
Definition: SavedSearch.php:21
SavedSearch\TranslateSearchGroupsToUrlParameters
static TranslateSearchGroupsToUrlParameters($SearchGroups)
Translate search group array into URL parameters (e.g.
Definition: SavedSearch.php:312
SavedSearch\GetSearchGroupsAsTextDescription
GetSearchGroupsAsTextDescription($IncludeHtml=TRUE, $StartWithBreak=TRUE, $TruncateLongWordsTo=0)
Get multi-line string describing search criteria.
Definition: SavedSearch.php:572
SavedSearch\SearchGroups
SearchGroups($NewSearchGroups=NULL)
Get/set search parameters from legacy array.
Definition: SavedSearch.php:143
SavedSearch\GetSearchFieldNames
GetSearchFieldNames()
Get list of fields to be searched.
Definition: SavedSearch.php:753
SavedSearch\__construct
__construct($SearchId, $SearchName=NULL, $UserId=NULL, $Frequency=NULL, $SearchParameters=NULL)
Object constructor.
Definition: SavedSearch.php:34
SavedSearch\Delete
Delete()
Delete saved search.
Definition: SavedSearch.php:817
MetadataSchema\MDFTYPE_USER
const MDFTYPE_USER
Definition: MetadataSchema.php:30
SavedSearch\SearchName
SearchName($NewValue=DB_NOVALUE)
Get/set name of search.
Definition: SavedSearch.php:190
SavedSearch\GetSearchGroupsAsUrlParameterArray
GetSearchGroupsAsUrlParameterArray()
Get search groups as an URL parameter array.
Definition: SavedSearch.php:394
SavedSearch\GetSearchGroupsAsUrlParameters
GetSearchGroupsAsUrlParameters()
Get search groups as URL parameters (e.g.
Definition: SavedSearch.php:270
SavedSearch\LastMatches
LastMatches()
Return array of most recently matched ResourceIds for a search.
Definition: SavedSearch.php:259
ResourceFactory
Factory for Resource objects.
Definition: ResourceFactory.php:13
CWUser
CWIS-specific user class.
Definition: CWUser.php:13
SavedSearch\SearchParameters
SearchParameters($NewParams=NULL)
Get/set search parameters.
Definition: SavedSearch.php:161
SavedSearch\GetSearchFrequencyList
static GetSearchFrequencyList()
Get array of possible search frequency descriptions.
Definition: SavedSearch.php:788
SavedSearch\TranslateSearchGroupsToSearchFieldNames
static TranslateSearchGroupsToSearchFieldNames($SearchGroups)
Extract list of fields to be searched from search group array.
Definition: SavedSearch.php:763
SavedSearch
Definition: SavedSearch.php:10
SavedSearch\SaveLastMatches
SaveLastMatches($ArrayofMatchingIds)
Save array of last matches.
Definition: SavedSearch.php:249