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


PHP ArrayHelper::flattenArray方法代码示例

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


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

示例1: fields

 /**
  * Parse category fields.
  *
  * @param CategoryModel $category
  * @param bool          $empty
  *
  * @return array
  */
 public function fields(CategoryModel $category, $empty = false)
 {
     // Always save id
     $fields = array('id' => array('label' => Craft::t('ID'), 'value' => $category->id), 'title' => array('label' => Craft::t('Title'), 'value' => (string) $category->getTitle()), 'group' => array('label' => Craft::t('Group'), 'value' => (string) $category->getGroup()));
     // Get element type
     $elementType = craft()->elements->getElementType(ElementType::Category);
     // Get nice attributes
     $availableAttributes = $elementType->defineAvailableTableAttributes();
     // Make 'em fit
     $attributes = array();
     foreach ($availableAttributes as $key => $result) {
         $attributes[$key] = $result['label'];
     }
     // Get static "fields"
     foreach ($category->getAttributes() as $handle => $value) {
         // Only show nice attributes
         if (array_key_exists($handle, $attributes)) {
             $fields[$handle] = array('label' => $attributes[$handle], 'value' => StringHelper::arrayToString(is_array($value) ? array_filter(ArrayHelper::flattenArray($value), 'strlen') : $value, ', '));
         }
     }
     // Get fieldlayout
     foreach (craft()->fields->getLayoutByType(ElementType::Category)->getFields() as $field) {
         // Get field values
         $field = $field->getField();
         $handle = $field->handle;
         $label = $field->name;
         $value = $empty ? '' : craft()->auditLog->parseFieldData($handle, $category->{$handle});
         // Set on fields
         $fields[$handle] = array('label' => $label, 'value' => $value);
     }
     // Return
     return $fields;
 }
开发者ID:boboldehampsink,项目名称:auditlog,代码行数:41,代码来源:AuditLog_CategoryService.php

示例2: parseFieldData

 /**
  * Parse field values.
  *
  * @param string $handle
  * @param mixed  $data
  *
  * @return string
  */
 protected function parseFieldData($handle, $data)
 {
     // Do we have any data at all
     if (!is_null($data)) {
         // Get field info
         $field = craft()->fields->getFieldByHandle($handle);
         // If it's a field ofcourse
         if (!is_null($field)) {
             // For some fieldtypes the're special rules
             switch ($field->type) {
                 case ExportModel::FieldTypeEntries:
                 case ExportModel::FieldTypeCategories:
                 case ExportModel::FieldTypeAssets:
                 case ExportModel::FieldTypeUsers:
                     // Show names
                     $data = $data instanceof ElementCriteriaModel ? implode(', ', $data->find()) : $data;
                     break;
                 case ExportModel::FieldTypeLightswitch:
                     // Make data human readable
                     switch ($data) {
                         case '0':
                             $data = Craft::t('No');
                             break;
                         case '1':
                             $data = Craft::t('Yes');
                             break;
                     }
                     break;
                 case ExportModel::FieldTypeTable:
                     // Parse table checkboxes
                     $table = array();
                     foreach ($data as $row) {
                         // Keep track of column #
                         $i = 1;
                         // Loop through columns
                         foreach ($row as $column => $value) {
                             // Get column
                             $column = isset($field->settings['columns'][$column]) ? $field->settings['columns'][$column] : (isset($field->settings['columns']['col' . $i]) ? $field->settings['columns']['col' . $i] : array('type' => 'dummy'));
                             // Keep track of column #
                             $i++;
                             // Parse
                             $table[] = $column['type'] == 'checkbox' ? $value == 1 ? Craft::t('Yes') : Craft::t('No') : $value;
                         }
                     }
                     // Return parsed data as array
                     $data = $table;
                     break;
                 case ExportModel::FieldTypeRichText:
                 case ExportModel::FieldTypeDate:
                 case ExportModel::FieldTypeRadioButtons:
                 case ExportModel::FieldTypeDropdown:
                     // Resolve to string
                     $data = (string) $data;
                     break;
                 case ExportModel::FieldTypeCheckboxes:
                 case ExportModel::FieldTypeMultiSelect:
                     // Parse multi select values
                     $multi = array();
                     foreach ($data as $row) {
                         $multi[] = $row->value;
                     }
                     // Return parsed data as array
                     $data = $multi;
                     break;
             }
         }
         // Get other operations
         craft()->plugins->call('registerExportOperation', array(&$data, $handle));
     } else {
         // Don't return null, return empty
         $data = '';
     }
     // If it's an object or an array, make it a string
     if (is_array($data)) {
         $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray($data)), ', ');
     }
     // If it's an object, make it a string
     if (is_object($data)) {
         $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray(get_object_vars($data))), ', ');
     }
     return $data;
 }
