本文整理汇总了PHP中SelectQuery::addWhere方法的典型用法代码示例。如果您正苦于以下问题:PHP SelectQuery::addWhere方法的具体用法?PHP SelectQuery::addWhere怎么用?PHP SelectQuery::addWhere使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SelectQuery
的用法示例。
在下文中一共展示了SelectQuery::addWhere方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: loadTypes
/**
* 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);
}
}
示例2: PersistentOrderedSet
/**
* 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);
}
示例3: getPartStructureIdsForTagGeneration
/**
* 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;
}
示例4: updateValue
/**
* 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: substr
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;
}
}
示例6: getTypeId
/**
* 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;
}
示例7: test
/**
* 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();
}
示例8: getStructuresForPlugin
/**
* 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;
}
示例9: deleteLog
/**
* 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: isItemTagged
/**
* 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: updateValue
/**
* 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: getValue
/**
* 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: getTagsForItemsNotByAgent
/**
* 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;
}
示例14: SelectQuery
/**
* 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: installPlugin
/**
* 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);
}
// }
}