예제 #1
0
 /**
  * Fetches from the DB a list of registered DataSetTypes.
  * @return void
  * @param array $preloadTypes An array containing a number of {@link Schema} type IDs to
  * load structure data for. This will avoid queries later on.
  */
 function loadTypes($preloadTypes)
 {
     debug::output("Fetching all our known Schemas from the database.", DEBUG_SYS1, "DataManager");
     // let's get all our known types
     $query = new SelectQuery();
     $query->addTable("dm_schema");
     $query->addColumn("id", "", "dm_schema");
     $query->addColumn("displayname", "", "dm_schema");
     $query->addColumn("description", "", "dm_schema");
     $query->addColumn("revision", "", "dm_schema");
     $query->addColumn("other_params", "", "dm_schema");
     $query->addWhere("dm_schema.active = 1");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, DATAMANAGER_DBID);
     if (!$result) {
         throwError(new UnknownDBError("DataManager"));
     }
     while ($result->hasMoreRows()) {
         $a = $result->getCurrentRow();
         $result->advanceRow();
         $otherParams = $a['other_params'] ? unserialize($a['other_params']) : null;
         $this->_schemas[$a['id']] = new Schema($a['id'], $a['displayname'], $a['revision'], $a['description'], $otherParams);
         $this->_schemas[$a['id']]->setManagerFlag();
         debug::output("Found type ID " . $a['id'] . ", revision " . $a['revision'], DEBUG_SYS2, "DataManager");
         unset($type);
     }
     $result->free();
     // now let's preload
     if ($preloadTypes) {
         $this->loadMultiple($preloadTypes);
     }
 }
 /**
  * Constructor.
  * @param object Id $setId The Id of this set.
  * @param integer $dbIndex The index of the database connection which has
  * 		tables in which to store the set.
  */
 function PersistentOrderedSet($setId, $dbIndex)
 {
     parent::OrderedSet($setId);
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     // Create our internal array
     $this->_dbIndex = $dbIndex;
     // populate our array with any previously stored items.
     $query = new SelectQuery();
     $query->addColumn("item_order", "item_order");
     $query->addColumn("item_id", "item_id");
     $query->addTable("sets");
     $query->addWhere("id = '" . addslashes($this->_setId->getIdString()) . "'");
     $query->addOrderBy("item_order");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $this->_dbIndex);
     $i = 0;
     $oldItems = array();
     while ($result->hasMoreRows()) {
         // Add the items to our array
         $this->_items[$i] = $result->field("item_id");
         // Store an array of the order-key/value relationships to reference
         // when updating any inconsistancies in order numbering.
         $oldItems[$result->field("item_order")] = $result->field("item_id");
         $i++;
         $result->advanceRow();
     }
     $result->free();
     // Make sure that we have our set is filled from 0 to count()
     reset($oldItems);
     $this->_updateOrders($oldItems);
 }
 /**
  * Answer the PartStructure Ids for which Tags should be auto-generated, in
  * the given repository.
  * 
  * @param object Id $repositoryId
  * @return object IdIterator
  * @access public
  * @since 11/21/06
  */
 function getPartStructureIdsForTagGeneration($repositoryId)
 {
     if (!isset($this->_cache[$repositoryId->getIdString()])) {
         $this->_cache[$repositoryId->getIdString()] = array();
         $query = new SelectQuery();
         $query->addColumn('fk_partstruct');
         $query->addTable('tag_part_map');
         $query->addWhere("fk_repository ='" . addslashes($repositoryId->getIdString()) . "'");
         $dbc = Services::getService("DatabaseManager");
         $result = $dbc->query($query, $this->getDatabaseIndex());
         // Add tag objects to an array, still sorted by frequency of usage
         $idManager = Services::getService('Id');
         while ($result->hasNext()) {
             $row = $result->next();
             $this->_cache[$repositoryId->getIdString()][] = $idManager->getId($row['fk_partstruct']);
         }
     }
     $iterator = new HarmoniIterator($this->_cache[$repositoryId->getIdString()]);
     return $iterator;
 }
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.repository.RepositoryException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}
  * 
  * @access public
  */
 function updateValue($value)
 {
     ArgumentValidator::validate($value, StringValidatorRule::getRule());
     // Store the size in the object in case its asked for again.
     try {
         $size = ByteSize::fromString($value);
     } catch (InvalidArgumentException $e) {
         $size = ByteSize::withValue(0);
     }
     $this->_size = $size->value();
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // Check to see if the name is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // If it already exists, use an update query.
     if ($result->field("count") > 0) {
         $query = new UpdateQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("size"));
         $query->setValues(array("'" . addslashes($this->_size) . "'"));
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("id", "size"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
예제 #5
0
 function _getCanonicalCourse($courseString)
 {
     $cm = Services::getService("CourseManagement");
     //$num = substr($courseString,4,4);
     $number = substr($courseString, 0, strlen($courseString) - 5);
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('cm_can');
     $query->addWhere("number='" . addslashes($number) . "'");
     $query->addColumn('id');
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         //$termType = new Type("Coursemanagement","edu.middlebury",$season);
         //$index = $cm->_typeToIndex('term',$termType);
         $dept = substr($courseString, 0, strlen($courseString) - 9);
         $type = new Type("Coursemanagement", "edu.middlebury", $dept);
         $stattype = new Type("Coursemanagement", "edu.middlebury", "default");
         $can = $cm->createCanonicalCourse($number, $number, "", $type, $stattype, 1);
         print "<font size=4><b>" . $number . "</b> </font>\n";
         return $can;
         //$canId =$can->getId();
         //return $canId->getIdString();
     } else {
         $row = $res->getCurrentRow();
         //$the_index = $row['id'];
         $idManager = Services::getService("Id");
         $id = $idManager->getId($row['id']);
         $can = $cm->getCanonicalCourse($id);
         print "<font size=4>" . $number . " </font>\n";
         return $can;
         //return $the_index;
     }
 }
 /**
  * A public function for getting a type id (and ensuring that it exists
  * in the database). One might consider implementing a Type manager for 
  * stuff like this that has no proper home.
  * 
  * @param object Type $type
  *
  * @return integer
  *
  * @access public
  *
  * @since 11/18/04
  */
 function getTypeId($type)
 {
     $dbc = Services::getService("DBHandler");
     // Check to see if the type already exists in the DB
     $query = new SelectQuery();
     $query->addColumn("type_id");
     $query->addTable("type");
     $query->addWhere("type_domain='" . addslashes($type->getDomain()) . "'");
     $query->addWhere("type_authority='" . addslashes($type->getAuthority()) . "'", _AND);
     $query->addWhere("type_keyword='" . addslashes($type->getKeyword()) . "'", _AND);
     $result = $dbc->query($query, $this->_dbIndex);
     // If we have a type id already, use that
     if ($result->getNumberOfRows()) {
         $typeId = $result->field("type_id");
         $result->free();
     } else {
         $result->free();
         $query = new InsertQuery();
         $query->setTable("type");
         $query->setAutoIncrementColumn("type_id", "type_type_id_seq");
         $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description"));
         $query->setValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'"));
         $result = $dbc->query($query, $this->_dbIndex);
         $typeId = $result->getLastAutoIncrementValue();
     }
     return $typeId;
 }
 /**
  * Tests the generateSQLQuery() without WHERE clause.
  */
 function test()
 {
     // insert one row
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->addRowOfValues(array("'Spaceboy'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     $lastId = $result->getLastAutoIncrementValue();
     // insert it again, the id must have increased by one
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 1);
     // add several rows at the same time
     $query->addRowOfValues(array("'Astrogirl'"));
     $result = $this->db->query($query);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 3);
     // now insert in the other test table
     $query = new InsertQuery();
     $query->setTable("test");
     $query->setColumns(array("FK", "value"));
     $query->addRowOfValues(array($lastId, "'Ziggy'"));
     $query->addRowOfValues(array($lastId + 1, "'Lost in the Stars'"));
     $query->addRowOfValues(array($lastId + 2, "'Headstar'"));
     $query->addRowOfValues(array($lastId + 3, "'Stardust'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     // join the inserted rows
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addTable("test", INNER_JOIN, "test.FK = test1.id");
     $query->addColumn("id", "dm86_id", "test");
     $query->addColumn("FK", "dm86_fk", "test");
     $query->addColumn("value", "dm86_value", "test");
     $query->addColumn("id", "dm98_id", "test1");
     $query->addColumn("value", "dm98_value", "test1");
     $query->addWhere("test1.id >= " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 4);
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId);
     $this->assertIdentical($result->field("dm86_value"), "Ziggy");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 1);
     $this->assertIdentical($result->field("dm86_value"), "Lost in the Stars");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 1);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 2);
     $this->assertIdentical($result->field("dm86_value"), "Headstar");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 2);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 3);
     $this->assertIdentical($result->field("dm86_value"), "Stardust");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 3);
     $this->assertIdentical($result->field("dm98_value"), "Astrogirl");
     $result->free();
     $query = new UpdateQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->setValues(array("'I changed you MF!'"));
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->field("value"), "I changed you MF!");
     $result->free();
     $query = new DeleteQuery();
     $query->setTable("test1");
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 0);
     $result->free();
 }
 /**
  * Initializes the structures of the Asset to allow for record creation
  * 
  * @return void
  * @access public
  * @since 3/1/06
  */
 public final function getStructuresForPlugin()
 {
     if (!isset($this->_structures)) {
         $db = Services::getService("DBHandler");
         $type = $this->_asset->getAssetType();
         $query = new SelectQuery();
         $query->addTable("plugin_manager");
         $query->addTable("plugin_type", INNER_JOIN, "plugin_type.type_id = plugin_manager.fk_plugin_type");
         $query->addWhere("plugin_type.type_domain = '" . addslashes($type->getDomain()) . "'");
         $query->addWhere("plugin_type.type_authority = '" . addslashes($type->getAuthority()) . "'");
         $query->addWhere("plugin_type.type_keyword = '" . addslashes($type->getKeyword()) . "'");
         $query->addColumn("*");
         $results = $db->query($query, IMPORTER_CONNECTION);
         $id = Services::getService("Id");
         $rm = Services::getService("Repository");
         $sites_rep = $rm->getRepository($id->getId("edu.middlebury.segue.sites_repository"));
         $structures = array();
         // populate structures array with displayname to id association
         while ($results->hasMoreRows()) {
             $result = $results->next();
             $rs = $sites_rep->getRecordStructure($id->getId($result['plugin_manager.fk_schema']));
             $structures[$rs->getDisplayName()] = $result['plugin_manager.fk_schema'];
         }
         $this->_structures = $structures;
     }
     return $this->_structures;
 }
 /**
  * Delete the log with the specified name.
  * 
  * @param string $logName
  * 
  * @throws object LoggingException An exception with one of the
  *		   following messages defined in org.osid.logging.LoggingException
  *		   may be thrown:  {@link
  *		   org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  *		   {@link org.osid.logging.LoggingException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.logging.LoggingException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.logging.LoggingException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  * 
  * @access public
  */
 function deleteLog($logName)
 {
     $log = $this->getLogForWriting($logName);
     $log = null;
     $dbc = Services::getService("DatabaseManager");
     // get the entry Ids
     $query = new SelectQuery();
     $query->addColumn("id");
     $query->addTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $result = $dbc->query($query, $this->_dbIndex);
     $entryIds = array();
     while ($result->hasMoreRows()) {
         $entryIds[] = "'" . addslashes($result->field("id")) . "'";
         $result->advanceRow();
     }
     $result->free();
     // delete the agent keys
     $query = new DeleteQuery();
     $query->setTable("log_agent");
     $query->addWhere("fk_entry IN (" . implode(", ", $entryIds) . ")");
     $dbc->query($query, $this->_dbIndex);
     // delete the node keys
     $query->setTable("log_node");
     $dbc->query($query, $this->_dbIndex);
     // delete the entries
     $query = new DeleteQuery();
     $query->setTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $dbc->query($query, $this->_dbIndex);
 }
