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));
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();
184 NULL, $Value, $Field->Id());
186 $Resource->Set($Field, $CName);
190 if (!isset($CFacts[$Field->Id()]))
192 $CFacts[$Field->Id()] = $Field->GetFactory();
195 $Class = $CFacts[$Field->Id()]->GetItemByName($Value);
198 $CFacts[$Field->Id()]->ClearCaches();
201 $Resource->Set($Field, $Class);
205 list($Point[
"X"], $Point[
"Y"]) = explode(
",", $Value);
206 $Resource->Set($Field, $Point);
210 if (preg_match(
"/^[0-9]+\$/", $Value))
212 $Value = intval($Value);
214 $Resource->Set($Field, $Value);
230 # make final resource (if any) non-temporary 231 if (isset($Resource))
233 $Resource->IsTempResource(FALSE);
234 $NewResourceIds[] = $Resource->Id();
240 # report to caller what resources were added 241 return $NewResourceIds;
252 # sanitize qualifier ID or retrieve from object 253 $QualifierId = is_object($ObjectOrId)
254 ? $ObjectOrId->Id() : intval($ObjectOrId);
256 # if new qualifier passed in 257 if ($NewObjectOrId !== NULL)
259 # sanitize qualifier ID to change to or retrieve it from object 260 $NewQualifierIdVal = is_object($NewObjectOrId)
261 ? $NewObjectOrId->Id() : intval($NewObjectOrId);
265 # qualifier should be cleared 266 $NewQualifierIdVal =
"NULL";
269 # for each metadata field 270 $Fields = $this->
Schema->GetFields();
271 foreach ($Fields as $Field)
273 # if field uses qualifiers and uses item-level qualifiers 274 $QualColName = $Field->DBFieldName().
"Qualifier";
275 if ($Field->UsesQualifiers()
276 && $Field->HasItemLevelQualifiers()
277 && $this->DB->FieldExists(
"Resources", $QualColName))
279 # set all occurrences to new qualifier value 280 $this->DB->Query(
"UPDATE Resources" 281 .
" SET ".$QualColName.
" = ".$NewQualifierIdVal.
"" 282 .
" WHERE ".$QualColName.
" = '".$QualifierId.
"'" 283 .
" AND SchemaId = ".intval($this->SchemaId));
287 # clear or change qualifier association with controlled names 288 # (NOTE: this should probably be done in a controlled name factory object) 289 $this->DB->Query(
"UPDATE ControlledNames" 290 .
" SET QualifierId = ".$NewQualifierIdVal
291 .
" WHERE QualifierId = '".$QualifierId.
"'");
293 # clear or change qualifier association with classifications 294 # (NOTE: this should probably be done in a classification factory object) 295 $this->DB->Query(
"UPDATE Classifications" 296 .
" SET QualifierId = ".$NewQualifierIdVal
297 .
" WHERE QualifierId = '".$QualifierId.
"'");
306 return $this->DB->Query(
307 "SELECT COUNT(DISTINCT ResourceId) AS ResourceCount" 308 .
" FROM ResourceRatings",
318 return $this->DB->Query(
319 "SELECT COUNT(DISTINCT UserId) AS UserCount" 320 .
" FROM ResourceRatings",
334 $Count = 10, $Offset = 0, $MaxDaysToGoBack = 90)
336 # assume that no resources will be found 337 $Resources = array();
339 # calculate cutoff date for resources 340 $CutoffDate = date(
"Y-m-d H:i:s", strtotime($MaxDaysToGoBack.
" days ago"));
342 # query for resource IDs 343 $this->DB->Query(
"SELECT ResourceId FROM Resources WHERE" 344 .
" DateOfRecordRelease > '".$CutoffDate.
"'" 345 .
" AND ResourceId >= 0" 346 .
" AND SchemaId = ".intval($this->SchemaId)
347 .
" ORDER BY DateOfRecordRelease DESC, DateOfRecordCreation DESC");
348 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
350 # filter out resources that aren't viewable to the public 354 # subset the results as requested 355 $ResourceIds = array_slice(
356 $ResourceIds, $Offset, $Count);
358 # for each resource ID found 359 foreach ($ResourceIds as $ResourceId)
361 # load resource and add to list of found resources 362 $Resources[$ResourceId] =
new Resource($ResourceId);
365 # return found resources to caller 379 # assume no resources will be found 380 $ResourceIds = array();
383 if ($this->
Schema->FieldExists($FieldId))
385 $Field = $this->
Schema->GetField($FieldId);
386 # construct query based on field type 387 switch ($Field->Type())
392 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 393 .
" FROM Resources WHERE " 394 .$Field->DBFieldName().
" IS NOT NULL" 395 .
" AND LENGTH(LTRIM(RTRIM(".$Field->DBFieldName().
"))) > 0" 396 .
" AND SchemaId = ".intval($this->SchemaId),
400 $Query =
"SELECT ResourceId FROM Resources" 401 .
" WHERE SchemaId = ".intval($this->SchemaId)
402 .
" ORDER BY ".$Field->DBFieldName()
403 .($Ascending ?
" ASC" :
" DESC");
409 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 410 .
" FROM Resources WHERE " 411 .$Field->DBFieldName().
" IS NOT NULL" 412 .
" AND SchemaId = ".intval($this->SchemaId),
416 $Query =
"SELECT ResourceId FROM Resources" 417 .
" WHERE SchemaId = ".intval($this->SchemaId)
418 .
" ORDER BY ".$Field->DBFieldName()
419 .($Ascending ?
" ASC" :
" DESC");
424 $Count = $this->DB->Query(
"SELECT COUNT(*) AS ResourceCount" 425 .
" FROM Resources WHERE " 426 .$Field->DBFieldName().
"Begin IS NOT NULL" 427 .
" AND SchemaId = ".intval($this->SchemaId),
431 $Query =
"SELECT ResourceId FROM Resources" 432 .
" WHERE SchemaId = ".intval($this->SchemaId)
433 .
" ORDER BY ".$Field->DBFieldName().
"Begin" 434 .($Ascending ?
" ASC" :
" DESC");
439 # if appropriate query was found 442 # if limited number of results were requested 446 $Query .=
" LIMIT ".intval($Limit);
449 # perform query and retrieve resource IDs 450 $this->DB->Query($Query);
451 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
455 # return resource IDs to caller 467 # compute this user's class 468 $UserClass = $this->ComputeUserClass($User);
470 # generate an array where the keys are ResourceIds affected by 471 # user comparisons for the current user 472 $UserComparisonsRIDs = array_flip(
473 $this->ResourcesWhereUserComparisonsMatterForViewing($User));
475 # (Note: We can use the $UserClass without a schema prefix as 476 # a cache key even though User Classes are schema specific 477 # because the values we're caching are ResourceIds. Since the 478 # ResourceIds already imply a schema, there's no ambiguity 479 # regarding which schema was involved when the stored UserClass 481 if (!isset(self::$UserClassPermissionsCache[$UserClass]))
483 # grab all the ResourceIds for this user class 484 $this->DB->Query(
"SELECT ResourceId, CanView FROM UserPermsCache WHERE" 485 .
" UserClass='".$UserClass.
"'");
487 self::$UserClassPermissionsCache[$UserClass] = $this->DB->FetchColumn(
488 "CanView",
"ResourceId");
491 # filter out those not requested 492 $Cache = array_intersect_key(
493 self::$UserClassPermissionsCache[$UserClass],
494 array_flip($ResourceIds) );
496 # figure out which resources we didn't have cached values for 497 # and iterate over those 498 $MissingIds = array_diff($ResourceIds, array_keys($Cache));
500 $PerUserKey = $this->SchemaId.
".UID_".$User->Id();
502 # batch inserts up into not more than 1000 resources per query 504 $QueryValues = array();
505 foreach ($MissingIds as $Id)
507 if (isset(self::$PerUserPermissionsCache[$PerUserKey]))
509 $CanView = self::$PerUserPermissionsCache[$PerUserKey];
513 # evaluate perms for this resource 517 $CanView = $Resource->UserCanView($User, FALSE);
524 # if this is a result we can cache persistently 525 # (i.e. not affected by user comparisons), do so 526 if (!isset($UserComparisonsRIDs[$Id]))
528 self::$UserClassPermissionsCache[$UserClass][$Id] = $CanView;
530 # add this to our queue of inserts 531 $QueryValues[]=
"(".$Id.
",'".$UserClass.
"',".($CanView?
"1":
"0").
")" ;
533 # if this chunk is full, insert it into the db and clear our queue 534 if (count($QueryValues)>=$ChunkSize)
537 "INSERT INTO UserPermsCache (ResourceId, UserClass, CanView) " 538 .
"VALUES ".implode(
",", $QueryValues) );
539 $QueryValues = array();
544 # this isn't a result we should cache persistently 545 # in the database, but we still want to cache it 546 # within this page load 547 self::$PerUserPermissionsCache[$PerUserKey] = $CanView;
551 $Cache[$Id] = $CanView;
554 # if we have values left to insert, do so 555 if (count($QueryValues))
558 "INSERT INTO UserPermsCache (ResourceId, UserClass, CanView) " 559 .
"VALUES ".implode(
",", $QueryValues) );
562 # if resource view permission check has any handlers that may 563 # modify our cached values 564 if ($GLOBALS[
"AF"]->IsHookedEvent(
"EVENT_RESOURCE_VIEW_PERMISSION_CHECK"))
566 # apply hooked functions to each value 567 foreach (array_keys($Cache) as $Id)
569 $SignalResult = $GLOBALS[
"AF"]->SignalEvent(
570 "EVENT_RESOURCE_VIEW_PERMISSION_CHECK",
574 "CanView" => $Cache[$Id],
575 "Schema" => $this->
Schema, ));
576 $Cache[$Id] = $SignalResult[
"CanView"];
580 # filter out the non-viewable resources, preserving the order 582 return array_intersect($ResourceIds,
583 array_keys(array_filter($Cache)) );
591 $this->DB->Query(
"DELETE FROM UserPermsCache");
602 # retrieve field names from schema 603 $FieldNames = array();
604 $Fields = $this->
Schema->GetFields();
605 foreach ($Fields as $Field)
607 $FieldNames[$Field->Id()] = $Field->Name();
610 # return field names to caller 628 $ValuesToMatch, $AllRequired=TRUE, $ReturnObjects=TRUE,
631 # start out assuming we won't find any resources 632 $Resources = array();
634 # fix up equality operator 635 if ($Operator ==
"==")
644 $Fields = $this->
Schema->GetFields();
645 foreach ($ValuesToMatch as $FieldId => $Value)
647 # only equality supported for NULL 648 if ($Operator !=
"=" && $Value ==
"NULL")
651 "Invalid operator, ".$Operator.
" not supported for NULL");
654 # convert supplied FieldId to canonical identifier 656 $FieldId, $this->SchemaId);
658 # check that provided operator is sane 659 switch ($Fields[$FieldId]->Type())
666 $ValidOps = array(
"=");
670 $ValidOps = array(
"=",
"!=");
676 $ValidOps = array(
"=",
"!=",
"<",
"<=",
">",
">=");
683 if (!in_array($Operator, $ValidOps))
685 throw new Exception(
"Operator ".$Operator.
" not supported for " 686 .$Field->TypeAsName().
" fields");
689 # add SQL fragments to Condition as needed 690 switch ($Fields[$FieldId]->Type())
699 $DBFname = $Fields[$FieldId]->DBFieldName();
700 # add comparison to condition 701 if ($Value ==
"NULL")
703 $Condition .= $LinkingTerm.
"(" 704 .$DBFname.
" IS NULL OR ".$DBFname.
" = '')";
708 $Condition .= $LinkingTerm.$DBFname.
" " 709 .$Operator.
" '".addslashes($Value).
"'";
714 $DBFname = $Fields[$FieldId]->DBFieldName();
716 if ($Value ==
"NULL")
718 $Condition .= $LinkingTerm.
"(" 719 .$DBFname.
"X IS NULL AND " 720 .$DBFname.
"Y IS NULL)";
724 $Vx = addslashes($Value[
"X"]);
725 $Vy = addslashes($value[
"Y"]);
727 $Condition .= $LinkingTerm.
"(" 728 .$DBFname.
"X = '".$Vx.
"' AND " 729 .$DBFname.
"Y = '".$Vy.
"')";
734 $TgtValues = array();
735 if (is_object($Value))
737 $TgtValues[]= $Value->Id();
739 elseif (is_numeric($Value))
741 $TgtValues[]= $Value;
743 elseif (is_array($Value))
745 foreach ($Value as $UserId => $UserNameOrObject)
747 $TgtValues[]= $UserId;
751 # if no users were specified 752 if (!count($TgtValues))
754 # return no results (nothing matches nothing) 759 # add conditional to match specified users 760 $Condition .= $LinkingTerm.
"(" 761 .
"ResourceId IN (SELECT ResourceId FROM " 762 .
"ResourceUserInts WHERE FieldId=".intval($FieldId)
764 .implode(
",", $TgtValues).
")) )";
769 throw new Exception(
"Unsupported field type");
772 $LinkingTerm = $AllRequired ?
" AND " :
" OR ";
775 # if there were valid conditions 776 if (strlen($Condition))
778 # build query statment 779 $Query =
"SELECT ResourceId FROM Resources WHERE (".$Condition
780 .
") AND SchemaId = ".intval($this->SchemaId);
782 # execute query to retrieve matching resource IDs 783 $this->DB->Query($Query);
784 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
788 # retrieve resource objects 789 foreach ($ResourceIds as $Id)
791 $Resources[$Id] =
new Resource($Id);
796 $Resources = $ResourceIds;
800 # return any resources found to caller 816 $ValueId, $User, $ForegroundUpdate=FALSE)
818 # if the specified user is matched by any UserIs or UserIsNot 819 # privset conditions for any resources, then put them in a class 821 $UserClass = count($this->ResourcesWhereUserComparisonsMatterForViewing($User))
822 ?
"UID_".$User->Id() :
823 $this->ComputeUserClass($User);
825 $CacheKey = $this->SchemaId.
".".$UserClass;
826 # if we haven't loaded any cached values, do so now 827 if (!isset(self::$VisibleResourceCountCache[$CacheKey]))
830 "SELECT ResourceCount, ValueId FROM " 831 .
"VisibleResourceCounts WHERE " 832 .
"SchemaId=".intval($this->SchemaId)
833 .
" AND UserClass='".addslashes($UserClass).
"'");
835 self::$VisibleResourceCountCache[$CacheKey] = $this->DB->FetchColumn(
836 "ResourceCount",
"ValueId");
839 # if we don't have a cached value for this class 840 if (!isset(self::$VisibleResourceCountCache[$CacheKey][$ValueId]))
842 # if we're doing a foreground update 843 if ($ForegroundUpdate)
845 # run the update callback 847 $ValueId, $User->Id());
849 # grab the newly generated value 850 $NewValue = $this->DB->Query(
851 "SELECT ResourceCount FROM " 852 .
"VisibleResourceCounts WHERE " 853 .
"SchemaId=".intval($this->SchemaId)
854 .
" AND UserClass='".addslashes($UserClass).
"' " 855 .
" AND ValueId=".intval($ValueId),
"ResourceCount");
857 # load it into our local cache 858 self::$VisibleResourceCountCache[$CacheKey][$ValueId] = $NewValue;
862 # otherwise (for background update), queue the update 863 # callback and return -1 864 $GLOBALS[
"AF"]->QueueUniqueTask(
865 array($this,
"UpdateAssociatedVisibleResourceCount"),
866 array($ValueId, $User->Id() ) );
871 # owtherwise, return the cached data 872 return self::$VisibleResourceCountCache[$CacheKey][$ValueId];
884 $User =
new CWUser($UserId);
886 # if the specified user is matched by any UserIs or UserIsNot 887 # privset conditions for any resources, then put them in a class 889 $UserClass = count($this->ResourcesWhereUserComparisonsMatterForViewing($User))
890 ?
"UID_".$User->Id() :
891 $this->ComputeUserClass($User);
894 "SELECT ResourceId FROM ResourceNameInts " 895 .
"WHERE ControlledNameId=".intval($ValueId) );
896 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
899 $ResourceIds, $User);
901 $ResourceCount = count($ResourceIds);
904 "INSERT INTO VisibleResourceCounts " 905 .
"(SchemaId, UserClass, ValueId, ResourceCount) " 907 .intval($this->SchemaId).
"," 908 .
"'".addslashes($UserClass).
"'," 909 .intval($ValueId).
"," 910 .$ResourceCount.
")");
920 $ResourceIds = $this->DB->Query(
921 "SELECT ResourceId FROM Resources " 922 .
"WHERE ResourceId > 0 AND SchemaId = ".intval($this->SchemaId));
923 $ResourceIds = $this->DB->FetchColumn(
"ResourceId");
926 $ResourceIds, $User);
928 return count($ResourceIds);
949 return $this->DB->Query(
" 950 SELECT COUNT(*) AS ResourceTotal 953 AND SchemaId = ".intval($this->SchemaId),
963 self::$VisibleResourceCountCache = array();
964 self::$UserClassPermissionsCache = array();
965 self::$PerUserPermissionsCache = array();
966 self::$UserClassCache = array();
967 self::$UserComparisonResourceCache = array();
968 self::$UserComparisonFieldCache = array();
971 # ---- PRIVATE INTERFACE ------------------------------------------------- 977 private static $VisibleResourceCountCache;
978 private static $UserClassPermissionsCache;
979 private static $PerUserPermissionsCache;
980 private static $UserClassCache;
981 private static $UserComparisonResourceCache;
982 private static $UserComparisonFieldCache;
991 private function ComputeUserClass($User)
993 # put the anonymous user into their own user class, otherwise 994 # use the UserId for a key into the ClassCache 995 $UserId = $User->IsAnonymous() ?
"XX-ANON-XX" : $User->Id();
997 $CacheKey = $this->SchemaId.
".".$UserId;
999 # check if we have a cached UserClass for this User 1000 if (!isset($this->UserClassCache[$CacheKey]))
1002 # assemble a list of the privilege flags (PRIV_SYSADMIN, 1003 # etc) that are checked when evaluating the UserCanView for 1004 # all fields in this schema 1005 $RelevantPerms = array();
1007 foreach ($this->
Schema->GetFields() as $Field)
1009 $RelevantPerms = array_merge(
1011 $Field->ViewingPrivileges()->PrivilegeFlagsChecked() );
1013 $RelevantPerms = array_unique($RelevantPerms);
1015 # whittle the list of all privs checked down to just the 1016 # list of privs that users in this class have 1017 $PermsInvolved = array();
1018 foreach ($RelevantPerms as $Perm)
1020 if ($User->HasPriv($Perm))
1022 $PermsInvolved[]= $Perm;
1026 # generate a string by concatenating all the involved 1027 # permissions then hashing the result (hashing gives 1028 # a fixed-size string for storing in the database) 1029 self::$UserClassCache[$CacheKey] = md5(implode(
"-", $PermsInvolved ));
1032 return self::$UserClassCache[$CacheKey];
1044 private function ResourcesWhereUserComparisonsMatterForViewing($User)
1046 $ResourceIds = array();
1048 # if we're checking the anonymous user, presume that 1049 # nothing will match 1050 if ($User->IsAnonymous())
1052 return $ResourceIds;
1055 $CacheKey = $this->SchemaId.
".".$User->Id();
1056 if (!isset(self::$UserComparisonResourceCache[$CacheKey]))
1060 # for each comparison type 1061 foreach (array(
"==",
"!=") as $ComparisonType)
1063 $UserComparisonFields = $this->GetUserComparisonFields(
1066 # if we have any fields to check 1067 if (count($UserComparisonFields) > 0 )
1069 # query the database for resources where one or more of the 1070 # user comparisons will be satisfied 1071 $SqlOp = ($ComparisonType ==
"==") ?
"= " :
"!= ";
1073 $DB->Query(
"SELECT R.ResourceId as ResourceId FROM ".
1074 "Resources R, ResourceUserInts RU WHERE ".
1075 "R.SchemaId = ".$this->SchemaId.
" AND ".
1076 "R.ResourceId = RU.ResourceId AND ".
1077 "RU.UserId ".$SqlOp.$User->Id().
" AND ".
1078 "RU.FieldId IN (".implode(
",", $UserComparisonFields).
")");
1079 $Result =
$DB->FetchColumn(
"ResourceId");
1081 # merge those resources into our results 1082 $ResourceIds = array_merge(
1088 self::$UserComparisonResourceCache[$CacheKey] = array_unique($ResourceIds);
1091 return self::$UserComparisonResourceCache[$CacheKey];
1100 private function GetUserComparisonFields($ComparisonType)
1102 $CacheKey = $this->SchemaId.
".".$ComparisonType;
1103 if (!isset(self::$UserComparisonFieldCache[$CacheKey]))
1105 # iterate through all the fields in the schema, 1106 # constructing a list of the User fields implicated 1107 # in comparisons of the desired type 1108 $UserComparisonFields = array();
1109 foreach ($this->
Schema->GetFields() as $Field)
1111 $UserComparisonFields = array_merge(
1112 $UserComparisonFields,
1113 $Field->ViewingPrivileges()->FieldsWithUserComparisons(
1116 self::$UserComparisonFieldCache[$CacheKey] =
1117 array_unique($UserComparisonFields);
1120 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.
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.