本文整理汇总了PHP中JsonHelper::decode方法的典型用法代码示例。如果您正苦于以下问题:PHP JsonHelper::decode方法的具体用法?PHP JsonHelper::decode怎么用?PHP JsonHelper::decode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类JsonHelper
的用法示例。
在下文中一共展示了JsonHelper::decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: safeUp
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
// Get all of the Tags fields
$tagFields = craft()->db->createCommand()->select('id, settings')->from('fields')->where(array('type' => 'Tags'))->queryAll();
foreach ($tagFields as $field) {
$settings = JsonHelper::decode($field['settings']);
if (!empty($settings['source']) && strncmp($settings['source'], 'tagset:', 7) == 0) {
$tagSetId = (int) mb_substr($settings['source'], 7);
// Does that tag set still exist?
$count = craft()->db->createCommand()->from('tagsets')->where(array('id' => $tagSetId))->count('id');
if ($count) {
// Now make sure all of the tags connected to this field actually belong to that set.
// Otherwise we should duplicate the tag into the correct set
$tags = craft()->db->createCommand()->select('r.id relationId, t.name')->from('relations r')->join('tags t', 't.id = r.childId')->where(array('and', 'r.fieldId = :fieldId', 't.setId != :setId'), array(':fieldId' => $field['id'], ':setId' => $tagSetId))->queryAll();
foreach ($tags as $tag) {
// Is there already a tag in the correct tag set with that name?
$newTagId = craft()->db->createCommand()->select('id')->from('tags')->where(array('setId' => $tagSetId, 'name' => $tag['name']))->queryScalar();
if (!$newTagId) {
// Create a new row in elements
craft()->db->createCommand()->insert('elements', array('type' => ElementType::Tag, 'enabled' => 1, 'archived' => 0));
// Get the new element ID
$newTagId = craft()->db->getLastInsertID();
$this->insert('tags', array('id' => $newTagId, 'setId' => $tagSetId, 'name' => $tag['name']));
}
// Update the relation
$this->update('relations', array('childId' => $newTagId), array('id' => $tag['relationId']));
}
} else {
// Just delete any relations with this field
$this->delete('relations', array('fieldId' => $field['id']));
}
}
}
return true;
}
示例2: safeUp
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
$rows = craft()->db->createCommand()->select('*')->from('widgets')->where('type=:type', array(':type' => 'Analytics_Explorer'))->queryAll();
if ($rows) {
foreach ($rows as $row) {
$oldSettings = JsonHelper::decode($row['settings']);
// old to new
$newSettings = [];
if (isset($oldSettings['chart'])) {
$newSettings['chart'] = $oldSettings['chart'];
}
if (isset($oldSettings['period'])) {
$newSettings['period'] = $oldSettings['period'];
}
$newSettings['options'] = [];
if (isset($oldSettings['dimension'])) {
$newSettings['options']['dimension'] = $oldSettings['dimension'];
}
if (isset($oldSettings['metric'])) {
$newSettings['options']['metric'] = $oldSettings['metric'];
}
switch ($oldSettings['menu']) {
case 'realtimeVisitors':
$type = 'Analytics_Realtime';
break;
default:
$type = 'Analytics_Report';
}
// update row
$newSettings = JsonHelper::encode($newSettings);
$updateCmd = craft()->db->createCommand()->update('widgets', array('type' => $type, 'settings' => $newSettings), 'id=:id', array('id' => $row['id']));
}
}
return true;
}
开发者ID:codeforamerica,项目名称:oakland-beta,代码行数:40,代码来源:m150921_000001_explorer_widget_to_realtime_and_reports.php
示例3: safeUp
/**
* Convert allowed source storage format from just an integer to "folder:X" format.
*
* @return bool
*/
public function safeUp()
{
// Grab all the Assets fields.
$fields = craft()->db->createCommand()->select('id, settings')->from('fields')->where('type = :type', array(':type' => "Assets"))->queryAll();
if ($fields) {
// Grab all of the top-level folder IDs
$folders = craft()->db->createCommand()->select('id, sourceId')->from('assetfolders')->where('parentId is null')->queryAll();
if ($folders) {
// Create an associative array of them by source ID
$folderIdsBySourceId = array();
foreach ($folders as $folder) {
$folderIdsBySourceId[$folder['sourceId']] = $folder['id'];
}
// Now update the fields
foreach ($fields as $field) {
$settings = JsonHelper::decode($field['settings']);
if (isset($settings['sources']) && is_array($settings['sources'])) {
// Are there any source IDs?
$anySourceIds = false;
foreach ($settings['sources'] as $key => $source) {
if (isset($folderIdsBySourceId[$source])) {
$settings['sources'][$key] = 'folder:' . $folderIdsBySourceId[$source];
$anySourceIds = true;
}
}
if ($anySourceIds) {
$this->update('fields', array('settings' => JsonHelper::encode($settings)), array('id' => $field['id']));
}
}
}
}
}
return true;
}
示例4: populateFromAsset
public static function populateFromAsset(AssetFileModel $asset)
{
if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) {
try {
$url = $asset->getUrl();
if (!UrlHelper::isAbsoluteUrl($url)) {
$protocol = craft()->request->isSecureConnection() ? 'https' : 'http';
$url = UrlHelper::getUrlWithProtocol($url, $protocol);
}
// See http://stackoverflow.com/questions/272361/how-can-i-handle-the-warning-of-file-get-contents-function-in-php
$rawData = @file_get_contents($url);
if ($rawData) {
$data = JsonHelper::decode($rawData);
if ($data['__embeddedasset__']) {
unset($data['__embeddedasset__']);
$embed = new EmbeddedAssetsModel();
$embed->id = $asset->id;
foreach ($data as $key => $value) {
$embed->{$key} = $value;
}
return $embed;
}
}
} catch (\Exception $e) {
return null;
}
}
return null;
}
示例5: getRecipients
/**
* @param mixed|null $element
*
* @throws \Exception
* @return array|string
*/
public function getRecipients($element = null)
{
$recipientsString = $this->getAttribute('recipients');
// Possibly called from entry edit screen
if (is_null($element)) {
return $recipientsString;
}
// Previously converted to array somehow?
if (is_array($recipientsString)) {
return $recipientsString;
}
// Previously stored as JSON string?
if (stripos($recipientsString, '[') === 0) {
return JsonHelper::decode($recipientsString);
}
// Still a string with possible twig generator code?
if (stripos($recipientsString, '{') !== false) {
try {
$recipients = craft()->templates->renderObjectTemplate($recipientsString, $element);
return array_unique(ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($recipients)));
} catch (\Exception $e) {
throw $e;
}
}
// Just a regular CSV list
if (!empty($recipientsString)) {
return ArrayHelper::filterEmptyStringsFromArray(ArrayHelper::stringToArray($recipientsString));
}
return array();
}
示例6: getTokenRoute
/**
* Searches for a token, and possibly returns a route for the request.
*
* @param string $token
*
* @return array|false
*/
public function getTokenRoute($token)
{
// Take the opportunity to delete any expired tokens
$this->deleteExpiredTokens();
$result = craft()->db->createCommand()->select('id, route, usageLimit, usageCount')->from('tokens')->where('token = :token', array(':token' => $token))->queryRow();
if ($result) {
// Usage limit enforcement (for future requests)
if ($result['usageLimit']) {
// Does it have any more life after this?
if ($result['usageCount'] < $result['usageLimit'] - 1) {
// Increment its count
$this->incrementTokenUsageCountById($result['id']);
} else {
// Just delete it
$this->deleteTokenById($result['id']);
}
}
// Figure out where we should route the request
$route = $result['route'];
if (is_string($route) && mb_strlen($route) && ($route[0] == '[' || $route[0] == '{')) {
$route = JsonHelper::decode($route);
}
return $route;
} else {
return false;
}
}
示例7: populateFromAsset
public static function populateFromAsset(AssetFileModel $asset)
{
if ($asset->kind === 'json' && strpos($asset->filename, EmbeddedAssetsPlugin::getFileNamePrefix(), 0) === 0) {
try {
$rawData = craft()->embeddedAssets->readAssetFile($asset);
if ($rawData) {
$data = JsonHelper::decode($rawData);
if ($data['__embeddedasset__']) {
unset($data['__embeddedasset__']);
$embed = new EmbeddedAssetsModel();
$embed->id = $asset->id;
foreach ($embed->attributeNames() as $key) {
if (isset($data[$key])) {
$embed->{$key} = $data[$key];
}
}
// For embedded assets saved with version 0.2.1 or below, this will provide a usable fallback
if (empty($embed->requestUrl)) {
$embed->requestUrl = $embed->url;
}
return $embed;
}
}
} catch (\Exception $e) {
EmbeddedAssetsPlugin::log("Error reading embedded asset data on asset {$asset->id} (\"{$e->getMessage()}\")", LogLevel::Error);
return null;
}
}
return null;
}
示例8: safeUp
/**
* Any migration code in here is wrapped inside of a transaction.
*
* @return bool
*/
public function safeUp()
{
// Get all Assets fields
$fields = craft()->db->createCommand()->select('fields.id, fields.settings')->from('fields fields')->where('fields.type = "Assets"')->queryAll();
$affectedFields = array();
// Select those, that have a dynamic default upload location set.
foreach ($fields as $field) {
$settings = JsonHelper::decode($field['settings']);
if (empty($settings['useSingleFolder']) && !empty($settings['defaultUploadLocationSubpath']) && strpos($settings['defaultUploadLocationSubpath'], '{') !== false) {
$affectedFields[] = $field;
}
}
$affectedElements = array();
// Get the element ids, that have Assets linked to them via affected fields that still reside in a temporary source.
if (!empty($affectedFields)) {
foreach ($affectedFields as $field) {
$data = $this->_getAffectedElements($field);
foreach ($data as $row) {
$affectedElements[$row['type']][] = $row['elementId'];
}
}
}
foreach ($affectedElements as $elementType => $ids) {
$criteria = craft()->elements->getCriteria($elementType);
$criteria->status = null;
$criteria->limit = null;
$criteria->id = $ids;
craft()->tasks->createTask('ResaveElements', Craft::t('Resaving {element} elements affected by Assets bug', array('element' => $elementType)), array('elementType' => $elementType, 'criteria' => $criteria->getAttributes()));
}
return true;
}
开发者ID:kentonquatman,项目名称:portfolio,代码行数:36,代码来源:m140731_000001_resave_elements_with_assets_in_temp_sources.php
示例9: actionReorderNav
public function actionReorderNav()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$navIds = JsonHelper::decode(craft()->request->getRequiredPost('ids'));
$navs = craft()->cpNav_nav->reorderNav($navIds);
$this->returnJson(array('success' => true, 'navs' => $navs));
}
示例10: actionReorderUserWidgets
/**
* Reorders widgets.
*/
public function actionReorderUserWidgets()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$widgetIds = JsonHelper::decode(craft()->request->getRequiredPost('ids'));
craft()->dashboard->reorderUserWidgets($widgetIds);
$this->returnJson(array('success' => true));
}
示例11: actionReorderRules
/**
* Updates the rules sort order.
*
* @return null
*/
public function actionReorderRules()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$ruleIds = JsonHelper::decode(craft()->request->getRequiredPost('ids'));
craft()->autoExpire->reorderRules($ruleIds);
$this->returnJson(array('success' => true));
}
示例12: actionReorderLocales
/**
* Saves the new locale order.
*
* @return null
*/
public function actionReorderLocales()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$localeIds = JsonHelper::decode(craft()->request->getRequiredPost('ids'));
$success = craft()->i18n->reorderSiteLocales($localeIds);
$this->returnJson(array('success' => $success));
}
示例13: _updateSaveUserOptions
private function _updateSaveUserOptions($options)
{
$oldOptions = JsonHelper::decode($options);
$whenNew = isset($oldOptions['usersSaveUserOnlyWhenNew']) ? $oldOptions['usersSaveUserOnlyWhenNew'] : '';
$userGroupIds = isset($oldOptions['usersSaveUserGroupIds']) ? $oldOptions['usersSaveUserGroupIds'] : '';
$newOptions = array('craft' => array('saveUser' => array('whenNew' => $whenNew, 'whenUpdated' => '', 'userGroupIds' => $userGroupIds)));
return JsonHelper::encode($newOptions);
}
开发者ID:aladrach,项目名称:Bluefoot-Craft-Starter,代码行数:8,代码来源:m150629_000000_sproutEmail_updateNotificationOptionsFormat.php
示例14: actionReorderAnnouncements
/**
* Updates the announcements sort order.
*
* @return null
*/
public function actionReorderAnnouncements()
{
$this->requirePostRequest();
$this->requireAjaxRequest();
$announcementIds = JsonHelper::decode(craft()->request->getRequiredPost('ids'));
$announcementIds = array_reverse($announcementIds);
craft()->maintenance->reorderAnnouncements($announcementIds);
$this->returnJson(array('success' => true));
}
示例15: actionSettingsIndexTemplate
/**
* Save Settings to the Database
*
* @return mixed Return to Page
*/
public function actionSettingsIndexTemplate()
{
$settingsModel = new SproutForms_SettingsModel();
$settings = craft()->db->createCommand()->select('settings')->from('plugins')->where('class=:class', array(':class' => 'SproutForms'))->queryScalar();
$settings = JsonHelper::decode($settings);
$settingsModel->setAttributes($settings);
$variables['settings'] = $settingsModel;
// Load our template
$this->renderTemplate('sproutforms/settings', $variables);
}