开发者ID:rutgerbakker7,项目名称:export,代码行数:90,代码来源:ExportService.php

示例3: parseFieldData

 protected function parseFieldData($field, $data)
 {
     if (!is_null($data)) {
         if (!is_null($field)) {
             switch ($field->type) {
                 case ExportModel::FieldTypeEntries:
                 case ExportModel::FieldTypeCategories:
                 case ExportModel::FieldTypeAssets:
                 case ExportModel::FieldTypeUsers:
                     $data = $data instanceof ElementCriteriaModel ? implode(', ', $data->find()) : $data;
                     break;
                 case ExportModel::FieldTypeLightswitch:
                     switch ($data) {
                         case '0':
                             $data = Craft::t('No');
                             break;
                         case '1':
                             $data = Craft::t('Yes');
                             break;
                     }
                     break;
                 case ExportModel::FieldTypeTable:
                     $table = array();
                     foreach ($data as $row) {
                         $i = 1;
                         foreach ($row as $column => $value) {
                             $column = isset($field->settings['columns'][$column]) ? $field->settings['columns'][$column] : (isset($field->settings['columns']['col' . $i]) ? $field->settings['columns']['col' . $i] : array('type' => 'dummy'));
                             $i++;
                             $table[] = $column['type'] == 'checkbox' ? $value == 1 ? Craft::t('Yes') : Craft::t('No') : $value;
                         }
                     }
                     $data = $table;
                     break;
                 case ExportModel::FieldTypeRichText:
                 case ExportModel::FieldTypeDate:
                 case ExportModel::FieldTypeRadioButtons:
                 case ExportModel::FieldTypeDropdown:
                     $data = (string) $data;
                     break;
                 case ExportModel::FieldTypeCheckboxes:
                 case ExportModel::FieldTypeMultiSelect:
                     $multi = array();
                     foreach ($data as $row) {
                         $multi[] = $row->value;
                     }
                     $data = $multi;
                     break;
             }
         }
     } else {
         $data = '';
     }
     if (is_array($data)) {
         $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray($data)), ', ');
     }
     if (is_object($data)) {
         $data = StringHelper::arrayToString(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::flattenArray(get_object_vars($data))), ', ');
     }
     return $data;
 }
开发者ID:transomdesign,项目名称:transom-craft-starter,代码行数:60,代码来源:SuperTableService.php

示例4: elementHasChanged

 /**
  * Check if an element has changed while saving.
  *
  * @param string $elementType
  * @param int    $id
  * @param array  $before
  * @param array  $after
  *
  * @return array
  */
 public function elementHasChanged($elementType, $id, $before, $after)
 {
     // Flatten arrays
     $flatBefore = ArrayHelper::flattenArray($before);
     $flatAfter = ArrayHelper::flattenArray($after);
     // Calculate the diffence
     $flatDiff = array_diff_assoc($flatAfter, $flatBefore);
     // Expand diff again
     $expanded = ArrayHelper::expandArray($flatDiff);
     // Add labels once again
     $diff = array();
     foreach ($expanded as $key => $value) {
         $diff[$key]['label'] = isset($before[$key]) ? $before[$key]['label'] : '';
         $diff[$key]['value'] = $value['value'];
     }
     // If there IS a difference
     if (count($diff)) {
         // Fire an "onElementChanged" event
         $event = new Event($this, array('elementType' => $elementType, 'id' => $id, 'diff' => $diff));
         $this->onElementChanged($event);
     }
     return $diff;
 }
