*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009, 2010 Hub Developer Team
+ * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 - 2011 Hub Developer Team
* @license GNU GPL 3.0 or any newer version
* @link http://www.ship-simu.org
*
}
/**
- * Checks wether the given group is set
+ * Checks whether the given group is set
*
* @param $groupName Group to check if found in list
- * @return $isset Wether the group is valid
+ * @return $isset Whether the group is valid
*/
public function isGroupSet ($groupName) {
//* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName);
// Add the instance itself to the list
$this->listEntries[$hash] = $instance;
- //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - START');
+ //* DEBUG: */ $this->debugOutput(__METHOD__.': '.$groupName . '/' . $subGroup . ' - FINISHED');
}
/**
// Is there another list?
if (!is_null($list)) {
// Then get it as well
- $array = $this->listGroups[$list]->getArrayFromList(null);
+ $array = $this->listGroups[$list]->getArrayFromList(NULL);
} // END - if
// Walk through all entries
foreach ($this->listIndex as $hash) {
- //* DEBUG: */ print __METHOD__.':hash='.$hash."\n";
+ //* DEBUG: */ print __METHOD__.':hash='.$hash.chr(10);
// Is the list entry set?
if ($this->isHashValid($hash)) {
// Add it
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
- //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
+ //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
// Add the hash to the index
$this->listIndex[] = $hash;
- //* DEBUG: */ print $groupName.'/'.count($this->listIndex)."\n";
+ //* DEBUG: */ print $groupName.'/'.count($this->listIndex).chr(10);
// Now add the entry to the list
$this->listEntries[$hash] = $entry;
- //* DEBUG: */ print $groupName.'/'.count($this->listEntries)."\n";
+ //* DEBUG: */ print $groupName.'/'.count($this->listEntries).chr(10);
//* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
}
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
- //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
+ //* DEBUG: */ $this->debugOutput('[' . __METHOD__ . ':' . __LINE__ . ']: groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
// Remove it from the list ...
unset($this->listEntries[$hash]);
$entry2 = crc32($entry['id']) . ':' . count($entry);
} else {
// Unsupported type detected
- $this->debugOutut(__METHOD__ . ': entry type ' . gettype($entry) . ' is unsupported.');
+ $this->debugOutut('[' . __METHOD__ . ':' . __LINE__ . ']: entry type ' . gettype($entry) . ' is unsupported.');
// @TODO Extend this somehow?
$entry2 = gettype($entry);
return $hash;
}
+ /**
+ * Clears an array of groups, all are being checked for existence
+ *
+ * @param $groupNames An array with existing list groups
+ * @return void
+ */
+ protected function clearGroups (array $groupNames) {
+ // Walk through all groups
+ foreach ($groupNames as $groupName) {
+ // Clear this group
+ $this->clearGroup($groupName);
+ } // END - foreach
+ }
+
+ /**
+ * Clears a single group by resetting it to its initial state (empty array)
+ *
+ * @param $groupName Name of an existing group to clear
+ * @return void
+ */
+ protected function clearGroup ($groupName) {
+ // Does this group exist?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Then clear this group list
+ $this->listGroups[$groupName]->clearList();
+
+ // Clear this list
+ $this->listIndex = array();
+ $this->listEntries = array();
+ }
+
/**
* Counts all entries in this list
*
}
/**
- * Checks wether the given hash is valid
+ * Checks whether the given hash is valid
*
* @param $hash The hash we should validate
- * @return $isValid Wether the given hash is valid
+ * @return $isValid Whether the given hash is valid
*/
public final function isHashValid ($hash) {
// Check it
return $entry;
}
+ /**
+ * Gets a full array from given group name
+ *
+ * @param $groupName The group name to get a list for
+ * @return $entries The array with all entries
+ * @throws NoListGroupException If the specified group is invalid
+ */
+ public function getArrayFromGroup ($groupName) {
+ // Is the group valid?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Init the entries' array
+ $entries = array();
+
+ // Get an iterator
+ $iteratorInstance = $this->listGroups[$groupName]->getIterator();
+
+ // Go through all entries
+ while ($iteratorInstance->valid()) {
+ // Get key
+ $entryIndex = $iteratorInstance->key();
+
+ // ... and the final entry which is the stored instance
+ $entry = $this->getEntry($entryIndex);
+
+ // Add it to the list
+ $entries[$iteratorInstance->current()] = $entry;
+
+ // Skip to next one
+ $iteratorInstance->next();
+ } // END - while
+
+ // Return the list
+ return $entries;
+ }
+
/**
* Updates the given entry by hash with given array
*
if (!$this->isHashValid($hash)) {
// Throw an exception here, hashIndex is unknown at this point
throw new InvalidListHashException(array($this, $hash, -999), self::EXCEPTION_INVALID_HASH);
- }
+ } // END - if
// Set the entry
$this->listEntries[$hash] = $entryArray;