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


PHP ArrayHelper::getFirstKey方法代码示例

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


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

示例1: getBodyHtml

 /**
  * @inheritDoc IWidget::getBodyHtml()
  *
  * @return string|false
  */
 public function getBodyHtml()
 {
     craft()->templates->includeTranslations('Entry saved.', 'Couldn’t save entry.');
     craft()->templates->includeJsResource('js/QuickPostWidget.js');
     $section = $this->_getSection();
     if (!$section) {
         return '<p>' . Craft::t('No section has been selected yet.') . '</p>';
     }
     $entryTypes = $section->getEntryTypes('id');
     if (!$entryTypes) {
         return '<p>' . Craft::t('No entry types exist for this section.') . '</p>';
     }
     if ($this->getSettings()->entryType && isset($entryTypes[$this->getSettings()->entryType])) {
         $entryTypeId = $this->getSettings()->entryType;
     } else {
         $entryTypeId = ArrayHelper::getFirstKey($entryTypes);
     }
     $entryType = $entryTypes[$entryTypeId];
     $params = array('sectionId' => $section->id, 'typeId' => $entryTypeId);
     craft()->templates->startJsBuffer();
     $html = craft()->templates->render('_components/widgets/QuickPost/body', array('section' => $section, 'entryType' => $entryType, 'settings' => $this->getSettings()));
     $fieldJs = craft()->templates->clearJsBuffer(false);
     craft()->templates->includeJs('new Craft.QuickPostWidget(' . $this->model->id . ', ' . JsonHelper::encode($params) . ', ' . "function() {\n" . $fieldJs . "\n});");
     return $html;
 }
开发者ID:JulesVan,项目名称:solutions-con,代码行数:30,代码来源:QuickPostWidget.php

示例2: saveSection


//.........这里部分代码省略.........
                     } else {
                         $entryType->hasTitleField = true;
                         $entryType->titleLabel = Craft::t('Title');
                         $entryType->titleFormat = null;
                     }
                     $this->saveEntryType($entryType);
                     $entryTypeId = $entryType->id;
                 }
                 // Now, regardless of whether the section type changed or not, let the section type make sure
                 // everything is cool
                 switch ($section->type) {
                     case SectionType::Single:
                         // Make sure that there is one and only one Entry Type and Entry for this section.
                         $singleEntryId = null;
                         if (!$isNewSection) {
                             // Make sure there's only one entry in this section
                             $entryIds = craft()->db->createCommand()->select('id')->from('entries')->where('sectionId = :sectionId', array(':sectionId' => $section->id))->queryColumn();
                             if ($entryIds) {
                                 $singleEntryId = array_shift($entryIds);
                                 // If there are any more, get rid of them
                                 if ($entryIds) {
                                     craft()->elements->deleteElementById($entryIds);
                                 }
                                 // Make sure it's enabled and all that.
                                 craft()->db->createCommand()->update('elements', array('enabled' => 1, 'archived' => 0), array('id' => $singleEntryId));
                                 craft()->db->createCommand()->update('entries', array('typeId' => $entryTypeId, 'authorId' => null, 'postDate' => DateTimeHelper::currentTimeForDb(), 'expiryDate' => null), array('id' => $singleEntryId));
                             }
                             // Make sure there's only one entry type for this section
                             if ($entryTypeIds) {
                                 $this->deleteEntryTypeById($entryTypeIds);
                             }
                         }
                         if (!$singleEntryId) {
                             // Create it, baby
                             $singleEntry = new EntryModel();
                             $singleEntry->locale = $firstSectionLocale->locale;
                             $singleEntry->sectionId = $section->id;
                             $singleEntry->typeId = $entryTypeId;
                             $singleEntry->getContent()->title = $section->name;
                             craft()->entries->saveEntry($singleEntry);
                         }
                         break;
                     case SectionType::Structure:
                         if (!$isNewSection && $isNewStructure) {
                             // Add all of the entries to the structure
                             $criteria = craft()->elements->getCriteria(ElementType::Entry);
                             $criteria->locale = ArrayHelper::getFirstKey($oldSectionLocales);
                             $criteria->sectionId = $section->id;
                             $criteria->status = null;
                             $criteria->localeEnabled = null;
                             $criteria->order = 'elements.id';
                             $criteria->limit = 25;
                             do {
                                 $batchEntries = $criteria->find();
                                 foreach ($batchEntries as $entry) {
                                     craft()->structures->appendToRoot($section->structureId, $entry, 'insert');
                                 }
                                 $criteria->offset += 25;
                             } while ($batchEntries);
                         }
                         break;
                 }
                 // Finally, deal with the existing entries...
                 if (!$isNewSection) {
                     $criteria = craft()->elements->getCriteria(ElementType::Entry);
                     // Get the most-primary locale that this section was already enabled in
                     $locales = array_values(array_intersect(craft()->i18n->getSiteLocaleIds(), array_keys($oldSectionLocales)));
                     if ($locales) {
                         $criteria->locale = $locales[0];
                         $criteria->sectionId = $section->id;
                         $criteria->status = null;
                         $criteria->localeEnabled = null;
                         $criteria->limit = null;
                         craft()->tasks->createTask('ResaveElements', Craft::t('Resaving {section} entries', array('section' => $section->name)), array('elementType' => ElementType::Entry, 'criteria' => $criteria->getAttributes()));
                     }
                 }
                 $success = true;
             } else {
                 $success = false;
             }
             // Commit the transaction regardless of whether we saved the section, in case something changed
             // in onBeforeSaveSection
             if ($transaction !== null) {
                 $transaction->commit();
             }
         } catch (\Exception $e) {
             if ($transaction !== null) {
                 $transaction->rollback();
             }
             throw $e;
         }
     } else {
         $success = false;
     }
     if ($success) {
         // Fire an 'onSaveSection' event
         $this->onSaveSection(new Event($this, array('section' => $section, 'isNewSection' => $isNewSection)));
     }
     return $success;
 }