예제 #10
0
 /**
  * Answer true if the current agent has tagged the item
  * 
  * @param object TaggedItem $item
  * @return boolean
  * @access public
  * @since 11/13/06
  */
 function isItemTagged($item)
 {
     $query = new SelectQuery();
     $query->addColumn('COUNT(*)', 'count');
     $query->addTable('tag');
     $query->addTable('tag_item', INNER_JOIN, "tag.fk_item = tag_item.db_id");
     $query->addWhere("tag.value='" . addslashes($this->getValue()) . "'");
     $query->addWhere("tag.user_id='" . addslashes($this->getCurrentUserIdString()) . "'");
     $query->addWhere("tag_item.id='" . addslashes($item->getIdString()) . "'");
     $query->addWhere("tag_item.system='" . addslashes($item->getSystem()) . "'");
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     if (intval($result->field('count')) > 0) {
         return true;
     } else {
         return false;
     }
 }
예제 #11
0
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.repository.RepositoryException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}
  * 
  * @access public
  */
 function updateValue($value)
 {
     if (!is_null($value)) {
         ArgumentValidator::validate($value, NonzeroLengthStringValidatorRule::getRule());
     }
     // Store the name in the object in case its asked for again.
     $this->_type = $value;
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // If we have a key, make sure it exists.
     if ($this->_type && $this->_type != "NULL") {
         // Check to see if the type is in the database
         $query = new SelectQuery();
         $query->addTable("dr_mime_type");
         $query->addColumn("id");
         $query->addWhere("type = '" . $this->_type . "'");
         $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         // If it doesn't exist, insert it.
         if (!$result->getNumberOfRows()) {
             $query = new InsertQuery();
             $query->setTable("dr_mime_type");
             $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq");
             $query->setColumns(array("type"));
             $query->setValues(array("'" . addslashes($this->_type) . "'"));
             $result2 = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
             $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'";
         } else {
             $mimeId = "'" . $result->field("id") . "'";
         }
         $result->free();
     } else {
         $mimeId = "NULL";
     }
     // add its id to the file.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->setColumns(array("fk_mime_type"));
     $query->setValues(array($mimeId));
     $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
예제 #12
0
 /**
  * Get the value for this Part.
  *	
  * @return object mixed (original type: java.io.Serializable)
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}
  * 
  * @access public
  */
 function getValue()
 {
     // If we don't have the name, load it from the database.
     if ($this->_size === NULL) {
         $dbHandler = Services::getService("DatabaseManager");
         // Get the name from the database,
         $query = new SelectQuery();
         $query->addTable("dr_file");
         $query->addColumn("size");
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
         $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         // If no name was found, return an empty string.
         if ($result->getNumberOfRows() == 0) {
             $this->_size = 0;
         } else {
             $this->_size = $result->field("size");
         }
         $result->free();
     }
     return $this->_size;
 }
예제 #13
0
 /**
  * Answer the tags not created by the given agent for one or more items
  * 
  * @param mixed $items The items to return tags for. This can be a single Item object,
  *		an ItemIterator, or an array of Item objects.
  * @param object Id $agentId
  * @param string $sortBy Return tags in alphanumeric order or by frequency of usage.
  * @param integer $max The maximum number of tags to return. The least frequently used
  * 		tags will be dropped first. If $max is 0, all tags will be returned.
  * @return object TagIterator
  * @access public
  * @since 11/10/06
  */
 function getTagsForItemsNotByAgent($items, $agentId, $sortBy = TAG_SORT_ALFA, $max = 0)
 {
     $query = new SelectQuery();
     $query->addColumn('value');
     $query->addColumn('COUNT(value)', 'occurances');
     $query->addTable('tag');
     $query->setGroupBy(array('value'));
     $query->addOrderBy('occurances', DESCENDING);
     $query->addWhere("user_id!='" . addslashes($agentId->getIdString()) . "'");
     if ($max) {
         $query->limitNumberOfRows($max);
     }
     $itemDbIds = array();
     // array
     if (is_array($items)) {
         foreach (array_keys($items) as $key) {
             $itemDbIds[] = "'" . addslashes($items[$key]->getDatabaseId()) . "'";
         }
     } else {
         if (method_exists($items, 'next')) {
             while ($items->hasNext()) {
                 $item = $items->next();
                 $itemDbIds[] = "'" . addslashes($item->getDatabaseId()) . "'";
             }
         } else {
             if (method_exists($items, 'getDatabaseId')) {
                 $itemDbIds[] = "'" . addslashes($items->getDatabaseId()) . "'";
             } else {
                 throwError(new Error("Invalid parameter, " . get_class($items) . ", for \$items", "Tagging"));
             }
         }
     }
     $query->addWhere("tag.fk_item IN (" . implode(", ", $itemDbIds) . ")");
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     // Add tag objects to an array, still sorted by frequency of usage
     $tags = array();
     while ($result->hasNext()) {
         $row = $result->next();
         $tags[$row['value']] = new Tag($row['value']);
         $tags[$row['value']]->setOccurances($row['occurances']);
     }
     // If necessary, sort these top tags alphabetically
     if ($sortBy == TAG_SORT_ALFA) {
         ksort($tags);
     }
     $iterator = new HarmoniIterator($tags);
     return $iterator;
 }
 /**
  * Given the object in table $table with id $id, get the field with name $key
  *
  * @param object Id $id The Id of the object in question
  * @param string $table The table that our object resides in
  * @param string $key The name of the field
  *
  * @return string
  *
  * @access private
  */
 function _getField($id, $table, $key)
 {
     // Validate the Id
     ArgumentValidator::validate($id, ExtendsValidatorRule::getRule("Id"), true);
     $idString = $id->getIdString();
     //just a select query
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable($table);
     $query->addWhere("id='" . addslashes($idString) . "'");
     $query->addColumn(addslashes($key));
     $res = $dbHandler->query($query);
     if (!$res->hasMoreRows()) {
         throwError(new Error("Cannot get key '" . $key . "' from non-existant object with id '" . $idString . "'", "CourseManagement", true));
     }
     $row = $res->getCurrentRow();
     $ret = $row[$key];
     return $ret;
 }
예제 #15
0
 /**
  * Installs a plugin
  * 
  * @param object HarmoniType $type gives us the location of plugin to be 
  * installed
  * @access public
  * @since 3/6/06
  */
 function installPlugin($type)
 {
     // @todo deal with new plugin readiness structure, and database tables
     $authZ = Services::getService("AuthZ");
     //		if ($authZ->isUserAuthorized("edu.middlebury.authorization.add_children", ??))	{
     $dr = Services::getService("Repository");
     $dm = Services::getService("DataTypeManager");
     $db = Services::getService("DBHandler");
     $id = Services::getService("Id");
     // a few things we need
     $site_rep = $dr->getRepository($id->getId("edu.middlebury.segue.sites_repository"));
     $pluginDir = $this->getConfiguration('plugin_dir');
     $types = $dm->getRegisteredTypes();
     // for partstructures
     // use the plugin type to get through the filesystem
     $domain = $type->getDomain();
     $authority = $type->getAuthority();
     $keyword = $type->getKeyword();
     $description = "The type for a {$domain} {$authority} {$keyword} plugin.";
     // write the type to the database
     $query = new InsertQuery();
     $query->setTable('plugin_type');
     $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description", "type_enabled"));
     $query->addRowOfValues(array("'" . addslashes($domain) . "'", "'" . addslashes($authority) . "'", "'" . addslashes($keyword) . "'", "'" . addslashes($description) . "'", '0'));
     $db->query($query, IMPORTER_CONNECTION);
     // grab the xml file
     $xmlFile = $pluginDir . "/" . $domain . "/" . $authority . "/" . $keyword . "/" . $authority . $keyword . "Plugin.xml";
     // if there is no file then the plugin has no data structures
     if (is_file($xmlFile)) {
         $document = new DOMDocument();
         $document->loadXML($xmlFile);
         $recordStructures = $document->documentElement->childNodes;
         // first create the recordstructure(s)
         foreach ($recordStructures as $rs) {
             if ($rs->hasAttribute("name")) {
                 $rsName = $rs->getAttribute("name");
                 $plugStruct = $site_rep->createRecordStructure($rsName, "This is the {$rsName} structure for holding data of the {$domain} {$authority} {$keyword} plugin", "", "");
                 $pSId = $plugStruct->getId();
                 $partStructures = $rs->childNodes;
                 // now create the partstructure(s)
                 foreach ($partStructures as $ps) {
                     if ($ps->hasAttribute("name") && $ps->hasAttribute("type")) {
                         $psName = $ps->getAttribute("name");
                         $psType = $ps->getAttribute("type");
                         if (in_array($psType, $types)) {
                             $plugStruct->createPartStructure($psName, "This is the {$psName} structure for holding data of the {$domain} {$authority} {$keyword} plugin", new Type("Repository", "edu.middlebury.segue", $psType), false, true, false);
                         }
                     }
                 }
                 // write to the DB the plugin and its structures
                 $typeId = null;
                 $query2 = new SelectQuery();
                 $query2->addTable("plugin_type");
                 $query2->addColumn("*");
                 $query2->addWhere("type_domain = '" . addslashes($domain) . "'");
                 $query2->addWhere("type_authority = '" . addslashes($authority) . "'");
                 $query2->addWhere("type_keyword = '" . addslashes($keyword) . "'");
                 $results = $db->query($query2, IMPORTER_CONNECTION);
                 if ($results->getNumberOfRows() == 1) {
                     $result = $results->next();
                     $typeId = $result['type_id'];
                     $results->free();
                     $query3 = new InsertQuery();
                     $query3->setTable("plugin_manager");
                     $query3->setColumns(array("fk_plugin_type", "fk_schema"));
                     $query3->addRowOfValues(array("'" . addslashes($typeId) . "'", "'" . addslashes($pSId->getIdString()) . "'"));
                     $db->query($query3, IMPORTER_CONNECTION);
                 } else {
                     $results->free();
                     throwError(new Error("PluginType not found", "Plugins", false));
                 }
             }
         }
     }
     if (!in_array($type->asString(), array_keys($this->getInstalledPlugins()))) {
         $this->addPluginToArray($type);
     }
     //	}
 }
예제 #16
0
 function _getProperties()
 {
     $dbManager = Services::getService("DatabaseManager");
     //get the record
     $query = new SelectQuery();
     $query->addTable('cm_section');
     $query->addColumn("*");
     $query->addWhere("id='" . addslashes($this->_id->getIdString()) . "'");
     $res = $dbManager->query($query);
     //make sure we can find that course
     if (!$res->hasMoreRows()) {
         print "<b>Warning!</b>  Can't get Properties of Course with id " . $this->_id . " since that id wasn't found in the database.";
         return null;
     }
     $row = $res->getCurrentRow();
     //grab (hopefully) the only row
     //make a type
     $courseType = $this->getSectionType();
     $propertiesType = new Type("PropertiesType", $courseType->getAuthority(), "properties");
     //create a custom Properties object
     $idManager = Services::getService("Id");
     $property = new HarmoniProperties($propertiesType);
     $displayName = $this->_node->getDisplayName();
     $property->addProperty('display_name', $displayName);
     $property->addProperty('title', $row['title']);
     $description = $this->_node->getDescription();
     $property->addProperty('description', $description);
     $property->addProperty('id', $idManager->getId($row['id']));
     $property->addProperty('number', $row['number']);
     $property->addProperty('type', $courseType);
     $statusType = $this->getStatus();
     $property->addProperty('status_type', $statusType);
     $property->addProperty('location', $row['location']);
     $res->free();
     return $property;
 }
예제 #17
0
 /**
  * Answer the mime type key
  * 
  * @param string $mimeType
  * @return integer
  * @access public
  * @since 2/13/06
  */
 function getMimeKey()
 {
     // If we have a key, make sure it exists.
     if ($this->_mimeType && $this->_mimeType != "NULL") {
         $dbc = Services::getService('DatabaseManager');
         // Check to see if the type is in the database
         $query = new SelectQuery();
         $query->addTable("dr_mime_type");
         $query->addColumn("id");
         $query->addWhere("type = '" . $this->_mimeType . "'");
         $result = $dbc->query($query, $this->getDBIndex());
         // If it doesn't exist, insert it.
         if (!$result->getNumberOfRows()) {
             $query = new InsertQuery();
             $query->setTable("dr_mime_type");
             $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq");
             $query->setColumns(array("type"));
             $query->setValues(array("'" . addslashes($this->_mimeType) . "'"));
             $result2 = $dbc->query($query, $this->getDBIndex());
             $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'";
         } else {
             $mimeId = "'" . $result->field("id") . "'";
         }
         $result->free();
     } else {
         $mimeId = "NULL";
     }
     return $mimeId;
 }
 /**
  * Given the object in table $table with id $id, get the field with name $key 
  * 
  * @param object Id $id The Id of the object in question
  * @param string $table The table that our object resides in
  * @param string $key The name of the field
  * 
  * @return string 
  * 
  * @access private
  */
 function _getField($id, $table, $key)
 {
     //just a select query
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable($table);
     $query->addWhere("id='" . addslashes($id->getIdString()) . "'");
     $query->addColumn(addslashes($key));
     $res = $dbHandler->query($query);
     $row = $res->getCurrentRow();
     $ret = $row[$key];
     return $ret;
 }
예제 #19
0
 /**
  * Loads dates from the database and sets the _datesInDB flag
  * 
  * @return void
  * @access public
  * @since 8/10/04
  */
 function _loadDates()
 {
     $dbHandler = Services::getService("DatabaseManager");
     // Get the content DataSet.
     $id = $this->_node->getId();
     $query = new SelectQuery();
     $query->addTable("dr_asset_info");
     $query->addColumn("effective_date");
     $query->addColumn("expiration_date");
     $query->addColumn("create_timestamp");
     $query->addColumn("creator");
     $query->addColumn("modify_timestamp");
     $query->addWhere("asset_id='" . $id->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_dbIndex);
     // If we have stored dates for this asset set them
     if ($result->getNumberOfRows()) {
         $this->_effectiveDate = $dbHandler->fromDBDate($result->field("effective_date"), $this->_dbIndex);
         $this->_expirationDate = $dbHandler->fromDBDate($result->field("expiration_date"), $this->_dbIndex);
         $this->_createDate = $dbHandler->fromDBDate($result->field("create_timestamp"), $this->_dbIndex);
         $this->_creator = $result->field("creator");
         $this->_modifyDate = $dbHandler->fromDBDate($result->field("modify_timestamp"), $this->_dbIndex);
         $this->_datesInDB = TRUE;
         if (!$this->_createDate) {
             $this->_createDate = DateAndTime::epoch();
         }
         if (!$this->_modifyDate) {
             $this->_modifyDate = DateAndTime::epoch();
         }
     } else {
         $this->_effectiveDate = NULL;
         $this->_expirationDate = NULL;
         $this->_createDate = DateAndTime::epoch();
         $this->_modifyDate = DateAndTime::epoch();
         $this->_creator = NULL;
         $this->_datesInDB = FALSE;
     }
     $result->free();
 }
예제 #20
0
 function _getCourseOffering($can, $term, $courseString)
 {
     //$num = substr($courseString,4,4);
     $number = substr($courseString, 0, strlen($courseString) - 5);
     $termId = $term->getId();
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('cm_offer');
     $query->addWhere("number='" . addslashes($number) . "'");
     $query->addWhere("fk_cm_term='" . addslashes($termId->getIdString()) . "'");
     $query->addColumn('id');
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         $deftype1 = new Type("CourseOfferingType", "edu.middlebury", "LDAP");
         $deftype2 = new Type("CourseOfferingStatusType", "edu.middlebury", "LDAP");
         $deftype3 = new Type("GradeType", "edu.middlebury", "LDAP");
         $offer = $can->createCourseOffering($number, $number, "", $termId, $deftype1, $deftype2, $deftype3);
         //	print "<font size=3 color='red'>#</font>\n";
         return $offer;
     } else {
         //print " ";
         $row = $res->getCurrentRow();
         $cm = Services::getService("CourseManagement");
         $idManager = Services::getService("Id");
         $id = $idManager->getId($row['id']);
         $offer = $cm->getCourseOffering($id);
         //print "<font size=3>#</font>\n";
         return $offer;
     }
 }
