objParentObject = $objParentObject; // Setup linked ShoppingCartItem object $this->objShoppingCartItem = $objShoppingCartItem; // Figure out if we're Editing or Creating New if ($this->objShoppingCartItem->__Restored) { $this->strTitleVerb = QApplication::Translate('Edit'); $this->blnEditMode = true; } else { $this->strTitleVerb = QApplication::Translate('Create'); $this->blnEditMode = false; } } /** * Static Helper Method to Create using PK arguments * You must pass in the PK arguments on an object to load, or leave it blank to create a new one. * If you want to load via QueryString or PathInfo, use the CreateFromQueryString or CreateFromPathInfo * static helper methods. Finally, specify a CreateType to define whether or not we are only allowed to * edit, or if we are also allowed to create a new one, etc. * * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl * @param integer $intShoppingCartId primary key value * @param integer $intProductId primary key value * @param QMetaControlCreateType $intCreateType rules governing ShoppingCartItem object creation - defaults to CreateOrEdit * @return ShoppingCartItemMetaControl */ public static function Create($objParentObject, $intShoppingCartId = null, $intProductId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intShoppingCartId) && strlen($intProductId)) { $objShoppingCartItem = ShoppingCartItem::Load($intShoppingCartId, $intProductId); // ShoppingCartItem was found -- return it! if ($objShoppingCartItem) return new ShoppingCartItemMetaControl($objParentObject, $objShoppingCartItem); // If CreateOnRecordNotFound not specified, throw an exception else if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) throw new QCallerException('Could not find a ShoppingCartItem object with PK arguments: ' . $intShoppingCartId . ', ' . $intProductId); // If EditOnly is specified, throw an exception } else if ($intCreateType == QMetaControlCreateType::EditOnly) throw new QCallerException('No PK arguments specified'); // If we are here, then we need to create a new record return new ShoppingCartItemMetaControl($objParentObject, new ShoppingCartItem()); } /** * Static Helper Method to Create using PathInfo arguments * * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl * @param QMetaControlCreateType $intCreateType rules governing ShoppingCartItem object creation - defaults to CreateOrEdit * @return ShoppingCartItemMetaControl */ public static function CreateFromPathInfo($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) { $intShoppingCartId = QApplication::PathInfo(0); $intProductId = QApplication::PathInfo(1); return ShoppingCartItemMetaControl::Create($objParentObject, $intShoppingCartId, $intProductId, $intCreateType); } /** * Static Helper Method to Create using QueryString arguments * * @param mixed $objParentObject QForm or QPanel which will be using this ShoppingCartItemMetaControl * @param QMetaControlCreateType $intCreateType rules governing ShoppingCartItem object creation - defaults to CreateOrEdit * @return ShoppingCartItemMetaControl */ public static function CreateFromQueryString($objParentObject, $intCreateType = QMetaControlCreateType::CreateOrEdit) { $intShoppingCartId = QApplication::QueryString('intShoppingCartId'); $intProductId = QApplication::QueryString('intProductId'); return ShoppingCartItemMetaControl::Create($objParentObject, $intShoppingCartId, $intProductId, $intCreateType); } /////////////////////////////////////////////// // PUBLIC CREATE and REFRESH METHODS /////////////////////////////////////////////// /** * Create and setup QListBox lstShoppingCart * @param string $strControlId optional ControlId to use * @return QListBox */ public function lstShoppingCart_Create($strControlId = null) { $this->lstShoppingCart = new QListBox($this->objParentObject, $strControlId); $this->lstShoppingCart->Name = QApplication::Translate('Shopping Cart'); $this->lstShoppingCart->Required = true; if (!$this->blnEditMode) $this->lstShoppingCart->AddItem(QApplication::Translate('- Select One -'), null); $objShoppingCartArray = ShoppingCart::LoadAll(); if ($objShoppingCartArray) foreach ($objShoppingCartArray as $objShoppingCart) { $objListItem = new QListItem($objShoppingCart->__toString(), $objShoppingCart->Id); if (($this->objShoppingCartItem->ShoppingCart) && ($this->objShoppingCartItem->ShoppingCart->Id == $objShoppingCart->Id)) $objListItem->Selected = true; $this->lstShoppingCart->AddItem($objListItem); } return $this->lstShoppingCart; } /** * Create and setup QLabel lblShoppingCartId * @param string $strControlId optional ControlId to use * @return QLabel */ public function lblShoppingCartId_Create($strControlId = null) { $this->lblShoppingCartId = new QLabel($this->objParentObject, $strControlId); $this->lblShoppingCartId->Name = QApplication::Translate('Shopping Cart'); $this->lblShoppingCartId->Text = ($this->objShoppingCartItem->ShoppingCart) ? $this->objShoppingCartItem->ShoppingCart->__toString() : null; $this->lblShoppingCartId->Required = true; return $this->lblShoppingCartId; } /** * Create and setup QListBox lstProduct * @param string $strControlId optional ControlId to use * @return QListBox */ public function lstProduct_Create($strControlId = null) { $this->lstProduct = new QListBox($this->objParentObject, $strControlId); $this->lstProduct->Name = QApplication::Translate('Product'); $this->lstProduct->Required = true; if (!$this->blnEditMode) $this->lstProduct->AddItem(QApplication::Translate('- Select One -'), null); $objProductArray = Product::LoadAll(); if ($objProductArray) foreach ($objProductArray as $objProduct) { $objListItem = new QListItem($objProduct->__toString(), $objProduct->Id); if (($this->objShoppingCartItem->Product) && ($this->objShoppingCartItem->Product->Id == $objProduct->Id)) $objListItem->Selected = true; $this->lstProduct->AddItem($objListItem); } return $this->lstProduct; } /** * Create and setup QLabel lblProductId * @param string $strControlId optional ControlId to use * @return QLabel */ public function lblProductId_Create($strControlId = null) { $this->lblProductId = new QLabel($this->objParentObject, $strControlId); $this->lblProductId->Name = QApplication::Translate('Product'); $this->lblProductId->Text = ($this->objShoppingCartItem->Product) ? $this->objShoppingCartItem->Product->__toString() : null; $this->lblProductId->Required = true; return $this->lblProductId; } /** * Create and setup QIntegerTextBox txtQuantity * @param string $strControlId optional ControlId to use * @return QIntegerTextBox */ public function txtQuantity_Create($strControlId = null) { $this->txtQuantity = new QIntegerTextBox($this->objParentObject, $strControlId); $this->txtQuantity->Name = QApplication::Translate('Quantity'); $this->txtQuantity->Text = $this->objShoppingCartItem->Quantity; $this->txtQuantity->Required = true; return $this->txtQuantity; } /** * Create and setup QLabel lblQuantity * @param string $strControlId optional ControlId to use * @param string $strFormat optional sprintf format to use * @return QLabel */ public function lblQuantity_Create($strControlId = null, $strFormat = null) { $this->lblQuantity = new QLabel($this->objParentObject, $strControlId); $this->lblQuantity->Name = QApplication::Translate('Quantity'); $this->lblQuantity->Text = $this->objShoppingCartItem->Quantity; $this->lblQuantity->Required = true; $this->lblQuantity->Format = $strFormat; return $this->lblQuantity; } /** * Refresh this MetaControl with Data from the local ShoppingCartItem object. * @param boolean $blnReload reload ShoppingCartItem from the database * @return void */ public function Refresh($blnReload = false) { if ($blnReload) $this->objShoppingCartItem->Reload(); if ($this->lstShoppingCart) { $this->lstShoppingCart->RemoveAllItems(); if (!$this->blnEditMode) $this->lstShoppingCart->AddItem(QApplication::Translate('- Select One -'), null); $objShoppingCartArray = ShoppingCart::LoadAll(); if ($objShoppingCartArray) foreach ($objShoppingCartArray as $objShoppingCart) { $objListItem = new QListItem($objShoppingCart->__toString(), $objShoppingCart->Id); if (($this->objShoppingCartItem->ShoppingCart) && ($this->objShoppingCartItem->ShoppingCart->Id == $objShoppingCart->Id)) $objListItem->Selected = true; $this->lstShoppingCart->AddItem($objListItem); } } if ($this->lblShoppingCartId) $this->lblShoppingCartId->Text = ($this->objShoppingCartItem->ShoppingCart) ? $this->objShoppingCartItem->ShoppingCart->__toString() : null; if ($this->lstProduct) { $this->lstProduct->RemoveAllItems(); if (!$this->blnEditMode) $this->lstProduct->AddItem(QApplication::Translate('- Select One -'), null); $objProductArray = Product::LoadAll(); if ($objProductArray) foreach ($objProductArray as $objProduct) { $objListItem = new QListItem($objProduct->__toString(), $objProduct->Id); if (($this->objShoppingCartItem->Product) && ($this->objShoppingCartItem->Product->Id == $objProduct->Id)) $objListItem->Selected = true; $this->lstProduct->AddItem($objListItem); } } if ($this->lblProductId) $this->lblProductId->Text = ($this->objShoppingCartItem->Product) ? $this->objShoppingCartItem->Product->__toString() : null; if ($this->txtQuantity) $this->txtQuantity->Text = $this->objShoppingCartItem->Quantity; if ($this->lblQuantity) $this->lblQuantity->Text = $this->objShoppingCartItem->Quantity; } /////////////////////////////////////////////// // PROTECTED UPDATE METHODS for ManyToManyReferences (if any) /////////////////////////////////////////////// /////////////////////////////////////////////// // PUBLIC SHOPPINGCARTITEM OBJECT MANIPULATORS /////////////////////////////////////////////// /** * This will save this object's ShoppingCartItem instance, * updating only the fields which have had a control created for it. */ public function SaveShoppingCartItem() { try { // Update any fields for controls that have been created if ($this->lstShoppingCart) $this->objShoppingCartItem->ShoppingCartId = $this->lstShoppingCart->SelectedValue; if ($this->lstProduct) $this->objShoppingCartItem->ProductId = $this->lstProduct->SelectedValue; if ($this->txtQuantity) $this->objShoppingCartItem->Quantity = $this->txtQuantity->Text; // Update any UniqueReverseReferences (if any) for controls that have been created for it // Save the ShoppingCartItem object $this->objShoppingCartItem->Save(); // Finally, update any ManyToManyReferences (if any) } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } /** * This will DELETE this object's ShoppingCartItem instance from the database. * It will also unassociate itself from any ManyToManyReferences. */ public function DeleteShoppingCartItem() { $this->objShoppingCartItem->Delete(); } /////////////////////////////////////////////// // PUBLIC GETTERS and SETTERS /////////////////////////////////////////////// /** * Override method to perform a property "Get" * This will get the value of $strName * * @param string $strName Name of the property to get * @return mixed */ public function __get($strName) { switch ($strName) { // General MetaControlVariables case 'ShoppingCartItem': return $this->objShoppingCartItem; case 'TitleVerb': return $this->strTitleVerb; case 'EditMode': return $this->blnEditMode; // Controls that point to ShoppingCartItem fields -- will be created dynamically if not yet created case 'ShoppingCartIdControl': if (!$this->lstShoppingCart) return $this->lstShoppingCart_Create(); return $this->lstShoppingCart; case 'ShoppingCartIdLabel': if (!$this->lblShoppingCartId) return $this->lblShoppingCartId_Create(); return $this->lblShoppingCartId; case 'ProductIdControl': if (!$this->lstProduct) return $this->lstProduct_Create(); return $this->lstProduct; case 'ProductIdLabel': if (!$this->lblProductId) return $this->lblProductId_Create(); return $this->lblProductId; case 'QuantityControl': if (!$this->txtQuantity) return $this->txtQuantity_Create(); return $this->txtQuantity; case 'QuantityLabel': if (!$this->lblQuantity) return $this->lblQuantity_Create(); return $this->lblQuantity; default: try { return parent::__get($strName); } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } } /** * Override method to perform a property "Set" * This will set the property $strName to be $mixValue * * @param string $strName Name of the property to set * @param string $mixValue New value of the property * @return mixed */ public function __set($strName, $mixValue) { try { switch ($strName) { // Controls that point to ShoppingCartItem fields case 'ShoppingCartIdControl': return ($this->lstShoppingCart = QType::Cast($mixValue, 'QControl')); case 'ProductIdControl': return ($this->lstProduct = QType::Cast($mixValue, 'QControl')); case 'QuantityControl': return ($this->txtQuantity = QType::Cast($mixValue, 'QControl')); default: return parent::__set($strName, $mixValue); } } catch (QCallerException $objExc) { $objExc->IncrementOffset(); throw $objExc; } } } ?>