本文整理汇总了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;
}
}
}