예제 #21
0
 /**
  * Populate the info for this item
  * 
  * @return void
  * @access public
  * @since 11/8/06
  */
 function _loadInfo()
 {
     if (!isset($this->_displayName) || !isset($this->_description)) {
         $query = new SelectQuery();
         $query->addColumn('db_id');
         $query->addColumn('display_name');
         $query->addColumn('description');
         $query->addTable('tag_item');
         $query->addWhere("id='" . addslashes($this->getIdString()) . "'");
         $dbc = Services::getService("DatabaseManager");
         $result = $dbc->query($query, $this->getDatabaseIndex());
         $this->_dbId = intval($result->field('db_id'));
         $this->_displayName = $result->field('display_name');
         $this->_description = $result->field('description');
     }
 }
예제 #22
0
 /**
  * Sychronize the cache. Remove any nodes from the cache whose AZs may have 
  * changed.
  * 
  * @return void
  * @access public
  * @since 12/20/05
  */
 function _synchronizeCache()
 {
     $dbHandler = Services::getService("DBHandler");
     foreach (array_keys($_SESSION['__isAuthorizedCacheAgents']) as $agentIdString) {
         // Select the nodeIds who's authorization situation may have changed
         // since the cache was last synchronized. Clear these Ids from the cache.
         $query = new SelectQuery();
         $query->addTable("az2_node");
         $query->setColumns(array("id"));
         $dbDate = $dbHandler->toDBDate($_SESSION['__isAuthorizedCacheTime'][$agentIdString], $this->_configuration->getProperty('database_index'));
         $query->addWhere("last_changed > " . $dbDate);
         // 		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
         $result = $dbHandler->query($query, $this->_configuration->getProperty('database_index'));
         while ($result->hasMoreRows()) {
             unset($_SESSION['__isAuthorizedCache'][$agentIdString][$result->field("id")]);
             $result->advanceRow();
         }
         $result->free();
         $_SESSION['__isAuthorizedCacheTime'][$agentIdString] = DateAndTime::now();
     }
 }
