/** * 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; }
/** * Answer true if this version is the current version. * * @return boolean * @access public * @since 1/8/08 */ public function isCurrent() { $query = new SelectQuery(); $query->addTable('segue_plugin_version'); $query->addColumn('version_id'); $query->addWhereEqual('node_id', $this->pluginInstance->getId()); $query->addOrderBy('tstamp', SORT_DESC); $query->limitNumberOfRows(1); $dbc = Services::getService('DBHandler'); $result = $dbc->query($query, IMPORTER_CONNECTION); if ($result->field('version_id') == $this->getVersionId()) { return true; } else { return false; } }
/** * Answer a list of most recently seen slot-names ordered recent-first. * * @return array * @access public * @since 9/22/08 */ public function getRecentSlots() { $slots = array(); $dbc = Services::getService('DatabaseManager'); $query = new SelectQuery(); $query->addTable('segue_accesslog'); $query->addColumn('fk_slotname'); $query->addColumn('tstamp'); $query->addWhereEqual('agent_id', $this->_getCurrentAgentId()); $query->addOrderBy('tstamp', DESCENDING); $query->limitNumberOfRows(50); $result = $dbc->query($query, IMPORTER_CONNECTION); while ($result->hasNext()) { $row = $result->next(); $slots[$row['fk_slotname']] = DateAndTime::fromString($row['tstamp'])->asString(); } // Add session-stored slots if (isset($_SESSION['segue_access_log'])) { foreach ($_SESSION['segue_access_log'] as $slotname => $tstamp) { $slots[$slotname] = $tstamp; } arsort($slots); } return array_keys($slots); }
/** * Assign the configuration of this Manager. Valid configuration options are as * follows: * database_index integer * database_name string * * @param object Properties $configuration (original type: java.util.Properties) * * @throws object OsidException An exception with one of the following * messages defined in org.osid.OsidException: {@link * org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED}, * {@link org.osid.OsidException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.OsidException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link * org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT} * * @access public */ function assignConfiguration(Properties $configuration) { $this->_configuration = $configuration; $dbIndex = $configuration->getProperty('database_index'); $dbName = $configuration->getProperty('database_name'); // ** parameter validation ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true); ArgumentValidator::validate($dbName, StringValidatorRule::getRule(), true); // ** end of parameter validation $this->_dbIndex = $dbIndex; // Store the Harmoni_Db adapter if it is configured. $harmoni_db_name = $this->_configuration->getProperty('harmoni_db_name'); if (!is_null($harmoni_db_name)) { try { $this->harmoni_db = Harmoni_Db::getDatabase($harmoni_db_name); } catch (UnknownIdException $e) { } } // do a test to see if our configuration worked. try { $dbHandler = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addColumn("id"); $query->addTable("az2_hierarchy"); $query->limitNumberOfRows(1); $queryResult = $dbHandler->query($query, $this->_dbIndex); } catch (QueryDatabaseException $e) { throw new ConfigurationErrorException("Database is not properly set up for AuthZ2."); } }
/** * Load the next batch of slots * * @return void * @access private * @since 12/4/07 */ private function loadNextBatch() { $query = new SelectQuery(); $query->addColumn('shortname'); $query->addTable('segue_slot'); $query->startFromRow($this->startingNumber + 1); $query->limitNumberOfRows(50); $query->addOrderBy('shortname'); // printpre($query->asString()); $dbc = Services::getService('DBHandler'); $result = $dbc->query($query, IMPORTER_CONNECTION); $slotNames = array(); while ($result->hasNext()) { $slotNames[] = $result->field('shortname'); $result->next(); $this->startingNumber++; } // printpre($slotNames); $slotMgr = SlotManager::instance(); $slots = $slotMgr->loadSlotsFromDb($slotNames); foreach ($slots as $slot) { $this->queue[] = $slot; } }