3 # FILE: ResourceFactory.php 5 # Part of the Collection Workflow Integration System (CWIS) 6 # Copyright 2011-2013 Edward Almasy and Internet Scout Research Group 7 # http://scout.wisc.edu/cwis/ 15 # ---- PUBLIC INTERFACE -------------------------------------------------- 28 # set up item factory base class 29 parent::__construct(
"Resource",
"Resources",
"ResourceId", NULL, FALSE,
30 "SchemaId = ".intval($this->SchemaId));
49 # check that resource to be duplicated exists 52 throw new InvalidArgumentException(
53 "No resource found with specified ID (".$ResourceId.
").");
56 # create new target resource 59 # load up resource to duplicate 60 $SrcResource =
new Resource($ResourceId);
62 # for each metadata field 63 $Fields = $this->
Schema->GetFields();
64 foreach ($Fields as $Field)
66 if ($Field->CopyOnResourceDuplication())
68 $NewValue = $SrcResource->GetByField($Field, TRUE);
70 # clear default value from destination resource that is 71 # set when creating a new resource 72 $DstResource->ClearByField($Field);
74 # copy value from source resource to destination resource 75 $DstResource->SetByField($Field, $NewValue);
79 # return new resource to caller 98 $In =
new XMLReader();
99 $Result = $In->open($FileName);
101 # throw exception if file could not be opened 102 if ($Result === FALSE)
104 throw new Exception(
"Unable to open file: ".$FileName);
107 # load possible tag names 108 $PossibleTags = array();
110 $Fields = $this->
Schema->GetFields();
111 foreach ($Fields as $FieldId => $Field)
113 $NormalizedName = preg_replace(
114 "/[^A-Za-z0-9]/",
"", $Field->Name());
115 $PossibleTags[$NormalizedName] = $Field;
118 # arrays to hold ControlledName and Classification factories 122 # while XML left to read 123 $NewResourceIds = array();
127 if ($In->nodeType == XMLReader::ELEMENT)
129 # if node indicates start of resource 130 if ($In->name ===
"Resource")
132 # if we already had a resource make it non-temporary 133 if (isset($Resource))
135 $Resource->IsTempResource(FALSE);
136 $NewResourceIds[] = $Resource->Id();
139 # create a new resource 142 # else if node is in list of possible tags 143 elseif (array_key_exists($In->name, $PossibleTags))
145 # if we have a current resource 146 if (isset($Resource))
148 # retrieve field and value 149 $DBFieldName = $In->name;
150 $Field = $PossibleTags[$DBFieldName];
155 # set value in resource based on field type 156 switch ($Field->Type())
164 $Resource->Set($Field, $Value);
168 $Resource->Set($Field,
169 (strtoupper($Value) ==
"TRUE") ? TRUE : FALSE);
174 if (!isset($CNFacts[$Field->Id()]))
176 $CNFacts[$Field->Id()] = $Field->GetFactory();
179 $CName = $CNFacts[$Field->Id()]->GetItemByName($Value);
182 $CNFacts[$Field->Id()]->ClearCaches();
185 $Resource->Set($Field, $CName);
189 if (!isset($CFacts[$Field->Id()]))
191 $CFacts[$Field->Id()] = $Field->GetFactory();
194 $Class = $CFacts[$Field->Id()]->GetItemByName($Value);
197 $CFacts[$Field->Id()]->ClearCaches();
200 $Resource->Set($Field, $Class);
204 list($Point[
"X"], $Point[
"Y"]) = explode(
",", $Value);
205 $Resource->Set($Field, $Point);
209 if (preg_match(
"/^[0-9]+\$/", $Value))
211 $Value = intval($Value);
213 $Resource->Set($Field, $Value);
229 # make final resource (if any) non-temporary 230 if (isset($Resource))
232 $Resource->IsTempResource(FALSE);
233 $NewResourceIds[] = $Resource->Id();
239 # report to caller what resources were added 240 return $NewResourceIds;
251 # sanitize qualifier ID or retrieve from object 252 $QualifierId = is_object($ObjectOrId)
253 ? $ObjectOrId->Id() : intval($ObjectOrId);
255 # if new qualifier passed in 256 if ($NewObjectOrId !== NULL)
258 # sanitize qualifier ID to change to or retrieve it from object 259 $NewQualifierIdVal = is_object($NewObjectOrId)
260 ? $NewObjectOrId->Id() : intval($NewObjectOrId);
264 # qualifier should be cleared 265 $NewQualifierIdVal =
"NULL";
268 # for each metadata field 269 $Fields = $this->
Schema->GetFields();
270 foreach ($Fields as $Field)
272 # if field uses qualifiers and uses item-level qualifiers 273 $QualColName = $Field->DBFieldName().
"Qualifier";
274 if ($Field->UsesQualifiers()
275 && $Field->HasItemLevelQualifiers()
276 && $this->DB->FieldExists(
"Resources", $QualColName))
278 # set all occurrences to new qualifier value 279 $this->DB->Query(
"UPDATE Resources" 280 .
" SET ".$QualColName.
" = ".$NewQualifierIdVal.
"" 281 .
" WHERE ".$QualColName.
" = '".$QualifierId.
"'" 282 .
" AND SchemaId = ".intval($this->SchemaId));
286 # clear or change qualifier association with controlled names 287 # (NOTE: this should probably be done in a controlled name factory object) 288 $this->DB->Query(
"UPDATE ControlledNames" 289 .
" SET QualifierId = ".$NewQualifierIdVal
290 .
" WHERE QualifierId = '".$QualifierId.
"'");
292 # clear or change qualifier association with classifications 293 # (NOTE: this should probably be done in a classification factory object) 294 $this->DB->Query(
"UPDATE Classifications" 295 .
" SET QualifierId = ".$NewQualifierIdVal
296 .
" WHERE QualifierId = '".$QualifierId.
"'");
305 return $this->DB->Query(
306 "SELECT COUNT(DISTINCT ResourceId) AS ResourceCount" 307 .
" FROM ResourceRatings",
317 return $this->DB->Query(
318 "SELECT COUNT(DISTINCT UserId) AS UserCount" 319 .
" FROM ResourceRatings",
333 $Count = 10, $Offset = 0, $MaxDaysToGoBack = 90)
335 # assume that no resources will be found 336 $Resources = array();
338 # calculate cutoff date for resources 339 $CutoffDate = date(
"Y-m-d H:i:s", strtotime($MaxDaysToGoBack.
" days ago"));
341 # query for resource IDs 342 $this->DB->Query(
"SELECT ResourceId FROM Resources WHERE" 343 .
" DateOfRecordRelease > '".$CutoffDate.
"'" 344 .
" AND ResourceId >= 0" 345 .
" AND SchemaId = ".intval($this->SchemaId)
346 .
" ORDER BY DateOfRecordRelease DESC, DateOfRecordCreation DESC");
347 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
349 # filter out resources that aren't viewable to current user 351 $ResourceIds, $GLOBALS[
"G_User"] );
353 # subset the results as requested 354 $ResourceIds = array_slice(
355 $ResourceIds, $Offset, $Count);
357 # for each resource ID found 358 foreach ($ResourceIds as $ResourceId)
360 # load resource and add to list of found resources 361 $Resources[$ResourceId] =
new Resource($ResourceId);
364 # return found resources to caller 378 # assume no resources will be found 379 $ResourceIds = array();
382 if ($this->
Schema->FieldExists($FieldId))
384 $Field = $this->
Schema->GetField($FieldId);
385 # construct query based on field type 386 switch ($Field->Type())
391 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 392 .
" FROM Resources WHERE " 393 .$Field->DBFieldName().
" IS NOT NULL" 394 .
" AND LENGTH(LTRIM(RTRIM(".$Field->DBFieldName().
"))) > 0" 395 .
" AND SchemaId = ".intval($this->SchemaId),
399 $Query =
"SELECT ResourceId FROM Resources" 400 .
" WHERE SchemaId = ".intval($this->SchemaId)
401 .
" ORDER BY ".$Field->DBFieldName()
402 .($Ascending ?
" ASC" :
" DESC");
408 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 409 .
" FROM Resources WHERE " 410 .$Field->DBFieldName().
" IS NOT NULL" 411 .
" AND SchemaId = ".intval($this->SchemaId),
415 $Query =
"SELECT ResourceId FROM Resources" 416 .
" WHERE SchemaId = ".intval($this->SchemaId)
417 .
" ORDER BY ".$Field->DBFieldName()
418 .($Ascending ?
" ASC" :
" DESC");
423 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 424 .
" FROM Resources WHERE " 425 .$Field->DBFieldName().
"Begin IS NOT NULL" 426 .
" AND SchemaId = ".intval($this->SchemaId),
430 $Query =
"SELECT ResourceId FROM Resources" 431 .
" WHERE SchemaId = ".intval($this->SchemaId)
432 .
" ORDER BY ".$Field->DBFieldName().
"Begin" 433 .($Ascending ?
" ASC" :
" DESC");
438 # if appropriate query was found 441 # if limited number of results were requested 445 $Query .=
" LIMIT ".intval($Limit);
448 # perform query and retrieve resource IDs 449 $this->DB->Query($Query);
450 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
454 # return resource IDs to caller 466 # compute this user's class 467 $UserClass = $this->ComputeUserClass($User);
469 # generate an array where the keys are ResourceIds affected by 470 # user comparisons for the current user 471 $UserComparisonsRIDs = array_flip(
472 $this->ResourcesWhereUserComparisonsMatterForViewing($User));
474 # (Note: We can use the $UserClass without a schema prefix as 475 # a cache key even though User Classes are schema specific 476 # because the values we're caching are ResourceIds. Since the 477 # ResourceIds already imply a schema, there's no ambiguity 478 # regarding which schema was involved when the stored UserClass 480 if (!isset(self::$UserClassPermissionsCache[$UserClass]))
482 # grab all the ResourceIds for this user class 483 $this->DB->Query(
"SELECT ResourceId, CanView FROM UserPermsCache WHERE" 484 .
" UserClass='".$UserClass.
"'");
486 self::$UserClassPermissionsCache[$UserClass] = $this->DB->FetchColumn(
487 "CanView",
"ResourceId");
490 # filter out those not requested 491 $Cache = array_intersect_key(
492 self::$UserClassPermissionsCache[$UserClass],
493 array_flip($ResourceIds) );
495 # figure out which resources we didn't have cached values for 496 # and iterate over those 497 $MissingIds = array_diff($ResourceIds, array_keys($Cache));
499 $PerUserKey = $this->SchemaId.
".UID_".$User->Id();
501 # batch inserts up into not more than 1000 resources per query 503 $QueryValues = array();
504 foreach ($MissingIds as $Id)
506 if (isset(self::$PerUserPermissionsCache[$PerUserKey]))
508 $CanView = self::$PerUserPermissionsCache[$PerUserKey];
512 # evaluate perms for this resource 516 $CanView = $Resource->UserCanView($User, FALSE);
523 # if this is a result we can cache persistently 524 # (i.e. not affected by user comparisons), do so 525 if (!isset($UserComparisonsRIDs[$Id]))
527 self::$UserClassPermissionsCache[$UserClass][$Id] = $CanView;
529 # add this to our queue of inserts 530 $QueryValues[]=
"(".$Id.
",'".$UserClass.
"',".($CanView?
"1":
"0").
")" ;
532 # if this chunk is full, insert it into the db and clear our queue 533 if (count($QueryValues)>=$ChunkSize)
536 "INSERT INTO UserPermsCache (ResourceId, UserClass, CanView) " 537 .
"VALUES ".implode(
",", $QueryValues) );
538 $QueryValues = array();
543 # this isn't a result we should cache persistently 544 # in the database, but we still want to cache it 545 # within this page load 546 self::$PerUserPermissionsCache[$PerUserKey] = $CanView;
550 $Cache[$Id] = $CanView;
553 # if we have values left to insert, do so 554 if (count($QueryValues))
557 "INSERT INTO UserPermsCache (ResourceId, UserClass, CanView) " 558 .
"VALUES ".implode(
",", $QueryValues) );
561 # if resource view permission check has any handlers that may 562 # modify our cached values 563 if ($GLOBALS[
"AF"]->IsHookedEvent(
"EVENT_RESOURCE_VIEW_PERMISSION_CHECK"))
565 # apply hooked functions to each value 566 foreach (array_keys($Cache) as $Id)
568 $SignalResult = $GLOBALS[
"AF"]->SignalEvent(
569 "EVENT_RESOURCE_VIEW_PERMISSION_CHECK",
573 "CanView" => $Cache[$Id],
574 "Schema" => $this->
Schema, ));
575 $Cache[$Id] = $SignalResult[
"CanView"];
579 # filter out the non-viewable resources, preserving the order 581 return array_intersect($ResourceIds,
582 array_keys(array_filter($Cache)) );
592 # retrieve field names from schema 593 $FieldNames = array();
594 $Fields = $this->
Schema->GetFields();
595 foreach ($Fields as $Field)
597 $FieldNames[$Field->Id()] = $Field->Name();
600 # return field names to caller 618 $ValuesToMatch, $AllRequired=TRUE, $ReturnObjects=TRUE,
621 # start out assuming we won't find any resources 622 $Resources = array();
624 # fix up equality operator 625 if ($Operator ==
"==")
634 $Fields = $this->
Schema->GetFields();
635 foreach ($ValuesToMatch as $FieldId => $Value)
637 # only equality supported for NULL 638 if ($Operator !=
"=" && $Value ==
"NULL")
641 "Invalid operator, ".$Operator.
" not supported for NULL");
644 # convert supplied FieldId to canonical identifier 646 $FieldId, $this->SchemaId);
648 # check that provided operator is sane 649 switch ($Fields[$FieldId]->Type())
656 $ValidOps = array(
"=");
660 $ValidOps = array(
"=",
"!=");
666 $ValidOps = array(
"=",
"!=",
"<",
"<=",
">",
">=");
673 if (!in_array($Operator, $ValidOps))
675 throw new Exception(
"Operator ".$Operator.
" not supported for " 676 .$Fields[$FieldId]->TypeAsName().
" fields");
679 # add SQL fragments to Condition as needed 680 switch ($Fields[$FieldId]->Type())
689 $DBFname = $Fields[$FieldId]->DBFieldName();
690 # add comparison to condition 691 if ($Value ==
"NULL")
693 $Condition .= $LinkingTerm.
"(" 694 .$DBFname.
" IS NULL OR ".$DBFname.
" = '')";
698 $Condition .= $LinkingTerm.$DBFname.
" " 699 .$Operator.
" '".addslashes($Value).
"'";
704 $DBFname = $Fields[$FieldId]->DBFieldName();
706 if ($Value ==
"NULL")
708 $Condition .= $LinkingTerm.
"(" 709 .$DBFname.
"X IS NULL AND " 710 .$DBFname.
"Y IS NULL)";
714 $Vx = addslashes($Value[
"X"]);
715 $Vy = addslashes($Value[
"Y"]);
717 $Condition .= $LinkingTerm.
"(" 718 .$DBFname.
"X = '".$Vx.
"' AND " 719 .$DBFname.
"Y = '".$Vy.
"')";
724 $TgtValues = array();
725 if (is_object($Value))
727 $TgtValues[]= $Value->Id();
729 elseif (is_numeric($Value))
731 $TgtValues[]= $Value;
733 elseif (is_array($Value))
735 foreach ($Value as $UserId => $UserNameOrObject)
737 $TgtValues[]= $UserId;
741 # if no users were specified 742 if (!count($TgtValues))
744 # return no results (nothing matches nothing) 749 # add conditional to match specified users 750 $Condition .= $LinkingTerm.
"(" 751 .
"ResourceId IN (SELECT ResourceId FROM " 752 .
"ResourceUserInts WHERE FieldId=".intval($FieldId)
754 .implode(
",", $TgtValues).
")) )";
759 throw new Exception(
"Unsupported field type");
762 $LinkingTerm = $AllRequired ?
" AND " :
" OR ";
765 # if there were valid conditions 766 if (strlen($Condition))
768 # build query statment 769 $Query =
"SELECT ResourceId FROM Resources WHERE (".$Condition
770 .
") AND SchemaId = ".intval($this->SchemaId);
772 # execute query to retrieve matching resource IDs 773 $this->DB->Query($Query);
774 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
778 # retrieve resource objects 779 foreach ($ResourceIds as $Id)
781 $Resources[$Id] =
new Resource($Id);
786 $Resources = $ResourceIds;
790 # return any resources found to caller 806 $ValueId, $User, $ForegroundUpdate=FALSE)
808 # if the specified user is matched by any UserIs or UserIsNot 809 # privset conditions for any resources, then put them in a class 811 $UserClass = count($this->ResourcesWhereUserComparisonsMatterForViewing($User))
812 ?
"UID_".$User->Id() :
813 $this->ComputeUserClass($User);
815 $CacheKey = $this->SchemaId.
".".$UserClass;
816 # if we haven't loaded any cached values, do so now 817 if (!isset(self::$VisibleResourceCountCache[$CacheKey]))
820 "SELECT ResourceCount, ValueId FROM " 821 .
"VisibleResourceCounts WHERE " 822 .
"SchemaId=".intval($this->SchemaId)
823 .
" AND UserClass='".addslashes($UserClass).
"'");
825 self::$VisibleResourceCountCache[$CacheKey] = $this->DB->FetchColumn(
826 "ResourceCount",
"ValueId");
829 # if we don't have a cached value for this class 830 if (!isset(self::$VisibleResourceCountCache[$CacheKey][$ValueId]))
832 # if we're doing a foreground update 833 if ($ForegroundUpdate)
835 # run the update callback 837 $ValueId, $User->Id());
839 # and call ourselves again 845 # otherwise (for background update), queue the update 846 # callback and return -1 847 $GLOBALS[
"AF"]->QueueUniqueTask(
848 array($this,
"UpdateAssociatedVisibleResourceCount"),
849 array($ValueId, $User->Id() ) );
854 # owtherwise, return the cached data 855 return self::$VisibleResourceCountCache[$CacheKey][$ValueId];
867 $User =
new CWUser($UserId);
869 # if the specified user is matched by any UserIs or UserIsNot 870 # privset conditions for any resources, then put them in a class 872 $UserClass = count($this->ResourcesWhereUserComparisonsMatterForViewing($User))
873 ?
"UID_".$User->Id() :
874 $this->ComputeUserClass($User);
877 "SELECT ResourceId FROM ResourceNameInts " 878 .
"WHERE ControlledNameId=".intval($ValueId) );
879 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
882 $ResourceIds, $User);
884 $ResourceCount = count($ResourceIds);
887 "INSERT INTO VisibleResourceCounts " 888 .
"(SchemaId, UserClass, ValueId, ResourceCount) " 890 .intval($this->SchemaId).
"," 891 .
"'".addslashes($UserClass).
"'," 892 .intval($ValueId).
"," 893 .$ResourceCount.
")");
903 $ResourceIds = $this->DB->Query(
904 "SELECT ResourceId FROM Resources " 905 .
"WHERE ResourceId > 0 AND SchemaId = ".intval($this->SchemaId));
906 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
909 $ResourceIds, $User);
911 return count($ResourceIds);
920 # and clear our visible resource count cache 922 "DELETE FROM VisibleResourceCounts WHERE " 923 .
"SchemaId=".intval($this->SchemaId).
" AND " 924 .
"ValueId IN (".implode(
",", $ValueIds).
")");
934 # get all the CName and Option fields 935 $Fields = $this->
Schema()->GetFields(
939 # pull out the Values associated with those 941 foreach ($Fields as $Field)
943 $Values += $Resource->Get($Field);
946 # and clear our visible resource count cache 948 array_keys($Values));
971 foreach ($ResourcesPerSchema as
$SchemaId => $ResourceIds)
973 $Result = array_merge($Result, $ResourceIds);
990 $DB->Query(
"SELECT ResourceId, SchemaId FROM Resources");
991 $ResourceSchemas =
$DB->FetchColumn(
"SchemaId",
"ResourceId");
994 foreach ($ResourceIds as $ResourceId)
996 $SchemaId = $ResourceSchemas[$ResourceId];
1010 return $this->DB->Query(
" 1011 SELECT COUNT(*) AS ResourceTotal 1013 WHERE ResourceId > 0 1014 AND SchemaId = ".intval($this->SchemaId),
1024 $DB->Query(
"DELETE FROM UserPermsCache");
1033 self::$VisibleResourceCountCache = array();
1034 self::$UserClassPermissionsCache = array();
1035 self::$PerUserPermissionsCache = array();
1036 self::$UserClassCache = array();
1037 self::$UserComparisonResourceCache = array();
1038 self::$UserComparisonFieldCache = array();
1041 # ---- PRIVATE INTERFACE ------------------------------------------------- 1047 private static $VisibleResourceCountCache;
1048 private static $UserClassPermissionsCache;
1049 private static $PerUserPermissionsCache;
1050 private static $UserClassCache;
1051 private static $UserComparisonResourceCache;
1052 private static $UserComparisonFieldCache;
1061 private function ComputeUserClass($User)
1063 # put the anonymous user into their own user class, otherwise 1064 # use the UserId for a key into the ClassCache 1065 $UserId = $User->IsAnonymous() ?
"XX-ANON-XX" : $User->Id();
1067 $CacheKey = $this->SchemaId.
".".$UserId;
1069 # check if we have a cached UserClass for this User 1070 if (!isset($this->UserClassCache[$CacheKey]))
1072 # assemble a list of the privilege flags (PRIV_SYSADMIN, 1073 # etc) that are checked when evaluating the UserCanView for 1074 # all fields in this schema 1075 $RelevantPerms = array();
1077 foreach ($this->
Schema->GetFields() as $Field)
1079 $RelevantPerms = array_merge(
1081 $Field->ViewingPrivileges()->PrivilegeFlagsChecked() );
1083 $RelevantPerms = array_unique($RelevantPerms);
1085 # whittle the list of all privs checked down to just the 1086 # list of privs that users in this class have 1087 $PermsInvolved = array();
1088 foreach ($RelevantPerms as $Perm)
1090 if ($User->HasPriv($Perm))
1092 $PermsInvolved[]= $Perm;
1096 # generate a string by concatenating all the involved 1097 # permissions then hashing the result (hashing gives 1098 # a fixed-size string for storing in the database) 1099 self::$UserClassCache[$CacheKey] = md5(implode(
"-", $PermsInvolved ));
1102 return self::$UserClassCache[$CacheKey];
1114 private function ResourcesWhereUserComparisonsMatterForViewing($User)
1116 $ResourceIds = array();
1118 # if we're checking the anonymous user, presume that 1119 # nothing will match 1120 if ($User->IsAnonymous())
1122 return $ResourceIds;
1125 $CacheKey = $this->SchemaId.
".".$User->Id();
1126 if (!isset(self::$UserComparisonResourceCache[$CacheKey]))
1130 # for each comparison type 1131 foreach (array(
"==",
"!=") as $ComparisonType)
1133 $UserComparisonFields = $this->GetUserComparisonFields(
1136 # if we have any fields to check 1137 if (count($UserComparisonFields) > 0 )
1139 # query the database for resources where one or more of the 1140 # user comparisons will be satisfied 1141 $SqlOp = ($ComparisonType ==
"==") ?
"= " :
"!= ";
1143 $DB->Query(
"SELECT R.ResourceId as ResourceId FROM ".
1144 "Resources R, ResourceUserInts RU WHERE ".
1145 "R.SchemaId = ".$this->SchemaId.
" AND ".
1146 "R.ResourceId = RU.ResourceId AND ".
1147 "RU.UserId ".$SqlOp.$User->Id().
" AND ".
1148 "RU.FieldId IN (".implode(
",", $UserComparisonFields).
")");
1149 $Result =
$DB->FetchColumn(
"ResourceId");
1151 # merge those resources into our results 1152 $ResourceIds = array_merge(
1158 self::$UserComparisonResourceCache[$CacheKey] = array_unique($ResourceIds);
1161 return self::$UserComparisonResourceCache[$CacheKey];
1170 private function GetUserComparisonFields($ComparisonType)
1172 $CacheKey = $this->SchemaId.
".".$ComparisonType;
1173 if (!isset(self::$UserComparisonFieldCache[$CacheKey]))
1175 # iterate through all the fields in the schema, 1176 # constructing a list of the User fields implicated 1177 # in comparisons of the desired type 1178 $UserComparisonFields = array();
1179 foreach ($this->
Schema->GetFields() as $Field)
1181 $UserComparisonFields = array_merge(
1182 $UserComparisonFields,
1183 $Field->ViewingPrivileges()->FieldsWithUserComparisons(
1186 self::$UserComparisonFieldCache[$CacheKey] =
1187 array_unique($UserComparisonFields);
1190 return self::$UserComparisonFieldCache[$CacheKey];
GetMatchingResources($ValuesToMatch, $AllRequired=TRUE, $ReturnObjects=TRUE, $Operator="==")
Find resources with values that match those specified.
static GetAnonymousUser()
Get the anonymous user (i.e., the User object that exists when no user is logged in), useful when a permission check needs to know if something should be visible to the general public.
AssociatedVisibleResourceCount($ValueId, $User, $ForegroundUpdate=FALSE)
Return the number of resources in this schema that are visible to a specified user and that have a gi...
static FlattenMultiSchemaResourceList($ResourcesPerSchema)
Take an array keyed by SchemaId with elements giving arrays of ResourceIds and merge it to a flattene...
GetRatedResourceUserCount()
Return number of users who have rated resources.
static Create($Term, $FieldId)
Create a new empty ControlledName if it's not already present.
SQL database abstraction object with smart query caching.
static Create($Name, $FieldId, $ParentId=NULL)
Add new classification to the hierarchy.
static BuildMultiSchemaResourceList($ResourceIds)
Take an array of ResourceIds and split it into an array keyed by SchemaId where the elements are arra...
GetResourceIdsSortedBy($FieldId, $Ascending=TRUE, $Limit=NULL)
Get resource IDs sorted by specified field.
UpdateAssociatedVisibleResourceCount($ValueId, $UserId)
Update the count of resources associated with a ControlledName that are visible to a specified user...
GetRecentlyReleasedResources($Count=10, $Offset=0, $MaxDaysToGoBack=90)
Get resources sorted by descending Date of Record Release, with Date of Record Creation as the second...
ImportResourcesFromXmlFile($FileName)
Import resource records from XML file.
static ClearViewingPermsCache()
Clear the cache of viewable resources.
ClearVisibleResourceCountForValues($ValueIds)
Clear cache of visible resources associated with a ControlledName.
FilterNonViewableResources($ResourceIds, $User)
Filter a list of resources leaving only those viewable by a specified user.
ClearQualifier($ObjectOrId, $NewObjectOrId=NULL)
Clear or change specific qualifier for all resources.
ClearCaches()
Clear internal caches.
Represents a "resource" in CWIS.
GetPossibleFieldNames()
Get possible field names for resources.
GetReleasedResourceTotal()
Get the total number of released resources in the collection.
ClearVisibleResourceCount($Resource)
Clear database visibility caches for all the CNames referenced by a specified resource.
Schema()
Get metadata schema associated with this resource factory.
__construct($SchemaId=MetadataSchema::SCHEMAID_DEFAULT)
Class constructor.
static Create($SchemaId)
Create a new resource.
Common factory class for item manipulation.
static ItemExists($Id)
Check whether an item exists with the specified ID.
GetRatedResourceCount()
Return number of resources that have ratings.
Factory for Resource objects.
CWIS-specific user class.
GetResourceTotal()
Get the total number of resources in the collection, even if they are not released.
GetVisibleResourceCount(CWUser $User)
Get the total number of resources visible to a specified user.
DuplicateResource($ResourceId)
Duplicate the specified resource and return to caller.