예제 #23
0
 /**
  * Returns the Ids of all groups a DMRecord ID is in.
  *
  * @param int $id
  * @return array An indexed array of the group ids (integers).
  */
 function getRecordSetIDsContainingID($id)
 {
     if (!$id) {
         return array();
     }
     // no ID
     $query = new SelectQuery();
     $query->addTable("dm_record_set");
     $query->addColumn("id");
     $query->addWhere("fk_record='" . addslashes($id) . "'");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, DATAMANAGER_DBID);
     $groupIds = array();
     while ($result->hasMoreRows()) {
         $groupIds[] = $result->field("id");
         $result->advanceRow();
     }
     $result->free();
     return $groupIds;
 }
 /**
  * Get a Properties object with the information about this object.
  *
  * @return object Properties
  *
  * @access private
  */
 function _getProperties()
 {
     //get the record
     $dbManager = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addTable('gr_gradable');
     $query->addColumn("*");
     $query->addWhere("id='" . addslashes($this->_id->getIdString()) . "'");
     $res = $dbManager->query($query);
     //make sure we can find that record
     if (!$res->hasMoreRows()) {
         print "<b>Warning!</b>  Can't get Properties of GradableObject with id " . $this->_id . " since that id wasn't found in the database.";
         return null;
     }
     $row = $res->getCurrentRow();
     //grab (hopefully) the only row
     //make a type
     $type = $this->getGradeType();
     $propertiesType = new Type("PropertiesType", $type->getAuthority(), "properties");
     //create a custom Properties object
     $idManager = Services::getService("Id");
     $property = new HarmoniProperties($propertiesType);
     $property->addProperty('id', $idManager->getId($row['id']));
     $scoringType = $this->getScoringDefinition();
     $property->addProperty('scoring_type', $scoringType);
     $gradeType = $this->getGradeType();
     $property->addProperty('grade_type', $gradeType);
     $gradeScale = $this->getGradeScale();
     $property->addProperty('grade_scale', $gradeScale);
     $property->addProperty('description', $row['description']);
     $property->addProperty('display_name', $row['name']);
     $property->addProperty('modified_date', $row['modified_date']);
     $property->addProperty('modified_by_agent_id', $idManager->getId($row['fk_modified_by_agent']));
     $property->addProperty('reference_id', $idManager->getId($row['fk_reference_id']));
     $property->addProperty('course_section_id', $idManager->getId($row['fk_cm_section']));
     $property->addProperty('weight', $row['weight']);
     $res->free();
     return $property;
 }
 /**
  * Get the key of the type.
  * 
  * @param object Type $type
  * @return integer
  * @access private
  * @since 3/9/05
  */
 function _getTypeKey(Type $type)
 {
     $dbc = Services::getService("DatabaseManager");
     // Check if the type exists and return its key if found.
     $query = new SelectQuery();
     $query->addTable($this->_typeTable);
     $query->addColumn('id');
     $query->addWhere("domain='" . addslashes($type->getDomain()) . "'");
     $query->addWhere("authority='" . addslashes($type->getAuthority()) . "'", _AND);
     $query->addWhere("keyword='" . addslashes($type->getKeyword()) . "'", _AND);
     $result = $dbc->query($query, $this->_dbId);
     if ($result->getNumberOfRows() == 1) {
         return $result->field('id');
     } else {
         $result->free();
         $query = new InsertQuery();
         $query->setTable($this->_typeTable);
         $query->setAutoIncrementColumn("id", $this->_typeTable . "_id_seq");
         $query->setColumns(array('domain', 'authority', 'keyword', 'description'));
         $query->setValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'"));
         $result = $dbc->query($query, $this->_dbId);
         return $result->getLastAutoIncrementValue();
     }
 }
