Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- Search for |

- File List
- File Members

# SPTRecommender.php

Go to the documentation of this file.

    00001 <?PHP
    00002
    00003 #
    00004 #   FILE:  SPT--Recommender.php
    00005 #
    00006 #   METHODS PROVIDED:
    00007 #       Recommender()
    00008 #           - constructor
    00009 #       SomeMethod($SomeParameter, $AnotherParameter)
    00010 #           - short description of method
    00011 #
    00012 #   AUTHOR:  Edward Almasy
    00013 #
    00014 #   Part of the Scout Portal Toolkit
    00015 #   Copyright 2002-2004 Internet Scout Project
    00016 #   http://scout.wisc.edu
    00017 #
    00018
    00019 class SPTRecommender extends Recommender {
    00020
    00021     function SPTRecommender()
    00022     {
    00023         # set up recommender configuration values for SPT
    00024         $ItemTableName = "Resources";
    00025         $ItemIdFieldName = "ResourceId";
    00026         $RatingTableName = "ResourceRatings";
    00027         $UserIdFieldName = "UserId";
    00028         $RatingFieldName = "Rating";
    00029
    00030         # build field info from SPT metadata schema
    00031         $this->Schema = new MetadataSchema();
    00032         $Fields = $this->Schema->GetFields();
    00033         foreach ($Fields as $Field)
    00034         {
    00035             if ($Field->Enabled() && $Field->IncludeInKeywordSearch())
    00036             {
    00037                 $FieldName = $Field->Name();
    00038                 $FieldInfo[$FieldName]["DBFieldName"] = $Field->DBFieldName();
    00039                 $FieldInfo[$FieldName]["Weight"] = $Field->SearchWeight();
    00040                 switch ($Field->Type())
    00041                 {
    00042                 case MetadataSchema::MDFTYPE_TEXT:
    00043                 case MetadataSchema::MDFTYPE_PARAGRAPH:
    00044                 case MetadataSchema::MDFTYPE_USER:
    00045                 case MetadataSchema::MDFTYPE_URL:
    00046                     $FieldInfo[$FieldName]["FieldType"] =
    00047                         Recommender::CONTENTFIELDTYPE_TEXT;
    00048                     break;
    00049
    00050                 case MetadataSchema::MDFTYPE_TREE:
    00051                 case MetadataSchema::MDFTYPE_CONTROLLEDNAME:
    00052                 case MetadataSchema::MDFTYPE_OPTION:
    00053                     $FieldInfo[$FieldName]["FieldType"] =
    00054                         Recommender::CONTENTFIELDTYPE_TEXT;
    00055                     break;
    00056
    00057                 case MetadataSchema::MDFTYPE_NUMBER:
    00058                 case MetadataSchema::MDFTYPE_FLAG:
    00059                         $FieldInfo[$FieldName]["FieldType"] =
    00060                             Recommender::CONTENTFIELDTYPE_NUMERIC;
    00061                         break;
    00062
    00063                 case MetadataSchema::MDFTYPE_DATE:
    00064                     $FieldInfo[$FieldName]["FieldType"] =
    00065                         Recommender::CONTENTFIELDTYPE_DATERANGE;
    00066                     break;
    00067
    00068                 case MetadataSchema::MDFTYPE_TIMESTAMP:
    00069                     $FieldInfo[$FieldName]["FieldType"] =
    00070                         Recommender::CONTENTFIELDTYPE_DATE;
    00071                     break;
    00072
    00073                 case MetadataSchema::MDFTYPE_IMAGE:
    00074                     # (for images we use their alt text)
    00075                     $FieldInfo[$FieldName]["FieldType"] =
    00076                         Recommender::CONTENTFIELDTYPE_TEXT;
    00077                     break;
    00078
    00079                 case MetadataSchema::MDFTYPE_FILE:
    00080                     # (for files we use the file name)
    00081                     $FieldInfo[$FieldName]["FieldType"] =
    00082                         Recommender::CONTENTFIELDTYPE_TEXT;
    00083                     break;
    00084                 }
    00085             }
    00086         }
    00087
    00088         # create our own schema object and tell it to cache values
    00089         $this->Schema = new MetadataSchema();
    00090         $this->Schema->CacheData(TRUE);
    00091
    00092         # create a database connection for recommender to use
    00093         $DB = new SPTDatabase();
    00094
    00095         # pass configuration info to real recommender object
    00096         $this->Recommender($DB, $ItemTableName, $RatingTableName,
    00097                 $ItemIdFieldName, $UserIdFieldName, $RatingFieldName,
    00098                 $FieldInfo);
    00099     }
    00100
    00101     # overloaded version of method to retrieve field values from DB
    00102     function GetFieldValue($ItemId, $FieldName)
    00103     {
    00104         static $Resources;
    00105
    00106         # if resource not already loaded
    00107         if (!isset($Resources[$ItemId]))
    00108         {
    00109             # get resource object
    00110             $Resources[$ItemId] = new Resource($ItemId);
    00111
    00112             # if cached resource limit exceeded
    00113             if (count($Resources) > 100)
    00114             {
    00115                 # dump oldest resource
    00116                 reset($Resources);
    00117                 list($DumpedItemId, $DumpedResources) = each($Resources);
    00118                 unset($Resources[$DumpedItemId]);
    00119             }
    00120         }
    00121
    00122         # retrieve field value from resource object and return to caller
    00123         $FieldValue = $Resources[$ItemId]->Get($FieldName);
    00124         return $FieldValue;
    00125     }
    00126
    00127     # ---- PRIVATE INTERFACE -------------------------------------------------
    00128
    00129     var $Schema;
    00130
    00131 };
    00132
    00133
    00134 ?>

Copyright 2009 Internet Scout