*
* @author Roland Haeder <webmaster@ship-simu.org>
* @version 0.0.0
- * @copyright Copyright (c) 2007, 2008 Roland Haeder, 2009 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
*
// 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');
}
/**
// Generate hash
$hash = $this->generateHash($groupName, $groupName, $entry);
- //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): hash='.$hash.'');
+ //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
// Add the hash to the index
$this->listIndex[] = $hash;
//* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
}
+ /**
+ * Removes given entry from the list group
+ *
+ * @param $groupName Group where we should remove the entry from
+ * @param $entry The entry we should remove
+ * @return void
+ * @throws NoListGroupException If the given group is not found
+ */
+ public function removeEntry ($groupName, $entry) {
+ //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - START');
+ // Is the group already added?
+ if (!$this->isGroupSet($groupName)) {
+ // Throw the exception here
+ throw new NoListGroupException(array($this, $groupName), self::EXCEPTION_GROUP_NOT_FOUND);
+ } // END - if
+
+ // Generate hash
+ $hash = $this->generateHash($groupName, $groupName, $entry);
+ //* DEBUG: */ $this->debugOutput(__METHOD__ . ': groupName=' . $groupName . ', entry=' . $entry . ', hash=' . $hash);
+
+ // Remove it from the list ...
+ unset($this->listEntries[$hash]);
+
+ // ... and hash list as well
+ unset($this->listIndex[array_search($hash, $this->listIndex)]);
+ //* DEBUG: */ $this->debugOutput(__METHOD__.'('.$this->__toString().'): '.$groupName . ' - FINISHED');
+ }
+
/**
* Generates a hash from given group, sub group and entry
*
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;