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 -------------------------------------------------- 25 $this->SchemaId = $SchemaId;
28 # set up item factory base class 29 parent::__construct(
"Resource",
"Resources",
"ResourceId", NULL, FALSE,
30 "SchemaId = ".intval($this->SchemaId));
40 # check that resource to be duplicated exists 43 throw new InvalidArgumentException(
44 "No resource found with specified ID (".$ResourceId.
").");
47 # create new target resource 50 # load up resource to duplicate 51 $SrcResource =
new Resource($ResourceId);
53 # for each metadata field 54 $Fields = $this->Schema->GetFields();
55 foreach ($Fields as $Field)
57 if ($Field->CopyOnResourceDuplication())
59 $NewValue = $SrcResource->GetByField($Field, TRUE);
61 # clear default value from destination resource that is 62 # set when creating a new resource 63 $DstResource->ClearByField($Field);
65 # copy value from source resource to destination resource 66 $DstResource->SetByField($Field, $NewValue);
70 # return new resource to caller 89 $In =
new XMLReader();
90 $Result = $In->open($FileName);
92 # throw exception if file could not be opened 93 if ($Result === FALSE)
95 throw new Exception(
"Unable to open file: ".$FileName);
98 # load possible tag names 99 $PossibleTags = array();
101 $Fields = $this->Schema->GetFields();
102 foreach ($Fields as $FieldId => $Field)
104 $NormalizedName = preg_replace(
105 "/[^A-Za-z0-9]/",
"", $Field->Name());
106 $PossibleTags[$NormalizedName] = $Field;
109 # arrays to hold ControlledName and Classification factories 113 # while XML left to read 114 $NewResourceIds = array();
118 if ($In->nodeType == XMLReader::ELEMENT)
120 # if node indicates start of resource 121 if ($In->name ===
"Resource")
123 # if we already had a resource make it non-temporary 124 if (isset($Resource))
126 $Resource->IsTempResource(FALSE);
127 $NewResourceIds[] = $Resource->Id();
130 # create a new resource 133 # else if node is in list of possible tags 134 elseif (array_key_exists($In->name, $PossibleTags))
136 # if we have a current resource 137 if (isset($Resource))
139 # retrieve field and value 140 $DBFieldName = $In->name;
141 $Field = $PossibleTags[$DBFieldName];
146 # set value in resource based on field type 147 switch ($Field->Type())
155 $Resource->Set($Field, $Value);
159 $Resource->Set($Field,
160 (strtoupper($Value) ==
"TRUE") ? TRUE : FALSE);
165 if (!isset($CNFacts[$Field->Id()]))
167 $CNFacts[$Field->Id()] = $Field->GetFactory();
170 $CName = $CNFacts[$Field->Id()]->GetItemByName($Value);
173 $CNFacts[$Field->Id()]->ClearCaches();
175 NULL, $Value, $Field->Id());
177 $Resource->Set($Field, $CName);
181 if (!isset($CFacts[$Field->Id()]))
183 $CFacts[$Field->Id()] = $Field->GetFactory();
186 $Class = $CFacts[$Field->Id()]->GetItemByName($Value);
189 $CFacts[$Field->Id()]->ClearCaches();
192 $Resource->Set($Field, $Class);
196 list($Point[
"X"], $Point[
"Y"]) = explode(
",", $Value);
197 $Resource->Set($Field, $Point);
201 if (preg_match(
"/^[0-9]+\$/", $Value))
203 $Value = intval($Value);
205 $Resource->Set($Field, $Value);
221 # make final resource (if any) non-temporary 222 if (isset($Resource))
224 $Resource->IsTempResource(FALSE);
225 $NewResourceIds[] = $Resource->Id();
231 # report to caller what resources were added 232 return $NewResourceIds;
243 # sanitize qualifier ID or retrieve from object 244 $QualifierId = is_object($ObjectOrId)
245 ? $ObjectOrId->Id() : intval($ObjectOrId);
247 # if new qualifier passed in 248 if ($NewObjectOrId !== NULL)
250 # sanitize qualifier ID to change to or retrieve it from object 251 $NewQualifierIdVal = is_object($NewObjectOrId)
252 ? $NewObjectOrId->Id() : intval($NewObjectOrId);
256 # qualifier should be cleared 257 $NewQualifierIdVal =
"NULL";
260 # for each metadata field 261 $Fields = $this->Schema->GetFields();
262 foreach ($Fields as $Field)
264 # if field uses qualifiers and uses item-level qualifiers 265 $QualColName = $Field->DBFieldName().
"Qualifier";
266 if ($Field->UsesQualifiers()
267 && $Field->HasItemLevelQualifiers()
268 && $this->DB->FieldExists(
"Resources", $QualColName))
270 # set all occurrences to new qualifier value 271 $this->DB->Query(
"UPDATE Resources" 272 .
" SET ".$QualColName.
" = ".$NewQualifierIdVal.
"" 273 .
" WHERE ".$QualColName.
" = '".$QualifierId.
"'" 274 .
" AND SchemaId = ".intval($this->SchemaId));
278 # clear or change qualifier association with controlled names 279 # (NOTE: this should probably be done in a controlled name factory object) 280 $this->DB->Query(
"UPDATE ControlledNames" 281 .
" SET QualifierId = ".$NewQualifierIdVal
282 .
" WHERE QualifierId = '".$QualifierId.
"'");
284 # clear or change qualifier association with classifications 285 # (NOTE: this should probably be done in a classification factory object) 286 $this->DB->Query(
"UPDATE Classifications" 287 .
" SET QualifierId = ".$NewQualifierIdVal
288 .
" WHERE QualifierId = '".$QualifierId.
"'");
297 return $this->DB->Query(
298 "SELECT COUNT(DISTINCT ResourceId) AS ResourceCount" 299 .
" FROM ResourceRatings",
309 return $this->DB->Query(
310 "SELECT COUNT(DISTINCT UserId) AS UserCount" 311 .
" FROM ResourceRatings",
325 $Count = 10, $Offset = 0, $MaxDaysToGoBack = 90)
327 # assume that no resources will be found 328 $Resources = array();
330 # calculate cutoff date for resources 331 $CutoffDate = date(
"Y-m-d H:i:s", strtotime($MaxDaysToGoBack.
" days ago"));
333 # query for resource IDs 334 $this->DB->Query(
"SELECT ResourceId FROM Resources WHERE" 335 .
" DateOfRecordRelease > '".$CutoffDate.
"'" 336 .
" AND ResourceId >= 0" 337 .
" AND SchemaId = ".intval($this->SchemaId)
338 .
" ORDER BY DateOfRecordRelease DESC, DateOfRecordCreation DESC");
339 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
341 # filter out resources that aren't viewable to the public 345 # subset the results as requested 346 $ResourceIds = array_slice(
347 $ResourceIds, $Offset, $Count);
349 # for each resource ID found 350 foreach ($ResourceIds as $ResourceId)
352 # load resource and add to list of found resources 353 $Resources[$ResourceId] =
new Resource($ResourceId);
356 # return found resources to caller 370 # assume no resources will be found 371 $ResourceIds = array();
374 if ($this->Schema->FieldExists($FieldId))
376 $Field = $this->Schema->GetField($FieldId);
377 # construct query based on field type 378 switch ($Field->Type())
383 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 384 .
" FROM Resources WHERE " 385 .$Field->DBFieldName().
" IS NOT NULL" 386 .
" AND LENGTH(LTRIM(RTRIM(".$Field->DBFieldName().
"))) > 0" 387 .
" AND SchemaId = ".intval($this->SchemaId),
391 $Query =
"SELECT ResourceId FROM Resources" 392 .
" WHERE SchemaId = ".intval($this->SchemaId)
393 .
" ORDER BY ".$Field->DBFieldName()
394 .($Ascending ?
" ASC" :
" DESC");
400 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 401 .
" FROM Resources WHERE " 402 .$Field->DBFieldName().
" IS NOT NULL" 403 .
" AND SchemaId = ".intval($this->SchemaId),
407 $Query =
"SELECT ResourceId FROM Resources" 408 .
" WHERE SchemaId = ".intval($this->SchemaId)
409 .
" ORDER BY ".$Field->DBFieldName()
410 .($Ascending ?
" ASC" :
" DESC");
415 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 416 .
" FROM Resources WHERE " 417 .$Field->DBFieldName().
"Begin IS NOT NULL" 418 .
" AND SchemaId = ".intval($this->SchemaId),
422 $Query =
"SELECT ResourceId FROM Resources" 423 .
" WHERE SchemaId = ".intval($this->SchemaId)
424 .
" ORDER BY ".$Field->DBFieldName().
"Begin" 425 .($Ascending ?
" ASC" :
" DESC");
430 # if appropriate query was found 433 # if limited number of results were requested 437 $Query .=
" LIMIT ".intval($Limit);
440 # perform query and retrieve resource IDs 441 $this->DB->Query($Query);
442 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
446 # return resource IDs to caller 458 # compute this user's class 459 $UserClass = $this->ComputeUserClass($User);
461 # generate an array where the keys are ResourceIds affected by 462 # user comparisons for the current user 463 $UserComparisonsRIDs = array_flip(
464 $this->ResourcesWhereUserComparisonsMatterForViewing($User));
466 # (Note: We can use the $UserClass without a schema prefix as 467 # a cache key even though User Classes are schema specific 468 # because the values we're caching are ResourceIds. Since the 469 # ResourceIds already imply a schema, there's no ambiguity 470 # regarding which schema was involved when the stored UserClass 472 if (!isset(self::$UserClassPermissionsCache[$UserClass]))
474 # grab all the ResourceIds for this user class 475 $this->DB->Query(
"SELECT ResourceId, CanView FROM UserPermsCache WHERE" 476 .
" UserClass='".$UserClass.
"'");
478 self::$UserClassPermissionsCache[$UserClass] = $this->DB->FetchColumn(
479 "CanView",
"ResourceId");
482 # filter out those not requested 483 $Cache = array_intersect_key(
484 self::$UserClassPermissionsCache[$UserClass],
485 array_flip($ResourceIds) );
487 # figure out which resources we didn't have cached values for 488 # and iterate over those 489 $MissingIds = array_diff($ResourceIds, array_keys($Cache));
491 $PerUserKey = $this->SchemaId.
".UID_".$User->Id();
493 # batch inserts up into not more than 1000 resources per query 495 $QueryValues = array();
496 foreach ($MissingIds as $Id)
498 if (isset(self::$PerUserPermissionsCache[$PerUserKey]))
500 $CanView = self::$PerUserPermissionsCache[$PerUserKey];
504 # evaluate perms for this resource 508 $CanView = $Resource->UserCanView($User, FALSE);
515 # if this is a result we can cache persistently 516 # (i.e. not affected by user comparisons), do so 517 if (!isset($UserComparisonsRIDs[$Id]))
519 self::$UserClassPermissionsCache[$UserClass][$Id] = $CanView;
521 # add this to our queue of inserts 522 $QueryValues[]=
"(".$Id.
",'".$UserClass.
"',".($CanView?
"1":
"0").
")" ;
524 # if this chunk is full, insert it into the db and clear our queue 525 if (count($QueryValues)>=$ChunkSize)
528 "INSERT INTO UserPermsCache (ResourceId, UserClass, CanView) " 529 .
"VALUES ".implode(
",", $QueryValues) );
530 $QueryValues = array();
535 # this isn't a result we should cache persistently 536 # in the database, but we still want to cache it 537 # within this page load 538 self::$PerUserPermissionsCache[$PerUserKey] = $CanView;
542 $Cache[$Id] = $CanView;
545 # if we have values left to insert, do so 546 if (count($QueryValues))
549 "INSERT INTO UserPermsCache (ResourceId, UserClass, CanView) " 550 .
"VALUES ".implode(
",", $QueryValues) );
553 # if resource view permission check has any handlers that may 554 # modify our cached values 555 if ($GLOBALS[
"AF"]->IsHookedEvent(
"EVENT_RESOURCE_VIEW_PERMISSION_CHECK"))
557 # apply hooked functions to each value 558 foreach (array_keys($Cache) as $Id)
560 $SignalResult = $GLOBALS[
"AF"]->SignalEvent(
561 "EVENT_RESOURCE_VIEW_PERMISSION_CHECK",
565 "CanView" => $Cache[$Id],
566 "Schema" => $this->Schema, ));
567 $Cache[$Id] = $SignalResult[
"CanView"];
571 # filter out the non-viewable resources, preserving the order 573 return array_intersect($ResourceIds,
574 array_keys(array_filter($Cache)) );
582 $this->DB->Query(
"DELETE FROM UserPermsCache");
593 # retrieve field names from schema 594 $FieldNames = array();
595 $Fields = $this->Schema->GetFields();
596 foreach ($Fields as $Field)
598 $FieldNames[$Field->Id()] = $Field->Name();
601 # return field names to caller 619 $ValuesToMatch, $AllRequired=TRUE, $ReturnObjects=TRUE,
622 # start out assuming we won't find any resources 623 $Resources = array();
625 # fix up equality operator 626 if ($Operator ==
"==")
635 $Fields = $this->Schema->GetFields();
636 foreach ($ValuesToMatch as $FieldId => $Value)
638 # only equality supported for NULL 639 if ($Operator !=
"=" && $Value ==
"NULL")
642 "Invalid operator, ".$Operator.
" not supported for NULL");
645 # retrieve metadata field ID if not supplied 646 if (!is_numeric($FieldId))
648 $FieldId = $this->Schema->GetFieldIdByName($FieldId);
651 # if we're attempting to search a field that isn't in our schema, 653 if (!isset($Fields[$FieldId]))
656 "Attempt to match values against a field " 657 .
"that doesn't exist in this schema");
660 # check that provided operator is sane 661 switch ($Fields[$FieldId]->Type())
668 $ValidOps = array(
"=");
672 $ValidOps = array(
"=",
"!=");
678 $ValidOps = array(
"=",
"!=",
"<",
"<=",
">",
">=");
685 if (!in_array($Operator, $ValidOps))
687 throw new Exception(
"Operator ".$Operator.
" not supported for " 688 .$Field->TypeAsName().
" fields");
691 # add SQL fragments to Condition as needed 692 switch ($Fields[$FieldId]->Type())
701 $DBFname = $Fields[$FieldId]->DBFieldName();
702 # add comparison to condition 703 if ($Value ==
"NULL")
705 $Condition .= $LinkingTerm.
"(" 706 .$DBFname.
" IS NULL OR ".$DBFname.
" = '')";
710 $Condition .= $LinkingTerm.$DBFname.
" " 711 .$Operator.
" '".addslashes($Value).
"'";
716 $DBFname = $Fields[$FieldId]->DBFieldName();
718 if ($Value ==
"NULL")
720 $Condition .= $LinkingTerm.
"(" 721 .$DBFname.
"X IS NULL AND " 722 .$DBFname.
"Y IS NULL)";
726 $Vx = addslashes($Value[
"X"]);
727 $Vy = addslashes($value[
"Y"]);
729 $Condition .= $LinkingTerm.
"(" 730 .$DBFname.
"X = '".$Vx.
"' AND " 731 .$DBFname.
"Y = '".$Vy.
"')";
736 $TgtValues = array();
737 if (is_object($Value))
739 $TgtValues[]= $Value->Id();
741 elseif (is_numeric($Value))
743 $TgtValues[]= $Value;
745 elseif (is_array($Value))
747 foreach ($Value as $UserId => $UserNameOrObject)
749 $TgtValues[]= $UserId;
753 # if no users were specified 754 if (!count($TgtValues))
756 # return no results (nothing matches nothing) 761 # add conditional to match specified users 762 $Condition .= $LinkingTerm.
"(" 763 .
"ResourceId IN (SELECT ResourceId FROM " 764 .
"ResourceUserInts WHERE FieldId=".intval($FieldId)
766 .implode(
",", $TgtValues).
")) )";
771 throw new Exception(
"Unsupported field type");
774 $LinkingTerm = $AllRequired ?
" AND " :
" OR ";
777 # if there were valid conditions 778 if (strlen($Condition))
780 # build query statment 781 $Query =
"SELECT ResourceId FROM Resources WHERE (".$Condition
782 .
") AND SchemaId = ".intval($this->SchemaId);
784 # execute query to retrieve matching resource IDs 785 $this->DB->Query($Query);
786 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
790 # retrieve resource objects 791 foreach ($ResourceIds as $Id)
793 $Resources[$Id] =
new Resource($Id);
798 $Resources = $ResourceIds;
802 # return any resources found to caller 818 $ValueId, $User, $ForegroundUpdate=FALSE)
820 # if the specified user is matched by any UserIs or UserIsNot 821 # privset conditions for any resources, then put them in a class 823 $UserClass = count($this->ResourcesWhereUserComparisonsMatterForViewing($User))
824 ?
"UID_".$User->Id() :
825 $this->ComputeUserClass($User);
827 $CacheKey = $this->SchemaId.
".".$UserClass;
828 # if we haven't loaded any cached values, do so now 829 if (!isset(self::$VisibleResourceCountCache[$CacheKey]))
832 "SELECT ResourceCount, ValueId FROM " 833 .
"VisibleResourceCounts WHERE " 834 .
"SchemaId=".intval($this->SchemaId)
835 .
" AND UserClass='".addslashes($UserClass).
"'");
837 self::$VisibleResourceCountCache[$CacheKey] = $this->DB->FetchColumn(
838 "ResourceCount",
"ValueId");
841 # if we don't have a cached value for this class 842 if (!isset(self::$VisibleResourceCountCache[$CacheKey][$ValueId]))
844 # if we're doing a foreground update 845 if ($ForegroundUpdate)
847 # run the update callback 849 $ValueId, $User->Id());
851 # grab the newly generated value 852 $NewValue = $this->DB->Query(
853 "SELECT ResourceCount FROM " 854 .
"VisibleResourceCounts WHERE " 855 .
"SchemaId=".intval($this->SchemaId)
856 .
" AND UserClass='".addslashes($UserClass).
"' " 857 .
" AND ValueId=".intval($ValueId),
"ResourceCount");
859 # load it into our local cache 860 self::$VisibleResourceCountCache[$CacheKey][$ValueId] = $NewValue;
864 # otherwise (for background update), queue the update 865 # callback and return -1 866 $GLOBALS[
"AF"]->QueueUniqueTask(
867 array($this,
"UpdateAssociatedVisibleResourceCount"),
868 array($ValueId, $User->Id() ) );
873 # owtherwise, return the cached data 874 return self::$VisibleResourceCountCache[$CacheKey][$ValueId];
886 $User =
new CWUser($UserId);
888 # if the specified user is matched by any UserIs or UserIsNot 889 # privset conditions for any resources, then put them in a class 891 $UserClass = count($this->ResourcesWhereUserComparisonsMatterForViewing($User))
892 ?
"UID_".$User->Id() :
893 $this->ComputeUserClass($User);
896 "SELECT ResourceId FROM ResourceNameInts " 897 .
"WHERE ControlledNameId=".intval($ValueId) );
898 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
901 $ResourceIds, $User);
903 $ResourceCount = count($ResourceIds);
906 "INSERT INTO VisibleResourceCounts " 907 .
"(SchemaId, UserClass, ValueId, ResourceCount) " 909 .intval($this->SchemaId).
"," 910 .
"'".addslashes($UserClass).
"'," 911 .intval($ValueId).
"," 912 .$ResourceCount.
")");
922 $ResourceIds = $this->DB->Query(
923 "SELECT ResourceId FROM Resources " 924 .
"WHERE ResourceId > 0 AND SchemaId = ".intval($this->SchemaId));
925 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
928 $ResourceIds, $User);
930 return count($ResourceIds);
951 return $this->DB->Query(
" 952 SELECT COUNT(*) AS ResourceTotal 955 AND SchemaId = ".intval($this->SchemaId),
965 self::$VisibleResourceCountCache = array();
966 self::$UserClassPermissionsCache = array();
967 self::$PerUserPermissionsCache = array();
968 self::$UserClassCache = array();
969 self::$UserComparisonResourceCache = array();
970 self::$UserComparisonFieldCache = array();
973 # ---- PRIVATE INTERFACE ------------------------------------------------- 979 private static $VisibleResourceCountCache;
980 private static $UserClassPermissionsCache;
981 private static $PerUserPermissionsCache;
982 private static $UserClassCache;
983 private static $UserComparisonResourceCache;
984 private static $UserComparisonFieldCache;
993 private function ComputeUserClass($User)
995 # put the anonymous user into their own user class, otherwise 996 # use the UserId for a key into the ClassCache 997 $UserId = $User->IsAnonymous() ?
"XX-ANON-XX" : $User->Id();
999 $CacheKey = $this->SchemaId.
".".$UserId;
1001 # check if we have a cached UserClass for this User 1002 if (!isset($this->UserClassCache[$CacheKey]))
1004 # assemble a list of the privilege flags (PRIV_SYSADMIN, 1005 # etc) that are checked when evaluating the UserCanView for 1006 # all fields in this schema 1007 $RelevantPerms = array();
1009 foreach ($this->Schema->GetFields() as $Field)
1011 $RelevantPerms = array_merge(
1013 $Field->ViewingPrivileges()->PrivilegeFlagsChecked() );
1015 $RelevantPerms = array_unique($RelevantPerms);
1017 # whittle the list of all privs checked down to just the 1018 # list of privs that users in this class have 1019 $PermsInvolved = array();
1020 foreach ($RelevantPerms as $Perm)
1022 if ($User->HasPriv($Perm))
1024 $PermsInvolved[]= $Perm;
1028 # generate a string by concatenating all the involved 1029 # permissions then hashing the result (hashing gives 1030 # a fixed-size string for storing in the database) 1031 self::$UserClassCache[$CacheKey] = md5(implode(
"-", $PermsInvolved ));
1034 return self::$UserClassCache[$CacheKey];
1046 private function ResourcesWhereUserComparisonsMatterForViewing($User)
1048 $ResourceIds = array();
1050 # if we're checking the anonymous user, presume that 1051 # nothing will match 1052 if ($User->IsAnonymous())
1054 return $ResourceIds;
1057 $CacheKey = $this->SchemaId.
".".$User->Id();
1058 if (!isset(self::$UserComparisonResourceCache[$CacheKey]))
1062 # for each comparison type 1063 foreach (array(
"==",
"!=") as $ComparisonType)
1065 $UserComparisonFields = $this->GetUserComparisonFields(
1068 # if we have any fields to check 1069 if (count($UserComparisonFields) > 0 )
1071 # query the database for resources where one or more of the 1072 # user comparisons will be satisfied 1073 $SqlOp = ($ComparisonType ==
"==") ?
"= " :
"!= ";
1075 $DB->Query(
"SELECT R.ResourceId as ResourceId FROM ".
1076 "Resources R, ResourceUserInts RU WHERE ".
1077 "R.SchemaId = ".$this->SchemaId.
" AND ".
1078 "R.ResourceId = RU.ResourceId AND ".
1079 "RU.UserId ".$SqlOp.$User->Id().
" AND ".
1080 "RU.FieldId IN (".implode(
",", $UserComparisonFields).
")");
1081 $Result =
$DB->FetchColumn(
"ResourceId");
1083 # merge those resources into our results 1084 $ResourceIds = array_merge(
1090 self::$UserComparisonResourceCache[$CacheKey] = array_unique($ResourceIds);
1093 return self::$UserComparisonResourceCache[$CacheKey];
1102 private function GetUserComparisonFields($ComparisonType)
1104 $CacheKey = $this->SchemaId.
".".$ComparisonType;
1105 if (!isset(self::$UserComparisonFieldCache[$CacheKey]))
1107 # iterate through all the fields in the schema, 1108 # constructing a list of the User fields implicated 1109 # in comparisons of the desired type 1110 $UserComparisonFields = array();
1111 foreach ($this->Schema->GetFields() as $Field)
1113 $UserComparisonFields = array_merge(
1114 $UserComparisonFields,
1115 $Field->ViewingPrivileges()->FieldsWithUserComparisons(
1118 self::$UserComparisonFieldCache[$CacheKey] =
1119 array_unique($UserComparisonFields);
1122 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...
GetRatedResourceUserCount()
Return number of users who have rated resources.
SQL database abstraction object with smart query caching.
static Create($Name, $FieldId, $ParentId=NULL)
Add new classification to the hierarchy.
GetResourceIdsSortedBy($FieldId, $Ascending=TRUE, $Limit=NULL)
Get resource IDs sorted by specified field.
ClearViewingPermsCache()
Clear the cache of viewable resources.
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.
Metadata type representing non-hierarchical controlled vocabulary values.
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.
__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.