\ingroup DAO
Inheritance: extends CustomField
 public function testSaveAndLoadCustomFieldValue()
 {
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'Abc';
     $saved = $customFieldValue->save();
     $this->assertTrue($saved);
     $id = $customFieldValue->id;
     $customFieldValue->forget();
     unset($customFieldValue);
     $customFieldValue = CustomFieldValue::getById($id);
     $this->assertEquals('Abc', $customFieldValue->value);
 }
 /**
  * formats the date accordingly
  *
  * @param value
  */
 function setValue($value)
 {
     $this->_timestamp = new Timestamp();
     $dateTimeParts = explode(" ", $value);
     $dateParts = explode("/", $dateTimeParts[0]);
     $timeParts = explode(":", $dateTimeParts[1]);
     $this->_timestamp->setDay($dateParts[0]);
     $this->_timestamp->setMonth($dateParts[1]);
     $this->_timestamp->setYear($dateParts[2]);
     $this->_timestamp->setHour($timeParts[0]);
     $this->_timestamp->setMinutes($timeParts[1]);
     parent::setValue($value);
     return true;
 }
 protected function SetupCustomFieldValue()
 {
     // Lookup Object PK information from Query String (if applicable)
     // Set mode to Edit or New depending on what's found
     $intCustomFieldValueId = QApplication::QueryString('intCustomFieldValueId');
     if ($intCustomFieldValueId) {
         $this->objCustomFieldValue = CustomFieldValue::Load($intCustomFieldValueId);
         if (!$this->objCustomFieldValue) {
             throw new Exception('Could not find a CustomFieldValue object with PK arguments: ' . $intCustomFieldValueId);
         }
         $this->strTitleVerb = QApplication::Translate('Edit');
         $this->blnEditMode = true;
     } else {
         $this->objCustomFieldValue = new CustomFieldValue();
         $this->strTitleVerb = QApplication::Translate('Create');
         $this->blnEditMode = false;
     }
 }
 public static function updateValueByDataIdAndOldValueAndNewValue($customFieldDataId, $oldValue, $newValue)
 {
     $quote = DatabaseCompatibilityUtil::getQuote();
     $customFieldTableName = MultipleValuesCustomField::getTableName();
     $baseCustomFieldTableName = BaseCustomField::getTableName();
     $customFieldValueTableName = CustomFieldValue::getTableName();
     $baseCustomFieldJoinColumnName = $baseCustomFieldTableName . '_id';
     $valueAttributeColumnName = 'value';
     $dataAttributeColumnName = static::getForeignKeyName('BaseCustomField', 'data');
     $sql = "update {$quote}{$customFieldValueTableName}{$quote}, {$quote}{$customFieldTableName}{$quote}, ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote} ";
     $sql .= "set {$quote}{$customFieldValueTableName}{$quote}.{$valueAttributeColumnName} = '{$newValue}' ";
     $sql .= "where {$quote}{$customFieldTableName}{$quote}.{$baseCustomFieldJoinColumnName} = ";
     // Not Coding Standard
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id ";
     $sql .= "AND {$quote}{$dataAttributeColumnName}{$quote} = {$customFieldDataId} ";
     $sql .= "AND {$quote}{$customFieldTableName}{$quote}.id = {$quote}{$customFieldValueTableName}{$quote}.{$customFieldTableName}_id ";
     $sql .= "AND {$quote}{$customFieldValueTableName}{$quote}.{$valueAttributeColumnName} = '{$oldValue}'";
     ZurmoRedBean::exec($sql);
 }
 /**
  * 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 CustomFieldValueMetaControl
  * @param integer $intCustomFieldValueId primary key value
  * @param QMetaControlCreateType $intCreateType rules governing CustomFieldValue object creation - defaults to CreateOrEdit
  * @return CustomFieldValueMetaControl
  */
 public static function Create($objParentObject, $intCustomFieldValueId = null, $intCreateType = QMetaControlCreateType::CreateOrEdit)
 {
     // Attempt to Load from PK Arguments
     if (strlen($intCustomFieldValueId)) {
         $objCustomFieldValue = CustomFieldValue::Load($intCustomFieldValueId);
         // CustomFieldValue was found -- return it!
         if ($objCustomFieldValue) {
             return new CustomFieldValueMetaControl($objParentObject, $objCustomFieldValue);
         } else {
             if ($intCreateType != QMetaControlCreateType::CreateOnRecordNotFound) {
                 throw new QCallerException('Could not find a CustomFieldValue object with PK arguments: ' . $intCustomFieldValueId);
             }
         }
         // 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 CustomFieldValueMetaControl($objParentObject, new CustomFieldValue());
 }
    /**
     * Deletes all associated CustomFieldValuesAsModifiedBy
     * @return void
     */
    public function DeleteAllCustomFieldValuesAsModifiedBy()
    {
        if (is_null($this->intUserAccountId)) {
            throw new QUndefinedPrimaryKeyException('Unable to call UnassociateCustomFieldValueAsModifiedBy on this unsaved UserAccount.');
        }
        // Get the Database Object for this Class
        $objDatabase = UserAccount::GetDatabase();
        // Journaling
        if ($objDatabase->JournalingDatabase) {
            foreach (CustomFieldValue::LoadArrayByModifiedBy($this->intUserAccountId) as $objCustomFieldValue) {
                $objCustomFieldValue->Journal('DELETE');
            }
        }
        // Perform the SQL Query
        $objDatabase->NonQuery('
				DELETE FROM
					`custom_field_value`
				WHERE
					`modified_by` = ' . $objDatabase->SqlVariable($this->intUserAccountId) . '
			');
    }
 public function Delete()
 {
     $objCustomFieldValue = CustomFieldValue::Load($this->CustomFieldValueId);
     //parent::Delete();
     $objDatabase = CustomFieldSelection::GetDatabase();
     // If the helper table exists
     if ($objCustomFieldValue && ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($this->EntityQtypeId))) {
         $strHelperTable = $strHelperTableArray[0];
         $strTableName = $strHelperTableArray[1];
         $strQuery = sprintf("UPDATE %s SET `cfv_%s`='' WHERE `%s_id`='%s';", $strHelperTable, $objCustomFieldValue->CustomFieldId, $strTableName, $this->EntityId);
         $objDatabase->NonQuery($strQuery);
     }
 }
Example #8
0
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objDefaultCustomFieldValue) {
         $objObject->objDefaultCustomFieldValue = CustomFieldValue::GetSoapObjectFromObject($objObject->objDefaultCustomFieldValue, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intDefaultCustomFieldValueId = null;
         }
     }
     if ($objObject->objCreatedByObject) {
         $objObject->objCreatedByObject = UserAccount::GetSoapObjectFromObject($objObject->objCreatedByObject, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intCreatedBy = null;
         }
     }
     if ($objObject->dttCreationDate) {
         $objObject->dttCreationDate = $objObject->dttCreationDate->__toString(QDateTime::FormatSoap);
     }
     if ($objObject->objModifiedByObject) {
         $objObject->objModifiedByObject = UserAccount::GetSoapObjectFromObject($objObject->objModifiedByObject, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intModifiedBy = null;
         }
     }
     return $objObject;
 }
 /**
  * @depends testSetAttributesWithPostForMultipleValuesCustomField
  */
 public function testUpdateValueOnCustomFieldRows()
 {
     $values = array('A', 'B', 'C');
     $customFieldData = CustomFieldData::getByName('updateItems');
     $customFieldData->serializedData = serialize($values);
     $this->assertTrue($customFieldData->save());
     $id = $customFieldData->id;
     $customField = new MultipleValuesCustomField();
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'A';
     $customField->values->add($customFieldValue);
     $customField->data = $customFieldData;
     $this->assertTrue($customField->save());
     $customField = new MultipleValuesCustomField();
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'B';
     $customField->values->add($customFieldValue);
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'C';
     $customField->values->add($customFieldValue);
     $customField->data = $customFieldData;
     $this->assertTrue($customField->save());
     $customField = new MultipleValuesCustomField();
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'C';
     $customField->values->add($customFieldValue);
     $customField->data = $customFieldData;
     $this->assertTrue($customField->save());
     $customField = new MultipleValuesCustomField();
     $customFieldValue = new CustomFieldValue();
     $customFieldValue->value = 'D';
     $customField->values->add($customFieldValue);
     $customField->data = $customFieldData;
     $this->assertTrue($customField->save());
     $quote = DatabaseCompatibilityUtil::getQuote();
     $customFieldTableName = MultipleValuesCustomField::getTableName();
     $baseCustomFieldTableName = BaseCustomField::getTableName();
     $customFieldValueTableName = CustomFieldValue::getTableName();
     $valueAttributeColumnName = 'value';
     $dataAttributeColumnName = RedBeanModel::getForeignKeyName('MultipleValuesCustomField', 'data');
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id}";
     $ids = ZurmoRedBean::getCol($sql);
     $beans = ZurmoRedBean::batch($customFieldTableName, $ids);
     $customFields = RedBeanModel::makeModels($beans, 'CustomField');
     $this->assertEquals(4, count($customFields));
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('B','C') ";
     // Not Coding Standard
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 2";
     $this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('C') ";
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 1";
     $this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('E') ";
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 1";
     $this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
     MultipleValuesCustomField::updateValueByDataIdAndOldValueAndNewValue($id, 'C', 'E');
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('B') ";
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 1";
     $this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('C') ";
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 1";
     $this->assertEquals(0, count(ZurmoRedBean::getCol($sql)));
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('E') ";
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 1";
     $this->assertEquals(2, count(ZurmoRedBean::getCol($sql)));
     $sql = "select {$quote}{$customFieldTableName}{$quote}.id from {$quote}{$customFieldTableName}{$quote} ";
     $sql .= "left join {$quote}{$baseCustomFieldTableName}{$quote} on ";
     $sql .= "{$quote}{$baseCustomFieldTableName}{$quote}.id = ";
     $sql .= "{$quote}{$customFieldTableName}{$quote}.basecustomfield_id ";
     $sql .= "where {$quote}{$dataAttributeColumnName}{$quote} = {$id} ";
     $sql .= "and (select count(*) from {$quote}{$customFieldValueTableName}{$quote} ";
     $sql .= "where {$quote}{$valueAttributeColumnName}{$quote} IN('B', 'E') ";
     $sql .= "and {$quote}{$customFieldTableName}{$quote}.id = {$customFieldValueTableName}.{$customFieldTableName}_id)";
     $sql .= " = 2";
     $this->assertEquals(1, count(ZurmoRedBean::getCol($sql)));
 }