예제 #26
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $dbHandler = Services::getService("DBHandler");
     $repositoryManager = Services::getService("Repository");
     $idManager = Services::getService("Id");
     print "lines 46 - 48 in exportexhibmdb.act.php need to be modified for database access";
     //		$mdbIndex = $dbHandler->addDatabase(
     //			new MySQLDatabase("host", "db", "uname", "password"));
     //		$dbHandler->connect($mdbIndex);
     exit;
     $dbHandler->connect(IMPORTER_CONNECTION);
     $exhibitionsQuery = new SelectQuery();
     $exhibitionsQuery->addTable("pressets");
     $exhibitionsQuery->addColumn("id", "exhibitionId");
     $exhibitionsQuery->addColumn("title", "exhibitionName");
     $exhibitionsQuery->addColumn("presentations", "slideshowIds");
     $exhibitionsQuery->addWhere("presentations IS NOT NULL");
     $exhibitionsQuery->addOrderBy("id");
     $exhibitionsResults = $dbHandler->query($exhibitionsQuery, $mdbIndex);
     while ($exhibitionsResults->hasMoreRows()) {
         $exhibition = $exhibitionsResults->next();
         $this->openExhibition($exhibition);
         $slideshowsQuery = new SelectQuery();
         $slideshowsQuery->addTable("preslists");
         $slideshowsQuery->addColumn("id", "slideshowId");
         $slideshowsQuery->addColumn("title", "slideshowName");
         $slideshowsQuery->addColumn("description", "slideshowDescription");
         $slideshowsQuery->addColumn("preslist", "slideOrder");
         $slideshowsQuery->addWhere("preslist IS NOT NULL");
         $slideshowsQuery->addWhere("presset = " . $exhibition['exhibitionId']);
         $slideshowsQuery->addOrderBy("id");
         $slideshowsResults = $dbHandler->query($slideshowsQuery, $mdbIndex);
         while ($slideshowsResults->hasNext()) {
             $slideshow = $slideshowsResults->next();
             $this->openSlideshow($slideshow);
             $order = explode(",", $slideshow['slideOrder']);
             foreach ($order as $presmediaId) {
                 $slideQuery = new SelectQuery();
                 $slideQuery->addTable("presmedia");
                 $slideQuery->addColumn("comment", "slideCaption");
                 $slideQuery->addColumn("media_id");
                 $slideQuery->addWhere("pres_id = " . $slideshow['slideshowId']);
                 $slideQuery->addWhere("id = " . $presmediaId);
                 $slideResult = $dbHandler->query($slideQuery, $mdbIndex);
                 if ($slideResult->getNumberOfRows() == 1) {
                     $slide = $slideResult->getCurrentRow();
                     $mediaQuery = new SelectQuery();
                     $mediaQuery->addTable("media");
                     $mediaQuery->addColumn("id");
                     $mediaQuery->addColumn("fname");
                     $mediaQuery->addWhere("id = " . $slide['media_id']);
                     $mediaResult = $dbHandler->query($mediaQuery, $mdbIndex);
                     if ($mediaResult->getNumberOfRows() == 1) {
                         $media = $mediaResult->getCurrentRow();
                         $idQuery = new SelectQuery();
                         $idQuery->addTable("dr_file");
                         $idQuery->addTable("dr_asset_record", INNER_JOIN, "dr_file.id = dr_asset_record.FK_record");
                         $idQuery->addColumn("dr_asset_record.FK_asset", "asset_id");
                         $idQuery->addColumn("dr_file.filename");
                         $idQuery->addWhere("dr_file.filename = '" . rawurlencode($media['fname']) . "'");
                         $idResult = $dbHandler->query($idQuery, IMPORTER_CONNECTION);
                         if ($idResult->getNumberOfRows() == 1) {
                             $idRow = $idResult->getCurrentRow();
                             $this->addSlide($slide, $idRow['asset_id']);
                         }
                         // @todo handle multiple id's
                         $idResult->free();
                         unset($idQuery);
                     } else {
                         $empty = "";
                         $this->addSlide($slide, $empty);
                     }
                     $mediaResult->free();
                     unset($mediaQuery);
                 }
                 //					else
                 //						print "Bad presmedia: ".$presmediaId."<br />";
                 $slideResult->free();
                 unset($slideQuery);
             }
             unset($order);
             $this->closeSlideshow();
         }
         $slideshowsResults->free();
         unset($slideshowQuery);
         $this->closeAndImportExhibition();
     }
     $exhibitionsResults->free();
     unset($exhibitionsQuery);
     $centerPane = $this->getActionRows();
     ob_start();
     // 		if ($this->_importer->hasErrors()) {
     // 			print("The bad news is that some errors occured during import, they are: <br />");
     // 			$this->_importer->printErrorMessages();
     // 		}
     // 		if ($this->_importer->hasAssets()) {
     // 			print("The good news is that ".count($this->_importer->getGoodAssetIds())." assets were created during import, they are: <br />");
     // 			$this->_importer->printGoodAssetIds();
     // 		}
     $centerPane->add(new Block(ob_get_contents(), 1));
     ob_end_clean();
     $dbHandler->disconnect($mdbIndex);
     return true;
 }
