本文整理匯總了PHP中X2Model::hasAttribute方法的典型用法代碼示例。如果您正苦於以下問題:PHP X2Model::hasAttribute方法的具體用法?PHP X2Model::hasAttribute怎麽用?PHP X2Model::hasAttribute使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類X2Model
的用法示例。
在下文中一共展示了X2Model::hasAttribute方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。
示例1: importRecordLinkAttribute
/**
* Handle setting link type fields and create linked records if specified
* @param string $modelName The model class being imported
* @param X2Model $model The currently importing model record
* @param Fields $fieldRecord Field to set
* @param string $importAttribute Value to set field
* @param array $relationships Attributes of Relationships to be created
* @param array $modelContainer Attributes of Models to be created
* @param array $createdLinkedModels Linked models that will be created
*/
protected function importRecordLinkAttribute($modelName, X2Model &$model, Fields $fieldRecord, $importAttribute, &$relationships, &$modelContainer, &$createdLinkedModels)
{
$fieldName = $fieldRecord->fieldName;
$className = ucfirst($fieldRecord->linkType);
if (ctype_digit($importAttribute)) {
$lookup = X2Model::model($className)->findByPk($importAttribute);
$model->{$fieldName} = $importAttribute;
if (!empty($lookup)) {
// Create a link to the existing record
$model->{$fieldName} = $lookup->nameId;
$relationship = new Relationships();
$relationship->firstType = $modelName;
$relationship->secondType = $className;
$relationship->secondId = $importAttribute;
$relationships[count($relationships) - 1][] = $relationship->attributes;
}
} else {
$lookup = X2Model::model($className)->findByAttributes(array('name' => $importAttribute));
if (isset($lookup)) {
$model->{$fieldName} = $lookup->nameId;
$relationship = new Relationships();
$relationship->firstType = $modelName;
$relationship->secondType = $className;
$relationship->secondId = $lookup->id;
$relationships[count($relationships) - 1][] = $relationship->attributes;
} elseif (isset($_SESSION['createRecords']) && $_SESSION['createRecords'] == 1 && !($modelName === 'BugReports' && $fieldRecord->linkType === 'BugReports')) {
// Skip creating related bug reports; the created report wouldn't hold any useful info.
$className = ucfirst($fieldRecord->linkType);
if (class_exists($className)) {
$lookup = new $className();
if ($_SESSION['skipActivityFeed'] === 1) {
$lookup->createEvent = false;
}
$lookup->name = $importAttribute;
if ($className === 'Contacts' || $modelName === 'X2Leads') {
$this->fixupImportedContactName($lookup);
}
if ($lookup->hasAttribute('visibility')) {
$lookup->visibility = 1;
}
if ($lookup->hasAttribute('description')) {
$lookup->description = "Generated by " . $modelName . " import.";
}
if ($lookup->hasAttribute('createDate')) {
$lookup->createDate = time();
}
if (!array_key_exists($className, $modelContainer)) {
$modelContainer = array_merge($modelContainer, array($className => array()));
}
// Ensure this linked record has not already been accounted for
$createNewLinkedRecord = true;
if ($model->hasAttribute('name')) {
$model->{$fieldName} = $lookup->name;
} else {
$model->{$fieldName} = $importAttribute;
}
foreach ($modelContainer[$className] as $record) {
if ($record['name'] === $lookup->name) {
$createNewLinkedRecord = false;
break;
}
}
if ($createNewLinkedRecord) {
$modelContainer[$className][] = $lookup->attributes;
if (isset($_SESSION['created'][$className])) {
$_SESSION['created'][$className]++;
} else {
$_SESSION['created'][$className] = 1;
}
}
$relationship = new Relationships();
$relationship->firstType = $modelName;
$relationship->secondType = $className;
$relationships[count($relationships) - 1][] = $relationship->attributes;
$createdLinkedModels[] = $model->{$fieldName};
}
} else {
$model->{$fieldName} = $importAttribute;
}
}
}