Skip to content

Commit

Permalink
Adding a convenience method to QListControl to add an array of item, …
Browse files Browse the repository at this point in the history
…or key value pairs like those create by Type tables
  • Loading branch information
spekary authored and mikeho committed Jun 30, 2011
1 parent d1ca5c0 commit 0a9359c
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions includes/qcodo/_core/qform/QListControl.class.php
Expand Up @@ -94,6 +94,31 @@ public function AddItemAt($intIndex, QListItem $objListItem) {
$this->objItemsArray[$intIndex] = $objListItem;
}

// Use this to add an array of items, or an array of key=>value pairs. Convenient for adding a list from a type table.
// When passing key=>val pairs, mixSelectedValues can be an array, or just a single value to compare against to indicate what is selected
public function AddItems (array $mixItemArray, $mixSelectedValues = null, $strItemGroup = null, $strOverrideParameters = null) {
$this->blnModified = true;
try {
$mixItemArray = QType::Cast($mixItemArray, QType::ArrayType);
} catch (QInvalidCastException $objExc) {
$objExc->IncrementOffset();
throw $objExc;
}

foreach ($mixItemArray as $val=>$item) {
$blnSelected = false;
if ($mixSelectedValues) {
if (gettype($mixSelectedValues) == QType::ArrayType) {
$blnSelected = in_array ($val, $mixSelectedValues);
}
else {
$blnSelected = ($val == $mixSelectedValues);
}
}
$this->AddItem ($item, $val, $blnSelected, $strItemGroup, $strOverrideParameters);
};
}

// Gets the ListItem at a specific location in objItemsArray
public function GetItem($intIndex) {
try {
Expand Down

0 comments on commit 0a9359c

Please sign in to comment.