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


PHP ContentModel::populateModels方法代码示例

本文整理汇总了PHP中ContentModel::populateModels方法的典型用法代码示例。如果您正苦于以下问题:PHP ContentModel::populateModels方法的具体用法?PHP ContentModel::populateModels怎么用?PHP ContentModel::populateModels使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在ContentModel的用法示例。


在下文中一共展示了ContentModel::populateModels方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _duplicateNonTranslatableFieldValues

 /**
  * Copies the new values of any non-translatable fields across the element's
  * other locales.
  *
  * @param BaseElementModel $element
  * @param ContentModel     $content
  * @param FieldLayoutModel $fieldLayout
  * @param array            &$nonTranslatableFields
  * @param array            &$otherContentModels
  *
  * @return null
  */
 private function _duplicateNonTranslatableFieldValues(BaseElementModel $element, ContentModel $content, FieldLayoutModel $fieldLayout, &$nonTranslatableFields, &$otherContentModels)
 {
     // Get all of the non-translatable fields
     $nonTranslatableFields = array();
     foreach ($fieldLayout->getFields() as $fieldLayoutField) {
         $field = $fieldLayoutField->getField();
         if ($field && !$field->translatable) {
             $fieldType = $field->getFieldType();
             if ($fieldType && $fieldType->defineContentAttribute()) {
                 $nonTranslatableFields[$field->id] = $field;
             }
         }
     }
     if ($nonTranslatableFields) {
         // Get the other locales' content
         $rows = craft()->db->createCommand()->from($this->contentTable)->where(array('and', 'elementId = :elementId', 'locale != :locale'), array(':elementId' => $element->id, ':locale' => $content->locale))->queryAll();
         // Remove the column prefixes
         foreach ($rows as $i => $row) {
             $rows[$i] = $this->_removeColumnPrefixesFromRow($row);
         }
         $otherContentModels = ContentModel::populateModels($rows);
         foreach ($otherContentModels as $otherContentModel) {
             foreach ($nonTranslatableFields as $field) {
                 $handle = $field->handle;
                 $otherContentModel->{$handle} = $content->{$handle};
             }
             $this->_saveContentRow($otherContentModel);
         }
     }
 }
开发者ID:kant312,项目名称:sop,代码行数:42,代码来源:ContentService.php

示例2: postSaveOperations

 /**
  * Performs post-save element operations, such as calling all fieldtypes' onAfterElementSave() methods.
  *
  * @param BaseElementModel $element
  * @param ContentModel $content
  */
 public function postSaveOperations(BaseElementModel $element, ContentModel $content)
 {
     // Get all of the fieldtypes
     $fields = craft()->fields->getAllFields();
     $fieldTypes = array();
     $fieldTypesWithDuplicateContent = array();
     foreach ($fields as $field) {
         $fieldType = craft()->fields->populateFieldType($field);
         if ($fieldType) {
             $fieldType->element = $element;
             $fieldTypes[] = $fieldType;
             if (!$field->translatable && $fieldType->defineContentAttribute()) {
                 $fieldTypesWithDuplicateContent[] = $fieldType;
             }
         }
     }
     // Are we dealing with other locales as well?
     if (Craft::hasPackage(CraftPackage::Localize)) {
         // Get the other locales' content
         $rows = craft()->db->createCommand()->from('content')->where(array('and', 'elementId = :elementId', 'locale != :locale'), array(':elementId' => $element->id, ':locale' => $content->locale))->queryAll();
         $otherContentModels = ContentModel::populateModels($rows);
         if ($otherContentModels) {
             foreach ($fieldTypesWithDuplicateContent as $fieldType) {
                 $handle = $fieldType->model->handle;
                 // Copy the content over!
                 foreach ($otherContentModels as $otherContentModel) {
                     $otherContentModel->{$handle} = $content->{$handle};
                 }
             }
             foreach ($otherContentModels as $otherContentModel) {
                 $this->saveContent($otherContentModel, false);
             }
         }
     } else {
         $otherContentModels = null;
     }
     // Now that all of the content saved for all locales,
     // call all fieldtypes' onAfterElementSave() functions
     foreach ($fieldTypes as $fieldType) {
         $fieldType->onAfterElementSave();
     }
     // Update the search keyword indexes
     $searchKeywordsByLocale = array();
     foreach ($fieldTypes as $fieldType) {
         $field = $fieldType->model;
         $handle = $field->handle;
         // Set the keywords for the content's locale
         $fieldSearchKeywords = $fieldType->getSearchKeywords($element->{$handle});
         $searchKeywordsByLocale[$content->locale][$field->id] = $fieldSearchKeywords;
         // Should we queue up the other locales' new keywords too?
         if ($otherContentModels && in_array($fieldType, $fieldTypesWithDuplicateContent)) {
             foreach ($otherContentModels as $otherContentModel) {
                 $searchKeywordsByLocale[$otherContentModel->locale][$field->id] = $fieldSearchKeywords;
             }
         }
     }
     foreach ($searchKeywordsByLocale as $localeId => $keywords) {
         craft()->search->indexElementFields($element->id, $localeId, $keywords);
     }
 }
开发者ID:kentonquatman,项目名称:portfolio,代码行数:66,代码来源:ContentService.php


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