CWIS Developer Documentation
Resource.php
Go to the documentation of this file.
1 <?PHP
2 #
3 # FILE: Resource.php
4 #
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/
8 #
9 
13 class Resource {
14 
15  # ---- PUBLIC INTERFACE --------------------------------------------------
16 
23  function Resource($ResourceId)
24  {
25  $this->DB = new Database();
26 
27  # save resource ID
28  $this->Id = intval($ResourceId);
29 
30  # locate resource in database
31  $this->DB->Query("SELECT * FROM Resources WHERE ResourceId = ".$this->Id);
32 
33  # if unable to locate resource
34  $Record = $this->DB->FetchRow();
35  if ($Record == FALSE)
36  {
37  # set status to -1 to indicate that creation failed
38  $this->LastStatus = -1;
39  }
40  else
41  {
42  # load in attributes from database
43  $this->DBFields = $Record;
44  $this->CumulativeRating = $Record["CumulativeRating"];
45 
46  # load our local metadata schema
47  $this->Schema = new MetadataSchema($this->DBFields["SchemaId"]);
48 
49  # set status to 1 to indicate that creation succeeded
50  $this->LastStatus = 1;
51  }
52  }
53 
59  static function Create($SchemaId)
60  {
61  # clean out any temp resource records more than three days old
62  $RFactory = new ResourceFactory();
63  $RFactory->CleanOutStaleTempItems(60 * 24 * 3);
64 
65  # lock DB tables to prevent next ID from being grabbed
66  $DB = new Database;
67  $DB->Query("LOCK TABLES Resources WRITE");
68 
69  # find next temp resource ID
70  $Id = $RFactory->GetNextTempItemId();
71 
72  # write out new resource record with temp resource ID
73  # Set DateLastModified = NOW() to avoid being pruned as a
74  # stale temp resource.
75  $DB->Query(
76  "INSERT INTO Resources
77  SET `ResourceId` = '".intval($Id)."',
78  `SchemaId` = '".intval($SchemaId)."',
79  `DateLastModified` = NOW() " );
80 
81  # release DB tables
82  $DB->Query("UNLOCK TABLES");
83 
84  # create new Resource object
85  $Resource = new Resource($Id);
86 
87  # set some additional fields for default resources
88  if ($SchemaId == MetadataSchema::SCHEMAID_DEFAULT)
89  {
90  $Resource->Set("Added By Id", $GLOBALS["G_User"]->Id());
91  $Resource->Set("Last Modified By Id", $GLOBALS["G_User"]->Id());
92  $Resource->Set("Date Of Record Creation", date("Y-m-d H:i:s"));
93  $Resource->Set("Date Last Modified", date("Y-m-d H:i:s"));
94  }
95 
96  # set any default values
97  $Schema = new MetadataSchema($SchemaId);
98  $Fields = $Schema->GetFields(MetadataSchema::MDFTYPE_OPTION
103  foreach ($Fields as $Field)
104  {
105  $DefaultValue = $Field->DefaultValue();
106 
107  # flip option default values to get into the form that
108  # Resource::Set() expects
109  if ($Field->Type() == MetadataSchema::MDFTYPE_OPTION
110  && is_array($DefaultValue))
111  {
112  $DefaultValue = array_flip($DefaultValue);
113  }
114 
115  $Resource->SetByField($Field, $DefaultValue);
116  }
117 
118  # update timestamps as required
119  $TimestampFields = $Schema->GetFields(MetadataSchema::MDFTYPE_TIMESTAMP);
120  foreach ($TimestampFields as $Field)
121  {
122  if ($Field->UpdateMethod() ==
124  {
125  $Resource->SetByField($Field, "now");
126  }
127  }
128 
129  # signal resource creation
130  $GLOBALS["AF"]->SignalEvent("EVENT_RESOURCE_CREATE", array(
131  "Resource" => $Resource,
132  ));
133 
134  # return new Resource object to caller
135  return $Resource;
136  }
137 
142  function Delete()
143  {
144  global $SysConfig;
145 
146  # signal that resource deletion is about to occur
147  global $AF;
148  $AF->SignalEvent("EVENT_RESOURCE_DELETE", array(
149  "Resource" => $this,
150  ));
151 
152  # grab list of classifications
153  $Classifications = $this->Classifications();
154 
155  # delete resource/classification intersections
156  $DB = $this->DB;
157  $DB->Query("DELETE FROM ResourceClassInts WHERE ResourceId = ".$this->Id());
158 
159  # for each classification type
160  foreach ($Classifications as $ClassType => $ClassesOfType)
161  {
162  # for each classification of that type
163  foreach ($ClassesOfType as $ClassId => $ClassName)
164  {
165  # recalculate resource count for classification
166  $Class = new Classification($ClassId);
167  $Class->RecalcResourceCount();
168  }
169  }
170 
171  # delete resource references
172  $DB->Query("
173  DELETE FROM ReferenceInts
174  WHERE SrcResourceId = '".addslashes($this->Id())."'
175  OR DstResourceId = '".addslashes($this->Id())."'");
176 
177  # delete resource/name intersections
178  $DB->Query("DELETE FROM ResourceNameInts WHERE ResourceId = ".$this->Id());
179 
180  # delete any associated images not in use by other resources
181  $DB->Query("SELECT ImageId FROM ResourceImageInts"
182  ." WHERE ResourceId = ".intval($this->Id()));
183  $ImageIds = $DB->FetchColumn("ImageId");
184  foreach ($ImageIds as $ImageId)
185  {
186  $DB->Query("SELECT ResourceId FROM ResourceImageInts"
187  ." WHERE ImageId = ".intval($ImageId)
188  ." AND ResourceId != ".intval($this->Id()));
189  if ($DB->NumRowsSelected() == 0)
190  {
191  $Image = new SPTImage($ImageId);
192  $Image->Delete();
193  }
194  }
195 
196  # delete any associated files
197  $Factory = new FileFactory(NULL);
198  $Files = $Factory->GetFilesForResource($this->Id());
199  foreach ($Files as $File)
200  {
201  $File->Delete();
202  }
203 
204  # delete resource record from database
205  $DB->Query("DELETE FROM Resources WHERE ResourceId = ".$this->Id());
206 
207  # drop item from search engine and recommender system
208  if ($SysConfig->SearchDBEnabled())
209  {
210  $SearchEngine = new SPTSearchEngine();
211  $SearchEngine->DropItem($this->Id());
212  }
213  if ($SysConfig->RecommenderDBEnabled())
214  {
215  $Recommender = new SPTRecommender();
216  $Recommender->DropItem($this->Id());
217  }
218 
219  # get the folders containing the resource
220  $FolderFactory = new FolderFactory();
221  $Folders = $FolderFactory->GetFoldersContainingItem(
222  $this->Id,
223  "Resource");
224 
225  # drop the resource from each folder it belongs to
226  foreach ($Folders as $Folder)
227  {
228  # mixed item type folder
229  if ($Folder->ContainsItem($this->Id, "Resource"))
230  {
231  $Folder->RemoveItem($this->Id, "Resource");
232  }
233 
234  # single item type folder
235  else
236  {
237  $Folder->RemoveItem($this->Id);
238  }
239  }
240 
241  # delete any resource comments
242  $DB->Query("DELETE FROM Messages WHERE ParentId = ".$this->Id);
243  }
244 
249  function Status() { return $this->LastStatus; }
250 
255  function Id() { return $this->Id; }
256 
261  function SchemaId() { return $this->DBFields["SchemaId"]; }
262 
269  function IsTempResource($NewSetting = NULL)
270  {
271  # if new temp resource setting supplied
272  if (!is_null($NewSetting))
273  {
274  # if caller requested to switch
275  $DB = $this->DB;
276  if ((($this->Id() < 0) && ($NewSetting == FALSE))
277  || (($this->Id() >= 0) && ($NewSetting == TRUE)))
278  {
279  # lock DB tables to prevent next ID from being grabbed
280  $DB->Query("LOCK TABLES Resources write");
281 
282  # get next resource ID as appropriate
283  $OldResourceId = $this->Id;
284  $Factory = new ResourceFactory($this->SchemaId());
285  if ($NewSetting == TRUE)
286  {
287  $this->Id = $Factory->GetNextTempItemId();
288  }
289  else
290  {
291  $this->Id = $Factory->GetNextItemId();
292  }
293 
294  # change resource ID
295  $DB->Query("UPDATE Resources SET ResourceId = ".
296  $this->Id. " WHERE ResourceId = ".$OldResourceId);
297 
298  # release DB tables
299  $DB->Query("UNLOCK TABLES");
300 
301  # change associations
302  unset($this->ClassificationCache);
303  $DB->Query("UPDATE ResourceClassInts SET ResourceId = ".
304  $this->Id. " WHERE ResourceId = ".$OldResourceId);
305  unset($this->ControlledNameCache);
306  unset($this->ControlledNameVariantCache);
307  $DB->Query("UPDATE ResourceNameInts SET ResourceId = ".
308  $this->Id. " WHERE ResourceId = ".$OldResourceId);
309  $DB->Query("UPDATE Files SET ResourceId = ".
310  $this->Id. " WHERE ResourceId = ".$OldResourceId);
311  $DB->Query("UPDATE ReferenceInts SET SrcResourceId = ".
312  $this->Id. " WHERE SrcResourceId = ".$OldResourceId);
313  $DB->Query("UPDATE ResourceImageInts SET ResourceId = ".
314  $this->Id. " WHERE ResourceId = ".$OldResourceId);
315 
316  # signal event as appropriate
317  if ($NewSetting === FALSE)
318  {
319  $GLOBALS["AF"]->SignalEvent("EVENT_RESOURCE_ADD", array(
320  "Resource" => $this,
321  ));
322  }
323  }
324  }
325 
326  # report to caller whether we are a temp resource
327  return ($this->Id() < 0) ? TRUE : FALSE;
328  }
329 
330 
331  # --- Generic Attribute Retrieval Methods -------------------------------
332 
347  function Get($FieldNameOrObject, $ReturnObject = FALSE, $IncludeVariants = FALSE)
348  {
349  # load field object if needed
350  $Field = is_object($FieldNameOrObject) ? $FieldNameOrObject
351  : $this->Schema->GetFieldByName($FieldNameOrObject);
352 
353  # return no value found if we don't have a valid field
354  if (!($Field instanceof MetadataField)) { return NULL; }
355 
356  # grab database field name
357  $DBFieldName = $Field->DBFieldName();
358 
359  # format return value based on field type
360  switch ($Field->Type())
361  {
365  $ReturnValue = isset($this->DBFields[$DBFieldName])
366  ? (string)$this->DBFields[$DBFieldName] : NULL;
367  break;
368 
370  $ReturnValue = isset($this->DBFields[$DBFieldName])
371  ? (int)$this->DBFields[$DBFieldName] : NULL;
372  break;
373 
375  $ReturnValue = isset($this->DBFields[$DBFieldName])
376  ? (bool)$this->DBFields[$DBFieldName] : NULL;
377  break;
378 
380  $ReturnValue = array("X" => (float)$this->DBFields[$DBFieldName."X"],
381  "Y" => (float)$this->DBFields[$DBFieldName."Y"]);
382  break;
383 
385  $Date = new Date($this->DBFields[$DBFieldName."Begin"],
386  $this->DBFields[$DBFieldName."End"],
387  $this->DBFields[$DBFieldName."Precision"]);
388  if ($ReturnObject)
389  {
390  $ReturnValue = $Date;
391  }
392  else
393  {
394  $ReturnValue = $Date->Formatted();
395  }
396  break;
397 
399  $ReturnValue = $this->DBFields[$DBFieldName];
400  break;
401 
403  # start with empty array
404  $ReturnValue = array();
405 
406  # if classification cache has not been loaded
407  if (!isset($this->ClassificationCache))
408  {
409  # load all classifications associated with this resource into cache
410  $this->ClassificationCache = array();
411  $this->DB->Query(
412  "SELECT Classifications.ClassificationId,"
413  ." Classifications.FieldId,ClassificationName"
414  ." FROM ResourceClassInts, Classifications"
415  ." WHERE ResourceClassInts.ResourceId = ".$this->Id
416  ." AND ResourceClassInts.ClassificationId"
417  ." = Classifications.ClassificationId");
418  while ($Record = $this->DB->FetchRow())
419  {
420  $this->ClassificationCache[$Record["ClassificationId"]]["Name"] =
421  $Record["ClassificationName"];
422  $this->ClassificationCache[$Record["ClassificationId"]]["FieldId"] =
423  $Record["FieldId"];
424  }
425  }
426 
427  # for each entry in classification cache
428  foreach ($this->ClassificationCache as $ClassificationId => $ClassificationInfo)
429  {
430  # if classification ID matches field we are looking for
431  if ($ClassificationInfo["FieldId"] == $Field->Id())
432  {
433  # add field to result
434  if ($ReturnObject)
435  {
436  $ReturnValue[$ClassificationId] = new Classification($ClassificationId);
437  }
438  else
439  {
440  $ReturnValue[$ClassificationId] = $ClassificationInfo["Name"];
441  }
442  }
443  }
444  break;
445 
448  # start with empty array
449  $ReturnValue = array();
450 
451  # if controlled name cache has not been loaded
452  if (!isset($this->ControlledNameCache))
453  {
454  # load all controlled names associated with this resource into cache
455  $this->ControlledNameCache = array();
456  $this->DB->Query(
457  "SELECT ControlledNames.ControlledNameId,"
458  ." ControlledNames.FieldId,ControlledName"
459  ." FROM ResourceNameInts, ControlledNames"
460  ." WHERE ResourceNameInts.ResourceId = ".$this->Id
461  ." AND ResourceNameInts.ControlledNameId"
462  ." = ControlledNames.ControlledNameId"
463  ." ORDER BY ControlledNames.ControlledName ASC");
464  while ($Record = $this->DB->FetchRow())
465  {
466  $this->ControlledNameCache[$Record["ControlledNameId"]]["Name"] = $Record["ControlledName"];
467  $this->ControlledNameCache[$Record["ControlledNameId"]]["FieldId"] = $Record["FieldId"];
468  }
469  }
470 
471  # if variant names requested and variant name cache has not been loaded
472  if ($IncludeVariants && !isset($this->ControlledNameVariantCache))
473  {
474  # load all controlled names associated with this resource into cache
475  $this->ControlledNameVariantCache = array();
476  $this->DB->Query("SELECT ControlledNames.ControlledNameId,"
477  ." ControlledNames.FieldId,"
478  ." ControlledName, VariantName"
479  ." FROM ResourceNameInts, ControlledNames, VariantNames"
480  ." WHERE ResourceNameInts.ResourceId = ".$this->Id
481  ." AND ResourceNameInts.ControlledNameId"
482  ." = ControlledNames.ControlledNameId"
483  ." AND VariantNames.ControlledNameId"
484  ." = ControlledNames.ControlledNameId");
485  while ($Record = $this->DB->FetchRow())
486  {
487  $this->ControlledNameVariantCache[$Record["ControlledNameId"]][]
488  = $Record["VariantName"];
489  }
490  }
491 
492  # for each entry in controlled name cache
493  foreach ($this->ControlledNameCache as $ControlledNameId => $ControlledNameInfo)
494  {
495  # if controlled name type matches field we are looking for
496  if ($ControlledNameInfo["FieldId"] == $Field->Id())
497  {
498  # if objects requested
499  if ($ReturnObject)
500  {
501  $ReturnValue[$ControlledNameId] =
502  new ControlledName($ControlledNameId);
503  }
504  else
505  {
506  # if variant names requested
507  if ($IncludeVariants)
508  {
509  # add field to result
510  $ReturnValue[] = $ControlledNameInfo["Name"];
511 
512  # add any variant names to result
513  if (isset($this->ControlledNameVariantCache[$ControlledNameId]))
514  {
515  $ReturnValue = array_merge(
516  $ReturnValue,
517  $this->ControlledNameVariantCache[$ControlledNameId]);
518  }
519  }
520  else
521  {
522  # add field with index to result
523  $ReturnValue[$ControlledNameId] =
524  $ControlledNameInfo["Name"];
525  }
526  }
527  }
528  }
529  break;
530 
532  $User = new CWUser(intval($this->DBFields[$DBFieldName]));
533  if ($ReturnObject)
534  {
535  $ReturnValue = $User;
536  }
537  else
538  {
539  $ReturnValue = $User->Get("UserName");
540  }
541  break;
542 
544  # start out assuming no images will be found
545  $ReturnValue = array();
546 
547  # find all images associated with this resource
548  $this->DB->Query("SELECT ImageId FROM ResourceImageInts"
549  ." WHERE ResourceId = ".intval($this->Id())
550  ." AND FieldId = ".intval($Field->Id()));
551 
552  # if images were found
553  if ($this->DB->NumRowsSelected())
554  {
555  # if we are to return an object
556  $ImageIds = $this->DB->FetchColumn("ImageId");
557  if ($ReturnObject)
558  {
559  # load array of Image objects for return value
560  foreach ($ImageIds as $ImageId)
561  {
562  $ReturnValue[$ImageId] = new SPTImage($ImageId);
563  }
564  }
565  else
566  {
567  # load array of Image ids for return value
568  $ReturnValue = $ImageIds;
569  }
570  }
571  break;
572 
574  # retrieve files using factory
575  $Factory = new FileFactory($Field->Id());
576  $ReturnValue = $Factory->GetFilesForResource(
577  $this->Id, $ReturnObject);
578  break;
579 
581  # query for resource references
582  $this->DB->Query("
583  SELECT * FROM ReferenceInts
584  WHERE FieldId = '".addslashes($Field->Id())."'
585  AND SrcResourceId = '".addslashes($this->Id())."'");
586 
587  $ReturnValue = array();
588 
589  # return each reference as a Resource object
590  if ($ReturnObject)
591  {
592  $FoundErrors = FALSE;
593 
594  while (FALSE !== ($Record = $this->DB->FetchRow()))
595  {
596  $ReferenceId = $Record["DstResourceId"];
597  $Reference = new Resource($ReferenceId);
598 
599  # the reference is bad, so flag that there were errors
600  if ($Reference->Status() != 1)
601  {
602  $FoundErrors = TRUE;
603  }
604 
605  else
606  {
607  $ReturnValue[$ReferenceId] = $Reference;
608  }
609  }
610 
611  # try to fix the errors by removing any references to
612  # resources that were bad
613  if ($FoundErrors)
614  {
615  $this->Set($Field, $ReturnValue);
616  }
617  }
618 
619  # return each reference as a resource ID
620  else
621  {
622  while (FALSE !== ($Record = $this->DB->FetchRow()))
623  {
624  $ReferenceId = $Record["DstResourceId"];
625  $ReturnValue[$ReferenceId] = $ReferenceId;
626  }
627  }
628  break;
629 
630  default:
631  # ERROR OUT
632  exit("<br>SPT - ERROR: attempt to retrieve unknown resource field type (".$Field->Type().")<br>\n");
633  break;
634  }
635 
636  # return formatted value to caller
637  return $ReturnValue;
638  }
643  function GetByField($FieldNameOrObject,
644  $ReturnObject = FALSE, $IncludeVariants = FALSE)
645  { return $this->Get($FieldNameOrObject, $ReturnObject, $IncludeVariants); }
646 
660  function GetByFieldId($FieldId, $ReturnObject = FALSE, $IncludeVariants = FALSE)
661  {
662  $Field = $this->Schema->GetField($FieldId);
663  return ($Field) ? $this->Get($Field, $ReturnObject, $IncludeVariants) : NULL;
664  }
665 
678  function GetAsArray($IncludeDisabledFields = FALSE, $ReturnObjects = TRUE)
679  {
680  # retrieve field info
681  $Fields = $this->Schema->GetFields();
682 
683  # for each field
684  foreach ($Fields as $Field)
685  {
686  # if field is enabled or caller requested disabled fields
687  if ($Field->Enabled() || $IncludeDisabledFields)
688  {
689  # retrieve info and add it to the array
690  $FieldStrings[$Field->Name()] = $this->Get($Field, $ReturnObjects);
691 
692  # if field uses qualifiers
693  if ($Field->UsesQualifiers())
694  {
695  # get qualifier attributes and add to the array
696  $FieldStrings[$Field->Name()." Qualifier"] =
697  $this->GetQualifierByField($Field, $ReturnObjects);
698  }
699  }
700  }
701 
702  # add in internal values
703  $FieldStrings["ResourceId"] = $this->Id();
704  $FieldStrings["CumulativeRating"] = $this->CumulativeRating();
705 
706  # return array to caller
707  return $FieldStrings;
708  }
709 
724  function GetMapped($MappedName, $ReturnObject = FALSE, $IncludeVariants = FALSE)
725  {
726  return $this->Schema->StdNameToFieldMapping($MappedName)
727  ? $this->GetByFieldId($this->Schema->StdNameToFieldMapping($MappedName),
728  $ReturnObject, $IncludeVariants)
729  : NULL;
730  }
731 
740  function GetQualifier($FieldName, $ReturnObject = TRUE)
741  {
742  $Field = $this->Schema->GetFieldByName($FieldName);
743  return $this->GetQualifierByField($Field, $ReturnObject);
744  }
745 
754  function GetQualifierByFieldId($FieldId, $ReturnObject = TRUE)
755  {
756  $Field = $this->Schema->GetField($FieldId);
757  return ($Field) ? $this->GetQualifierByField($Field, $ReturnObject) : NULL;
758  }
759 
768  function GetQualifierByField($Field, $ReturnObject = TRUE)
769  {
770  # return NULL if field is invalid
771  if (!($Field instanceof MetadataField)) { return NULL; }
772 
773  # assume no qualifiers if not otherwise determined
774  $ReturnValue = NULL;
775 
776  # if field uses qualifiers
777  if ($Field->UsesQualifiers())
778  {
779  # retrieve qualifiers based on field type
780  switch ($Field->Type())
781  {
785  # retrieve list of items
786  $Items = $this->Get($Field);
787 
788  # if field uses item-level qualifiers
789  if ($Field->HasItemLevelQualifiers())
790  {
791  # determine general item name in DB
792  $TableName = ($Field->Type() == MetadataSchema::MDFTYPE_TREE)
793  ? "Classification" : "ControlledName";
794 
795  # for each item
796  foreach ($Items as $ItemId => $ItemName)
797  {
798  # look up qualifier for item
799  $QualId = $this->DB->Query(
800  "SELECT * FROM ".$TableName."s"
801  ." WHERE ".$TableName."Id = ".$ItemId
802  , "QualifierId");
803 
804 
805  if ($QualId > 0)
806  {
807  # if object was requested by caller
808  if ($ReturnObject)
809  {
810  # load qualifier and add to return value array
811  $ReturnValue[$ItemId] = new Qualifier($QualId);
812  }
813  else
814  {
815  # add qualifier ID to return value array
816  $ReturnValue[$ItemId] = $QualId;
817  }
818  }
819  else
820  {
821  # add NULL to return value array for this item
822  $ReturnValue[$ItemId] = NULL;
823  }
824  }
825  }
826  else
827  {
828  # for each item
829  foreach ($Items as $ItemId => $ItemName)
830  {
831  # if object was requested by caller
832  if ($ReturnObject)
833  {
834  # load default qualifier and add to return value array
835  $ReturnValue[$ItemId] = new Qualifier($Field->DefaultQualifier());
836  }
837  else
838  {
839  # add default qualifier ID to return value array
840  $ReturnValue[$ItemId] = $Field->DefaultQualifier();
841  }
842  }
843  }
844  break;
845 
846  default:
847  # if field uses item-level qualifiers
848  if ($Field->HasItemLevelQualifiers())
849  {
850  # if qualifier available
851  if ($this->DBFields[$Field->DBFieldName()."Qualifier"] > 0)
852  {
853  # if object was requested by caller
854  if ($ReturnObject)
855  {
856  # return qualifier for field
857  $ReturnValue = new Qualifier($this->DBFields[$Field->DBFieldName()."Qualifier"]);
858  }
859  else
860  {
861  # return qualifier ID for field
862  $ReturnValue = $this->DBFields[$Field->DBFieldName()."Qualifier"];
863  }
864  }
865  }
866  else
867  {
868  # if default qualifier available
869  if ($Field->DefaultQualifier() > 0)
870  {
871  # if object was requested by caller
872  if ($ReturnObject)
873  {
874  # return default qualifier
875  $ReturnValue = new Qualifier($Field->DefaultQualifier());
876  }
877  else
878  {
879  # return default qualifier ID
880  $ReturnValue = $Field->DefaultQualifier();
881  }
882  }
883  }
884  break;
885  }
886  }
887 
888  # return qualifier object or ID (or array of same) to caller
889  return $ReturnValue;
890  }
891 
899  function FieldIsSet($FieldNameOrObject, $IgnorePadding=FALSE)
900  {
901  # load field object if needed
902  $Field = is_object($FieldNameOrObject) ? $FieldNameOrObject
903  : $this->Schema->GetFieldByName($FieldNameOrObject);
904 
905  # return no value found if we don't have a valid field
906  if (!($Field instanceof MetadataField)) { return FALSE; }
907 
908  # get the value
909  $Value = $this->Get($Field);
910 
911  # checks depend on the field type
912  switch ($Field->Type())
913  {
918  return isset($Value)
919  && strlen($Value)
920  && (!$IgnorePadding || ($IgnorePadding && strlen(trim($Value))));
921 
923  return isset($Value)
924  && strlen($Value);
925 
927  return isset($Value["X"])
928  && isset($Value["Y"])
929  && strlen(trim($Value["X"]))
930  && strlen(trim($Value["Y"]));
931 
933  return isset($Value)
934  && strlen(trim($Value))
935  && $Value != "0000-00-00";
936 
938  return isset($Value)
939  && strlen(trim($Value))
940  && $Value != "0000-00-00 00:00:00";
941 
948  return count($Value) > 0;
949 
951  $Factory = new CWUserFactory();
952  return isset($Value)
953  && strlen($Value)
954  && $Factory->UserNameExists($Value);
955 
956  default:
957  return FALSE;
958  }
959  }
960 
961  # --- Generic Attribute Setting Methods ---------------------------------
962 
968  function Set($FieldNameOrObject, $NewValue)
969  {
970  # load field object if needed
971  $Field = is_object($FieldNameOrObject) ? $FieldNameOrObject
972  : $this->Schema->GetFieldByName($FieldNameOrObject);
973 
974  # return if we don't have a valid field
975  if (!($Field instanceof MetadataField)) { return; }
976 
977  # grab commonly-used values for local use
978  $DB = $this->DB;
979  $ResourceId = $this->Id;
980 
981  # grab database field name
982  $DBFieldName = $Field->DBFieldName();
983 
984  # Flag to deterimine if we've actually changed anything.
985  $UpdateModTime = FALSE;
986 
987  # store value in DB based on field type
988  switch ($Field->Type())
989  {
993  if ($this->DBFields[$DBFieldName] != $NewValue)
994  {
995  # save value directly to DB
996  $DB->Query("UPDATE Resources SET `"
997  .$DBFieldName."` = '".addslashes($NewValue)."' "
998  ."WHERE ResourceId = ".$ResourceId);
999 
1000  # save value locally
1001  $this->DBFields[$DBFieldName] = $NewValue;
1002  $UpdateModTime=TRUE;
1003  }
1004  break;
1005 
1007  if ( $this->DBFields[$DBFieldName] != $NewValue )
1008  {
1009  # save value directly to DB
1010  if (is_null($NewValue))
1011  {
1012  $DB->Query("UPDATE Resources SET `"
1013  .$DBFieldName."` = NULL"
1014  ." WHERE ResourceId = ".$ResourceId);
1015  }
1016  else
1017  {
1018  $DB->Query("UPDATE Resources SET `"
1019  .$DBFieldName."` = ".intval($NewValue)
1020  ." WHERE ResourceId = ".$ResourceId);
1021  }
1022 
1023  # save value locally
1024  $this->DBFields[$DBFieldName] = $NewValue;
1025  $UpdateModTime = TRUE;
1026  }
1027  break;
1028 
1029 
1031  if ($this->DBFields[$DBFieldName."X"] != $NewValue["X"] ||
1032  $this->DBFields[$DBFieldName."Y"] != $NewValue["Y"] )
1033  {
1034  if (is_null($NewValue))
1035  {
1036  $DB->Query("UPDATE Resources SET "
1037  ."`".$DBFieldName."X` = NULL, "
1038  ."`".$DBFieldName."Y` = NULL "
1039  ."WHERE ResourceId = ".$ResourceId);
1040  $this->DBFields[$DBFieldName."X"] = NULL;
1041  $this->DBFields[$DBFieldName."Y"] = NULL;
1042  }
1043  else
1044  {
1045  $DB->Query("UPDATE Resources SET "
1046  ."`".$DBFieldName."X` = ".(strlen($NewValue["X"])
1047  ? "'".$NewValue["X"]."'" : "NULL").", "
1048  ."`".$DBFieldName."Y` = ".(strlen($NewValue["Y"])
1049  ? "'".$NewValue["Y"]."'" : "NULL")
1050  ." WHERE ResourceId = ".$ResourceId);
1051 
1052  $Digits = $Field->PointDecimalDigits();
1053 
1054  $this->DBFields[$DBFieldName."X"] =
1055  strlen($NewValue["X"]) ? round($NewValue["X"], $Digits) : NULL;
1056  $this->DBFields[$DBFieldName."Y"] =
1057  strlen($NewValue["Y"]) ? round($NewValue["Y"], $Digits) : NULL;
1058  }
1059  $UpdateModTime = TRUE;
1060  }
1061  break;
1062 
1064  if ($this->DBFields[$DBFieldName] != $NewValue)
1065  {
1066  # save value directly to DB
1067  if (is_null($NewValue))
1068  {
1069  $DB->Query("UPDATE Resources SET `"
1070  .$DBFieldName."` = NULL"
1071  ." WHERE ResourceId = ".$ResourceId);
1072  }
1073  else
1074  {
1075  $NewValue = $NewValue ? "1" : "0";
1076  $DB->Query("UPDATE Resources SET `"
1077  .$DBFieldName."` = ".$NewValue
1078  ." WHERE ResourceId = ".$ResourceId);
1079  }
1080 
1081  $this->DBFields[$DBFieldName] = $NewValue;
1082 
1083  # recalculate counts for any associated classifications if necessary
1084  if ($DBFieldName == "ReleaseFlag")
1085  {
1086  $DB->Query("SELECT ClassificationId FROM ResourceClassInts"
1087  ." WHERE ResourceId = ".$ResourceId);
1088  while ($ClassId = $DB->FetchField("ClassificationId"))
1089  {
1090  $Class = new Classification($ClassId);
1091  $Class->RecalcResourceCount();
1092  }
1093  }
1094  $UpdateModTime = TRUE;
1095  }
1096  break;
1097 
1099  # if value passed in was object
1100  if (is_object($NewValue))
1101  {
1102  # retrieve user ID from object
1103  $UserId = $NewValue->Get("UserId");
1104  }
1105  # else if value passed in was user name
1106  elseif (is_string($NewValue) && strlen($NewValue))
1107  {
1108  # create user object and retrieve user ID from there
1109  $User = new CWUser($NewValue);
1110  $UserId = $User->Get("UserId");
1111  }
1112  else
1113  {
1114  # assume value is user ID and use value directly
1115  $UserId = $NewValue;
1116  }
1117 
1118  if ($this->DBFields[$DBFieldName] != $UserId)
1119  {
1120  # save value directly to DB
1121  $DB->Query("UPDATE Resources SET `"
1122  .$DBFieldName."` = '".$UserId."' "
1123  ."WHERE ResourceId = ".$ResourceId);
1124 
1125  # save value locally
1126  $this->DBFields[$DBFieldName] = $UserId;
1127  $UpdateModTime = TRUE;
1128  }
1129  break;
1130 
1132  # if we were given a date object
1133  if (is_object($NewValue))
1134  {
1135  # use supplied date object
1136  $Date = $NewValue;
1137  }
1138  else
1139  {
1140  # create date object
1141  $Date = new Date($NewValue);
1142  }
1143 
1144  $OldDate = new Date(
1145  $this->DBFields[$DBFieldName."Begin"],
1146  $this->DBFields[$DBFieldName."End"]);
1147 
1148  if ($OldDate->BeginDate() != $Date->BeginDate() ||
1149  $OldDate->EndDate() != $Date->EndDate() ||
1150  $OldDate->Precision() != $Date->Precision() )
1151  {
1152  # extract values from date object and store in DB
1153  $BeginDate = "'".$Date->BeginDate()."'";
1154  if (strlen($BeginDate) < 3) { $BeginDate = "NULL"; }
1155  $EndDate = "'".$Date->EndDate()."'";
1156  if (strlen($EndDate) < 3) { $EndDate = "NULL"; }
1157 
1158  $DB->Query("UPDATE Resources SET "
1159  .$DBFieldName."Begin = ".$BeginDate.", "
1160  .$DBFieldName."End = ".$EndDate.", "
1161  .$DBFieldName."Precision = '".$Date->Precision()."' "
1162  ."WHERE ResourceId = ".$ResourceId);
1163 
1164  # save values locally
1165  $this->DBFields[$DBFieldName."Begin"] = $Date->BeginDate();
1166  $this->DBFields[$DBFieldName."End"] = $Date->EndDate();
1167  $this->DBFields[$DBFieldName."Precision"] = $Date->Precision();
1168  $UpdateModTime=TRUE;
1169  }
1170  break;
1171 
1173  if (is_null($NewValue) || !strlen(trim($NewValue)))
1174  {
1175  $DateValue = $NewValue;
1176 
1177  if (!is_null($this->DBFields[$DBFieldName]))
1178  {
1179  # save value directly to DB
1180  $DB->Query("UPDATE Resources SET "
1181  ."`".$DBFieldName."` = NULL "
1182  ."WHERE ResourceId = ".$ResourceId);
1183  $UpdateModTime = TRUE;
1184  }
1185  }
1186  else
1187  {
1188  # assume value is date and use directly
1189  $TimestampValue = strtotime($NewValue);
1190 
1191  # use the new value if the date is valid
1192  if ($TimestampValue !== FALSE && $TimestampValue >= 0)
1193  {
1194  $DateValue = date("Y-m-d H:i:s", $TimestampValue);
1195 
1196  if ($this->DBFields[$DBFieldName] != $DateValue)
1197  {
1198  # save value directly to DB
1199  $DB->Query("UPDATE Resources SET "
1200  ."`".$DBFieldName."` = '".addslashes($DateValue)."' "
1201  ."WHERE ResourceId = ".$ResourceId);
1202  $UpdateModTime=TRUE;
1203  }
1204  }
1205 
1206  # continue using the old value if invalid
1207  else
1208  {
1209  $DateValue = $this->Get($Field);
1210  }
1211  }
1212 
1213  # save value locally
1214  $this->DBFields[$DBFieldName] = $DateValue;
1215  break;
1216 
1218  $OldValue = $this->Get($Field);
1219 
1220  # if incoming value is array
1221  if (is_array($NewValue))
1222  {
1223  if ($OldValue != $NewValue)
1224  {
1225  # for each element of array
1226  foreach ($NewValue as
1227  $ClassificationId => $ClassificationName)
1228  {
1229  $Class = new Classification($ClassificationId);
1230  if ($Class->Status() == Classification::CLASSSTAT_OK)
1231  {
1232  # associate with resource if not already associated
1233  $this->AddAssociation("ResourceClassInts",
1234  "ClassificationId",
1235  $ClassificationId);
1236  $Class->RecalcResourceCount();
1237  }
1238  }
1239  $UpdateModTime=TRUE;
1240  }
1241  }
1242  else
1243  {
1244  # associate with resource if not already associated
1245  if (is_object($NewValue))
1246  {
1247  $Class = $NewValue;
1248  $NewValue = $Class->Id();
1249  }
1250  else
1251  {
1252  $Class = new Classification($NewValue);
1253  }
1254 
1255  if (!array_key_exists($Class->Id(), $OldValue))
1256  {
1257 
1258  $this->AddAssociation("ResourceClassInts",
1259  "ClassificationId",
1260  $NewValue);
1261  $Class->RecalcResourceCount();
1262  $UpdateModTime=TRUE;
1263  }
1264  }
1265 
1266  # clear our classification cache
1267  if ($UpdateModTime)
1268  {
1269  unset($this->ClassificationCache);
1270  }
1271  break;
1272 
1275  $OldValue = $this->Get($Field);
1276 
1277  # Clear other values if this field expects unique options
1278  if ($Field->AllowMultiple() === FALSE)
1279  {
1280  # If we're fed an array for a unique option,
1281  # just use the last element of the array
1282  if (is_array($NewValue)){
1283  $NewValue = array_pop($NewValue);
1284  }
1285 
1286  if (!array_key_exists($NewValue, $OldValue))
1287  {
1288 
1289  $this->RemoveAllAssociations("ResourceNameInts",
1290  "ControlledNameId",
1291  $Field );
1292  $UpdateModTime=TRUE;
1293  }
1294  }
1295 
1296  # if incoming value is array
1297  if (is_array($NewValue) && ($Field->AllowMultiple() !== FALSE) )
1298  {
1299  if ($OldValue != $NewValue)
1300  {
1301  # for each element of array
1302  foreach ($NewValue as $ControlledNameId => $ControlledName)
1303  {
1304  # associate with resource if not already associated
1305  $this->AddAssociation("ResourceNameInts",
1306  "ControlledNameId",
1307  $ControlledNameId);
1308  }
1309  $UpdateModTime=TRUE;
1310  }
1311  }
1312  else
1313  {
1314  # associate with resource if not already associated
1315  if (is_object($NewValue)) { $NewValue = $NewValue->Id(); }
1316  if (!array_key_exists($NewValue, $OldValue))
1317  {
1318  $this->AddAssociation("ResourceNameInts",
1319  "ControlledNameId",
1320  $NewValue);
1321  $UpdateModTime=TRUE;
1322  }
1323  }
1324 
1325  if ($UpdateModTime)
1326  {
1327  # clear our controlled name cache
1328  unset($this->ControlledNameCache);
1329  unset($this->ControlledNameVariantCache);
1330  }
1331 
1332  break;
1333 
1335  # associate value(s) with resource
1336  $this->AddAssociation(
1337  "ResourceImageInts", "ImageId", $NewValue, $Field);
1338  break;
1339 
1341  # convert incoming value to array if necessary
1342  if (!is_array($NewValue)) { $NewValue = array($NewValue); }
1343 
1344  # for each incoming file
1345  $Factory = new FileFactory($Field->Id());
1346  foreach ($NewValue as $File)
1347  {
1348  # make copy of file
1349  $NewFile = $Factory->Copy($File);
1350 
1351  # associate copy with this resource and field
1352  $NewFile->ResourceId($this->Id);
1353  $NewFile->FieldId($Field->Id());
1354  }
1355  # Since we make a fresh copy of the File whenever Set is called,
1356  # we'll always update the modification time for this field.
1357  $UpdateModTime = TRUE;
1358  break;
1359 
1361  # convert incoming value to array to simplify the workflow
1362  if (is_scalar($NewValue) || $NewValue instanceof Resource)
1363  {
1364  $NewValue = array($NewValue);
1365  }
1366 
1367  # delete existing resource references
1368  $this->ClearByField($Field);
1369 
1370  # add each reference
1371  foreach ($NewValue as $ReferenceOrId)
1372  {
1373  # initially issume it's a reference ID and not an object...
1374  $ReferenceId = $ReferenceOrId;
1375 
1376  # ... but get the reference ID if it's an object
1377  if ($ReferenceOrId instanceof Resource)
1378  {
1379  $ReferenceId = $ReferenceOrId->Id();
1380  }
1381 
1382  # skip blank reference IDs
1383  if (strlen(trim($ReferenceId)) < 1)
1384  {
1385  continue;
1386  }
1387 
1388  # skip reference IDs that don't look right
1389  if (!is_numeric($ReferenceId))
1390  {
1391  continue;
1392  }
1393 
1394  # skip references to the current resource
1395  if ($ReferenceId == $this->Id())
1396  {
1397  continue;
1398  }
1399 
1400  # add the reference to the references table
1401  $DB->Query("
1402  INSERT INTO ReferenceInts (
1403  FieldId,
1404  SrcResourceId,
1405  DstResourceId)
1406  VALUES (
1407  ".addslashes($Field->Id()).",
1408  ".addslashes($this->Id()).",
1409  ".addslashes($ReferenceId).")");
1410  }
1411  break;
1412 
1413  default:
1414  # ERROR OUT
1415  exit("<br>SPT - ERROR: attempt to set unknown resource field type<br>\n");
1416  break;
1417  }
1418 
1419  if ($UpdateModTime && !$this->IsTempResource())
1420  {
1421  # update modification timestamps
1422  global $G_User;
1423  $UserId = $G_User->IsLoggedIn() ? $G_User->Get("UserId") : -1;
1424  $DB->Query("DELETE FROM ResourceFieldTimestamps "
1425  ."WHERE ResourceId=".$this->Id." AND "
1426  ."FieldId=".$Field->Id() );
1427  $DB->Query("INSERT INTO ResourceFieldTimestamps "
1428  ."(ResourceId,FieldId,ModifiedBy,Timestamp) VALUES ("
1429  .$this->Id.",".$Field->Id().","
1430  .$UserId.",NOW())");
1431  }
1432  }
1437  function SetByField($Field, $NewValue) { $this->Set($Field, $NewValue); }
1438 
1439  # set value by field ID
1440  function SetByFieldId($FieldId, $NewValue)
1441  {
1442  $Field = $this->Schema->GetField($FieldId);
1443  $this->Set($Field, $NewValue);
1444  }
1445 
1446  # set qualifier by field name
1447  function SetQualifier($FieldName, $NewValue)
1448  {
1449  $Field = $this->Schema->GetFieldByName($FieldName);
1450  $this->SetQualifierByField($Field, $NewValue);
1451  }
1452 
1453  # set qualifier by field ID
1454  function SetQualifierByFieldId($FieldId, $NewValue)
1455  {
1456  $Field = $this->Schema->GetField($FieldId);
1457  $this->SetQualifierByField($Field, $NewValue);
1458  }
1459 
1460  # set qualifier using field object
1461  function SetQualifierByField($Field, $NewValue)
1462  {
1463  # if field uses qualifiers and uses item-level qualifiers
1464  if ($Field->UsesQualifiers() && $Field->HasItemLevelQualifiers())
1465  {
1466  # if qualifier object passed in
1467  if (is_object($NewValue))
1468  {
1469  # grab qualifier ID from object
1470  $QualifierId = $NewValue->Id();
1471  }
1472  else
1473  {
1474  # assume value passed in is qualifier ID
1475  $QualifierId = $NewValue;
1476  }
1477 
1478  # update qualifier value in database
1479  $DBFieldName = $Field->DBFieldName();
1480  $this->DB->Query("UPDATE Resources SET "
1481  .$DBFieldName."Qualifier = '".$QualifierId."' "
1482  ."WHERE ResourceId = ".$this->Id);
1483 
1484  # update local qualifier value
1485  $this->DBFields[$DBFieldName."Qualifier"] = $QualifierId;
1486  }
1487  }
1488 
1489  # clear value by field ID
1490  function ClearByFieldId($FieldId, $ValueToClear = NULL)
1491  {
1492  $Field = $this->Schema->GetField($FieldId);
1493  $this->ClearByField($Field, $ValueToClear);
1494  }
1495 
1496  # clear value using field object
1497  function Clear($Field, $ValueToClear = NULL)
1498  {
1499  # convert field name to object if necessary
1500  if (!is_object($Field))
1501  {
1502  $Field = $this->Schema->GetFieldByName($Field);
1503  }
1504 
1505  # grab commonly-used values for local use
1506  $DB = $this->DB;
1507  $ResourceId = $this->Id;
1508 
1509  # grab database field name
1510  $DBFieldName = $Field->DBFieldName();
1511 
1512  $UpdateModTime=FALSE;
1513 
1514  # store value in DB based on field type
1515  switch ($Field->Type())
1516  {
1524  if (strlen($this->DBFields[$DBFieldName])>0)
1525  {
1526  # clear value in DB
1527  $DB->Query("UPDATE Resources SET `"
1528  .$DBFieldName."` = NULL "
1529  ."WHERE ResourceId = ".$ResourceId);
1530 
1531  # clear value locally
1532  $this->DBFields[$DBFieldName] = NULL;
1533  $UpdateModTime=TRUE;
1534  }
1535  break;
1536 
1538  if (!is_null($this->DBFields[$DBFieldName."X"]) ||
1539  !is_null($this->DBFields[$DBFieldName."Y"]) )
1540  {
1541  # Clear DB Values
1542  $DB->Query("UPDATE Resources SET "
1543  ."`".$DBFieldName."X` = NULL ,"
1544  ."`".$DBFieldName."Y` = NULL "
1545  ."WHERE ResourceId = ".$ResourceId);
1546 
1547  # Clear local values
1548  $this->DBFields[$DBFieldName."X"] = NULL;
1549  $this->DBFields[$DBFieldName."Y"] = NULL;
1550  $UpdateModTime=TRUE;
1551  }
1552  break;
1553 
1555  if (!is_null($this->DBFields[$DBFieldName."Begin"]) ||
1556  !is_null($this->DBFields[$DBFieldName."End"]) ||
1557  !is_null($this->DBFields[$DBFieldName."Precision"]))
1558  {
1559  # clear date object values in DB
1560  $DB->Query("UPDATE Resources SET "
1561  .$DBFieldName."Begin = '', "
1562  .$DBFieldName."End = '', "
1563  .$DBFieldName."Precision = '' "
1564  ."WHERE ResourceId = ".$ResourceId);
1565 
1566  # clear value locally
1567  $this->DBFields[$DBFieldName."Begin"] = NULL;
1568  $this->DBFields[$DBFieldName."End"] = NULL;
1569  $this->DBFields[$DBFieldName."Precision"] = NULL;
1570  $UpdateModTime=TRUE;
1571  }
1572  break;
1573 
1575  $OldValue = $this->Get($Field);
1576 
1577  # if value to clear supplied
1578  if ($ValueToClear !== NULL)
1579  {
1580  # if supplied value is array
1581  if (is_array($ValueToClear))
1582  {
1583  # for each element of array
1584  foreach ($ValueToClear as $ClassificationId => $Dummy)
1585  {
1586  if (array_key_exists($ClassificationId, $OldValue))
1587  {
1588  # remove association with resource (if any)
1589  $this->RemoveAssociation("ResourceClassInts",
1590  "ClassificationId",
1591  $ClassificationId);
1592  $Class = new Classification($ClassificationId);
1593  $Class->RecalcResourceCount();
1594  $UpdateModTime=TRUE;
1595  }
1596  }
1597  }
1598  else
1599  {
1600  if (array_key_exists($ValueToClear, $OldValue))
1601  {
1602  # remove association with resource (if any)
1603  $this->RemoveAssociation("ResourceClassInts",
1604  "ClassificationId",
1605  $ValueToClear);
1606  $Class = new Classification($ValueToClear);
1607  $Class->RecalcResourceCount();
1608  $UpdateModTime=TRUE;
1609  }
1610  }
1611  }
1612  else
1613  {
1614  if (count($OldValue)>0)
1615  {
1616  # remove all associations for resource and field
1617  $this->RemoveAllAssociations("ResourceClassInts", "ClassificationId", $Field);
1618 
1619  # recompute resource count
1620  $Values = $this->Get($Field);
1621  foreach ($Values as $ClassificationId => $Dummy)
1622  {
1623  $Class = new Classification($ClassificationId);
1624  $Class->RecalcResourceCount();
1625  }
1626  $UpdateModTime=TRUE;
1627  }
1628  }
1629 
1630  # clear our classification cache
1631  if ($UpdateModTime)
1632  {
1633  unset($this->ClassificationCache);
1634  }
1635  break;
1636 
1639  $OldValue = $this->Get($Field);
1640  # if value to clear supplied
1641  if ($ValueToClear !== NULL)
1642  {
1643  # if incoming value is array
1644  if (is_array($ValueToClear))
1645  {
1646  # for each element of array
1647  foreach ($ValueToClear as $ControlledNameId =>
1648  $ControlledName)
1649  {
1650  if (array_key_exists($ControlledNameId, $OldValue))
1651  {
1652  # remove association with resource (if any)
1653  $this->RemoveAssociation("ResourceNameInts",
1654  "ControlledNameId",
1655  $ControlledNameId);
1656  $UpdateModTime=TRUE;
1657  }
1658  }
1659  }
1660  else
1661  {
1662  if (array_key_exists($ValueToClear, $OldValue))
1663  {
1664  # remove association with resource (if any)
1665  $this->RemoveAssociation("ResourceNameInts",
1666  "ControlledNameId",
1667  $ValueToClear);
1668  $UpdateModTime=TRUE;
1669  }
1670  }
1671  }
1672  else
1673  {
1674  if (count($OldValue)>0)
1675  {
1676  # remove all associations for resource and field
1677  $this->RemoveAllAssociations("ResourceNameInts", "ControlledNameId", $Field);
1678  $UpdateModTime=TRUE;
1679  }
1680  }
1681 
1682  if ($UpdateModTime)
1683  {
1684  # clear our controlled name cache
1685  unset($this->ControlledNameCache);
1686  unset($this->ControlledNameVariantCache);
1687  }
1688  break;
1689 
1691  # if value to clear supplied
1692  if ($ValueToClear !== NULL)
1693  {
1694  # convert value to array if necessary
1695  $Files = $ValueToClear;
1696  if (!is_array($Files)) { $Files = array($Files); }
1697 
1698  # convert values to objects if necessary
1699  foreach ($Files as $Index => $File)
1700  {
1701  if (!is_object($File))
1702  {
1703  $Files[$Index] = new File($File);
1704  }
1705  }
1706  }
1707  else
1708  {
1709  # use all files associated with resource
1710  $Files = $this->Get($Field, TRUE);
1711  }
1712 
1713  # delete files
1714  foreach ($Files as $File) { $File->Delete(); }
1715  break;
1716 
1718  # if value to clear supplied
1719  if ($ValueToClear !== NULL)
1720  {
1721  # convert value to array if necessary
1722  $Images = $ValueToClear;
1723  if (!is_array($Images)) { $Images = array($Images); }
1724 
1725  # convert values to objects if necessary
1726  foreach ($Images as $Index => $Image)
1727  {
1728  if (!is_object($Image))
1729  {
1730  $Images[$Index] = new SPTImage($Image);
1731  }
1732  }
1733  }
1734  else
1735  {
1736  # use all images associated with resource
1737  $Images = $this->Get($Field, TRUE);
1738  }
1739 
1740  # delete images if we are the last resource referencing
1741  # a particular image.
1742  foreach ($Images as $Image) {
1743  $Cnt = $this->DB->Query(
1744  "SELECT COUNT(*) AS Cnt FROM ResourceImageInts WHERE ".
1745  "ImageId=".$Image->Id(), "Cnt");
1746  if ($Cnt==1)
1747  $Image->Delete();
1748  }
1749 
1750  # remove connections to images
1751  $UpdateModTime = $this->RemoveAssociation(
1752  "ResourceImageInts", "ImageId", $Images, $Field);
1753  break;
1754 
1756  # remove references from the references table
1757  $DB->Query("
1758  DELETE FROM ReferenceInts
1759  WHERE FieldId = '".addslashes($Field->Id())."'
1760  AND SrcResourceId = '".addslashes($this->Id())."'");
1761  break;
1762 
1763  default:
1764  # ERROR OUT
1765  exit("<br>SPT - ERROR: attempt to clear unknown resource field type<br>\n");
1766  break;
1767  }
1768 
1769  if ($UpdateModTime && !$this->IsTempResource())
1770  {
1771  # update modification timestamps
1772  global $G_User;
1773  $UserId = $G_User->IsLoggedIn() ? $G_User->Get("UserId") : -1;
1774  $DB->Query("DELETE FROM ResourceFieldTimestamps "
1775  ."WHERE ResourceId=".$this->Id." AND "
1776  ."FieldId=".$Field->Id() );
1777  $DB->Query("INSERT INTO ResourceFieldTimestamps "
1778  ."(ResourceId,FieldId,ModifiedBy,Timestamp) VALUES ("
1779  .$this->Id.",".$Field->Id().","
1780  .$UserId.",NOW())");
1781  }
1782  }
1783  function ClearByField($Field, $ValueToClear = NULL)
1784  { $this->Clear($Field, $ValueToClear); }
1785 
1786 
1787  # --- Field-Specific or Type-Specific Attribute Retrieval Methods -------
1788 
1789  # return 2D array of classifications associated with resource
1790  # (first index is classification (field) name, second index is classification ID)
1791  function Classifications()
1792  {
1793  $DB = $this->DB;
1794 
1795  # start with empty array
1796  $Names = array();
1797 
1798  # for each controlled name
1799  $DB->Query("SELECT ClassificationName, MetadataFields.FieldName, "
1800  ."ResourceClassInts.ClassificationId FROM ResourceClassInts, "
1801  ."Classifications, MetadataFields "
1802  ."WHERE ResourceClassInts.ResourceId = ".$this->Id." "
1803  ."AND ResourceClassInts.ClassificationId = Classifications.ClassificationId "
1804  ."AND Classifications.FieldId = MetadataFields.FieldId ");
1805  while ($Record = $DB->FetchRow())
1806  {
1807  # add name to array
1808  $Names[$Record["FieldName"]][$Record["ClassificationId"]] =
1809  $Record["ClassificationName"];
1810  }
1811 
1812  # return array to caller
1813  return $Names;
1814  }
1815 
1816 
1817  # --- Ratings Methods ---------------------------------------------------
1818 
1819  # return cumulative rating (range is usually 0-100)
1820  function CumulativeRating() { return $this->CumulativeRating; }
1821 
1822  # return cumulative rating scaled to 1/10th (range is usually 0-10)
1824  {
1825  if ($this->CumulativeRating == NULL)
1826  {
1827  return NULL;
1828  }
1829  else
1830  {
1831  return intval(($this->CumulativeRating + 5) / 10);
1832  }
1833  }
1834 
1835  # return current number of ratings for resource
1836  function NumberOfRatings()
1837  {
1838  # if number of ratings not already set
1839  if (!isset($this->NumberOfRatings))
1840  {
1841  # obtain number of ratings
1842  $this->NumberOfRatings =
1843  $this->DB->Query("SELECT Count(*) AS NumberOfRatings "
1844  ."FROM ResourceRatings "
1845  ."WHERE ResourceId = ".$this->Id,
1846  "NumberOfRatings"
1847  );
1848 
1849  # recalculate cumulative rating if it looks erroneous
1850  if (($this->NumberOfRatings > 0) && !$this->CumulativeRating())
1851  {
1852  $this->UpdateCumulativeRating();
1853  }
1854  }
1855 
1856  # return number of ratings to caller
1857  return $this->NumberOfRatings;
1858  }
1859 
1860  # update individual rating for resource
1861  function Rating($NewRating = NULL, $UserId = NULL)
1862  {
1863  $DB = $this->DB;
1864 
1865  # if user ID not supplied
1866  if ($UserId == NULL)
1867  {
1868  # if user is logged in
1869  global $User;
1870  if ($User->IsLoggedIn())
1871  {
1872  # use ID of current user
1873  $UserId = $User->Get("UserId");
1874  }
1875  else
1876  {
1877  # return NULL to caller
1878  return NULL;
1879  }
1880  }
1881 
1882  # sanitize $NewRating
1883  if (!is_null($NewRating))
1884  {
1885  $NewRating = intval($NewRating);
1886  }
1887 
1888  # if there is a rating for resource and user
1889  $DB->Query("SELECT Rating FROM ResourceRatings "
1890  ."WHERE UserId = ${UserId} AND ResourceId = ".$this->Id);
1891  if ($Record = $DB->FetchRow())
1892  {
1893  # if new rating was supplied
1894  if ($NewRating != NULL)
1895  {
1896  # update existing rating
1897  $DB->Query("UPDATE ResourceRatings "
1898  ."SET Rating = ${NewRating}, DateRated = NOW() "
1899  ."WHERE UserId = ${UserId} AND ResourceId = ".$this->Id);
1900 
1901  # update cumulative rating value
1902  $this->UpdateCumulativeRating();
1903 
1904  # return value is new rating
1905  $Rating = $NewRating;
1906  }
1907  else
1908  {
1909  # get rating value to return to caller
1910  $Rating = $Record["Rating"];
1911  }
1912  }
1913  else
1914  {
1915  # if new rating was supplied
1916  if ($NewRating != NULL)
1917  {
1918  # add new rating
1919  $DB->Query("INSERT INTO ResourceRatings "
1920  ."(ResourceId, UserId, DateRated, Rating) "
1921  ."VALUES ("
1922  .$this->Id.", "
1923  ."${UserId}, "
1924  ."NOW(), "
1925  ."${NewRating})");
1926 
1927  # update cumulative rating value
1928  $this->UpdateCumulativeRating();
1929 
1930  # return value is new rating
1931  $Rating = $NewRating;
1932  }
1933  else
1934  {
1935  # return value is NULL
1936  $Rating = NULL;
1937  }
1938  }
1939 
1940  # return rating value to caller
1941  return $Rating;
1942  }
1943 
1944 
1945  # --- Resource Comment Methods ------------------------------------------
1946 
1947  # return comments as array of Message objects
1948  function Comments()
1949  {
1950  # read in comments if not already loaded
1951  if (!isset($this->Comments))
1952  {
1953  $this->DB->Query("SELECT MessageId FROM Messages "
1954  ."WHERE ParentId = ".$this->Id
1955  ." AND ParentType = 2 "
1956  ."ORDER BY DatePosted DESC");
1957  while ($MessageId = $this->DB->FetchField("MessageId"))
1958  {
1959  $this->Comments[] = new Message($MessageId);
1960  }
1961  }
1962 
1963  # return array of comments to caller
1964  return $this->Comments;
1965  }
1966 
1967  # return current number of comments
1968  function NumberOfComments()
1969  {
1970  # obtain number of comments if not already set
1971  if (!isset($this->NumberOfComments))
1972  {
1973  $this->NumberOfComments =
1974  $this->DB->Query("SELECT Count(*) AS NumberOfComments "
1975  ."FROM Messages "
1976  ."WHERE ParentId = ".$this->Id
1977  ." AND ParentType = 2",
1978  "NumberOfComments"
1979  );
1980  }
1981 
1982  # return number of comments to caller
1983  return $this->NumberOfComments;
1984  }
1985 
1986 
1987  # --- Permission Methods -------------------------------------------------
1988 
1996  function UserCanView(User $User)
1997  {
1998  # cannot view a resource that is not valid
1999  if ($this->Status() !== 1) { return FALSE; }
2000 
2001  # get viewing privilege set for resource
2002  $Schema = new MetadataSchema($this->SchemaId());
2003  $ResourcePrivs = $Schema->ViewingPrivileges();
2004 
2005  # get privilege set for user
2006  $UserPrivs = $User->Privileges();
2007 
2008  # user can view if privileges are greater than resource set
2009  $CanView = $UserPrivs->IsGreaterThan($ResourcePrivs, $this);
2010 
2011  # allow plugins to modify result of the permission check
2012  $SignalResult = $GLOBALS["AF"]->SignalEvent(
2013  "EVENT_RESOURCE_VIEW_PERMISSION_CHECK",
2014  array("Resource" => $this, "User" => $User, "CanView" => $CanView));
2015  $CanView = $SignalResult["CanView"];
2016 
2017  return $CanView;
2018  }
2019 
2026  function UserCanEdit($User)
2027  {
2028  # cannot edit a resource that you cannot view
2029  if (!$this->UserCanView($User)) { return FALSE; }
2030 
2031  # get editing privilege set for resource
2032  $Schema = new MetadataSchema($this->SchemaId());
2033  $ResourcePrivs = $Schema->EditingPrivileges();
2034 
2035  # get privilege set for user
2036  $UserPrivs = $User->Privileges();
2037 
2038  # user can edit if privileges are greater than resource set
2039  $CanEdit = $UserPrivs->IsGreaterThan($ResourcePrivs, $this);
2040 
2041  # allow plugins to modify result of permission check
2042  $SignalResult = $GLOBALS["AF"]->SignalEvent(
2043  "EVENT_RESOURCE_EDIT_PERMISSION_CHECK", array(
2044  "Resource" => $this,
2045  "User" => $User,
2046  "CanEdit" => $CanEdit));
2047  $CanEdit = $SignalResult["CanEdit"];
2048 
2049  # report back to caller whether user can edit field
2050  return $CanEdit;
2051  }
2052 
2059  function UserCanViewField($User, $FieldOrFieldName)
2060  {
2061  # get field object (if not supplied)
2062  $Field = is_object($FieldOrFieldName) ? $FieldOrFieldName
2063  : $this->Schema->GetFieldByName($FieldOrFieldName);
2064 
2065  # field absolutely cannot be viewed if it is not valid
2066  if (!($Field instanceof MetadataField)) { return FALSE; }
2067 
2068  # field should not be viewed if it is disabled
2069  if (!$Field->Enabled())
2070  {
2071  $CanView = FALSE;
2072  }
2073  else
2074  {
2075  # if the user can edit the field they can also view it
2076  if ($this->UserCanEditField($User, $Field))
2077  {
2078  $CanView = TRUE;
2079  }
2080  else
2081  {
2082  # get appropriate privilege set for field
2083  $FieldPrivs = $Field->ViewingPrivileges();
2084 
2085  # get privilege set for user
2086  $UserPrivs = $User->Privileges();
2087 
2088  # user can view if privileges are greater than field set
2089  $CanView = $UserPrivs->IsGreaterThan($FieldPrivs, $this);
2090  }
2091  }
2092 
2093  # allow plugins to modify result of permission check
2094  $SignalResult = $GLOBALS["AF"]->SignalEvent(
2095  "EVENT_FIELD_VIEW_PERMISSION_CHECK", array(
2096  "Field" => $Field,
2097  "Resource" => $this,
2098  "User" => $User,
2099  "CanView" => $CanView));
2100  $CanView = $SignalResult["CanView"];
2101 
2102  # report back to caller whether user can view field
2103  return $CanView;
2104  }
2105 
2112  function UserCanAuthorField($User, $FieldOrFieldName)
2113  {
2114  # fields hard-coded to not be authorable
2115  $UnauthorableFields = array(
2116  "Cumulative Rating",
2117  "Date Of Record Creation",
2118  "Date Of Record Release",
2119  "Date Last Modified",
2120  "Last Modified By Id");
2121 
2122  # get field object (if not supplied)
2123  $Field = is_object($FieldOrFieldName) ? $FieldOrFieldName
2124  : $this->Schema->GetFieldByName($FieldOrFieldName);
2125 
2126  # field absolutely cannot be authored if it is not valid
2127  if (!($Field instanceof MetadataField)) { return FALSE; }
2128 
2129  # field should not be authored if it is disabled or is on "no author" list
2130  # or user is not the resource creator
2131  if (!$Field->Enabled()
2132  || in_array($Field->Name(), $UnauthorableFields)
2133  || ($User->Name() != $this->Get("Added By Id")))
2134  {
2135  $CanAuthor = FALSE;
2136  }
2137  else
2138  {
2139  # get appropriate privilege set for field
2140  $FieldPrivs = $Field->AuthoringPrivileges();
2141 
2142  # get privilege set for user
2143  $UserPrivs = $User->Privileges();
2144 
2145  # user can author if privileges are greater than field set
2146  $CanAuthor = $UserPrivs->IsGreaterThan($FieldPrivs, $this);
2147  }
2148 
2149  # allow plugins to modify result of permission check
2150  $SignalResult = $GLOBALS["AF"]->SignalEvent(
2151  "EVENT_FIELD_AUTHOR_PERMISSION_CHECK", array(
2152  "Field" => $Field,
2153  "Resource" => $this,
2154  "User" => $User,
2155  "CanAuthor" => $CanAuthor));
2156  $CanAuthor = $SignalResult["CanAuthor"];
2157 
2158  # report back to caller whether user can author field
2159  return $CanAuthor;
2160  }
2161 
2168  function UserCanEditField($User, $FieldOrFieldName)
2169  {
2170  # fields hard-coded to not be editable
2171  $UneditableFields = array(
2172  "Cumulative Rating",
2173  "Date Of Record Creation",
2174  "Date Of Record Release",
2175  "Date Last Modified",
2176  "Last Modified By Id");
2177 
2178  # get field object (if not supplied)
2179  $Field = is_object($FieldOrFieldName) ? $FieldOrFieldName
2180  : $this->Schema->GetFieldByName($FieldOrFieldName);
2181 
2182  # field absolutely cannot be edited if it is not valid
2183  if (!($Field instanceof MetadataField)) { return FALSE; }
2184 
2185  # field should not be edited if it is disabled or is on "no edit" list
2186  if (!$Field->Enabled() || in_array($Field->Name(), $UneditableFields))
2187  {
2188  $CanEdit = FALSE;
2189  }
2190  else
2191  {
2192  # get appropriate privilege set for field
2193  $FieldPrivs = $Field->EditingPrivileges();
2194 
2195  # get privilege set for user
2196  $UserPrivs = $User->Privileges();
2197 
2198  # user can edit if privileges are greater than field set
2199  $CanEdit = $UserPrivs->IsGreaterThan($FieldPrivs, $this);
2200  }
2201 
2202  # allow plugins to modify result of permission check
2203  $SignalResult = $GLOBALS["AF"]->SignalEvent(
2204  "EVENT_FIELD_EDIT_PERMISSION_CHECK", array(
2205  "Field" => $Field,
2206  "Resource" => $this,
2207  "User" => $User,
2208  "CanEdit" => $CanEdit));
2209  $CanEdit = $SignalResult["CanEdit"];
2210 
2211  # report back to caller whether user can edit field
2212  return $CanEdit;
2213  }
2214 
2215  # ---- PRIVATE INTERFACE -------------------------------------------------
2216 
2217  private $DB;
2218  private $Schema;
2219  private $DBFields;
2220  private $Id;
2221  private $NumberOfRatings;
2222  private $CumulativeRating;
2223  private $NumberOfComments;
2224  private $Comments;
2225  private $LastStatus;
2226  private $ControlledNameCache;
2227  private $ControlledNameVariantCache;
2228  private $ClassificationCache;
2229 
2230  # recalculate and save cumulative rating value for resource
2231  private function UpdateCumulativeRating()
2232  {
2233  # grab totals from DB
2234  $this->DB->Query("SELECT COUNT(Rating) AS Count, "
2235  ."SUM(Rating) AS Total FROM ResourceRatings "
2236  ."WHERE ResourceId = ".$this->Id);
2237  $Record = $this->DB->FetchRow();
2238 
2239  # calculate new cumulative rating
2240  $this->CumulativeRating = round($Record["Total"] / $Record["Count"]);
2241 
2242  # save new cumulative rating in DB
2243  $this->DB->Query("UPDATE Resources "
2244  ."SET CumulativeRating = ".$this->CumulativeRating." "
2245  ."WHERE ResourceId = ".$this->Id);
2246  }
2247 
2258  private function AddAssociation($TableName, $FieldName, $Value, $Field = NULL)
2259  {
2260  # start out assuming no association will be added
2261  $AssociationAdded = FALSE;
2262 
2263  # convert new value to array if necessary
2264  $Values = is_array($Value) ? $Value : array($Value);
2265 
2266  # for each new value
2267  foreach ($Values as $Value)
2268  {
2269  # retrieve ID from value if necessary
2270  if (is_object($Value)) { $Value = $Value->Id(); }
2271 
2272  # if value is not already associated with resource
2273  if ($this->DB->Query("SELECT COUNT(*) AS RecordCount FROM ".$TableName
2274  ." WHERE ResourceId = ".$this->Id
2275  ." AND ".$FieldName." = ".intval($Value)
2276  .($Field ? " AND FieldId = ".intval($Field->Id()) : ""),
2277  "RecordCount") == 0)
2278  {
2279  # associate value with resource
2280  $this->DB->Query("INSERT INTO ".$TableName." SET"
2281  ." ResourceId = ".intval($this->Id)
2282  .", ".$FieldName." = ".intval($Value)
2283  .($Field ? ", FieldId = ".intval($Field->Id()) : ""));
2284  $AssociationAdded = TRUE;
2285  }
2286  }
2287 
2288  # report to caller whether association was added
2289  return $AssociationAdded;
2290  }
2291 
2302  private function RemoveAssociation($TableName, $FieldName, $Value, $Field = NULL)
2303  {
2304  # start out assuming no association will be removed
2305  $AssociationRemoved = FALSE;
2306 
2307  # convert value to array if necessary
2308  $Values = is_array($Value) ? $Value : array($Value);
2309 
2310  # for each value
2311  foreach ($Values as $Value)
2312  {
2313  # retrieve ID from value if necessary
2314  if (is_object($Value)) { $Value = $Value->Id(); }
2315 
2316  # remove any intersections with target ID from DB
2317  $this->DB->Query("DELETE FROM ".$TableName
2318  ." WHERE ResourceId = ".intval($this->Id)
2319  .($Field ? " AND FieldId = ".intval($Field->Id()) : "")
2320  ." AND ".$FieldName." = ".intval($Value));
2321  }
2322 
2323  # report to caller whether association was added
2324  return $AssociationRemoved;
2325  }
2326 
2327  # remove all intersections for resource and field (if any)
2328  private function RemoveAllAssociations($TableName, $TargetFieldName, $Field)
2329  {
2330  # retrieve list of entries for this field and resource
2331  $Entries = $this->Get($Field);
2332 
2333  # for each entry
2334  foreach ($Entries as $EntryId => $EntryName)
2335  {
2336  # remove intersection
2337  $this->RemoveAssociation($TableName, $TargetFieldName, $EntryId);
2338  }
2339  }
2340 }
GetByField($FieldNameOrObject, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Old method for retrieving values, deprecated in favor of Get().
Definition: Resource.php:643
GetFilesForResource($ResourceOrResourceId, $ReturnObjects=TRUE)
Retrieve all files (names or objects) for specified resource.
Definition: FileFactory.php:38
Set($FieldNameOrObject, $NewValue)
Set value using field name or field object.
Definition: Resource.php:968
SetQualifier($FieldName, $NewValue)
Definition: Resource.php:1447
Metadata schema (in effect a Factory class for MetadataField).
Resource($ResourceId)
Object constructor for loading an existing resource.
Definition: Resource.php:23
Abstraction for forum messages and resource comments.
Definition: Message.php:15
SQL database abstraction object with smart query caching.
GetAsArray($IncludeDisabledFields=FALSE, $ReturnObjects=TRUE)
Retrieve all resource values as an array.
Definition: Resource.php:678
Id()
Retrieve numerical resource ID.
Definition: Resource.php:255
UserCanEditField($User, $FieldOrFieldName)
Check whether user is allowed to edit specified metadata field.
Definition: Resource.php:2168
SetQualifierByField($Field, $NewValue)
Definition: Resource.php:1461
Rating($NewRating=NULL, $UserId=NULL)
Definition: Resource.php:1861
Status()
Retrieve result of last operation if available.
Definition: Resource.php:249
NumberOfComments()
Definition: Resource.php:1968
NumberOfRatings()
Definition: Resource.php:1836
GetQualifier($FieldName, $ReturnObject=TRUE)
Retrieve qualifier by field name.
Definition: Resource.php:740
Factory object for Folder class, used to retrieve and manage Folders and groups of Folders...
Copy($FileToCopy)
Create copy of File and return to caller.
Definition: FileFactory.php:84
Metadata type representing non-hierarchical controlled vocabulary values.
UserCanEdit($User)
Determine if the given user can edit the resource.
Definition: Resource.php:2026
const MDFTYPE_CONTROLLEDNAME
CWIS-specific user factory class.
PHP
Definition: OAIClient.php:39
Factory for manipulating File objects.
Definition: FileFactory.php:13
GetQualifierByFieldId($FieldId, $ReturnObject=TRUE)
Retrieve qualifier by field ID.
Definition: Resource.php:754
Encapsulates a full-size, preview, and thumbnail image.
Definition: SPTImage.php:13
UserCanAuthorField($User, $FieldOrFieldName)
Check whether user is allowed to author specified metadata field.
Definition: Resource.php:2112
UserCanView(User $User)
Determine if the given user can view the resource, e.g., on the full record page. ...
Definition: Resource.php:1996
Clear($Field, $ValueToClear=NULL)
Definition: Resource.php:1497
GetByFieldId($FieldId, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using field ID.
Definition: Resource.php:660
IsTempResource($NewSetting=NULL)
Get/set whether resource is a temporary record.
Definition: Resource.php:269
Get($FieldNameOrObject, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using field name or field object.
Definition: Resource.php:347
SetByField($Field, $NewValue)
Method replaced by Resource::Set(), preserved for backward compatibility.
Definition: Resource.php:1437
Object representing a locally-defined type of metadata field.
GetMapped($MappedName, $ReturnObject=FALSE, $IncludeVariants=FALSE)
Retrieve value using standard (mapped) field name.
Definition: Resource.php:724
Represents a &quot;resource&quot; in CWIS.
Definition: Resource.php:13
GetQualifierByField($Field, $ReturnObject=TRUE)
Retrieve qualifier by Field object.
Definition: Resource.php:768
ClearByFieldId($FieldId, $ValueToClear=NULL)
Definition: Resource.php:1490
const CLASSSTAT_OK
Status code indicating operation completed successfully.
SetQualifierByFieldId($FieldId, $NewValue)
Definition: Resource.php:1454
SchemaId()
Retrieve ID of schema for resource.
Definition: Resource.php:261
ScaledCumulativeRating()
Definition: Resource.php:1823
const UPDATEMETHOD_ONRECORDCREATE
static Create($SchemaId)
Create a new resource.
Definition: Resource.php:59
UserCanViewField($User, $FieldOrFieldName)
Check whether user is allowed to view specified metadata field.
Definition: Resource.php:2059
Metadata type representing hierarchical (&quot;Tree&quot;) controlled vocabulary values.
SetByFieldId($FieldId, $NewValue)
Definition: Resource.php:1440
Classifications()
Definition: Resource.php:1791
ClearByField($Field, $ValueToClear=NULL)
Definition: Resource.php:1783
Class representing a stored (usually uploaded) file.
Definition: File.php:13
Factory for Resource objects.
CWIS-specific user class.
Definition: CWUser.php:13
CumulativeRating()
Definition: Resource.php:1820
FieldIsSet($FieldNameOrObject, $IgnorePadding=FALSE)
Determine if the value for a field is set.
Definition: Resource.php:899
Delete()
Remove resource (and accompanying associations) from database and delete any associated files...
Definition: Resource.php:142