当前位置: 首页>>代码示例>>PHP>>正文


PHP X2Model::hasAttribute方法代码示例

本文整理汇总了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;
         }
     }
 }
开发者ID:keyeMyria,项目名称:CRM,代码行数:91,代码来源:AdminController.php


注:本文中的X2Model::hasAttribute方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。