예제 #27
0
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.repository.RepositoryException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}
  * 
  * @access public
  */
 function updateValue($value)
 {
     //		ArgumentValidator::validate($value, StringValidatorRule::getRule());
     $dbHandler = Services::getService("DatabaseManager");
     // Delete the row if we are setting the value to null
     if (is_null($value)) {
         $query = new DeleteQuery();
         $query->setTable("dr_file_data");
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         $this->_asset->updateModificationDate();
         return;
     }
     // Store the data in the object in case its asked for again.
     //		$this->_data = $value;
     // Make sure that the dr_file row is inserted.
     $query = new InsertQuery();
     $query->setTable("dr_file");
     $query->addValue("id", $this->_recordId->getIdString());
     try {
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     } catch (QueryDatabaseException $e) {
         // If an error is thrown inserting (because the file already exists)
         // ignore it.
     }
     $dbHandler->beginTransaction($this->_configuration->getProperty("database_index"));
     // Base64 encode the data to preserve it,
     // then write it to the database.
     // Check to see if the data is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file_data");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // If it already exists, use an update query.
     if ($result->field("count") > 0) {
         $query = new UpdateQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("data"));
         $query->setValues(array("'" . base64_encode($value) . "'"));
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("fk_file", "data"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . base64_encode($value) . "'"));
     }
     $result->free();
     //		printpre($query);
     //		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // Update the size row.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->addValue("size", strval(strlen($value)));
     $query->addWhereEqual("id", $this->_recordId->getIdString());
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $dbHandler->commitTransaction($this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
 /**
  * Sets the node's internal information
  * 
  * @access public
  * @since 10/6/05
  */
 function getNodeInfo()
 {
     $dbHandler = Services::getService("DBHandler");
     // 		$dbIndexConcerto =$dbHandler->addDatabase(new
     // 			MySQLDatabase("localhost", "whitey_concerto", "test", "test"));
     $query = new SelectQuery();
     $query->addTable("xml_id_matrix");
     $query->addColumn("conc_id");
     $query->addColumn("xml_id");
     $id = $this->_node->getAttribute("xml:id");
     $query->addWhere("xml_id = '" . addslashes($id) . "'");
     //$dbHandler->connect($dbIndexConcerto);
     $results = $dbHandler->query($query, IMPORTER_CONNECTION);
     if ($results->getNumberOfRows() == 1) {
         $result = $results->next();
         $idManager = Services::getService("Id");
         $this->_info['recordStructureId'] = $idManager->getId($result['conc_id']);
     } else {
         $this->addError("Bad XML IDREF: " . $id);
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Harmoni");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNonNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Error", "Events involving critical system errors.");
             $item = new AgentNodeEntryItem("RecordImport Error", "Bad XML IDREF: " . htmlspecialchars($id));
             $item->addNodeId($this->_parent->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     }
     $results->free();
 }
예제 #29
0
 /**
  * Do a single query to load all of the small-valued parts for the record;
  * that is, everything but the file and thumb data.
  * 
  * @return void
  * @access private
  * @since 11/17/05
  */
 function _loadParts()
 {
     if ($this->_partsLoaded) {
         return;
     }
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable("dr_file");
     $query->addTable("dr_file_url", LEFT_JOIN, "dr_file.id = dr_file_url.fk_file");
     $query->addTable("dr_thumbnail", LEFT_JOIN, "dr_file.id = dr_thumbnail.fk_file");
     $query->addTable("dr_mime_type", LEFT_JOIN, "dr_file.fk_mime_type = file_mime_type.id", "file_mime_type");
     $query->addTable("dr_mime_type", LEFT_JOIN, "dr_thumbnail.fk_mime_type = thumbnail_mime_type.id", "thumbnail_mime_type");
     $query->addColumn("filename");
     $query->addColumn("size");
     $query->addColumn("dr_file.width", "file_width");
     $query->addColumn("dr_file.height", "file_height");
     $query->addColumn("dr_file_url.url", "url");
     $query->addColumn("file_mime_type.type", "file_type");
     $query->addColumn("thumbnail_mime_type.type", "thumbnail_type");
     $query->addColumn("dr_thumbnail.width", "thumb_width");
     $query->addColumn("dr_thumbnail.height", "thumb_height");
     $query->addWhere("dr_file.id = '" . $this->_id->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     if ($result->getNumberOfRows()) {
         $this->_parts['FILE_NAME']->_updateValue($result->field('filename'));
         $this->_parts['FILE_URL']->_updateValue($result->field('url'));
         $this->_parts['FILE_SIZE']->_updateValue($result->field('size'));
         $this->_parts['MIME_TYPE']->_updateValue($result->field('file_type'));
         $this->_parts['DIMENSIONS']->_updateValue(array($result->field('file_width'), $result->field('file_height')));
         $this->_parts['THUMBNAIL_MIME_TYPE']->_updateValue($result->field('thumbnail_type'));
         $this->_parts['THUMBNAIL_DIMENSIONS']->_updateValue(array($result->field('thumb_width'), $result->field('thumb_height')));
     }
     $this->_partsLoaded = true;
 }
예제 #30
0
 /**
  * Traverses up and caches whatever needs to be cached.
  * @access public
  * @param string idValue The string id of the node to start traversal from.
  * @param integer levels Specifies how many levels of nodes to traverse. If this is negative
  * then the traversal will go on until the last level is processed.
  * @return void
  **/
 function _traverseUp($idValue, $levels)
 {
     $dbHandler = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     // the original value of levels
     $originalLevels = $levels;
     // 		echo "<br /><br /><br /><b>=== TraverseUp: Caching node # $idValue, $levels levels up</b><br />";
     // MySQL has a limit of 31 tables in a select query, thus essentially
     // there is a limit to the max value of $levels.
     // if levels > 31 or levels is negative (full traversal)
     // then set it to 31
     if ($levels > 31 || $levels < 0) {
         $levels = 31;
     }
     // generate query
     $query->addColumn("fk_child", "level0_id", "level0");
     $query->addColumn("fk_parent", "level1_id", "level0");
     $query->addTable("az2_j_node_node", NO_JOIN, "", "level0");
     $query->addOrderBy("level0_id");
     $query->addOrderBy("level1_id");
     // now left join with itself.
     // maximum number of joins is 31, we've used 1 already, so there are 30 left
     for ($level = 1; $level <= $levels - 1; $level++) {
         $joinc = "level" . ($level - 1) . ".fk_hierarchy = level" . $level . ".fk_hierarchy AND level" . ($level - 1) . ".fk_parent = level" . $level . ".fk_child";
         $query->addTable("az2_j_node_node", LEFT_JOIN, $joinc, "level" . $level);
         $query->addColumn("fk_parent", "level" . ($level + 1) . "_id", "level" . $level);
         $query->addOrderBy("level" . ($level + 1) . "_id");
     }
     // this is the where clause
     $where = "level0.fk_hierarchy = '" . addslashes($this->_hierarchyId) . "' AND level0.fk_child = '" . addslashes($idValue) . "'";
     $query->addWhere($where);
     //		echo "<pre>\n";
     //		echo MySQL_SQLGenerator::generateSQLQuery($query);
     //		echo "</pre>\n";
     // execute the query
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     if ($queryResult->hasNext() == 0) {
         $queryResult->free();
         return;
     }
     // note that the query only returns ids of nodes; thus, for each id,
     // we would need to fetch the actual node information from the node table.
     // for all rows returned by the query
     while ($queryResult->hasMoreRows()) {
         $row = $queryResult->getCurrentRow();
         // check all non-null values in current row
         // see if it is cached, if not create a group object and cache it
         for ($level = 0; $level <= $levels; $level++) {
             $nodeId = $row["level{$level}_id"];
             // ignore null values
             if (is_null($nodeId)) {
                 // 					echo "<br />--- skipping to next row (null value encountered)<br />";
                 break;
             }
             // 				echo "<br /><b>Level: $level - Node # $nodeId</b>";
             // if the node has not been cached, then we must create it
             // 				echo "<br />--- CACHE UPDATE: ";
             if (!$this->_isCached($nodeId)) {
                 $nodes = $this->getNodesFromDB($nodeId);
                 // must be only one node
                 if (count($nodes) != 1) {
                     throw new OperationFailedException(count($nodes) . " nodes found. Expecting 1.");
                 }
                 $displayName = $nodes[0]->getDisplayName();
                 // 					echo "Creating node # <b>$nodeId - '$displayName'</b>, ";
                 // insert node into cache
                 $this->_cache[$nodeId][0] = $nodes[0];
                 $this->_cache[$nodeId][1] = 0;
                 $this->_cache[$nodeId][2] = 0;
             }
             // 				else
             // 					echo "Node already in cache, ";
             // update the levels fetched up, if necessary
             $old = $this->_cache[$nodeId][2];
             // 				print " old=$old levels=$levels level=$level, ";
             if ($old >= 0 && $old < $levels - $level) {
                 if ($originalLevels < 0) {
                     // if fully, then the node is fetched fully as well
                     $this->_cache[$nodeId][2] = -1;
                 } else {
                     // if not fully, then set the value appropriately
                     $this->_cache[$nodeId][2] = $levels - $level;
                 }
                 // 					echo "changing level of caching from <b>$old</b> to <b>".$this->_cache[$nodeId][2]."</b>";
             }
             // 				else
             // 					echo "no need to set level of caching";
             // now, update tree structure
             // 				echo "<br />--- TREE STRUCTURE UPDATE: ";
             // get the current node (create it, if necessary)
             if ($this->_tree->nodeExists($nodeId)) {
                 $node = $this->_tree->getNode($nodeId);
             } else {
                 // 					echo "Creating new tree node # <b>$nodeId</b>, ";
                 $node = new TreeNode($nodeId);
                 $nullValue = NULL;
                 // getting rid of PHP warnings by specifying
                 // this second argument
                 $this->_tree->addNode($node, $nullValue);
             }
             // does the current node have a child?
             // if no, there is nothing to update
             if ($level == 0) {
                 // 					echo "Skipping leaf node, continuing with parent";
                 continue;
             } else {
                 // get the child id
                 $childId = $row["level" . ($level - 1) . "_id"];
                 // get the child node
                 $child = $this->_tree->getNode($childId);
                 // has the child been added? if no, add it!
                 if (!$node->isChild($child)) {
                     // 						echo "adding node # <b>$nodeId</b> as a parent of node # <b>$childId</b>";
                     // print_r($child);
                     // print_r($node);
                     $this->_tree->addNode($child, $node);
                 }
                 // 					else
                 // 						echo "already child";
             }
         }
         $queryResult->advanceRow();
     }
     $queryResult->free();
 }