Example #10
0
 protected function DeleteEntityQtypeCustomFields()
 {
     $objEntityQtypeCustomFieldArray = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
     if ($objEntityQtypeCustomFieldArray) {
         foreach ($objEntityQtypeCustomFieldArray as $objEntityQtypeCustomField) {
             // If the EntityQtype needs to be deleted, you must delete EntityQtypeId for all roles in RoleEntityQTypeCustomFieldAuthorization
             $objRoleEntityCustomAuthArray = RoleEntityQtypeCustomFieldAuthorization::LoadArrayByEntityQtypeCustomFieldId($objEntityQtypeCustomField->EntityQtypeCustomFieldId);
             if ($objRoleEntityCustomAuthArray) {
                 foreach ($objRoleEntityCustomAuthArray as $objRoleEntityCustomAuth) {
                     $objRoleEntityCustomAuth->Delete();
                 }
             }
             // If there was Asset Type Custom field Delete AssetCustomField
             if ($objEntityQtypeCustomField->EntityQtypeId == 1) {
                 $this->DeleteAssetCustomFieldAssetModels();
             }
             // If the helper table exists for that EntityQtype delete the columns in the helper table
             if ($strHelperTableArray = CustomFieldValue::GetHelperTableByEntityQtypeId($objEntityQtypeCustomField->EntityQtypeId)) {
                 $strHelperTable = $strHelperTableArray[0];
                 $objDatabase = CustomField::GetDatabase();
                 $strQuery = sprintf("ALTER TABLE %s DROP `cfv_%s`;", $strHelperTable, $objEntityQtypeCustomField->CustomFieldId);
                 $objDatabase->NonQuery($strQuery);
             }
             // Delete the EntityQtypeCustomField last
             $objEntityQtypeCustomField->Delete();
         }
     }
 }
 /**
  * Internally called method to assist with early binding of objects
  * on load methods.  Can only early-bind references that this class owns in the database.
  * @param string $strParentAlias the alias of the parent (if any)
  * @param string $strAlias the alias of this object
  * @param array $objExpansionMap map of referenced columns to be immediately expanded via early-binding
  * @param QueryExpansion an already instantiated QueryExpansion object (used as a utility object to assist with object expansion)
  */
 public static function ExpandQuery($strParentAlias, $strAlias, $objExpansionMap, QQueryExpansion $objQueryExpansion)
 {
     if ($strAlias) {
         $objQueryExpansion->AddFromItem(sprintf('LEFT JOIN `custom_field` AS `%s__%s` ON `%s`.`%s` = `%s__%s`.`custom_field_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`custom_field_id` AS `%s__%s__custom_field_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`custom_field_qtype_id` AS `%s__%s__custom_field_qtype_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`default_custom_field_value_id` AS `%s__%s__default_custom_field_value_id`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`short_description` AS `%s__%s__short_description`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`active_flag` AS `%s__%s__active_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`required_flag` AS `%s__%s__required_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`all_asset_models_flag` AS `%s__%s__all_asset_models_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`searchable_flag` AS `%s__%s__searchable_flag`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`created_by` AS `%s__%s__created_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`creation_date` AS `%s__%s__creation_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_by` AS `%s__%s__modified_by`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $objQueryExpansion->AddSelectItem(sprintf('`%s__%s`.`modified_date` AS `%s__%s__modified_date`', $strParentAlias, $strAlias, $strParentAlias, $strAlias));
         $strParentAlias = $strParentAlias . '__' . $strAlias;
     }
     if (is_array($objExpansionMap)) {
         foreach ($objExpansionMap as $strKey => $objValue) {
             switch ($strKey) {
                 case 'default_custom_field_value_id':
                     try {
                         CustomFieldValue::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'created_by':
                     try {
                         UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 case 'modified_by':
                     try {
                         UserAccount::ExpandQuery($strParentAlias, $strKey, $objValue, $objQueryExpansion);
                         break;
                     } catch (QCallerException $objExc) {
                         $objExc->IncrementOffset();
                         throw $objExc;
                     }
                 default:
                     throw new QCallerException(sprintf('Unknown Object to Expand in %s: %s', $strParentAlias, $strKey));
             }
         }
     }
 }
 /**
  * Refresh this MetaControl with Data from the local CustomField object.
  * @param boolean $blnReload reload CustomField from the database
  * @return void
  */
 public function Refresh($blnReload = false)
 {
     if ($blnReload) {
         $this->objCustomField->Reload();
     }
     if ($this->lblCustomFieldId) {
         if ($this->blnEditMode) {
             $this->lblCustomFieldId->Text = $this->objCustomField->CustomFieldId;
         }
     }
     if ($this->lstCustomFieldQtype) {
         $this->lstCustomFieldQtype->SelectedValue = $this->objCustomField->CustomFieldQtypeId;
     }
     if ($this->lblCustomFieldQtypeId) {
         $this->lblCustomFieldQtypeId->Text = $this->objCustomField->CustomFieldQtypeId ? CustomFieldQtype::$NameArray[$this->objCustomField->CustomFieldQtypeId] : null;
     }
     if ($this->lstDefaultCustomFieldValue) {
         $this->lstDefaultCustomFieldValue->RemoveAllItems();
         $this->lstDefaultCustomFieldValue->AddItem(QApplication::Translate('- Select One -'), null);
         $objDefaultCustomFieldValueArray = CustomFieldValue::LoadAll();
         if ($objDefaultCustomFieldValueArray) {
             foreach ($objDefaultCustomFieldValueArray as $objDefaultCustomFieldValue) {
                 $objListItem = new QListItem($objDefaultCustomFieldValue->__toString(), $objDefaultCustomFieldValue->CustomFieldValueId);
                 if ($this->objCustomField->DefaultCustomFieldValue && $this->objCustomField->DefaultCustomFieldValue->CustomFieldValueId == $objDefaultCustomFieldValue->CustomFieldValueId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstDefaultCustomFieldValue->AddItem($objListItem);
             }
         }
     }
     if ($this->lblDefaultCustomFieldValueId) {
         $this->lblDefaultCustomFieldValueId->Text = $this->objCustomField->DefaultCustomFieldValue ? $this->objCustomField->DefaultCustomFieldValue->__toString() : null;
     }
     if ($this->txtShortDescription) {
         $this->txtShortDescription->Text = $this->objCustomField->ShortDescription;
     }
     if ($this->lblShortDescription) {
         $this->lblShortDescription->Text = $this->objCustomField->ShortDescription;
     }
     if ($this->chkActiveFlag) {
         $this->chkActiveFlag->Checked = $this->objCustomField->ActiveFlag;
     }
     if ($this->lblActiveFlag) {
         $this->lblActiveFlag->Text = $this->objCustomField->ActiveFlag ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->chkRequiredFlag) {
         $this->chkRequiredFlag->Checked = $this->objCustomField->RequiredFlag;
     }
     if ($this->lblRequiredFlag) {
         $this->lblRequiredFlag->Text = $this->objCustomField->RequiredFlag ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->chkAllAssetModelsFlag) {
         $this->chkAllAssetModelsFlag->Checked = $this->objCustomField->AllAssetModelsFlag;
     }
     if ($this->lblAllAssetModelsFlag) {
         $this->lblAllAssetModelsFlag->Text = $this->objCustomField->AllAssetModelsFlag ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->chkSearchableFlag) {
         $this->chkSearchableFlag->Checked = $this->objCustomField->SearchableFlag;
     }
     if ($this->lblSearchableFlag) {
         $this->lblSearchableFlag->Text = $this->objCustomField->SearchableFlag ? QApplication::Translate('Yes') : QApplication::Translate('No');
     }
     if ($this->lstCreatedByObject) {
         $this->lstCreatedByObject->RemoveAllItems();
         $this->lstCreatedByObject->AddItem(QApplication::Translate('- Select One -'), null);
         $objCreatedByObjectArray = UserAccount::LoadAll();
         if ($objCreatedByObjectArray) {
             foreach ($objCreatedByObjectArray as $objCreatedByObject) {
                 $objListItem = new QListItem($objCreatedByObject->__toString(), $objCreatedByObject->UserAccountId);
                 if ($this->objCustomField->CreatedByObject && $this->objCustomField->CreatedByObject->UserAccountId == $objCreatedByObject->UserAccountId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstCreatedByObject->AddItem($objListItem);
             }
         }
     }
     if ($this->lblCreatedBy) {
         $this->lblCreatedBy->Text = $this->objCustomField->CreatedByObject ? $this->objCustomField->CreatedByObject->__toString() : null;
     }
     if ($this->calCreationDate) {
         $this->calCreationDate->DateTime = $this->objCustomField->CreationDate;
     }
     if ($this->lblCreationDate) {
         $this->lblCreationDate->Text = sprintf($this->objCustomField->CreationDate) ? $this->objCustomField->__toString($this->strCreationDateDateTimeFormat) : null;
     }
     if ($this->lstModifiedByObject) {
         $this->lstModifiedByObject->RemoveAllItems();
         $this->lstModifiedByObject->AddItem(QApplication::Translate('- Select One -'), null);
         $objModifiedByObjectArray = UserAccount::LoadAll();
         if ($objModifiedByObjectArray) {
             foreach ($objModifiedByObjectArray as $objModifiedByObject) {
                 $objListItem = new QListItem($objModifiedByObject->__toString(), $objModifiedByObject->UserAccountId);
                 if ($this->objCustomField->ModifiedByObject && $this->objCustomField->ModifiedByObject->UserAccountId == $objModifiedByObject->UserAccountId) {
                     $objListItem->Selected = true;
                 }
                 $this->lstModifiedByObject->AddItem($objListItem);
             }
         }
     }
     if ($this->lblModifiedBy) {
         $this->lblModifiedBy->Text = $this->objCustomField->ModifiedByObject ? $this->objCustomField->ModifiedByObject->__toString() : null;
     }
     if ($this->lblModifiedDate) {
         if ($this->blnEditMode) {
             $this->lblModifiedDate->Text = $this->objCustomField->ModifiedDate;
         }
     }
 }
Example #13
0
 /**
  * Counts all associated CustomFieldValuesAsModifiedBy
  * @return int
  */
 public function CountCustomFieldValuesAsModifiedBy()
 {
     if (is_null($this->intUserAccountId)) {
         return 0;
     }
     return CustomFieldValue::CountByModifiedBy($this->intUserAccountId);
 }
 public function dtgCustomFieldValue_Bind()
 {
     // Get Total Count b/c of Pagination
     $this->dtgCustomFieldValue->TotalItemCount = CustomFieldValue::CountAll();
     $objClauses = array();
     if ($objClause = $this->dtgCustomFieldValue->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     if ($objClause = $this->dtgCustomFieldValue->LimitClause) {
         array_push($objClauses, $objClause);
     }
     $this->dtgCustomFieldValue->DataSource = CustomFieldValue::LoadAll($objClauses);
 }
 protected function lstDefaultCustomFieldValue_Create()
 {
     $this->lstDefaultCustomFieldValue = new QListBox($this);
     $this->lstDefaultCustomFieldValue->Name = QApplication::Translate('Default Custom Field Value');
     $this->lstDefaultCustomFieldValue->AddItem(QApplication::Translate('- Select One -'), null);
     $objDefaultCustomFieldValueArray = CustomFieldValue::LoadAll();
     if ($objDefaultCustomFieldValueArray) {
         foreach ($objDefaultCustomFieldValueArray as $objDefaultCustomFieldValue) {
             $objListItem = new QListItem($objDefaultCustomFieldValue->__toString(), $objDefaultCustomFieldValue->CustomFieldValueId);
             if ($this->objCustomField->DefaultCustomFieldValue && $this->objCustomField->DefaultCustomFieldValue->CustomFieldValueId == $objDefaultCustomFieldValue->CustomFieldValueId) {
                 $objListItem->Selected = true;
             }
             $this->lstDefaultCustomFieldValue->AddItem($objListItem);
         }
     }
 }
 public static function GetSoapObjectFromObject($objObject, $blnBindRelatedObjects)
 {
     if ($objObject->objCustomFieldValue) {
         $objObject->objCustomFieldValue = CustomFieldValue::GetSoapObjectFromObject($objObject->objCustomFieldValue, false);
     } else {
         if (!$blnBindRelatedObjects) {
             $objObject->intCustomFieldValueId = null;
         }
     }
     return $objObject;
 }
 public static function GetSoapArrayFromArray($objArray)
 {
     if (!$objArray) {
         return null;
     }
     $objArrayToReturn = array();
     foreach ($objArray as $objObject) {
         array_push($objArrayToReturn, CustomFieldValue::GetSoapObjectFromObject($objObject, true));
     }
     return unserialize(serialize($objArrayToReturn));
 }
Example #18
0
 /**
  * Creates the custom field controls while looping through an array of CustomField objects
  *
  * @param array $objCustomFieldArray of CustomField objects
  * @param bool $blnEditMode if creating a new entity or editing an existing one
  * @param QForm $objForm e.g., AssetEditForm
  * @return array $arrCustomFields of labels and inputs for all custom field controls
  */
 public static function CustomFieldControlsCreate($objCustomFieldArray, $blnEditMode, $objForm, $blnLabels = true, $blnInputs = true, $blnSearch = false)
 {
     $arrCustomFields = array();
     for ($i = 0; $i < count($objCustomFieldArray); $i++) {
         if ($blnLabels) {
             // Create Label for each custom field
             if (CustomFieldQtype::ToString($objCustomFieldArray[$i]->CustomFieldQtypeId) == 'text area') {
                 $arrCustomFields[$i]['lbl'] = new QPanel($objForm);
                 if ($blnEditMode) {
                     $arrCustomFields[$i]['lbl']->CssClass = 'scrollBox';
                 }
             } else {
                 $arrCustomFields[$i]['lbl'] = new QLabel($objForm);
             }
             $arrCustomFields[$i]['lbl']->Name = $objCustomFieldArray[$i]->ShortDescription;
             if ($blnEditMode && $objCustomFieldArray[$i]->CustomFieldSelection && $objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldValue && $objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldValue->ShortDescription != null) {
                 $arrCustomFields[$i]['lbl']->Text = nl2br($objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldValue->ShortDescription);
             } elseif ($blnEditMode && (!$objCustomFieldArray[$i]->CustomFieldSelection || empty($objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldValue->ShortDescription) && $objCustomFieldArray[$i]->CustomFieldQtypeId == 2)) {
                 $arrCustomFields[$i]['lbl']->Text = 'None';
             }
         }
         if ($blnInputs) {
             // Create input for each custom field (either text or list)
             // Create text inputs
             if (CustomFieldQtype::ToString($objCustomFieldArray[$i]->CustomFieldQtypeId) == 'text' || CustomFieldQtype::ToString($objCustomFieldArray[$i]->CustomFieldQtypeId) == 'text area') {
                 $arrCustomFields[$i]['input'] = new QTextBox($objForm, $blnSearch ? null : "cf" . $objCustomFieldArray[$i]->CustomFieldId);
                 $arrCustomFields[$i]['input']->Name = $objCustomFieldArray[$i]->ShortDescription;
                 $arrCustomFields[$i]['input']->Required = false;
                 $arrCustomFields[$i]['input']->CausesValidation = true;
                 if (CustomFieldQtype::ToString($objCustomFieldArray[$i]->CustomFieldQtypeId) == 'text area' && !$blnSearch) {
                     $arrCustomFields[$i]['input']->TextMode = QTextMode::MultiLine;
                 }
                 // This is so that the browser doesn't form.submit() when the user presses the enter key on a text input
                 if (!$blnSearch && CustomFieldQtype::ToString($objCustomFieldArray[$i]->CustomFieldQtypeId) != 'text area') {
                     if ($objForm instanceof QControl) {
                         $arrCustomFields[$i]['input']->AddAction(new QEnterKeyEvent(), new QAjaxControlAction($objForm, 'btnSave_Click'));
                     } else {
                         $arrCustomFields[$i]['input']->AddAction(new QEnterKeyEvent(), new QAjaxAction('btnSave_Click'));
                     }
                     $arrCustomFields[$i]['input']->AddAction(new QEnterKeyEvent(), new QTerminateAction());
                 } elseif ($blnSearch) {
                     if ($objForm instanceof QControl) {
                         $arrCustomFields[$i]['input']->AddAction(new QEnterKeyEvent(), new QServerControlAction($objForm, 'btnSearch_Click'));
                     } else {
                         $arrCustomFields[$i]['input']->AddAction(new QEnterKeyEvent(), new QServerAction('btnSearch_Click'));
                     }
                     $arrCustomFields[$i]['input']->AddAction(new QEnterKeyEvent(), new QTerminateAction());
                 }
                 if ($blnEditMode && $objCustomFieldArray[$i]->CustomFieldSelection) {
                     $arrCustomFields[$i]['input']->Text = $objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldValue->ShortDescription;
                 } elseif (!$blnEditMode && !$blnSearch && $objCustomFieldArray[$i]->RequiredFlag && $objCustomFieldArray[$i]->DefaultCustomFieldValueId) {
                     $arrCustomFields[$i]['input']->Text = $objCustomFieldArray[$i]->DefaultCustomFieldValue->ShortDescription;
                 }
             } elseif (CustomFieldQtype::ToString($objCustomFieldArray[$i]->CustomFieldQtypeId) == 'select') {
                 $arrCustomFields[$i]['input'] = new QListBox($objForm, $blnSearch ? null : "cf" . $objCustomFieldArray[$i]->CustomFieldId);
                 $arrCustomFields[$i]['input']->Name = $objCustomFieldArray[$i]->ShortDescription;
                 $arrCustomFields[$i]['input']->Required = false;
                 $objCustomFieldValueArray = CustomFieldValue::LoadArrayByCustomFieldId($objCustomFieldArray[$i]->CustomFieldId, QQ::Clause(QQ::OrderBy(QQN::CustomFieldValue()->ShortDescription)));
                 if ($objCustomFieldValueArray) {
                     // The - Select One - item cannot be removed without also updating CustomField::UpdateControls()
                     $arrCustomFields[$i]['input']->AddItem('- Select One -', null);
                     foreach ($objCustomFieldValueArray as $objCustomFieldValue) {
                         $objListItem = new QListItem($objCustomFieldValue->__toString(), $objCustomFieldValue->CustomFieldValueId);
                         if ($blnEditMode && $objCustomFieldArray[$i]->CustomFieldSelection && $objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldValueId == $objCustomFieldValue->CustomFieldValueId) {
                             $objListItem->Selected = true;
                         } elseif (!$blnEditMode && !$blnSearch && $objCustomFieldArray[$i]->RequiredFlag && $objCustomFieldArray[$i]->DefaultCustomFieldValueId && $objCustomFieldArray[$i]->DefaultCustomFieldValueId == $objCustomFieldValue->CustomFieldValueId) {
                             $objListItem->Selected = true;
                         }
                         $arrCustomFields[$i]['input']->AddItem($objListItem);
                     }
                 }
             }
             if ($objCustomFieldArray[$i]->RequiredFlag && !$blnSearch) {
                 $arrCustomFields[$i]['input']->Required = true;
             }
         }
         // Set reference IDs for btnSave_Click() for each custom field
         $arrCustomFields[$i]['CustomFieldId'] = $objCustomFieldArray[$i]->CustomFieldId;
         if ($blnEditMode && $objCustomFieldArray[$i]->CustomFieldSelection) {
             $arrCustomFields[$i]['CustomFieldSelectionId'] = $objCustomFieldArray[$i]->CustomFieldSelection->CustomFieldSelectionId;
         }
         //Set an RoleEntityQtypeCustomFieldAuthorization object of View Authorization and for Edit Authorization for each custom field
         $arrCustomFields[$i]['ViewAuth'] = $objCustomFieldArray[$i]->objRoleAuthView;
         $arrCustomFields[$i]['EditAuth'] = $objCustomFieldArray[$i]->objRoleAuthEdit;
         // Set all reference booleans for display logic
         //set if the custom field must show or not
         if ($objCustomFieldArray[$i]->objRoleAuthView && $objCustomFieldArray[$i]->objRoleAuthView->AuthorizedFlag || !$objCustomFieldArray[$i]->objRoleAuthView) {
             $arrCustomFields[$i]['blnView'] = true;
         } else {
             $arrCustomFields[$i]['blnView'] = false;
         }
         // set if the custom field is editable or not
         if ($objCustomFieldArray[$i]->objRoleAuthEdit && $objCustomFieldArray[$i]->objRoleAuthEdit->AuthorizedFlag || !$objCustomFieldArray[$i]->objRoleAuthEdit) {
             $arrCustomFields[$i]['blnEdit'] = true;
         } else {
             $arrCustomFields[$i]['blnEdit'] = false;
         }
         //set if the custom field is requiered or not
         if ($objCustomFieldArray[$i]->objRoleAuthEdit && $objCustomFieldArray[$i]->objRoleAuthEdit->EntityQtypeCustomField->CustomField->RequiredFlag) {
             $arrCustomFields[$i]['blnRequired'] = true;
         } else {
             $arrCustomFields[$i]['blnRequired'] = false;
         }
     }
     return $arrCustomFields;
 }
Example #19
0
 protected function UpdateAssetModelCustomFields()
 {
     //$arrAssetCustomFieldsToAdd = array();
     // $this->chkAssetCustomFields->SelectedValues;
     // Generate array of Custom Field values for All Asset Models must be presented in all cases
     /*
     $arrAllAssetModelsFlaggedObjects = EntityQtypeCustomField::LoadArrayByEntityQtypeId(QApplication::Translate(EntityQtype::Asset));
     $arrAllAssetModelsFlag = array();
     foreach ($arrAllAssetModelsFlaggedObjects as $arrAllAssetModelsFlaggedObject){
       if ($arrAllAssetModelsFlaggedObject->CustomField->AllAssetModelsFlag){
         $arrAllAssetModelsFlag[] = $arrAllAssetModelsFlaggedObject->CustomField->CustomFieldId;
       }
     }
     
      $arrAssetCustomFieldsToAdd = array_merge($this->chkAssetCustomFields->SelectedValues,$arrAllAssetModelsFlag);
     */
     $arrAssetCustomFieldsToAdd = array_unique($this->chkAssetCustomFields->SelectedValues);
     // If new asset model add AssetCustomFields for All together with selected
     if (!$this->blnEditMode) {
         foreach ($arrAssetCustomFieldsToAdd as $keyAssetCustomField) {
             $newAssetCustomField = new AssetCustomFieldAssetModel();
             $newAssetCustomField->CustomFieldId = $keyAssetCustomField;
             $newAssetCustomField->AssetModelId = $this->objAssetModel->AssetModelId;
             $newAssetCustomField->Save();
         }
     } else {
         $currentAssetCustomFields = AssetCustomFieldAssetModel::LoadArrayByAssetModelId($this->objAssetModel->AssetModelId);
         foreach ($currentAssetCustomFields as $currentAssetCustomField) {
             if (!$currentAssetCustomField->CustomField->AllAssetModelsFlag && !in_array($currentAssetCustomField->CustomField->CustomFieldId, $arrAssetCustomFieldsToAdd)) {
                 // If blnEditMode some Assets for this Model can be already assigned and them values
                 // for this custom field must be set to null
                 $arrAssetsAssignedToModel = new Asset();
                 $arrAssetsAssignedToModel = $arrAssetsAssignedToModel->LoadArrayByAssetModelId($this->objAssetModel->AssetModelId);
                 if (count($arrAssetsAssignedToModel) > 0) {
                     $arrAssetOfModel = array();
                     foreach ($arrAssetsAssignedToModel as $objAssetAssignedToModel) {
                         array_push($arrAssetOfModel, $objAssetAssignedToModel->AssetId);
                     }
                     $arrAssetOfModel = implode(",", $arrAssetOfModel);
                     //print $arrAssetOfModel; exit;
                     $objDatabase = CustomField::GetDatabase();
                     $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET `cfv_%s`= NULL WHERE `asset_id` IN({$arrAssetOfModel});", $currentAssetCustomField->CustomFieldId);
                     $objDatabase->NonQuery($strQuery);
                 }
                 // then Delete Associations
                 $currentAssetCustomField->Delete();
             }
         }
         foreach ($arrAssetCustomFieldsToAdd as $keyAssetCustomField) {
             $blnToAdd = true;
             foreach ($currentAssetCustomFields as $currentAssetCustomField) {
                 if ($currentAssetCustomField->CustomField->CustomFieldId == $arrAssetCustomFieldsToAdd) {
                     $blnToAdd = false;
                 }
             }
             if ($blnToAdd) {
                 $newAssetCustomField = new AssetCustomFieldAssetModel();
                 $newAssetCustomField->CustomFieldId = $keyAssetCustomField;
                 $newAssetCustomField->AssetModelId = $this->objAssetModel->AssetModelId;
                 $newAssetCustomField->Save();
                 // If custom field is required add default value to appropriate Assets
                 $objCustomFieldToAdd = new CustomField();
                 $objCustomFieldToAdd = $objCustomFieldToAdd->Load($keyAssetCustomField);
                 if ($objCustomFieldToAdd->RequiredFlag) {
                     $arrAssetsAssignedToModel = new Asset();
                     $arrAssetsAssignedToModel = $arrAssetsAssignedToModel->LoadArrayByAssetModelId($this->objAssetModel->AssetModelId);
                     if (count($arrAssetsAssignedToModel) > 0) {
                         $txtDefaultValue = CustomFieldValue::LoadByCustomFieldValueId($objCustomFieldToAdd->DefaultCustomFieldValueId);
                         $arrAssetOfModel = array();
                         foreach ($arrAssetsAssignedToModel as $objAssetAssignedToModel) {
                             array_push($arrAssetOfModel, $objAssetAssignedToModel->AssetId);
                         }
                         $arrAssetOfModel = implode(",", $arrAssetOfModel);
                         $objDatabase = CustomField::GetDatabase();
                         $strQuery = sprintf("UPDATE `asset_custom_field_helper` SET `cfv_%s`= %s WHERE `asset_id` IN({$arrAssetOfModel});", $keyAssetCustomField, $txtDefaultValue);
                         $objDatabase->NonQuery($strQuery);
                     }
                 }
                 //
             }
         }
     }
 }
 protected function dtgCustomFieldValue_Bind()
 {
     // Because we want to enable pagination AND sorting, we need to setup the $objClauses array to send to LoadAll()
     // Remember!  We need to first set the TotalItemCount, which will affect the calcuation of LimitClause below
     $this->dtgCustomFieldValue->TotalItemCount = CustomFieldValue::CountAll();
     // Setup the $objClauses Array
     $objClauses = array();
     // 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->dtgCustomFieldValue->OrderByClause) {
         array_push($objClauses, $objClause);
     }
     // Add the LimitClause information, as well
     if ($objClause = $this->dtgCustomFieldValue->LimitClause) {
         array_push($objClauses, $objClause);
     }
     // Set the DataSource to be the array of all CustomFieldValue objects, given the clauses above
     $this->dtgCustomFieldValue->DataSource = CustomFieldValue::LoadAll($objClauses);
 }
Example #21
0
 protected function lstTramorField_Change($strFormId, $strControlId, $strParameter)
 {
     $objControl = QForm::GetControl($strControlId);
     if ($objControl->SelectedValue != null) {
         $search = strtolower($objControl->SelectedValue);
         if ($this->in_array_nocase($search, $this->arrTracmorField)) {
             $objControl->Warning = "This value has already been selected.";
             $objControl->SelectedIndex = 0;
             unset($this->arrTracmorField[substr($objControl->Name, 3)]);
         } else {
             $objControl->Warning = "";
             $txtDefault = $this->txtMapDefaultValueArray[substr($objControl->Name, 3)];
             $lstDefault = $this->lstMapDefaultValueArray[substr($objControl->Name, 3)];
             $dtpDefault = $this->dtpDateArray[substr($objControl->Name, 3)];
             $this->arrTracmorField[substr($objControl->Name, 3)] = $search;
             if (substr($objControl->SelectedValue, 0, 8) == "contact_") {
                 $objCustomField = CustomField::LoadByCustomFieldId(substr($objControl->SelectedValue, 8));
                 // type = Text or TextBox
                 if ($objCustomField->CustomFieldQtypeId != 2) {
                     $txtDefault->Required = $objCustomField->RequiredFlag;
                     // If it is a required text field, then assign the default text for a new entity only
                     if ($objCustomField->RequiredFlag && $objCustomField->DefaultCustomFieldValueId) {
                         $txtDefault->Text = $objCustomField->DefaultCustomFieldValue->ShortDescription;
                     } else {
                         $txtDefault->Text = "";
                     }
                     $txtDefault->Display = true;
                     $lstDefault->Display = false;
                     $dtpDefault->Display = false;
                 } else {
                     $lstDefault->RemoveAllItems();
                     $lstDefault->AddItem('- Select One -', null);
                     $lstDefault->Required = true;
                     $objCustomFieldValueArray = CustomFieldValue::LoadArrayByCustomFieldId(substr($objControl->SelectedValue, 8), QQ::Clause(QQ::OrderBy(QQN::CustomFieldValue()->ShortDescription)));
                     if ($objCustomFieldValueArray) {
                         foreach ($objCustomFieldValueArray as $objCustomFieldValue) {
                             $objListItem = new QListItem($objCustomFieldValue->__toString(), $objCustomFieldValue->CustomFieldValueId);
                             // If it is a required field, then select the value on new entities by default
                             if ($objCustomField->RequiredFlag && $objCustomField->DefaultCustomFieldValueId && $objCustomField->DefaultCustomFieldValueId == $objCustomFieldValue->CustomFieldValueId) {
                                 $objListItem->Selected = true;
                             }
                             $lstDefault->AddItem($objListItem);
                         }
                     }
                     $txtDefault->Display = false;
                     $lstDefault->Display = true;
                     $dtpDefault->Display = false;
                 }
             }
             $txtDefault->Display = true;
             $lstDefault->Display = false;
             $dtpDefault->Display = false;
         }
     } else {
         unset($this->arrTracmorField[substr($objControl->Name, 3)]);
     }
 }
Example #22
0
 public function Delete()
 {
     $arrEntityQtype = EntityQtypeCustomField::LoadArrayByCustomFieldId($this->CustomFieldId);
     parent::Delete();
     foreach ($arrEntityQtype as $objEntityQtype) {
         $strHelperTableArray = $this->GetHelperTableByEntityQtypeId($objEntityQtype->EntityQtypeId);
         $strHelperTable = $strHelperTableArray[0];
         $strTableName = $strHelperTableArray[1];
         $strQuery = sprintf("UPDATE %s SET `cfv_%s` = NULL WHERE `cfv_%s` = '%s'", $strHelperTable, $this->CustomFieldId, $this->CustomFieldId, $this->ShortDescription);
         $objDatabase = CustomFieldValue::GetDatabase();
         $objDatabase->NonQuery($strQuery);
     }
     /*		  $objCondition = QQ::Equal(QQN::CustomFieldSelection()->CustomFieldValueId, $this->CustomFieldValueId);
     			$objClauses = QQ::Clause(QQ::Expand(QQN::CustomFieldSelection()->CustomFieldValue));
     			// Select all CustomFieldSelections (and expanded CustomFieldValues) by CustomFieldValueId
     			$objCustomFieldSelectionArray = CustomFieldSelection::QueryArray($objCondition, $objClauses);
     			//parent::Delete();
     			$intRowsToDeleteArray = array();
     			// Create an array switched by helper tables (to minimize number of queries)
     			foreach ($objCustomFieldSelectionArray as $objCustomFieldSelection) {
     			  if ($this->GetHelperTableByEntityQtypeId($objCustomFieldSelection->EntityQtypeId)) {
     			    $intRowsToDeleteArray[$objCustomFieldSelection->EntityQtypeId][] = $objCustomFieldSelection->EntityId;
     			  }
     			}
     			$objDatabase = CustomFieldValue::GetDatabase();
     			// For each helper table
     			foreach (array_keys($intRowsToDeleteArray) as $intEntityQtypeId) {
     				$strHelperTableArray = $this->GetHelperTableByEntityQtypeId($intEntityQtypeId);
     				$strHelperTable = $strHelperTableArray[0];
       			$strTableName = $strHelperTableArray[1];
     				
     				$strQuery = sprintf("UPDATE %s SET `cfv_%s`='' WHERE `%s_id` IN (%s);", $strHelperTable, $objCustomFieldSelection->CustomFieldValue->CustomFieldId, $strTableName, implode(', ', $intRowsToDeleteArray[$intEntityQtypeId]));
             $objDatabase->NonQuery($strQuery);
     			}*/
 }
 /**
  * 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 = CustomFieldValue::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 CustomFieldValue, given the clauses above
     $this->DataSource = CustomFieldValue::QueryArray($objCondition, $objClauses);
 }
Example #24
0
 protected function UpdateCustomFieldFields()
 {
     // If switching from select to text or textarea, delete any CustomFieldValues that may exist
     if ($this->blnEditMode && $this->objCustomField->CustomFieldQtypeId == 2 && ($this->lstCustomFieldQtype->SelectedValue == 1 || $this->lstCustomFieldQtype->SelectedValue == 3)) {
         $objCustomFieldValueArray = CustomFieldValue::LoadArrayByCustomFieldId($this->objCustomField->CustomFieldId);
         if ($objCustomFieldValueArray) {
             foreach ($objCustomFieldValueArray as $objCustomFieldValue) {
                 $objCustomFieldValue->Delete();
             }
         }
     }
     // If changing the short_description, we need to change all of the values in the DatagridColumnPreference table
     if ($this->blnEditMode && $this->objCustomField->ShortDescription != $this->txtShortDescription->Text) {
         $strQuery = sprintf("UPDATE datagrid_column_preference SET column_name = '%s' WHERE column_name = '%s'", $this->txtShortDescription->Text, $this->objCustomField->ShortDescription);
         $objDatabase = QApplication::$Database[1];
         $objDatabase->NonQuery($strQuery);
     }
     // Assign the object variables from the form controls
     $this->objCustomField->CustomFieldQtypeId = $this->lstCustomFieldQtype->SelectedValue;
     $this->objCustomField->ShortDescription = $this->txtShortDescription->Text;
     $this->objCustomField->ActiveFlag = $this->chkActiveFlag->Checked;
     $this->objCustomField->RequiredFlag = $this->chkRequiredFlag->Checked;
 }