/** * * @param object Type $type2 * * @return boolean * * @access public */ public final function isEqual(Type $type2) { if (null != $type2 && null != $type2->getDomain() && null != $type2->getAuthority() && null != $type2->getKeyword() && null != $this->getDomain() && null != $this->getAuthority() && null != $this->getKeyword()) { return $this->getDomain() == $type2->getDomain() && $this->getAuthority() == $type2->getAuthority() && $this->getKeyword() == $type2->getKeyword() ? TRUE : FALSE; } return false; }
/** * Get all the groups with the specified search criteria and search Type. * * @param object mixed $searchCriteria (original type: java.io.Serializable) * @param object Type $groupSearchType * * @return object AgentIterator * * @throws object AgentException An exception with one of the * following messages defined in org.osid.agent.AgentException may * be thrown: {@link * org.osid.agent.AgentException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.agent.AgentException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.agent.AgentException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.agent.AgentException#UNIMPLEMENTED UNIMPLEMENTED}, * {@link org.osid.agent.AgentException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.agent.AgentException#UNKNOWN_TYPE UNKNOWN_TYPE} * * @access public */ function getGroupsBySearch($searchCriteria, Type $groupSearchType) { $typeString = $groupSearchType->getDomain() . "::" . $groupSearchType->getAuthority() . "::" . $groupSearchType->getKeyword(); // get the Group Search object $groupSearch = $this->_groupSearches[$typeString]; if (!is_object($groupSearch)) { throwError(new Error(AgentException::UNKNOWN_TYPE() . ", " . $groupSearchType->asString(), "GroupManager", true)); } return $groupSearch->getGroupsBySearch($searchCriteria); }
/** * 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(); } }
function _loadPlugins() { // cache the installed plugins $db = Services::getService("DBHandler"); $pm = Services::getService("Plugs"); $query = new SelectQuery(); $query->addTable("plugin_type"); $query->addColumn("*"); $query->addOrderBy('type_id'); $results = $db->query($query, IMPORTER_CONNECTION); $dis = array(); $en = array(); while ($results->hasNext()) { $result = $results->next(); $pluginType = new Type($result['type_domain'], $result['type_authority'], $result['type_keyword']); $class = $this->getPluginClass($pluginType); if (class_exists($class)) { $pluginType = new Type($pluginType->getDomain(), $pluginType->getAuthority(), $pluginType->getKeyword(), call_user_func(array($class, 'getPluginDescription'))); } if ($result['type_enabled'] == 1) { $this->_enabledPlugins[HarmoniType::typeToString($pluginType)] = $pluginType; } else { $this->_disabledPlugins[HarmoniType::typeToString($pluginType)] = $pluginType; } } $this->_cachePluginArrays(); }
/** * Attempts to create the specified node as root node in the database. * @access public * @param object nodeId The id of the node. * @param object type The type of the node. * @param string displayName The display name of the node. * @param string description The description of the node. * @return void **/ function createRootNode(Id $nodeId, Type $type, $displayName, $description) { // ** parameter validation $stringRule = StringValidatorRule::getRule(); ArgumentValidator::validate($displayName, $stringRule, true); ArgumentValidator::validate($description, $stringRule, true); // ** end of parameter validation // check that the node does not exist in the cache $idValue = $nodeId->getIdString(); if ($this->_isCached($idValue)) { // The node has already been cached! throw new OperationFailedException("Node, '{$idValue}' is already cached."); } // attempt to insert the node now $dbHandler = Services::getService("DatabaseManager"); // 1. Insert the type $domain = $type->getDomain(); $authority = $type->getAuthority(); $keyword = $type->getKeyword(); $typeDescription = $type->getDescription(); // check whether the type is already in the DB, if not insert it if (isset($this->harmoni_db)) { if (!isset($this->createRootNode_selectType_stmt)) { $query = $this->harmoni_db->select(); $query->addTable("az2_node_type"); $query->addColumn("id"); $query->addWhereRawEqual("domain", '?'); $query->addWhereRawEqual("authority", '?'); $query->addWhereRawEqual("keyword", '?'); $this->createRootNode_selectType_stmt = $query->prepare(); } $this->createRootNode_selectType_stmt->bindValue(1, $domain); $this->createRootNode_selectType_stmt->bindValue(2, $authority); $this->createRootNode_selectType_stmt->bindValue(3, $keyword); $this->createRootNode_selectType_stmt->execute(); $queryResult = $this->createRootNode_selectType_stmt->getResult(); } else { $query = new SelectQuery(); $query->addTable("az2_node_type"); $query->addColumn("id"); $query->addWhereEqual("domain", $domain); $query->addWhereEqual("authority", $authority); $query->addWhereEqual("keyword", $keyword); $queryResult = $dbHandler->query($query, $this->_dbIndex); } if ($queryResult->hasNext()) { // if the type is already in the database $typeIdValue = $queryResult->field("id"); // get the id $queryResult->free(); } else { // if not, insert it $queryResult->free(); if (isset($this->harmoni_db)) { if (!isset($this->createRootNode_insertType_stmt)) { $query = $this->harmoni_db->insert(); $query->setTable("az2_node_type"); // $query->setAutoIncrementColumn("id", "az2_node_type_id_seq"); $query->addRawValue("domain", '?'); $query->addRawValue("authority", '?'); $query->addRawValue("keyword", '?'); $query->addRawValue("description", '?'); $this->createRootNode_insertType_stmt = $query->prepare(); } $this->createRootNode_insertType_stmt->bindValue(1, $domain); $this->createRootNode_insertType_stmt->bindValue(2, $authority); $this->createRootNode_insertType_stmt->bindValue(3, $keyword); $this->createRootNode_insertType_stmt->bindValue(4, $typeDescription); $this->createRootNode_insertType_stmt->execute(); $queryResult = $this->createRootNode_insertType_stmt->getResult(); } else { $query = new InsertQuery(); $query->setTable("az2_node_type"); $query->setAutoIncrementColumn("id", "az2_node_type_id_seq"); $query->addValue("domain", $domain); $query->addValue("authority", $authority); $query->addValue("keyword", $keyword); $query->addValue("description", $typeDescription); $queryResult = $dbHandler->query($query, $this->_dbIndex); } $typeIdValue = $queryResult->getLastAutoIncrementValue(); } // 2. Now that we know the id of the type, insert the node itself if (isset($this->harmoni_db)) { if (!isset($this->createRootNode_insertNode_stmt)) { $query = $this->harmoni_db->insert(); $query->setTable("az2_node"); $query->addRawValue("id", '?'); $query->addRawValue("display_name", '?'); $query->addRawValue("description", '?'); $query->addRawValue("fk_hierarchy", '?'); $query->addRawValue("fk_type", '?'); $this->createRootNode_insertNode_stmt = $query->prepare(); } $this->createRootNode_insertNode_stmt->bindValue(1, $idValue); $this->createRootNode_insertNode_stmt->bindValue(2, $displayName); $this->createRootNode_insertNode_stmt->bindValue(3, $description); $this->createRootNode_insertNode_stmt->bindValue(4, $this->_hierarchyId); $this->createRootNode_insertNode_stmt->bindValue(5, $typeIdValue); $this->createRootNode_insertNode_stmt->execute(); $queryResult = $this->createRootNode_insertNode_stmt->getResult(); } else { $query = new InsertQuery(); $query->setTable("az2_node"); $query->addValue("id", $idValue); $query->addValue("display_name", $displayName); $query->addValue("description", $description); $query->addValue("fk_hierarchy", $this->_hierarchyId); $query->addValue("fk_type", $typeIdValue); $queryResult = $dbHandler->query($query, $this->_dbIndex); } if ($queryResult->getNumberOfRows() != 1) { //"Could not insert the node (it already exists?)"; throw new OperationFailedException($queryResult->getNumberOfRows() . " nodes found. Expecting 1. Node already exists?"); } // create the node object to return $node = new AuthZ2_Node($nodeId, $type, $displayName, $description, $this); // then cache it $this->_cache[$idValue][0] = $node; $this->_cache[$idValue][1] = -1; // fully cached up and down because $this->_cache[$idValue][2] = -1; // in fact this node does not have any ancestors or descendents // update _tree $nullValue = NULL; // getting rid of PHP warnings by specifying // this second argument $this->_tree->addNode(new TreeNode($idValue), $nullValue); return $node; }
/** * Answer the organizer above the reference node that can accept the component type given. * * @param object SiteComponent $refNode * @param object Type $componentType * @return object OrganizerSiteComponent * @access public * @since 1/15/09 * @static */ public static function getOrganizerForComponentType(SiteComponent $refNode, Type $componentType) { // For pages and sections, find the menu above our component. if ($componentType->getDomain() == 'segue-multipart') { $parentComponent = $refNode->getParentComponent(); while ($parentComponent) { if ($parentComponent->getComponentClass() == 'MenuOrganizer') { return $parentComponent; } $parentComponent = $parentComponent->getParentComponent(); } // If we didn't find a menu above our ref node, maybe we started in a heading. // Search down for a menu. $director = SiteDispatcher::getSiteDirector(); $rootNode = $director->getRootSiteComponent($refNode->getId()); $result = $rootNode->acceptVisitor(new GetMenuBelowSiteVisitor()); if ($result) { return $result; } // If we still haven't found a menu, then there isn't one in this site. // Nothing more we can do. throw new OperationFailedException("Cannot create a " . $componentType->getKeyword() . ". Site " . $rootNode->getSlot()->getShortname() . " - '" . $rootNode->getDisplayName() . "' does not have any menus to add this component to."); } else { $parentComponent = $refNode->getParentComponent(); while ($parentComponent) { if ($parentComponent->getComponentClass() == 'FlowOrganizer' || $parentComponent->getComponentClass() == 'MenuOrganizer') { return $parentComponent; } } // If we haven't found a flow organizer above the refNode, something is wrong. throw new OperationFailedException("Cannot create a " . $componentType->getKeyword() . ". A ContentOrganizer was not found above reference node " . $refNode->getId()); } }
/** * print an option tag * * @param object Type $type * @return void * @access private * @since 12/14/07 */ private function printTypeOption(Type $type) { print "\n\t\t\t<option value='" . $type->asString() . "'>"; if (isset($this->_classNames[$type->getKeyword()])) { print $this->_classNames[$type->getKeyword()]; } else { try { $pluginManager = Services::getService("PluginManager"); $class = $pluginManager->getPluginClass($type); print call_user_func(array($class, 'getPluginDisplayName')); } catch (UnknownIdException $e) { print $type->getKeyword(); } } print "</option>"; }
/** * Perform a search of the specified Type and get all the Assets that * satisfy the SearchCriteria. Iterators return a set, one at a time. * * @param object mixed $searchCriteria (original type: java.io.Serializable) * @param object Type $searchType * @param object Properties $searchProperties * * @return object AssetIterator * * @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}, {@link * org.osid.repository.RepositoryException#UNKNOWN_TYPE * UNKNOWN_TYPE} * * @access public */ function getAssetsBySearch($searchCriteria, Type $searchType, Properties $searchProperties) { if ($searchProperties->getType()->isEqual(new Type('Repository', 'edu.middlebury', 'null'))) { $searchProperties = null; } // Check that we support the searchType $supported = FALSE; foreach (array_keys($this->_searchTypes) as $key) { if ($searchType->isEqual($this->_searchTypes[$key])) { $supported = TRUE; $searchName = $key; break; } } if ($supported) { $search = new $searchName($this); $assetIds = $search->searchAssets($searchCriteria, $searchProperties); // get the assets for the resuting ids $assets = array(); // Order if (is_object($searchProperties) && $searchProperties->getProperty("order") == "DisplayName") { foreach ($assetIds as $key => $id) { $asset = $this->getAsset($assetIds[$key], FALSE); $assets[$asset->getDisplayName() . $id->getIdString()] = $asset; } } else { if (is_object($searchProperties) && $searchProperties->getProperty("order") == "Id") { foreach ($assetIds as $key => $id) { $assets[$assetIds[$key]->getIdString()] = $this->getAsset($assetIds[$key], FALSE); } } else { if (is_object($searchProperties) && $searchProperties->getProperty("order") == "ModificationDate") { foreach ($assetIds as $key => $id) { $asset = $this->getAsset($assetIds[$key], FALSE); $date = $asset->getModificationDate(); $assets[$date->asString() . $id->getIdString()] = $asset; } } else { if (is_object($searchProperties) && $searchProperties->getProperty("order") == "CreationDate") { foreach ($assetIds as $key => $id) { $asset = $this->getAsset($assetIds[$key], FALSE); $date = $asset->getCreationDate(); $assets[$date->asString() . $id->getIdString()] = $asset; } } else { foreach ($assetIds as $key => $id) { $assets[] = $this->getAsset($assetIds[$key], FALSE); } } } } } // Filter based on type // This can probably be moved to the search modules to improve // performance by eliminating these assets before they are otherwise // operated on. if (is_object($searchProperties) && is_array($searchProperties->getProperty("allowed_types")) && count($searchProperties->getProperty("allowed_types"))) { $allowedTypes = $searchProperties->getProperty("allowed_types"); foreach (array_keys($assets) as $key) { $type = $assets[$key]->getAssetType(); $allowed = FALSE; foreach (array_keys($allowedTypes) as $typeKey) { if ($type->isEqual($allowedTypes[$typeKey])) { $allowed = TRUE; break; } } if (!$allowed) { unset($assets[$key]); } } } // Order Direction if (is_object($searchProperties) && $searchProperties->getProperty("direction") == "DESC") { krsort($assets); } else { ksort($assets); } // create an AssetIterator and return it $assetIterator = new HarmoniAssetIterator($assets); return $assetIterator; } else { throwError(new Error(RepositoryException::UNKNOWN_TYPE() . " " . $searchType->getDomain() . "::" . $searchType->getAuthority() . "::" . $searchType->getKeyword(), "Repository", 1)); } }
/** * Answer the database id for the type passed. * * @param object Type $type * @return string * @access public * @since 3/1/06 */ function _getTypeId(Type $type) { if (!isset($this->_typeIds)) { $this->_typeIds = array(); } if (!isset($this->_typeIds[$type->asString()])) { $dbc = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addColumn("id"); $query->addTable("log_type"); $query->addWhere("domain = '" . addslashes($type->getDomain()) . "'"); $query->addWhere("authority = '" . addslashes($type->getAuthority()) . "'"); $query->addWhere("keyword = '" . addslashes($type->getKeyword()) . "'"); $results = $dbc->query($query, $this->_dbIndex); if ($results->getNumberOfRows()) { $this->_typeIds[$type->asString()] = $results->field("id"); $results->free(); } else { $results->free(); $query = new InsertQuery(); $query->setTable("log_type"); $query->setAutoIncrementColumn("id", "log_type_id_seq"); $query->setColumns(array("domain", "authority", "keyword", "description")); $query->addRowOfValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'")); $results = $dbc->query($query, $this->_dbIndex); $this->_typeIds[$type->asString()] = $results->getLastAutoIncrementValue(); } } return $this->_typeIds[$type->asString()]; }
/** * Convert an OKI Type to a delimited string * * @param object Type $aType * @param string $glue * @return string * @access public * @since 6/1/05 * @static */ public static function typeToString(Type $type, $delimiter = "::") { return $type->getDomain() . $delimiter . $type->getAuthority() . $delimiter . $type->getKeyword(); }
/** * Answer the nodes matching a type * * @param object Type $type * @return array * @access private * @since 4/3/08 */ private function getNodesFromDbByType_Harmoni_Db(Type $type) { $this->getNodesByType_stmt->bindValue($this->getNodesByType_domain_key, $type->getDomain()); $this->getNodesByType_stmt->bindValue($this->getNodesByType_authority_key, $type->getAuthority()); $this->getNodesByType_stmt->bindValue($this->getNodesByType_keyword_key, $type->getKeyword()); $this->getNodesByType_stmt->execute(); $nodeQueryResult = $this->getNodesByType_stmt->fetchAll(); $this->getNodesByType_stmt->closeCursor(); $result = array(); $idManager = Services::getService("Id"); if (!count($nodeQueryResult)) { throw new UnknownIdException("No nodes found for type " . $type->asString()); } foreach ($nodeQueryResult as $nodeRow) { $idValue = $nodeRow['id']; $id = $idManager->getId($idValue); $type = new HarmoniType($nodeRow['domain'], $nodeRow['authority'], $nodeRow['keyword'], $nodeRow['type_description']); $node = new HarmoniNode($id, $type, $nodeRow['display_name'], $nodeRow['description'], $this); $result[] = $node; } return $result; }
/** * Return a string version of a type. * * @param object Type $type * @return string * @access private * @since 3/15/05 */ function _getTypeString(Type $type) { return $type->getDomain() . "::" . $type->getAuthority() . "::" . $type->getKeyword(); }