开发者ID:jmstan,项目名称:craft-website,代码行数:101,代码来源:SectionsService.php

示例3: getIndexHtml

 /**
  * @inheritDoc IElementType::getIndexHtml()
  *
  * @param ElementCriteriaModel $criteria
  * @param array                $disabledElementIds
  * @param array                $viewState
  * @param null|string          $sourceKey
  * @param null|string          $context
  * @param bool                 $includeContainer
  * @param bool                 $showCheckboxes
  *
  * @return string
  */
 public function getIndexHtml($criteria, $disabledElementIds, $viewState, $sourceKey, $context, $includeContainer, $showCheckboxes)
 {
     $variables = array('viewMode' => $viewState['mode'], 'context' => $context, 'elementType' => new ElementTypeVariable($this), 'disabledElementIds' => $disabledElementIds, 'collapsedElementIds' => craft()->request->getParam('collapsedElementIds'), 'showCheckboxes' => $showCheckboxes);
     // Special case for sorting by structure
     if (isset($viewState['order']) && $viewState['order'] == 'structure') {
         $source = $this->getSource($sourceKey, $context);
         if (isset($source['structureId'])) {
             $criteria->order = 'lft asc';
             $variables['structure'] = craft()->structures->getStructureById($source['structureId']);
             // Are they allowed to make changes to this structure?
             if ($context == 'index' && $variables['structure'] && !empty($source['structureEditable'])) {
                 $variables['structureEditable'] = true;
                 // Let StructuresController know that this user can make changes to the structure
                 craft()->userSession->authorize('editStructure:' . $variables['structure']->id);
             }
         } else {
             unset($viewState['order']);
         }
     } else {
         if (!empty($viewState['order']) && $viewState['order'] == 'score') {
             $criteria->order = 'score';
         } else {
             $sortableAttributes = $this->defineSortableAttributes();
             if ($sortableAttributes) {
                 $order = !empty($viewState['order']) && isset($sortableAttributes[$viewState['order']]) ? $viewState['order'] : ArrayHelper::getFirstKey($sortableAttributes);
                 $sort = !empty($viewState['sort']) && in_array($viewState['sort'], array('asc', 'desc')) ? $viewState['sort'] : 'asc';
                 // Combine them, accounting for the possibility that $order could contain multiple values,
                 // and be defensive about the possibility that the first value actually has "asc" or "desc"
                 // typeId             => typeId [sort]
                 // typeId, title      => typeId [sort], title
                 // typeId, title desc => typeId [sort], title desc
                 // typeId desc        => typeId [sort]
                 $criteria->order = preg_replace('/^(.*?)(?:\\s+(?:asc|desc))?(,.*)?$/i', "\$1 {$sort}\$2", $order);
             }
         }
     }
     switch ($viewState['mode']) {
         case 'table':
             // Get the table columns
             $variables['attributes'] = $this->getTableAttributesForSource($sourceKey);
             // Give each attribute a chance to modify the criteria
             foreach ($variables['attributes'] as $attribute) {
                 $this->prepElementCriteriaForTableAttribute($criteria, $attribute[0]);
             }
             break;
     }
     $variables['elements'] = $criteria->find();
     $template = '_elements/' . $viewState['mode'] . 'view/' . ($includeContainer ? 'container' : 'elements');
     return craft()->templates->render($template, $variables);
 }
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:63,代码来源:BaseElementType.php


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