开发者ID:boboldehampsink,项目名称:auditlog,代码行数:33,代码来源:AuditLogService.php

示例5: fields

 /**
  * Parse user fields.
  *
  * @param UserModel $user
  * @param bool      $empty
  *
  * @return array
  */
 public function fields(UserModel $user, $empty = false)
 {
     // Check if we are saving new groups
     $groupIds = craft()->request->getPost('groups', false);
     // If this is before saving, or no groups have changed
     if (!count($this->before) || !$groupIds) {
         // Get user's groups
         $groups = craft()->userGroups->getGroupsByUserId($user->id);
     } else {
         // This is after saving
         // Get posted groups
         $groups = array();
         foreach ($groupIds as $id) {
             $groups[] = craft()->userGroups->getGroupById($id);
         }
     }
     // Always save id
     $fields = array('id' => array('label' => Craft::t('ID'), 'value' => $user->id), 'groups' => array('label' => Craft::t('Groups'), 'value' => implode(', ', $groups)));
     // Get element type
     $elementType = craft()->elements->getElementType(ElementType::User);
     // Get nice attributes
     $availableAttributes = $elementType->defineAvailableTableAttributes();
     // Make 'em fit
     $attributes = array();
     foreach ($availableAttributes as $key => $result) {
         $attributes[$key] = $result['label'];
     }
     // Get static "fields"
     foreach ($user->getAttributes() as $handle => $value) {
         // Only show nice attributes
         if (array_key_exists($handle, $attributes)) {
             $fields[$handle] = array('label' => $attributes[$handle], 'value' => StringHelper::arrayToString(is_array($value) ? array_filter(ArrayHelper::flattenArray($value), 'strlen') : $value, ', '));
         }
     }
     // Get fieldlayout
     foreach (craft()->fields->getLayoutByType(ElementType::User)->getFields() as $field) {
         // Get field values
         $field = $field->getField();
         $handle = $field->handle;
         $label = $field->name;
         $value = $empty ? '' : craft()->auditLog->parseFieldData($handle, $user->{$handle});
         // Set on fields
         $fields[$handle] = array('label' => $label, 'value' => $value);
     }
     // Return
     return $fields;
 }
开发者ID:boboldehampsink,项目名称:auditlog,代码行数:55,代码来源:AuditLog_UserService.php

示例6: fields

 /**
  * Parse entry fields.
  *
  * @param EntryModel $entry
  * @param bool       $empty
  *
  * @return array
  */
 public function fields(EntryModel $entry, $empty = false)
 {
     // Always save id and title
     $fields = array('id' => array('label' => Craft::t('ID'), 'value' => $entry->id), 'title' => array('label' => Craft::t('Title'), 'value' => $entry->title), 'section' => array('label' => Craft::t('Section'), 'value' => $entry->section->name));
     // Get element type
     $elementType = craft()->elements->getElementType(ElementType::Entry);
     // Get nice attributes
     $attributes = $elementType->defineTableAttributes();
     // Get static "fields"
     foreach ($entry->getAttributes() as $handle => $value) {
         // Only show nice attributes
         if (array_key_exists($handle, $attributes)) {
             $fields[$handle] = array('label' => $attributes[$handle], 'value' => StringHelper::arrayToString(is_array($value) ? array_filter(ArrayHelper::flattenArray($value), 'strlen') : $value, ', '));
         }
     }
     // Get fieldlayout
     $entrytype = $entry->getType();
     $tabs = craft()->fields->getLayoutById($entrytype->fieldLayoutId)->getTabs();
     foreach ($tabs as $tab) {
         foreach ($tab->getFields() as $field) {
             // Get field values
             $field = $field->getField();
             $handle = $field->handle;
             $label = $field->name;
             $value = $empty ? '' : craft()->auditLog->parseFieldData($handle, $entry->{$handle});
             // Set on fields
             $fields[$handle] = array('label' => $label, 'value' => $value);
         }
     }
     // Return
     return $fields;
 }
开发者ID:webremote,项目名称:auditlog,代码行数:40,代码来源:AuditLog_EntryService.php


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