/**
  * 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);
 }
Exemplo n.º 2
0
 /**
  * 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;
     }
 }
 /**
  * Returns a list of the tables that exist in the currently connected database.
  * @return array
  * @access public
  */
 function getTableList()
 {
     $query = new SelectQuery();
     $query->addTable("pg_stat_user_tables");
     $query->addColumn("relname");
     $query->addOrderBy("relname", ASCENDING);
     $res = $this->query($query);
     $list = array();
     while ($res->hasMoreRows()) {
         $list[] = $res->field(0);
         $res->advanceRow();
     }
     $res->free();
     return $list;
 }
Exemplo n.º 4
0
 /**
  * Answer agentIds that have stored tags
  * 
  * @return object IdIterator
  * @access public
  * @since 11/1/06
  */
 function getAgentIds()
 {
     $query = new SelectQuery();
     $query->addColumn('user_id');
     $query->addColumn('COUNT(user_id)', 'occurances');
     $query->addTable('tag');
     $query->setGroupBy(array('user_id'));
     $query->addOrderBy('occurances', DESCENDING);
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     // Add tag objects to an array, still sorted by frequency of usage
     $agentIds = array();
     $idManager = Services::getService('Id');
     while ($result->hasNext()) {
         $row = $result->next();
         $agentIds[] = $idManager->getId($row['user_id']);
     }
     $iterator = new HarmoniIterator($agentIds);
     return $iterator;
 }
Exemplo n.º 5
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();
 }
 /**
  * Answer an array of all of the property keys inexistance
  * 
  * @return array
  * @access public
  * @since 11/1/05
  */
 function getAllPropertyKeys()
 {
     $propertyKeys = array();
     $dbHandler = Services::getService("DBHandler");
     //select the propertykeys
     $query = new SelectQuery();
     $query->addTable("agent_properties");
     $query->addColumn("DISTINCT property_key");
     // 		$query->addTable("type", LEFT_JOIN, "agent_properties.fk_type_id=type.type_id");
     // 		$query->addColumn("property_key");
     // 		$query->addColumn("type_domain");
     // 		$query->addColumn("type_authority");
     // 		$query->addColumn("type_keyword");
     // 		$query->addColumn("type_description");
     $query->addOrderBy("property_key");
     $result = $dbHandler->query($query, $this->_dbIndex);
     while ($result->hasMoreRows()) {
         $propertyKeys[] = $result->field('property_key');
         // 			$propertyKeys[$result->field('property_key')] = new Type(
         // 				$result->field('type_domain'),
         // 				$result->field('type_authority'),
         // 				$result->field('type_keyword'),
         // 				$result->field('type_description'));
         $result->advanceRow();
     }
     $result->free();
     return $propertyKeys;
     //return the properties
 }
 /**
  * Get the Timespans during which all Agents are uncommitted.
  * The time complexity may not be great on this one.
  *
  * @param object Id[] $agents
  * @param int $start
  * @param int $end
  *
  * @return object TimespanIterator
  *
  * @throws object SchedulingException An exception with one of
  *         the following messages defined in
  *         org.osid.scheduling.SchedulingException may be thrown:   {@link
  *         org.osid.scheduling.SchedulingException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.scheduling.SchedulingException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.scheduling.SchedulingException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.scheduling.SchedulingException#UNIMPLEMENTED
  *         UNIMPLEMENTED}, {@link
  *         org.osid.scheduling.SchedulingException#NULL_ARGUMENT
  *         NULL_ARGUMENT}, {@link
  *         org.osid.scheduling.SchedulingException#UNKNOWN_ID UNKNOWN_ID},
  *         {@link org.osid.scheduling.SchedulingException#END_BEFORE_START
  *         END_BEFORE_START}
  *
  * @access public
  */
 function getAvailableTimes(array $agents, $start, $end)
 {
     if (count($agents) == 0) {
         $array[] = new HarmoniTimespan($start, $end);
         $ret = new HarmoniTimespanIterator($array);
         return $ret;
     }
     //get all schedule item rows with the appropriate time and agents
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('sc_item');
     $query->addTable('sc_commit', INNER_JOIN, "sc_item.id=sc_commit.fk_sc_item");
     $query->addColumn('sc_item.id');
     $where = "(end_date >= '" . addslashes($start) . "'";
     $where .= " OR start_date <= '" . addslashes($end) . "') AND (";
     $firstElement = true;
     foreach ($agents as $agentId) {
         if (!$firstElement) {
             $where .= " OR ";
         } else {
             $firstElement = false;
         }
         $where .= "sc_commit.fk_agent_id='" . addslashes($agentId->getIdString()) . "'";
     }
     $where .= ")";
     $query->addOrderBy('sc_item.id');
     $query->addWhere($where);
     $res = $dbHandler->query($query);
     //find times not conflicted by these items
     //yes I know $mister11 is a terible name for the variable.  Deal with it :-P.
     //We'll
     $availableTimes = array();
     $availableTimes[$start] = new HarmoniTimeSpan($start, $end);
     //print_r($thearray);
     $idManager = Services::getService("IdManager");
     $lastId = "";
     while ($res->hasMoreRows()) {
         $row = $res->getCurrentRow();
         $res->advanceRow();
         $idString = $row['id'];
         if ($lastId != $idString) {
             $id = $idManager->getId($idString);
             $item = $this->getScheduleItem($id);
             $availableTimes = $this->_restrict($item, $availableTimes);
             $lastId = $idString;
         }
     }
     //print_r($thearray);
     //ksort($thearray);
     $ret = new HarmoniTimespanIterator($availableTimes);
     return $ret;
 }
Exemplo n.º 8
0
 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();
 }
