/** * Counts all many-to-many associated NameItems * @return int */ public function CountNameItems() { if (is_null($this->intId)) { return 0; } return NameItem::CountByPerson($this->intId); }
/** * Given a search term, this will try and match all similarly matched individuals. * This will utilize soundex and other indexing methodologies. * * @param string $strName * @param QQCondition $objCondition * @param QQClause[] $objClauses * @param QQNodePerson $objPersonNode * @return void */ public static function PrepareQqForSearch($strName, QQCondition &$objCondition, &$objClauses, QQNodePerson $objPersonNode = null) { if (!$objPersonNode) { $objPersonNode = QQN::Person(); } $strNameItemArray = NameItem::GetNormalizedArrayFromNameString($strName, true); // First, get the applicable NameItem $intNameItemIdArrayArray = array(); foreach ($strNameItemArray as $strNameItem) { $intNameItemIdArray = array(); $strQuery = sprintf("SELECT * FROM name_item WHERE (soundex(name) = soundex('%s') OR name LIKE '%s%%')", mysql_escape_string($strNameItem), mysql_escape_string($strNameItem)); $objNameItemArray = NameItem::InstantiateDbResult(NameItem::GetDatabase()->Query($strQuery)); foreach ($objNameItemArray as $objNameItem) { $intNameItemIdArray[] = $objNameItem->Id; } $intNameItemIdArrayArray[] = $intNameItemIdArray; } // Build the search array from Person $intIndex = 0; foreach ($intNameItemIdArrayArray as $intNameItemIdArray) { if (!count($intNameItemIdArray)) { $objCondition = QQ::None(); return; } $intIndex++; $strAlias = 'assn_' . $intIndex; if ($intIndex == 2) { $objClauses[] = QQ::Distinct(); } $objClauses[] = QQ::CustomFrom('person_nameitem_assn', $strAlias); if (count($intNameItemIdArray) == 1) { $objCondition = QQ::AndCondition($objCondition, QQ::Equal(QQ::CustomNode($strAlias . '.person_id'), $objPersonNode->Id), QQ::Equal(QQ::CustomNode($strAlias . '.name_item_id'), $intNameItemIdArray[0])); } else { $objCondition = QQ::AndCondition($objCondition, QQ::Equal(QQ::CustomNode($strAlias . '.person_id'), $objPersonNode->Id), QQ::In(QQ::CustomNode($strAlias . '.name_item_id'), $intNameItemIdArray)); } } }
/** * Main utility method to aid with data binding. It is used by the default BindAllRows() databinder but * could and should be used by any custom databind methods that would be used for instances of this * MetaDataGrid, by simply passing in a custom QQCondition and/or QQClause. * * If a paginator is set on this DataBinder, it will use it. If not, then no pagination will be used. * It will also perform any sorting (if applicable). * * @param QQCondition $objConditions override the default condition of QQ::All() to the query, itself * @param QQClause[] $objOptionalClauses additional optional QQClause object or array of QQClause objects for the query * @return void */ public function MetaDataBinder(QQCondition $objCondition = null, $objOptionalClauses = null) { // Setup input parameters to default values if none passed in if (!$objCondition) { $objCondition = QQ::All(); } $objClauses = $objOptionalClauses ? $objOptionalClauses : array(); // We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below if ($this->Paginator) { $this->TotalItemCount = NameItem::QueryCount($objCondition, $objClauses); } // If a column is selected to be sorted, and if that column has a OrderByClause set on it, then let's add // the OrderByClause to the $objClauses array if ($objClause = $this->OrderByClause) { array_push($objClauses, $objClause); } // Add the LimitClause information, as well if ($objClause = $this->LimitClause) { array_push($objClauses, $objClause); } // Set the DataSource to be a Query result from NameItem, given the clauses above $this->DataSource = NameItem::QueryArray($objCondition, $objClauses); }
/** * 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 NameItemMetaControl * @param integer $intId primary key value * @param QMetaControlCreateType $intCreateType rules governing NameItem object creation - defaults to CreateOrEdit * @return NameItemMetaControl */ public static function Create($objParentObject, $intId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit) { // Attempt to Load from PK Arguments if (strlen($intId)) { $objNameItem = NameItem::Load($intId); // NameItem was found -- return it! if ($objNameItem) { return new NameItemMetaControl($objParentObject, $objNameItem); } else { if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) { throw new QCallerException('Could not find a NameItem object with PK arguments: ' . $intId); } } // 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 NameItemMetaControl($objParentObject, new NameItem()); }
/** * Given an array of normalized name items, this will associate them all to a valid NameItem object. * If any particular NameItem object does not exist, it will be created. * @param string[] $strNameArray * @param Person $objPerson * @return void */ public static function AssociateNameItemArrayForPerson($strNameArray, Person $objPerson) { $intDoneArray = array(); foreach ($strNameArray as $strName) { $objNameItem = NameItem::LoadByName($strName); if (!$objNameItem) { $objNameItem = new NameItem(); $objNameItem->Name = $strName; $objNameItem->Save(); } if (!array_key_exists($objNameItem->Id, $intDoneArray)) { $objPerson->AssociateNameItem($objNameItem); $intDoneArray[$objNameItem->Id] = $objNameItem->Id; } } }
public static function GetSoapArrayFromArray($objArray) { if (!$objArray) { return null; } $objArrayToReturn = array(); foreach ($objArray as $objObject) { array_push($objArrayToReturn, NameItem::GetSoapObjectFromObject($objObject, true)); } return unserialize(serialize($objArrayToReturn)); }
protected function lstNameItems_Update() { if ($this->lstNameItems) { $this->objPerson->UnassociateAllNameItems(); $objSelectedListItems = $this->lstNameItems->SelectedItems; if ($objSelectedListItems) { foreach ($objSelectedListItems as $objListItem) { $this->objPerson->AssociateNameItem(NameItem::Load($objListItem->Value)); } } } }