Skip to content

Commit

Permalink
Minor syntax and comment cleanup on QListControl and added CountItems…
Browse files Browse the repository at this point in the history
…() method
  • Loading branch information
mikeho committed Jun 30, 2011
1 parent 0a9359c commit 67c924d
Showing 1 changed file with 35 additions and 14 deletions.
49 changes: 35 additions & 14 deletions includes/qcodo/_core/qform/QListControl.class.php
Expand Up @@ -75,7 +75,12 @@ public function AddItem($mixListItemOrName, $strValue = null, $blnSelected = nul
array_push($this->objItemsArray, $objListItem);
}

// Used if you want to add a LIstItem at a specific location in objItemsArray
/**
* Allows you to add a QListItem to this QListControl at a specific location in the current item array
* @param integer $intIndex the index of the location to add the new item to
* @param QListItem $objListItem the item to add
* @throws QIndexOutOfRangeException
*/
public function AddItemAt($intIndex, QListItem $objListItem) {
$this->blnModified = true;
try {
Expand All @@ -94,31 +99,39 @@ 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;
/**
* Allows you to add an array of key/value pairs to the ListControl. Convenient especially for adding a list from a type table,
* e.g. by passing in SomeType::$NameArray. The list of seleted values can either be an array of values, or just a single value.
* @param array $mixItemArray name/value pairs of QListItems to add to this QListControl
* @param mixed $mixSelectedValues can be an array of selected values, or just an atomic value, that is selected (optional)
* @param string $strItemGroup
* @param string $strOverrideParameters
*/
public function AddItems($mixItemArray, $mixSelectedValues = null, $strItemGroup = null, $strOverrideParameters = null) {
try {
$mixItemArray = QType::Cast($mixItemArray, QType::ArrayType);
} catch (QInvalidCastException $objExc) {
$objExc->IncrementOffset();
throw $objExc;
}
foreach ($mixItemArray as $val=>$item) {

foreach ($mixItemArray as $strValue => $strName) {
$blnSelected = false;

// Check to See if we are "selected"
if ($mixSelectedValues) {
if (gettype($mixSelectedValues) == QType::ArrayType) {
$blnSelected = in_array ($val, $mixSelectedValues);
}
else {
$blnSelected = ($val == $mixSelectedValues);
$blnSelected = in_array($strValue, $mixSelectedValues);
} else {
$blnSelected = ($strValue== $mixSelectedValues);
}
}
$this->AddItem ($item, $val, $blnSelected, $strItemGroup, $strOverrideParameters);
};

// Add It
$this->AddItem($strName, $strValue, $blnSelected, $strItemGroup, $strOverrideParameters);
}
}

// Gets the ListItem at a specific location in objItemsArray
public function GetItem($intIndex) {
try {
Expand All @@ -145,6 +158,14 @@ public function GetAllItems() {
return $this->objItemsArray;
}

/**
* Returns the count of items in this QListControl
* @return integer
*/
public function CountItems() {
return count($this->objItemsArray);
}

// Removes all the items in objItemsArray
public function RemoveAllItems() {
$this->blnModified = true;
Expand Down

0 comments on commit 67c924d

Please sign in to comment.