Exemplo n.º 9
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $dbHandler = Services::getService("DBHandler");
     $rm = Services::getService("Repository");
     $agentM = Services::getService("Agent");
     $idManager = Services::getService("Id");
     print "lines 46 - 49 in authtrans.act.php need to be modified for database access";
     //		$mdbIndex = $dbHandler->addDatabase(
     //			new MySQLDatabase("host", "db", "uname", "password"));
     //		$dbHandler->connect($mdbIndex);
     exit;
     $searchTypes = $agentM->getAgentSearchTypes();
     $searchType = $searchTypes->next();
     $centerPane = $this->getActionRows();
     ob_start();
     $unamesQuery = new SelectQuery();
     $unamesQuery->addTable("users");
     $unamesQuery->addColumn("uname");
     $unamesQuery->addColumn("email");
     $unamesQuery->addOrderBy("uname");
     $unamesResults = $dbHandler->query($unamesQuery, $mdbIndex);
     $unameToId = array();
     // key on mdb uname value to c_beta id
     while ($unamesResults->hasMoreRows()) {
         $unamePair = $unamesResults->next();
         if (!is_null($unamePair['email'])) {
             $agents = $agentM->getAgentsBySearch($unamePair['email'], $searchType);
             if ($agents->hasNext()) {
                 $agent = $agents->next();
             }
             $unameToId[$unamePair['uname']] = $agent->getId();
         }
     }
     // ===== at this point we have unames and ids
     $mediasetsQuery = new SelectQuery();
     $mediasetsQuery->addTable("mediasets");
     $mediasetsQuery->addColumn("title");
     $mediasetsQuery->addColumn("editors");
     $mediasetsQuery->addColumn("presenters");
     $mediasetsQuery->addColumn("search");
     $mediasetsQuery->addOrderBy("title");
     $mediasetsResults = $dbHandler->query($mediasetsQuery, $mdbIndex);
     $repositories = $rm->getRepositories();
     $reps = array();
     while ($repositories->hasNext()) {
         $rep = $repositories->next();
         $reps[$rep->getDisplayName()] = array('id' => $rep->getId());
     }
     unset($reps['All Exhibitions']);
     // ===== at this point we have repository id's associated with displaynames
     while ($mediasetsResults->hasMoreRows()) {
         $mediasetInfo = $mediasetsResults->next();
         if (isset($reps[$mediasetInfo['title']])) {
             $editors = unserialize($mediasetInfo['editors']);
             $presenters = unserialize($mediasetInfo['presenters']);
             if (count($editors) > 0) {
                 $reps[$mediasetInfo['title']]['editors'] = array();
             }
             foreach ($editors as $editor) {
                 if (isset($unameToId[trim($editor)])) {
                     $reps[$mediasetInfo['title']]['editors'][] = $unameToId[trim($editor)];
                 }
             }
             if (count($presenters) > 0) {
                 $reps[$mediasetInfo['title']]['presenters'] = array();
             }
             foreach ($presenters as $presenter) {
                 if (isset($unameToId[trim($presenter)])) {
                     $reps[$mediasetInfo['title']]['presenters'][] = $unameToId[trim($presenter)];
                 }
             }
             switch ($mediasetInfo['search']) {
                 case '1':
                     $reps[$mediasetInfo['title']]['search'] = 'edu.middlebury.agents.everyone';
                     break;
                 case '2':
                     $reps[$mediasetInfo['title']]['search'] = 'edu.middlebury.agents.users';
                     break;
                 case '3':
                     $reps[$mediasetInfo['title']]['search'] = 'CN=All Faculty,OU=General,OU=Groups,DC=middlebury,DC=edu';
                     break;
                 default:
                     break;
             }
         }
     }
     // ===== at this point reps has presenters and editors for each mediaset
     $pressetsQuery = new SelectQuery();
     $pressetsQuery->addTable("pressets");
     $pressetsQuery->addColumn("title");
     $pressetsQuery->addColumn("presenters");
     $pressetsQuery->addColumn("owner");
     $pressetsQuery->addColumn("view");
     $pressetsQuery->addOrderBy("title");
     $pressetsResults = $dbHandler->query($pressetsQuery, $mdbIndex);
     $erep = $rm->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository"));
     $exhibitions = $erep->getAssets();
     $exhibits = array();
     while ($exhibitions->hasNext()) {
         $exhibit = $exhibitions->next();
         $exhibits[$exhibit->getDisplayName()] = array('id' => $exhibit->getId());
     }
     // ===== at this point we have exhibition id's associated with display names
     while ($pressetsResults->hasMoreRows()) {
         $pressetInfo = $pressetsResults->next();
         if (isset($exhibits[$pressetInfo['title']])) {
             $presenters = unserialize($pressetInfo['presenters']);
             if (!is_null($pressetInfo['owner'])) {
                 $owners = $agentM->getAgentsBySearch($pressetInfo['owner'], $searchType);
                 if ($owners->count() == 1) {
                     $owner = $owners->next();
                     $exhibits[$pressetInfo['title']]['owner'] = $owner->getId();
                 }
             }
             if (count($presenters) > 0) {
                 $exhibits[$pressetInfo['title']]['presenters'] = array();
             }
             foreach ($presenters as $presenter) {
                 if (isset($unameToId[trim($presenter)])) {
                     $exhibits[$pressetInfo['title']]['presenters'][] = $unameToId[trim($presenter)];
                 }
             }
             switch ($pressetInfo['view']) {
                 case '1':
                     $reps[$pressetInfo['title']]['view'] = 'everyone';
                     break;
                 case '2':
                     $reps[$pressetInfo['title']]['view'] = 'users';
                     break;
                 case '3':
                     $reps[$mediasetInfo['title']]['search'] = 'CN=All Faculty,OU=General,OU=Groups,DC=middlebury,DC=edu';
                     break;
                 default:
                     break;
             }
         }
     }
     // ===== at this point all the necessary authz's should be queued up
     $uIdToAuths = array();
     // key on c_beta uId's value to assoc array
     // ===== GIVE THE AUTHORIZATIONS
     $authZ = Services::getService("AuthZ");
     $viewFunctions = array($idManager->getId('edu.middlebury.authorization.access'), $idManager->getId('edu.middlebury.authorization.view'), $idManager->getId('edu.middlebury.authorization.comment'));
     $editFunctions = array($idManager->getId('edu.middlebury.authorization.modify'), $idManager->getId('edu.middlebury.authorization.delete'), $idManager->getId('edu.middlebury.authorization.add_children'), $idManager->getId('edu.middlebury.authorization.remove_children'));
     $adminFunctions = array($idManager->getId('edu.middlebury.authorization.view_authorizations'), $idManager->getId('edu.middlebury.authorization.modify_authorizations'));
     foreach ($reps as $repAuths) {
         $repId = $repAuths['id'];
         if (isset($repAuths['editors'])) {
             foreach ($repAuths['editors'] as $editorId) {
                 foreach ($viewFunctions as $vfnId) {
                     $this->addAuth($editorId, $vfnId, $repId, $uIdToAuths);
                     // 					$authZ->createAuthorization(
                     // 						$editorId,
                     // 						$vfnId,
                     // 						$repId);
                 }
                 foreach ($editFunctions as $efnId) {
                     $this->addAuth($editorId, $efnId, $repId, $uIdToAuths);
                     // 					$authZ->createAuthorization(
                     // 						$editorId,
                     // 						$efnId,
                     // 						$repId);
                 }
                 foreach ($adminFunctions as $afnId) {
                     $this->addAuth($editorId, $afnId, $repId, $uIdToAuths);
                     // 					$authZ->createAuthorization(
                     // 						$editorId,
                     // 						$afnId,
                     // 						$repId);
                 }
             }
         }
         if (isset($repAuths['presenters'])) {
             foreach ($repAuths['presenters'] as $presenterId) {
                 foreach ($viewFunctions as $vfnId) {
                     $this->addAuth($presenterId, $vfnId, $repId, $uIdToAuths);
                     // 					$authZ->createAuthorization(
                     // 						$presenterId,
                     // 						$vfnId,
                     // 						$repId);
                 }
             }
         }
         if (isset($repAuths['search'])) {
             $grpId = $idManager->getId($repAuths['search']);
             foreach ($viewFunctions as $vfnId) {
                 $this->addAuth($grpId, $vfnId, $repId, $uIdToAuths);
                 // 					$authZ->createAuthorization(
                 // 						$grpId,
                 // 						$vfnId,
                 // 						$repId);
             }
         }
     }
     // ===== all authorizations for collections should be set
     foreach ($exhibits as $exAuths) {
         $exId = $exAuths['id'];
         if (isset($exAuths['presenters'])) {
             foreach ($exAuths['presenters'] as $editorId) {
                 foreach ($viewFunctions as $vfnId) {
                     $this->addAuth($editorId, $vfnId, $exId, $uIdToAuths);
                     // 					$authZ->createAuthorization(
                     // 						$editorId,
                     // 						$vfnId,
                     // 						$exId);
                 }
                 foreach ($editFunctions as $efnId) {
                     $this->addAuth($editorId, $efnId, $exId, $uIdToAuths);
                     // 					$authZ->createAuthorization(
                     // 						$editorId,
                     // 						$efnId,
                     // 						$exId);
                 }
             }
         }
         if (isset($exAuths['owner'])) {
             foreach ($viewFunctions as $vfnId) {
                 $this->addAuth($editorId, $vfnId, $exId, $uIdToAuths);
                 // 					$authZ->createAuthorization(
                 // 						$editorId,
                 // 						$vfnId,
                 // 						$exId);
             }
             foreach ($editFunctions as $efnId) {
                 $this->addAuth($editorId, $efnId, $exId, $uIdToAuths);
                 // 					$authZ->createAuthorization(
                 // 						$editorId,
                 // 						$efnId,
                 // 						$exId);
             }
             foreach ($adminFunctions as $afnId) {
                 $this->addAuth($editorId, $afnId, $exId, $uIdToAuths);
                 // 					$authZ->createAuthorization(
                 // 						$editorId,
                 // 						$afnId,
                 // 						$exId);
             }
         }
     }
     // this is where the magic happens (if you have a lot of old authz's you may want to add statusstars to this loop)
     foreach ($uIdToAuths as $uidstring => $fids) {
         foreach ($fids as $fidstring => $qids) {
             foreach ($qids as $qidstring => $true) {
                 $authZ->createAuthorization($idManager->getId($uidstring), $idManager->getId($fidstring), $idManager->getId($qidstring));
             }
         }
     }
     // ===== all authorizations for exhibitions should be set
     $centerPane->add(new Block(ob_get_contents(), 1));
     ob_end_clean();
     $dbHandler->disconnect($mdbIndex);
     return true;
 }
 /**
  * Load the authoritative value list
  *
  * WARNING: NOT in OSID
  * 
  * @return void
  * @access private
  * @since 4/25/06
  */
 function _loadAuthoritativeValueStrings()
 {
     if (!isset($this->_authoritativeValueStrings)) {
         $this->_authoritativeValueStrings = array();
         $query = new SelectQuery();
         $query->addTable('dr_authoritative_values');
         $query->addColumn('value');
         $id = $this->getId();
         $query->addWhere("fk_partstructure = '" . addslashes($id->getIdString()) . "'");
         $query->addWhere("fk_repository = '" . addslashes($this->_repositoryId->getIdString()) . "'");
         $query->addOrderBy("value", ASCENDING);
         $dbc = Services::getService("DBHandler");
         $configuration = $this->manager->_configuration;
         $result = $dbc->query($query, $configuration->getProperty('database_index'));
         while ($result->hasMoreRows()) {
             $this->_authoritativeValueStrings[] = $result->field('value');
             $result->advanceRow();
         }
         $result->free();
     }
 }
