本文整理汇总了PHP中StringHelper::arrayToString方法的典型用法代码示例。如果您正苦于以下问题:PHP StringHelper::arrayToString方法的具体用法?PHP StringHelper::arrayToString怎么用?PHP StringHelper::arrayToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类StringHelper
的用法示例。
在下文中一共展示了StringHelper::arrayToString方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: _end
private function _end()
{
$settings = $this->getSettings();
craft()->content->contentTable = $this->_originalContentTable;
craft()->content->fieldColumnPrefix = $this->_originalFieldColumnPrefix;
craft()->content->fieldContext = $this->_originalFieldContext;
$keywords = StringHelper::arrayToString($this->_keywords, ' ');
craft()->search->indexElementFields($settings->ownerId, $settings->locale, [$settings->fieldId => $keywords]);
}
示例2: determineRobotsOutput
protected function determineRobotsOutput($robotsArray)
{
$robotsMap = array("noindex" => "index", "nofollow" => "follow", "noarchive" => "archive", "noimageindex" => "imageindex", "nosnippet" => "snippet", "noodp" => "odp", "noydir" => "ydir");
$robotOutputValues = "";
foreach ($robotsMap as $negativeValue => $positiveValue) {
$robotString = StringHelper::arrayToString($robotsArray);
if (stristr($robotString, $negativeValue) === FALSE) {
$robotOutputValues .= $robotsMap[$negativeValue] . ",";
} else {
$robotOutputValues .= $negativeValue . ",";
}
}
// Remove the trailing comma from our string
$robotOutputValues = rtrim($robotOutputValues, ",");
return $robotOutputValues;
}
示例3: indexElementAttributes
/**
* Indexes the attributes of a given element defined by its element type.
*
* @param BaseElementModel $element
* @param string|null $localeId
* @return bool Whether the indexing was a success.
*/
public function indexElementAttributes(BaseElementModel $element, $localeId = null)
{
// Get the element type
$elementTypeClass = $element->getElementType();
$elementType = craft()->elements->getElementType($elementTypeClass);
// Does it have any searchable attributes?
$searchableAttributes = $elementType->defineSearchableAttributes();
if ($elementType->hasTitles()) {
$searchableAttributes[] = 'title';
}
foreach ($searchableAttributes as $attribute) {
$value = $element->{$attribute};
$value = StringHelper::arrayToString($value);
$this->_indexElementKeywords($element->id, $attribute, '0', $localeId, $value);
}
return true;
}
示例4: getSearchKeywords
/**
* @inheritDoc IFieldType::getSearchKeywords()
*
* @param mixed $value
*
* @return string
*/
public function getSearchKeywords($value)
{
return StringHelper::arrayToString($value, ' ');
}
示例5: 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;
}
示例6: 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;
}
示例7: actionRestoreForms
/**
* Restore Forms
*
*/
public function actionRestoreForms()
{
$this->requirePostRequest();
$restoreFile = craft()->request->getPost('restoreForms');
$filePath = \CUploadedFile::getInstanceByName('restoreForms');
$sqlFileContents = StringHelper::arrayToString(IOHelper::getFileContents($filePath->getTempName(), true), '');
$result = craft()->db->createCommand()->setText($sqlFileContents)->queryAll();
}
示例8: 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;
}
示例9: parseFieldData
/**
* Parse field values.
*
* @param string $handle
* @param mixed $data
*
* @return string
*/
public 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 AuditLogModel::FieldTypeEntries:
case AuditLogModel::FieldTypeCategories:
case AuditLogModel::FieldTypeAssets:
case AuditLogModel::FieldTypeUsers:
// Show names
$data = implode(', ', $data->find());
break;
case AuditLogModel::FieldTypeLightswitch:
// Make data human readable
switch ($data) {
case '0':
$data = Craft::t('No');
break;
case '1':
$data = Craft::t('Yes');
break;
}
break;
}
}
} else {
// Don't return null, return empty
$data = '';
}
// If it's an array, make it a string
if (is_array($data)) {
$data = StringHelper::arrayToString(array_filter(ArrayHelper::flattenArray($data), 'strlen'), ', ');
}
// If it's an object, make it a string
if (is_object($data)) {
$data = StringHelper::arrayToString(array_filter(ArrayHelper::flattenArray(get_object_vars($data)), 'strlen'), ', ');
}
return $data;
}
示例10: 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;
}
示例11: prepRobotsAsString
public static function prepRobotsAsString($robotsArray)
{
return StringHelper::arrayToString($robotsArray);
}
示例12: 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;
}