Exemplo n.º 11
0
 /**
  * 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;
     }
 }
Exemplo n.º 12
0
 /**
  * Execute
  * 
  * @return void
  * @access public
  * @since 3/26/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException('This command can only be run by admins or from the command-line.');
     }
     header("Content-Type: text/plain");
     if (RequestContext::value('help') || RequestContext::value('h') || RequestContext::value('?')) {
         throw new HelpRequestedException($this->usage);
     }
     $outDir = RequestContext::value('d');
     if (empty($outDir)) {
         throw new InvalidArgumentException("An output directory must be specified.\n\n" . $this->usage);
     }
     if (!is_dir($outDir) || !is_writable($outDir)) {
         throw new InvalidArgumentException("The output directory doesn't exist or is not writeable.\n\n" . $this->usage);
     }
     foreach (SlotAbstract::getLocationCategories() as $category) {
         $baseUrl = SiteDispatcher::getBaseUrlForLocationCategory($category);
         if (!preg_match('/^https?:\\/\\/.+/', $baseUrl)) {
             throw new ConfigurationErrorException('Please set a base URL for the \'' . $category . '\' category with SiteDispatcher::setBaseUrlForLocationCategory($category, $url); in config/slots.conf.php');
         }
     }
     while (ob_get_level()) {
         ob_end_flush();
     }
     flush();
     /*********************************************************
      * Check for a running export
      *********************************************************/
     $dbc = Services::getService('DatabaseManager');
     $query = new SelectQuery();
     $query->addColumn('slot');
     $query->addColumn('pid');
     $query->addTable('site_export_queue');
     $query->addWhereNotEqual('pid', 0);
     $result = $dbc->query($query);
     // If we are exporting, check the status of the export process
     if ($result->hasMoreRows()) {
         // Don't start a new export if one is running.
         if ($this->isRunning($result->field('pid'))) {
             print "An export is already running\n";
             exit;
         } else {
             $query = new UpdateQuery();
             $query->setTable('site_export_queue');
             $query->addValue('status', 'DIED');
             $query->addRawValue('pid', 'NULL');
             $query->addValue('info', 'Process ' . $result->field('pid') . ' has died.');
             $query->addWhereEqual('slot', $result->field('slot'));
             $query->addWhereEqual('pid', $result->field('pid'));
             $dbc->query($query);
         }
     }
     /*********************************************************
      * If there aren't any other exports happening, run our export
      *********************************************************/
     // Find the next slot to update
     $query = new SelectQuery();
     $query->addColumn('slot');
     $query->addTable('site_export_queue', NO_JOIN, '', 'q');
     $query->addTable('segue_slot', INNER_JOIN, 'q.slot = s.shortname', 's');
     $query->addWhereNull('pid');
     $query->addWhereNull('status');
     $query->addWhereNull('alias_target');
     $query->addWhereNotEqual('site_id', '');
     $query->addOrderBy('priority', DESCENDING);
     $query->addOrderBy('slot', ASCENDING);
     $result = $dbc->query($query);
     // Exit if there is nothing to do.
     if (!$result->hasMoreRows()) {
         print "The queue is empty\n";
         exit;
     }
     $slot = $result->field('slot');
     $slotMgr = SlotManager::instance();
     $slotObj = $slotMgr->getSlotByShortname($slot);
     $baseUrl = SiteDispatcher::getBaseUrlForLocationCategory($slotObj->getLocationCategory());
     // Mark that we are running
     $query = new UpdateQuery();
     $query->setTable('site_export_queue');
     $query->addValue('pid', strval(getmypid()));
     $query->addWhereEqual('slot', $slot);
     $dbc->query($query);
     // Run the export
     $start = microtime(true);
     try {
         $exportDirname = $slot . "-html";
         $exportDir = $outDir . "/" . $exportDirname;
         $archivePath = $outDir . '/' . $exportDirname . ".zip";
         if (file_exists($exportDir)) {
             $this->deleteRecursive($exportDir);
         }
         mkdir($exportDir);
         if (file_exists($archivePath)) {
             unlink($archivePath);
         }
         // Set the user to be an admin.
         $idMgr = Services::getService("Id");
         $authType = new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB");
         $_SESSION['__AuthenticatedAgents']['Authentication::edu.middlebury.harmoni::Harmoni DB'] = $idMgr->getId('17008');
         $authZ = Services::getService("AuthZ");
         $isAuthorizedCache = $authZ->getIsAuthorizedCache();
         $isAuthorizedCache->dirtyUser();
         // Close the session. If we don't, a lock on the session file will
         // cause the request initiated via wget to hang.
         session_write_close();
         // Do the export
         $urlParts = parse_url($baseUrl);
         $urlPrefix = rtrim($urlParts['path'], '/');
         $include = array($urlPrefix . '/gui2', $urlPrefix . '/images', $urlPrefix . '/javascript', $urlPrefix . '/polyphony', $urlPrefix . '/repository', $urlPrefix . '/plugin_manager', $urlPrefix . '/rss', $urlPrefix . '/dataport/html/site/' . $slot);
         if (defined('WGET_PATH')) {
             $wget = WGET_PATH;
         } else {
             $wget = 'wget';
         }
         if (defined('WGET_OPTIONS')) {
             $wgetOptions = WGET_OPTIONS;
         } else {
             $wgetOptions = '';
         }
         $command = $wget . " " . $wgetOptions . " -r --page-requisites --html-extension --convert-links --no-directories -e robots=off " . "--directory-prefix=" . escapeshellarg($exportDir . '/content') . " " . "--include=" . escapeshellarg(implode(',', $include)) . " " . "--header=" . escapeshellarg("Cookie: " . session_name() . "=" . session_id()) . " " . escapeshellarg($baseUrl . '/dataport/html/site/' . $slot);
         print "Cookie: " . session_name() . "=" . session_id() . "\n";
         // 			throw new Exception($command);
         exec($command, $output, $exitCode);
         if ($exitCode) {
             throw new Exception('Wget Failed. ' . implode("\n", $output));
         }
         // Copy the main HTML file to index.html
         copy($exportDir . '/content/' . $slot . '.html', $exportDir . '/content/index.html');
         // Copy the index.html file up a level to make it easy to find
         file_put_contents($exportDir . '/index.html', preg_replace('/(src|href)=([\'"])([^\'"\\/]+)([\'"])/', '$1=$2content/$3$4', file_get_contents($exportDir . '/content/index.html')));
         // Zip up the result
         $archive = new ZipArchive();
         if ($archive->open($archivePath, ZIPARCHIVE::CREATE) !== TRUE) {
             throw new Exception("Could not create zip archive.");
         }
         $this->addDirectoryToZip($archive, $exportDir, $exportDirname);
         $archive->close();
         // Remove the directory
         $this->deleteRecursive($exportDir);
         // Mark our success
         $query = new UpdateQuery();
         $query->setTable('site_export_queue');
         $query->addRawValue('pid', 'NULL');
         $query->addValue('status', 'SUCCESS');
         $query->addValue('running_time', strval(round(microtime(true) - $start, 2)));
         $query->addWhereEqual('slot', $slot);
         $dbc->query($query);
     } catch (Exception $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($archivePath)) {
             unlink($archivePath);
         }
         // Mark our failure
         $query = new UpdateQuery();
         $query->setTable('site_export_queue');
         $query->addRawValue('pid', 'NULL');
         $query->addValue('status', 'EXCEPTION');
         $query->addValue('info', $e->getMessage());
         $query->addValue('running_time', strval(round(microtime(true) - $start, 2)));
         $query->addWhereEqual('slot', $slot);
         $dbc->query($query);
         throw $e;
     }
     exit;
 }
Exemplo n.º 13
0
 /**
  * Get the student roster.	Include only students with the specified
  * Enrollment Status Type.  This returns all the enrollments of all the course 
  * sections.  Keep in mind that they will be ordered by the students that are in
  * section.  Each student may be enrolled in several CoursesSctions.
  *
  * @param object Type $enrollmentStatusType
  *
  * @return object EnrollmentRecordIterator
  *
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE
  *		   UNKNOWN_TYPE}
  *
  * @access public
  */
 function getRosterByType(Type $enrollmentStatusType)
 {
     $idManager = Services::getService('IdManager');
     $dbManager = Services::getService("DatabaseManager");
     $courseSectionIterator = $this->getCourseSections();
     //quit out if there is not any CourseSection
     $array = array();
     if (!$courseSectionIterator->hasNextCourseSection()) {
         $ret = new HarmoniEnrollmentRecordIterator($array);
         return $ret;
     }
     //set up a query
     $query = new SelectQuery();
     $query->addTable('cm_enroll');
     $query->addColumn('id');
     //set up a where
     $where = "(";
     $first = true;
     //add necesary or's
     while ($courseSectionIterator->hasNextCourseSection()) {
         if (!$first) {
             $where .= " OR ";
         }
         $first = false;
         $section = $courseSectionIterator->nextCourseSection();
         $sectionId = $section->getId();
         $where .= "fk_cm_section='" . addslashes($sectionId->getIdString()) . "'";
     }
     //finish query
     $typeIndex = $this->_typeToIndex('enroll_stat', $enrollmentStatusType);
     $query->addWhere($where . ") AND fk_cm_enroll_stat_type='" . addslashes($typeIndex) . "'");
     $query->addOrderBy('id');
     $res = $dbManager->query($query);
     //add all EnrollmentRecords to an array
     while ($res->hasMoreRows()) {
         $row = $res->getCurrentRow();
         $res->advanceRow();
         $array[] = new HarmoniEnrollmentRecord($idManager->getId($row['id']));
     }
     //return them as an iterator
     $ret = new HarmoniEnrollmentRecordIterator($array);
     return $ret;
     //oldcode
     /*
     
     
     		$idManager = Services::getService('IdManager');
     		$dbManager = Services::getService("DatabaseManager");
     
     		$query= new SelectQuery;
     		$query->addTable('cm_enroll');
     		$query->addColumn('id');
     		$typeIndex = $this->_typeToIndex('enroll_stat',$enrollmentStatusType);
     
     		$courseSectionIterator = $this->getCourseSections();
     
     		while($courseSectionIterator->hasNextCourseSection()){
     			$section = $courseSectionIterator->nextCourseSection();
     			$sectionId = $section->getId();			
     			$query->addWhere("fk_cm_section='".addslashes($sectionId->getIdString())."' AND fk_cm_enroll_stat_type='".addslashes($typeIndex)."'");
     		}
     		$query->addOrderBy('id');
     $res=$dbManager->query($query);
     
     		$array=array();
     		while($res->hasMoreRows()){
     				$row = $res->getCurrentRow();
     				$res->advanceRow();
     				
     				$array[] = new HarmoniEnrollmentRecord($idManager->getId($row['id']));
     			}
     		$ret = new HarmoniEnrollmentRecordIterator($array);
     		return $ret;
     */
     /*
     
     
     
     $dbManager = Services::getService("DatabaseManager");
     
     $array=array();
     
     $courseSectionIterator = $this->getCourseSections();
     
     $typeIndex = $this->_typeToIndex('enroll_stat',$enrollmentStatusType);
     
     while($courseSectionIterator->hasNextCourseSection()){
     	$section = $courseSectionIterator->nextCourseSection();
     	$sectionId = $section->getId();
     
     	$query= new SelectQuery;
     	$query->addTable('cm_enroll');
     	//$query->addColumn('fk_student_id');
     	$query->addColumn('id');			
     	$query->addWhere("fk_cm_section='".addslashes($sectionId->getIdString())."' AND fk_cm_enroll_stat_type='".addslashes($typeIndex)."'");
     
     
     	$res=$dbManager->query($query);
     	$idManager = Services::getService('IdManager');
     	while($res->hasMoreRows()){
     		$row = $res->getCurrentRow();
     		$res->advanceRow();
     		
     		$array[] = new HarmoniEnrollmentRecord($idManager->getId($row['id']));
     	}
     }
     $ret = new HarmoniEnrollmentRecordIterator($array);
     return $ret;
     */
 }
 /**
  * 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 ($searchType->isEqual(new Type("Repository", "edu.middlebury.harmoni", "Keyword", "Search with a string for keywords."))) {
         if (!is_string($searchCriteria)) {
             throw new OperationFailedException('search criteria should be a string.');
         }
         // Convert the criteria to the proper character set.
         $encoding = $this->config['encoding'];
         if (!is_null($encoding)) {
             $searchCriteria = iconv('UTF-8', $encoding, $searchCriteria);
         }
         $query = new SelectQuery();
         $query->addTable($this->config['table']);
         $query->addColumn($this->config['id_column']);
         $query->addWhereLike($this->config['id_column'], '%' . $searchCriteria . '%');
         foreach ($this->config['columns'] as $column) {
             $query->addColumn($column);
             $query->addWhereLike($column, '%' . $searchCriteria . '%', _OR);
         }
         if ($this->config['order_column']) {
             $query->addOrderBy($this->config['order_column'], $this->config['order_direction']);
         }
         return new SimpleTableAssetIterator($this, $this->config, $this->dbc->query($query, $this->dbIndex));
     } else {
         if ($searchType->isEqual(new Type("Repository", "edu.middlebury.harmoni", "RootAssets", "Search for just the 'root' or 'top level' assets which are not assets of other assets."))) {
             return $this->getAssets();
         } else {
             throw new UnknownTypeException('UNKNOWN_TYPE');
         }
     }
 }
Exemplo n.º 15
0
 /**
  * Auxilliary private function that returns Authorizations according to a
  * criteria. Null values are interpreted as wildmarks. Warning: $returnExplicitOnly = false
  * will increase the running time significantly - USE SPARINGLY!
  * @access public
  * @param string aId The string id of an agent.
  * @param string fId The string id of a function.
  * @param string qId The string id of a qualifier. This parameter can not be null
  * and used as a wildmark.
  * @param object fType The type of a function.
  * @param boolean returnExplicitOnly If True, only explicit Authorizations
  *		will be returned.
  * @param boolean searchUp If true, the ancester nodes of the qualifier will
  *		be checked as well
  * @param boolean isActiveNow If True, only active Authorizations will be returned.
  * @return ref object An AuthorizationIterator.
  **/
 function getAZs($aId, $fId, $qId, $fType, $returnExplicitOnly, $searchUp, $isActiveNow, $groupIds = array())
 {
     // 		printpre (func_get_args());
     // ** parameter validation
     $rule = StringValidatorRule::getRule();
     ArgumentValidator::validate($groupIds, ArrayValidatorRuleWithRule::getRule(OptionalRule::getRule($rule)), true);
     ArgumentValidator::validate($aId, OptionalRule::getRule($rule), true);
     ArgumentValidator::validate($fId, OptionalRule::getRule($rule), true);
     ArgumentValidator::validate($qId, OptionalRule::getRule($rule), true);
     ArgumentValidator::validate($fType, OptionalRule::getRule(ExtendsValidatorRule::getRule("Type")), true);
     ArgumentValidator::validate($returnExplicitOnly, BooleanValidatorRule::getRule(), true);
     ArgumentValidator::validate($isActiveNow, BooleanValidatorRule::getRule(), true);
     // ** end of parameter validation
     $idManager = Services::getService("Id");
     // the parameter that influences the result most is $returnExplicitOnly
     // 1) If $returnExplicitOnly is TRUE, then we only need to check for Authorizations
     // that have been explicitly created, i.e. no need to look for inherited
     // authorizations
     // 2) If $returnExplicitOnly is FALSE, then we need to include inherited Authorizations
     // as well.
     // this array will store the ids of all qualifiers to be checked for authorizations
     $qualifiers = array();
     // check all ancestors of given qualifier
     $hierarchyManager = Services::getService("Hierarchy");
     if (isset($qId)) {
         $qualifierId = $idManager->getId($qId);
         $node = $hierarchyManager->getNode($qualifierId);
         $hierarchy = $hierarchyManager->getHierarchyForNode($node);
         if ($searchUp) {
             // these are the ancestor nodes
             $nodes = $hierarchy->traverse($qualifierId, Hierarchy::TRAVERSE_MODE_DEPTH_FIRST, Hierarchy::TRAVERSE_DIRECTION_UP, Hierarchy::TRAVERSE_LEVELS_ALL);
             // now get the id of each node and store in array
             while ($nodes->hasNext()) {
                 $info = $nodes->next();
                 $id = $info->getNodeId();
                 $qualifiers[] = $id->getIdString();
             }
         } else {
             $qualifiers = array($qId);
         }
     }
     //		print_r($qualifiers);
     // setup the query
     $dbHandler = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addColumn("authorization_id", "id");
     $query->addColumn("fk_agent", "aid");
     $query->addColumn("fk_function", "fid");
     $query->addColumn("fk_qualifier", "qid");
     $query->addColumn("authorization_effective_date", "eff_date");
     $query->addColumn("authorization_expiration_date", "exp_date");
     $query->addTable("az_authorization");
     // now include criteria
     // the qualifiers criteria
     if (isset($qualifiers) && count($qualifiers)) {
         $query->addWhereIn('az_authorization.fk_qualifier', $qualifiers);
     }
     // Agents/Groups
     if (isset($aId)) {
         $agentIds = array($aId);
     } else {
         $agentIds = array();
     }
     $allAgentIds = array_merge($agentIds, $groupIds);
     // the agent criteria
     if (count($allAgentIds)) {
         $query->addWhereIn('az_authorization.fk_agent', $allAgentIds);
     }
     // the function criteria
     if (isset($fId)) {
         $joinc = "az_authorization.fk_function = az_function.function_id";
         $query->addTable("az_function", INNER_JOIN, $joinc);
         $query->addWhereEqual("az_authorization.fk_function", $fId);
     }
     // the function type criteria
     if (isset($fType)) {
         // do not join with az_function if we did already
         if (!isset($fId)) {
             $joinc = "az_authorization.fk_function = az_function.function_id";
             $query->addTable("az_function", INNER_JOIN, $joinc);
         }
         // now join with type
         $joinc = "az_function.fk_type = type.type_id";
         $query->addTable("type", INNER_JOIN, $joinc);
         $query->addWhereEqual("type.type_domain", $fType->getDomain());
         $query->addWhereEqual("type.type_authority", $fType->getAuthority());
         $query->addWhereEqual("type.type_keyword", $fType->getKeyword());
     }
     // the isActiveNow criteria
     if ($isActiveNow) {
         $where = "(authorization_effective_date IS NULL OR (NOW() >= authorization_effective_date))";
         $query->addWhere($where);
         $where = "(authorization_expiration_date IS NULL OR (NOW() < authorization_expiration_date))";
         $query->addWhere($where);
     }
     $query->addOrderBy("authorization_id");
     //		echo "<pre>\n";
     //		echo MySQL_SQLGenerator::generateSQLQuery($query);
     //		echo "</pre>\n";
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     // this array will store the authorizations that will be returned
     $authorizations = array();
     // we only want to create one implicitAZ for a given Agent/Function/Qualifier
     // combo, so maintain a list of already created ones to skip
     $createdImplicitAZs = array();
     $i = 0;
     // process all rows and create the explicit authorizations
     while ($queryResult->hasMoreRows()) {
         $row = $queryResult->getCurrentRow();
         // 			printpre($row);
         $idValue = $row['id'];
         $id = $idManager->getId($idValue);
         if (isset($this->_authorizations[$idValue])) {
             $authorization = $this->_authorizations[$idValue];
         } else {
             $agentId = $idManager->getId($row['aid']);
             $functionId = $idManager->getId($row['fid']);
             $explicitQualifierId = $idManager->getId($row['qid']);
             $effectiveDate = $dbHandler->fromDBDate($row['eff_date'], $this->_dbIndex);
             $expirationDate = $dbHandler->fromDBDate($row['exp_date'], $this->_dbIndex);
             // create the explicit authorization (each explicit authorization
             // has a corresponding row in the authorization db table)
             $authorization = new HarmoniAuthorization($idValue, $agentId, $functionId, $explicitQualifierId, true, $this, $effectiveDate, $expirationDate);
             $this->_authorizations[$idValue] = $authorization;
         }
         // Explicit AZ for ancestor qualifiers and groups should have
         // corresponding implicit AZs
         // in decendents, but not appear in their AZs directly.
         // Therefore, only add the explicit AZ if it is for the requested
         // qualifier and agent if we are fetching more than just the explicitAZs.
         if ($row['qid'] == $qId && $row['aid'] == $aId || $returnExplicitOnly) {
             $authorizations[] = $authorization;
         }
         // now create the implicit authorizations
         // the implicit authorizations will be created for all nodes
         // on the hierarchy path(s) between the node with the explicit authorization
         // and the node on which getAZs() was called.
         // If the row's qualifier and agent are what we asked for however,
         // then the AZ is explicit and doesn't need an implicit AZ as well.
         if ((!$returnExplicitOnly || $searchUp) && ($row['qid'] != $qId || $aId && $row['aid'] != $aId)) {
             // 				printpre("Building Implicit AZs...");
             // 				var_dump($returnExplicitOnly);
             // 				var_dump($searchUp);
             // if this is an AZ that is implicit because of a group instead
             // of because of the hierarchy, create it.
             if ($row['qid'] == $qId && $row['aid'] != $aId) {
                 // 					printpre("In first clause (AuthorizationCache)");
                 $qualifierId = $idManager->getId($qId);
                 // If we are getting implicit AZs for a given agent, make sure
                 // that the implicit AZ has their Id.
                 if ($aId) {
                     $agentId = $idManager->getId($aId);
                 } else {
                     $agentId = $authorization->getAgentId();
                 }
                 $function = $authorization->getFunction();
                 $functionId = $function->getId();
                 $effectiveDate = $authorization->getEffectiveDate();
                 $expirationDate = $authorization->getExpirationDate();
                 $implicit = new HarmoniAuthorization(null, $agentId, $functionId, $qualifierId, false, $this, $effectiveDate, $expirationDate);
                 $azHash = $agentId->getIdString() . "::" . $functionId->getIdString() . "::" . $qualifierId->getIdString();
                 if (!in_array($azHash, $createdImplicitAZs)) {
                     $authorizations[] = $implicit;
                     $createdImplicitAZs[] = $azHash;
                 }
             } else {
                 if (!$returnExplicitOnly && $qId) {
                     // 					printpre("In second clause (AuthorizationCache)");
                     // If we are getting implicit AZs for a given agent, make sure
                     // that the implicit AZ has their Id.
                     if ($aId) {
                         $agentId = $idManager->getId($aId);
                     } else {
                         $agentId = $authorization->getAgentId();
                     }
                     $function = $authorization->getFunction();
                     $functionId = $function->getId();
                     $effectiveDate = $authorization->getEffectiveDate();
                     $expirationDate = $authorization->getExpirationDate();
                     $implicitQualifierId = $idManager->getId($qId);
                     $implicit = new HarmoniAuthorization(null, $agentId, $functionId, $implicitQualifierId, false, $this, $effectiveDate, $expirationDate);
                     $azHash = $agentId->getIdString() . "::" . $functionId->getIdString() . "::" . $implicitQualifierId->getIdString();
                     if (!in_array($azHash, $createdImplicitAZs)) {
                         $authorizations[] = $implicit;
                         $createdImplicitAZs[] = $azHash;
                     }
                 } else {
                     if (!$returnExplicitOnly) {
                         printpre($row);
                         printpre("In third clause (AuthorizationCache)");
                         $explicitQualifier = $authorization->getQualifier();
                         $explicitQualifierId = $explicitQualifier->getId();
                         // If we are getting implicit AZs for a given agent, make sure
                         // that the implicit AZ has their Id.
                         if ($aId) {
                             $agentId = $idManager->getId($aId);
                         } else {
                             $agentId = $authorization->getAgentId();
                         }
                         $function = $authorization->getFunction();
                         $functionId = $function->getId();
                         $effectiveDate = $authorization->getEffectiveDate();
                         $expirationDate = $authorization->getExpirationDate();
                         // this is set 2
                         $authZManager = Services::getService("AuthZ");
                         $hierarchies = $authZManager->getQualifierHierarchies();
                         while ($hierarchies->hasNext()) {
                             $hierarchyId = $hierarchies->next();
                             $hierarchy = $hierarchyManager->getHierarchy($hierarchyId);
                             $timer = new Timer();
                             $timer->start();
                             $nodes = $hierarchy->traverse($explicitQualifierId, Hierarchy::TRAVERSE_MODE_DEPTH_FIRST, Hierarchy::TRAVERSE_DIRECTION_DOWN, Hierarchy::TRAVERSE_LEVELS_ALL);
                             $timer->end();
                             printf("LoadAZTime: %1.6f <br/>", $timer->printTime());
                             // now get the id of each node and store in array
                             $set2 = array();
                             // skip the first node
                             $nodes->next();
                             while ($nodes->hasNext()) {
                                 $info = $nodes->next();
                                 $nodeId = $info->getNodeId();
                                 $implicit = new HarmoniAuthorization(null, $agentId, $functionId, $nodeId, false, $this, $effectiveDate, $expirationDate);
                                 $azHash = $agentId->getIdString() . "::" . $functionId->getIdString() . "::" . $nodeId->getIdString();
                                 // 							printpre($azHash);
                                 // Weird bugs were happening, with $createdImplicitAZs
                                 // but I can't figure out what is going on.
                                 if (!in_array($azHash, $createdImplicitAZs)) {
                                     $authorizations[] = $implicit;
                                     // 								$createdImplicitAZs[] = $azHash;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $queryResult->advanceRow();
     }
     $queryResult->free();
     return $authorizations;
 }
Exemplo n.º 16
0
 /**
  * Get the Schedule for this Section.  Schedules are defined in scheduling
  * OSID.  ScheduleItems are returned in chronological order by increasing
  * start date.
  *	
  * @return object ScheduleItemIterator
  * 
  * @throws object CourseManagementException An exception
  *		   with one of the following messages defined in
  *		   org.osid.coursemanagement.CourseManagementException may be
  *		   thrown:	{@link
  *		   org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}
  * 
  * @access public
  */
 function getSchedule()
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addTable('cm_schedule');
     $query->addTable('sc_item', INNER_JOIN, 'cm_schedule.fk_sc_item = sc_item.id');
     $query->addColumn('cm_schedule.fk_sc_item');
     $query->addWhere("cm_schedule.fk_id='" . addslashes($this->_id->getIdString()) . "'");
     $query->addOrderBy('sc_item.start');
     $res = $dbManager->query($query);
     $array = array();
     $sm = Services::getService("SchedulingManager");
     $idManager = Services::getService("IdManager");
     while ($res->hasMoreRows()) {
         $row = $res->getCurrentRow();
         $res->advanceRow();
         $id = $idManager->getId($row['fk_sc_item']);
         $si = $sm->getScheduleItem($id);
         $array[] = $si;
     }
     $ret = new HarmoniScheduleItemIterator($array);
     return $ret;
 }
Exemplo n.º 17
0
 /**
  * Make the changes to the database required to go from harmoni-0.11.0 to harmoni-0.12.0.
  * 
  * @param integer $dbIndes
  * @return void
  * @access public
  * @since 9/13/07
  */
 public static function harmoni_0_12_0_update($dbIndex)
 {
     $dbc = Services::getService("DBHandler");
     $tables = $dbc->getTableList($dbIndex);
     $changeTables = array('j_node_node', 'node_ancestry');
     $changeTableStatus = array('j_node_node' => false, 'node_ancestry' => false);
     // Check which tables need to be updated and update if needed.
     foreach ($changeTables as $table) {
         if (in_array($table, $tables)) {
             $result = $dbc->query(new GenericSQLQuery("DESCRIBE " . $table), $dbIndex);
             $result = $result->returnAsSelectQueryResult();
             while ($result->hasNext()) {
                 if ($result->field("Field") == 'fk_hierarchy') {
                     $changeTableStatus[$table] = true;
                     break;
                 }
                 $result->advanceRow();
             }
             if (!$changeTableStatus[$table]) {
                 // Alter the table
                 printpre("Adding column fk_hierarchy to {$table}");
                 $dbc->query(new GenericSQLQuery("ALTER TABLE `" . $table . "` ADD `fk_hierarchy` VARCHAR( 170 ) FIRST ;"), $dbIndex);
             }
         }
     }
     // Select the hierarchy ids and update the table
     if (in_array(false, $changeTableStatus)) {
         // Look up which nodes belong to which hierarchy
         $query = new SelectQuery();
         $query->addTable("node");
         $query->addColumn("node_id");
         $query->addColumn("fk_hierarchy");
         $query->addOrderBy("fk_hierarchy");
         $hierarchies = array();
         $result = $dbc->query($query, $dbIndex);
         while ($result->hasMoreRows()) {
             // Create an array to hold the ids of all nodes in the hierarchy
             if (!isset($hierarchies[$result->field('fk_hierarchy')])) {
                 $hierarchies[$result->field('fk_hierarchy')] = array();
             }
             $hierarchies[$result->field('fk_hierarchy')][] = $result->field('node_id');
             $result->advanceRow();
         }
         $result->free();
         // Update each table's fk_hierarchy
         foreach ($hierarchies as $hierarchyId => $nodeIds) {
             if (!$changeTableStatus['j_node_node']) {
                 $query = new UpdateQuery();
                 $query->addValue('fk_hierarchy', $hierarchyId);
                 $query->setTable('j_node_node');
                 $query->addWhere("fk_child IN ('" . implode("', '", $nodeIds) . "')");
                 $result = $dbc->query($query, $dbIndex);
                 printpre("Updated fk_hierarchy on " . $result->getNumberOfRows() . " rows in j_node_node.");
             }
             if (!$changeTableStatus['j_node_node']) {
                 $query = new UpdateQuery();
                 $query->addValue('fk_hierarchy', $hierarchyId);
                 $query->setTable('node_ancestry');
                 $query->addWhere("fk_node IN ('" . implode("', '", $nodeIds) . "')");
                 $result = $dbc->query($query, $dbIndex);
                 printpre("Updated fk_hierarchy on " . $result->getNumberOfRows() . " rows in node_ancestry.");
             }
         }
         // Alter the table to be NOT NULL
         foreach ($changeTables as $table) {
             if (!$changeTableStatus[$table]) {
                 // Alter the table
                 $dbc->query(new GenericSQLQuery("ALTER TABLE `" . $table . "` CHANGE `fk_hierarchy` `fk_hierarchy`  VARCHAR( 170 ) NOT NULL"), $dbIndex);
                 printpre("Altering column fk_hierarchy in {$table} to be NOT NULL.");
             }
         }
     }
     // Alter the names of the Scheduling columns
     if (in_array('sc_item', $tables)) {
         try {
             $dbc->query(new GenericSQLQuery("ALTER TABLE `sc_item` CHANGE `start` `start_date` BIGINT( 20 ) NULL DEFAULT NULL , CHANGE `end` `end_date` BIGINT( 20 ) NULL DEFAULT NULL "), $dbIndex);
             printpre("Renaming columns start and end to start_date and end_date in the sc_item table.");
         } catch (QueryDatabaseException $e) {
         }
     }
 }
Exemplo n.º 18
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;
 }
Exemplo n.º 19
0
 /**
  * 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);
 }
 /**
  * Return the names of writable Logs.
  *	
  * @return object StringIterator
  * 
  * @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}
  * 
  * @access public
  */
 function getLogNamesForWriting()
 {
     $dbc = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addColumn("log_name");
     $query->addTable("log_entry");
     $query->setDistinct(true);
     $query->addOrderBy("log_name");
     $results = $dbc->query($query, $this->_dbIndex);
     $names = array();
     while ($results->hasNext()) {
         $names[] = $results->field("log_name");
         $results->advanceRow();
     }
     $results->free();
     $iterator = new HarmoniIterator($names);
     return $iterator;
 }
 /**
  * Answer an array of the versions for this plugin instance with the most 
  * recent version first.
  *
  * @return array of SeguePluginVersion objects
  * @access public
  * @since 1/7/08
  */
 public function getVersions()
 {
     if (!isset($this->versions)) {
         $this->versions = array();
         $query = new SelectQuery();
         $query->addTable('segue_plugin_version');
         $query->addColumn('version_id');
         $query->addColumn('tstamp');
         $query->addColumn('comment');
         $query->addColumn('agent_id');
         $query->addWhereEqual('node_id', $this->getId());
         $query->addOrderBy('tstamp', SORT_DESC);
         $dbc = Services::getService('DBHandler');
         $result = $dbc->query($query, IMPORTER_CONNECTION);
         $idMgr = Services::getService("Id");
         $number = $result->getNumberOfRows();
         while ($result->hasNext()) {
             $row = $result->next();
             $this->versions[] = new SeguePluginVersion($this, $row['version_id'], DateAndTime::fromString($row['tstamp']), $idMgr->getId($row['agent_id']), $number, $row['comment']);
             $number--;
         }
     }
     return $this->versions;
 }
Exemplo n.º 22
0
 /**
  * Answer all items with this tag in a particular system
  * 
  * @return object ItemsIterator
  * @access public
  * @since 11/2/06
  */
 function getItemsForAgentInSystem($agentId, $system)
 {
     $query = new SelectQuery();
     $query->addColumn('tag_item.db_id');
     $query->addColumn('tag_item.id');
     $query->addColumn('tag_item.system');
     $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($agentId->getIdString()) . "'");
     $query->addWhere("tag_item.system='" . addslashes($system) . "'");
     $query->addOrderBy('tag.tstamp', DESCENDING);
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     $iterator = new TaggedItemIterator($result);
     return $iterator;
 }
Exemplo n.º 23
0
 /**
  * Answer a list of categories in this log.
  * 
  * Warning: NOT IN OSID
  * 
  * @return array
  * @access public
  * @since 6/10/08
  */
 public function getCategories()
 {
     $query = new SelectQuery();
     $query->addTable('log_entry');
     $query->addColumn('DISTINCT (category)', 'cat');
     $query->addWhereEqual('log_name', $this->_name);
     $query->addOrderBy('category');
     $dbc = Services::getService('DatabaseManager');
     $result = $dbc->query($query, $this->_dbIndex);
     $categories = array();
     while ($result->hasNext()) {
         $row = $result->next();
         $categories[] = $row['cat'];
     }
     return $categories;
 }
 /**
  * Load the next bunch of items
  * 
  * @return void
  * @access public
  * @since 3/1/06
  */
 function loadNext()
 {
     $dbc = Services::getService("DatabaseManager");
     // get the list of the next set of Ids
     $query = new SelectQuery();
     $query->addTable("log_entry");
     $query->addColumn("id", "entry_id", "log_entry");
     $query->setDistinct(true);
     $query->addOrderBy("timestamp", DESCENDING);
     $this->addWhereClauses($query);
     $query->limitNumberOfRows($this->_numPerLoad);
     if ($this->_currentRow) {
         $query->startFromRow($this->_currentRow + 1);
     }
     // 		printpre('CurrentRow at load: '.$this->_currentRow);
     // 		printpre($query->asString());
     $results = $dbc->query($query, $this->_dbIndex);
     $nextIds = array();
     while ($results->hasNext()) {
         $row = $results->next();
         $nextIds[] = $row['entry_id'];
     }
     // 		printpre($nextIds);
     /*********************************************************
      * Load the rows for the next set of Ids
      *********************************************************/
     $query = new SelectQuery();
     $query->addTable("log_entry");
     $query->addColumn("id", "id", "log_entry");
     $query->addColumn("timestamp", "timestamp", "log_entry");
     $query->addColumn("category", "category", "log_entry");
     $query->addColumn("description", "description", "log_entry");
     $query->addColumn("backtrace", "backtrace", "log_entry");
     $subQuery = new SelectQuery();
     $subQuery->addColumn("*");
     $subQuery->addTable("log_agent");
     $subQuery->addWhereIn("fk_entry", $nextIds);
     $query->addDerivedTable($subQuery, LEFT_JOIN, "log_entry.id = tmp_agent.fk_entry", "tmp_agent");
     $query->addColumn("fk_agent", "agent_id", "tmp_agent");
     $subQuery = new SelectQuery();
     $subQuery->addColumn("*");
     $subQuery->addTable("log_node");
     $subQuery->addWhereIn("fk_entry", $nextIds);
     $query->addDerivedTable($subQuery, LEFT_JOIN, "log_entry.id = tmp_node.fk_entry", "tmp_node");
     $query->addColumn("fk_node", "node_id", "tmp_node");
     $query->addWhereIn("id", $nextIds);
     $query->addOrderBy("timestamp", DESCENDING);
     $query->addOrderBy("id", ASCENDING);
     //  		printpre($query->asString());
     $results = $dbc->query($query, $this->_dbIndex);
     $i = $this->_current;
     $currentEntryId = null;
     $timestamp = null;
     $category = null;
     $description = null;
     $backtrace = '';
     $agents = array();
     $nodes = array();
     while ($results->hasNext()) {
         $row = $results->next();
         // Create the entry if we have all of the data for it.
         if ($currentEntryId && $currentEntryId != $row["id"]) {
             // 				printpre("Creating Entry: ".$currentEntryId." ".$timestamp." -- ".($i+1)." of ".$this->_count);
             $this->_entries[$i] = new HarmoniEntry($dbc->fromDBDate($timestamp, $this->_dbIndex), $category, $description, $backtrace, array_unique($agents), array_unique($nodes), $this->_formatType, $this->_priorityType);
             $i++;
             $this->_currentRow++;
             $currentEntryId = null;
             $timestamp = null;
             $category = null;
             $description = null;
             $backtrace = '';
             $agents = array();
             $nodes = array();
         }
         $currentEntryId = $row["id"];
         $timestamp = $row["timestamp"];
         $category = $row["category"];
         $description = $row["description"];
         $backtrace = $row["backtrace"];
         $agents[] = $row["agent_id"];
         $nodes[] = $row["node_id"];
         // 			printpre($currentEntryId." ".$timestamp." ".$this->_currentRow);
     }
     $results->free();
     // get the last entry if we are at the end of the iterator
     if ($currentEntryId && $i == $this->_count - 1) {
         // 			printpre("Creating Entry: ".$currentEntryId." ".$timestamp." -- ".($i+1)." of ".$this->_count);
         $this->_entries[$i] = new HarmoniEntry($dbc->fromDBDate($timestamp, $this->_dbIndex), $category, $description, $backtrace, array_unique($agents), array_unique($nodes), $this->_formatType, $this->_priorityType);
     }
 }
Exemplo n.º 25
0
 /**
  * Answer An AZ query for implicit AZs
  * 
  * @param array $agentIds The agent Ids to match
  * @param string fId The string id of a function.
  * @param string qId The string id of a qualifier. This parameter can not be null
  * and used as a wildmark.
  * @param object fType The type of a function.
  * @param boolean isActiveNow If True, only active Authorizations will be returned.
  * @return SelectQueryInterface 
  * @access protected
  * @since 4/23/08
  */
 protected function getImplicitAZQuery(array $agentIds, $fId, $qId, $fType, $isActiveNow)
 {
     $query = new SelectQuery();
     $query->addColumn("fk_explicit_az");
     $query->addColumn("id", "id", "az2_implicit_az");
     $query->addColumn("fk_agent", "aid");
     $query->addColumn("fk_function", "fid");
     $query->addColumn("fk_qualifier", "qid");
     $query->addColumn("effective_date", "eff_date");
     $query->addColumn("expiration_date", "exp_date");
     $query->addTable("az2_implicit_az");
     // now include criteria
     // the qualifiers criteria
     if (isset($qId)) {
         $query->addWhereEqual('fk_qualifier', $qId);
     }
     // the agent criteria
     if (count($agentIds)) {
         $query->addWhereIn('fk_agent', $agentIds);
     }
     // the function criteria
     if (isset($fId)) {
         $joinc = "az2_implicit_az.fk_function = az2_function.id";
         $query->addTable("az2_function", INNER_JOIN, $joinc);
         $query->addWhereEqual("fk_function", $fId);
     }
     // the function type criteria
     if (isset($fType)) {
         // do not join with az_function if we did already
         if (!isset($fId)) {
             $joinc = "az2_implicit_az.fk_function = az2_function.id";
             $query->addTable("az2_function", INNER_JOIN, $joinc);
         }
         // now join with type
         $joinc = "az2_function.fk_type = az2_function_type.id";
         $query->addTable("az2_function_type", INNER_JOIN, $joinc);
         $query->addWhereEqual("domain", $fType->getDomain());
         $query->addWhereEqual("authority", $fType->getAuthority());
         $query->addWhereEqual("keyword", $fType->getKeyword());
     }
     // the isActiveNow criteria
     if ($isActiveNow) {
         $where = "(effective_date IS NULL OR (NOW() >= effective_date))";
         $query->addWhere($where);
         $where = "(expiration_date IS NULL OR (NOW() < expiration_date))";
         $query->addWhere($where);
     }
     $query->addOrderBy("az2_implicit_az.id");
     return $query;
 }