本文整理汇总了PHP中Joomla\Utilities\ArrayHelper::getValue方法的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper::getValue方法的具体用法?PHP ArrayHelper::getValue怎么用?PHP ArrayHelper::getValue使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Joomla\Utilities\ArrayHelper
的用法示例。
在下文中一共展示了ArrayHelper::getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: createThumbnail
/**
* Create a thumbnail from an image file.
*
* <code>
* $myFile = "/tmp/myfile.jpg";
*
* $options = array(
* "destination" => "image/mypic.jpg",
* "width" => 200,
* "height" => 200,
* "scale" => JImage::SCALE_INSIDE
* );
*
* $file = new PrismFileImage($myFile);
* $file->createThumbnail($options);
*
* </code>
*
* @param array $options Some options used in the process of generating thumbnail.
*
* @throws \InvalidArgumentException
* @throws \RuntimeException
*
* @return string A location to the new file.
*/
public function createThumbnail($options)
{
$width = ArrayHelper::getValue($options, "width", 100);
$height = ArrayHelper::getValue($options, "height", 100);
$scale = ArrayHelper::getValue($options, "scale", \JImage::SCALE_INSIDE);
$destination = ArrayHelper::getValue($options, "destination");
if (!$destination) {
throw new \InvalidArgumentException(\JText::_("LIB_PRISM_ERROR_INVALID_FILE_DESTINATION"));
}
// Generate thumbnail.
$image = new \JImage();
$image->loadFile($this->file);
if (!$image->isLoaded()) {
throw new \RuntimeException(\JText::sprintf('LIB_PRISM_ERROR_FILE_NOT_FOUND', $this->file));
}
// Resize the file as a new object
$thumb = $image->resize($width, $height, true, $scale);
$fileName = basename($this->file);
$ext = \JString::strtolower(\JFile::getExt(\JFile::makeSafe($fileName)));
switch ($ext) {
case "gif":
$type = IMAGETYPE_GIF;
break;
case "png":
$type = IMAGETYPE_PNG;
break;
case IMAGETYPE_JPEG:
default:
$type = IMAGETYPE_JPEG;
}
$thumb->toFile($destination, $type);
return $destination;
}
示例2: load
/**
* Load transactions from database.
*
* <code>
* $options = array(
* "ids" => array(1,2,3),
* "txn_status" => "completed"
* );
*
* $transactions = new Crowdfunding\Transactions(\JFactory::getDbo());
* $transactions->load($options);
*
* foreach($transactions as $transaction) {
* echo $transaction->txn_id;
* echo $transaction->txn_amount;
* }
*
* </code>
*
* @param array $options
*
* @throws \UnexpectedValueException
*/
public function load($options = array())
{
$ids = !isset($options["ids"]) ? null : (array) $options["ids"];
if (!is_array($ids) or !$ids) {
return;
}
ArrayHelper::toInteger($ids);
// Load project data
$query = $this->db->getQuery(true);
$query->select("a.id, a.txn_date, a.txn_id, a.txn_amount, a.txn_currency, a.txn_status, " . "a.extra_data, a.status_reason, a.project_id, a.reward_id, a.investor_id, " . "a.receiver_id, a.service_provider, a.reward_state")->from($this->db->quoteName("#__crowdf_transactions", "a"))->where("a.id IN ( " . implode(",", $ids) . " )");
// Filter by status.
$status = ArrayHelper::getValue($options, "txn_status", null, "cmd");
if (!empty($status)) {
$query->where("a.txn_status = " . $this->db->quote($status));
}
$this->db->setQuery($query);
$results = $this->db->loadObjectList();
// Convert JSON string into an array.
if (!empty($results)) {
foreach ($results as $key => $result) {
if (!empty($result->extra_data)) {
$result->extra_data = json_decode($result->extra_data, true);
$results[$key] = $result;
}
}
} else {
$results = array();
}
$this->items = $results;
}
示例3: getForm
/**
* Method to get the record form.
*
* @param array $data Data for the form.
* @param boolean $loadData True if the form is to load its own data (default case), false if not.
*
* @return JForm A JForm object on success, false on failure.
*
* @since 1.6
*/
public function getForm($data = array(), $loadData = true)
{
// The folder and element vars are passed when saving the form.
if (empty($data)) {
$item = $this->getItem();
$folder = $item->folder;
$element = $item->element;
} else {
$folder = ArrayHelper::getValue($data, 'folder', '', 'cmd');
$element = ArrayHelper::getValue($data, 'element', '', 'cmd');
}
// Add the default fields directory
JForm::addFieldPath(JPATH_PLUGINS . '/' . $folder . '/' . $element . '/field');
// These variables are used to add data from the plugin XML files.
$this->setState('item.folder', $folder);
$this->setState('item.element', $element);
// Get the form.
$form = $this->loadForm('com_plugins.plugin', 'plugin', array('control' => 'jform', 'load_data' => $loadData));
if (empty($form)) {
return false;
}
// Modify the form based on access controls.
if (!$this->canEditState((object) $data)) {
// Disable fields for display.
$form->setFieldAttribute('ordering', 'disabled', 'true');
$form->setFieldAttribute('enabled', 'disabled', 'true');
// Disable fields while saving.
// The controller has already verified this is a record you can edit.
$form->setFieldAttribute('ordering', 'filter', 'unset');
$form->setFieldAttribute('enabled', 'filter', 'unset');
}
return $form;
}
示例4: prepareRedirectLink
/**
* This method prepare a link where the user will be redirected
* after action he has done.
*
* <code>
* array(
* "view",
* "layout"
* "id",
* "url_var",
* "force_direction" // This is a link that will be used instead generated by the system.
* );
* </code>
* @param array $options
*
* @throws \InvalidArgumentException
*
* @return string
*/
protected function prepareRedirectLink($options)
{
$view = ArrayHelper::getValue($options, 'view');
$task = ArrayHelper::getValue($options, 'task');
$itemId = ArrayHelper::getValue($options, 'id', 0, 'uint');
$urlVar = ArrayHelper::getValue($options, 'url_var', 'id');
// Remove standard parameters
unset($options['view'], $options['task'], $options['id'], $options['url_var']);
$link = $this->defaultLink;
// Redirect to different of common views
if (null !== $view) {
$link .= '&view=' . $view;
if ($itemId > 0) {
$link .= $this->getRedirectToItemAppend($itemId, $urlVar);
} else {
$link .= $this->getRedirectToListAppend();
}
return $link;
}
// Prepare redirection
switch ($task) {
case 'apply':
$link .= '&view=' . $this->view_item . $this->getRedirectToItemAppend($itemId, $urlVar);
break;
case 'save2new':
$link .= '&view=' . $this->view_item . $this->getRedirectToItemAppend();
break;
default:
$link .= '&view=' . $this->view_list . $this->getRedirectToListAppend();
break;
}
// Generate additional parameters
$extraParams = $this->prepareExtraParameters($options);
return $link . $extraParams;
}
示例5: getAmount
/**
* Generate a string of amount based on location.
* The method uses PHP NumberFormatter ( Internationalization Functions ).
* If the internationalization library is not loaded, the method generates a simple string ( 100 USD, 500 EUR,... )
*
* <code>
* $options = array(
* "intl" => true",
* "locale" => "en_GB",
* "symbol" => "£",
* "position" => 0 // 0 for symbol on the left side, 1 for symbole on the right side.
* );
*
* $amount = Prism\Utilities\StringHelper::getAmount(100, GBP, $options);
*
* echo $amount;
* </code>
*
* @param float $amount Amount value.
* @param string $currency Currency Code ( GBP, USD, EUR,...)
* @param array $options Options - "intl", "locale", "symbol",...
*
* @return string
*/
public static function getAmount($amount, $currency, array $options = array())
{
$useIntl = ArrayHelper::getValue($options, 'intl', false, 'bool');
$locale = ArrayHelper::getValue($options, 'locale');
$symbol = ArrayHelper::getValue($options, 'symbol');
$position = ArrayHelper::getValue($options, 'position', 0, 'int');
// Use PHP Intl library.
if ($useIntl and extension_loaded('intl')) {
// Generate currency string using PHP NumberFormatter ( Internationalization Functions )
// Get current locale code.
if (!$locale) {
$lang = \JFactory::getLanguage();
$locale = $lang->getName();
}
$numberFormat = new \NumberFormatter($locale, \NumberFormatter::CURRENCY);
$result = $numberFormat->formatCurrency($amount, $currency);
} else {
// Generate a custom currency string.
if (\JString::strlen($symbol) > 0) {
// Symbol
if (0 === $position) {
// Symbol at the beginning.
$result = $symbol . $amount;
} else {
// Symbol at end.
$result = $amount . $symbol;
}
} else {
// Code
$result = $amount . $currency;
}
}
return $result;
}
示例6: sticky_publish
/**
* Stick items
*
* @return void
*
* @since 1.6
*/
public function sticky_publish()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$ids = $this->input->get('cid', array(), 'array');
$values = array('sticky_publish' => 1, 'sticky_unpublish' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');
if (empty($ids)) {
JError::raiseWarning(500, JText::_('COM_BANNERS_NO_BANNERS_SELECTED'));
} else {
// Get the model.
/** @var BannersModelBanner $model */
$model = $this->getModel();
// Change the state of the records.
if (!$model->stick($ids, $value)) {
JError::raiseWarning(500, $model->getError());
} else {
if ($value == 1) {
$ntext = 'COM_BANNERS_N_BANNERS_STUCK';
} else {
$ntext = 'COM_BANNERS_N_BANNERS_UNSTUCK';
}
$this->setMessage(JText::plural($ntext, count($ids)));
}
}
$this->setRedirect('index.php?option=com_banners&view=banners');
}
示例7: save
public function save($key = null, $urlVar = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$app = JFactory::getApplication();
/** @var $app JApplicationAdministrator */
$data = $app->input->post->get('jform', array(), 'array');
$itemId = ArrayHelper::getValue($data, 'id');
$redirectOptions = array('task' => $this->getTask(), 'id' => $itemId);
$model = $this->getModel();
/** @var $model GamificationModelPoint */
$form = $model->getForm($data, false);
/** @var $form JForm */
if (!$form) {
throw new Exception(JText::_('COM_GAMIFICATION_ERROR_FORM_CANNOT_BE_LOADED'));
}
// Validate the form
$validData = $model->validate($form, $data);
// Check for errors.
if ($validData === false) {
$this->displayNotice($form->getErrors(), $redirectOptions);
return;
}
try {
$itemId = $model->save($validData);
$redirectOptions['id'] = $itemId;
} catch (Exception $e) {
JLog::add($e->getMessage(), JLog::ERROR, 'com_gamification');
throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
}
$this->displayMessage(JText::_('COM_GAMIFICATION_POINTS_SAVED'), $redirectOptions);
}
示例8: load
/**
* Load locations data by ID from database.
*
* <code>
* $options = array(
* "ids" => array(1,2,3,4,5), // Load locations by IDs.
* "search" => "London" // It is a phrase for searching.
* );
*
* $locations = new Socialcommunity\Locations(JFactory::getDbo());
* $locations->load($options);
*
* foreach($locations as $location) {
* echo $location["name"];
* echo $location["country_code"];
* }
* </code>
*
* @param array $options
*/
public function load(array $options = array())
{
$ids = ArrayHelper::getValue($options, 'ids', array(), 'array');
$search = ArrayHelper::getValue($options, 'search', '', 'string');
$countryId = ArrayHelper::getValue($options, 'country_id', 0, 'int');
ArrayHelper::toInteger($ids);
$query = $this->db->getQuery(true);
$query->select('a.id, a.name, a.latitude, a.longitude, a.country_code, a.state_code, a.timezone, a.published')->from($this->db->quoteName('#__itpsc_locations', 'a'));
if (count($ids) > 0) {
$query->where('a.id IN ( ' . implode(',', $ids) . ' )');
}
// Filter by country ID ( use subquery to get country code ).
if ($countryId > 0) {
$subQuery = $this->db->getQuery(true);
$subQuery->select('sqc.code')->from($this->db->quoteName('#__itpsc_countries', 'sqc'))->where('sqc.id = ' . (int) $countryId);
$query->where('a.country_code = ( ' . $subQuery . ' )');
}
if ($query !== null and $query !== '') {
$escaped = $this->db->escape($search, true);
$quoted = $this->db->quote('%' . $escaped . '%', false);
$query->where('a.name LIKE ' . $quoted);
}
$this->db->setQuery($query);
$this->items = (array) $this->db->loadAssocList('id');
}
示例9: publish
/**
* Enable/Disable an extension (if supported).
*
* @return void
*
* @since 1.6
*/
public function publish()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$ids = $this->input->get('cid', array(), 'array');
$values = array('publish' => 1, 'unpublish' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');
if (empty($ids)) {
JError::raiseWarning(500, JText::_('COM_INSTALLER_ERROR_NO_EXTENSIONS_SELECTED'));
} else {
// Get the model.
$model = $this->getModel('manage');
// Change the state of the records.
if (!$model->publish($ids, $value)) {
JError::raiseWarning(500, implode('<br />', $model->getErrors()));
} else {
if ($value == 1) {
$ntext = 'COM_INSTALLER_N_EXTENSIONS_PUBLISHED';
} elseif ($value == 0) {
$ntext = 'COM_INSTALLER_N_EXTENSIONS_UNPUBLISHED';
}
$this->setMessage(JText::plural($ntext, count($ids)));
}
}
$this->setRedirect(JRoute::_('index.php?option=com_installer&view=manage', false));
}
示例10: save
public function save($key = null, $urlVar = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$data = $this->input->post->get('jform', array(), 'array');
$itemId = ArrayHelper::getValue($data, 'id');
$responseOptions = array('task' => $this->getTask(), 'id' => $itemId);
$model = $this->getModel();
/** @var $model EmailTemplatesModelEmail */
$form = $model->getForm($data, false);
/** @var $form JForm */
if (!$form) {
throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_FORM_CANNOT_BE_LOADED'));
}
// Validate the form data
$validData = $model->validate($form, $data);
// Check for errors
if ($validData === false) {
$this->displayNotice($form->getErrors(), $responseOptions);
return;
}
try {
$itemId = $model->save($validData);
$responseOptions['id'] = $itemId;
} catch (Exception $e) {
JLog::add($e->getMessage());
throw new Exception(JText::_('COM_EMAILTEMPLATES_ERROR_SYSTEM'));
}
$this->displayMessage(JText::_('COM_EMAILTEMPLATES_EMAIL_SAVED_SUCCESSFULLY'), $responseOptions);
}
示例11: save
public function save($key = null, $urlVar = null)
{
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$data = $this->input->post->get('jform', array(), 'array');
$itemId = ArrayHelper::getValue($data, "id");
$redirectData = array("task" => $this->getTask(), "id" => $itemId);
$model = $this->getModel();
/** @var $model GamificationModelRank */
$form = $model->getForm($data, false);
/** @var $form JForm */
if (!$form) {
throw new Exception(JText::_("COM_GAMIFICATION_ERROR_FORM_CANNOT_BE_LOADED"), 500);
}
// Validate the form
$validData = $model->validate($form, $data);
// Check for errors
if ($validData === false) {
$this->displayNotice($form->getErrors(), $redirectData);
return;
}
try {
$itemId = $model->save($validData);
$redirectData["id"] = $itemId;
} catch (Exception $e) {
JLog::add($e->getMessage());
throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
}
$this->displayMessage(JText::_('COM_GAMIFICATION_LEVEL_SAVED'), $redirectData);
}
示例12: read
public function read()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
// Get items to publish from the request.
$cid = $this->input->get('cid', array(), 'array');
$data = array('read' => 1, 'notread' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($data, $task, 0, 'int');
$redirectOptions = array("view" => "notifications");
// Make sure the item ids are integers
ArrayHelper::toInteger($cid);
if (empty($cid)) {
$this->displayNotice(JText::_($this->text_prefix . '_NO_ITEM_SELECTED'), $redirectOptions);
return;
}
try {
$model = $this->getModel();
$model->read($cid, $value);
} catch (RuntimeException $e) {
$this->displayWarning($e->getMessage(), $redirectOptions);
return;
} catch (Exception $e) {
JLog::add($e->getMessage());
throw new Exception(JText::_('COM_GAMIFICATION_ERROR_SYSTEM'));
}
if ($value == 1) {
$msg = $this->text_prefix . '_N_ITEMS_READ';
} else {
$msg = $this->text_prefix . '_N_ITEMS_NOT_READ';
}
$this->displayMessage(JText::plural($msg, count($cid)), $redirectOptions);
}
示例13: renderListData
/**
* Shows the data formatted for the list view
*
* @param string $data Elements data
* @param stdClass &$thisRow All the data in the lists current row
* @param array $opts Rendering options
*
* @return string formatted value
*/
public function renderListData($data, stdClass &$thisRow, $opts = array())
{
$listModel = $this->getListModel();
$params = $this->getParams();
$w = (int) $params->get('fb_gm_table_mapwidth');
$h = (int) $params->get('fb_gm_table_mapheight');
$z = (int) $params->get('fb_gm_table_zoomlevel');
$data = FabrikWorker::JSONtoData($data, true);
foreach ($data as $i => &$d) {
if ($params->get('fb_gm_staticmap_tableview')) {
$d = $this->_staticMap($d, $w, $h, $z, $i, true, ArrayHelper::fromObject($thisRow));
}
if ($params->get('icon_folder') == '1' && ArrayHelper::getValue($opts, 'icon', 1)) {
// $$$ rob was returning here but that stopped us being able to use links and icons together
$d = $this->replaceWithIcons($d, 'list', $listModel->getTmpl());
} else {
if (!$params->get('fb_gm_staticmap_tableview')) {
$d = $params->get('fb_gm_staticmap_tableview_type_coords', 'num') == 'dms' ? $this->_dmsformat($d) : $this->_microformat($d);
}
}
if (ArrayHelper::getValue($opts, 'rollover', 1)) {
$d = $this->rollover($d, $thisRow, 'list');
}
if (ArrayHelper::getValue($opts, 'link', 1)) {
$d = $listModel->_addLink($d, $this, $thisRow, $i);
}
}
return $this->renderListDataFinal($data);
}
示例14: featured
/**
* Method to toggle the featured setting of a list of contacts.
*
* @return void
*
* @since 1.6
*/
public function featured()
{
// Check for request forgeries
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$ids = $this->input->get('cid', array(), 'array');
$values = array('featured' => 1, 'unfeatured' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');
// Get the model.
/** @var ContactModelContact $model */
$model = $this->getModel();
// Access checks.
foreach ($ids as $i => $id) {
$item = $model->getItem($id);
if (!JFactory::getUser()->authorise('core.edit.state', 'com_contact.category.' . (int) $item->catid)) {
// Prune items that you can't change.
unset($ids[$i]);
JError::raiseNotice(403, JText::_('JLIB_APPLICATION_ERROR_EDITSTATE_NOT_PERMITTED'));
}
}
if (empty($ids)) {
JError::raiseWarning(500, JText::_('COM_CONTACT_NO_ITEM_SELECTED'));
} else {
// Publish the items.
if (!$model->featured($ids, $value)) {
JError::raiseWarning(500, $model->getError());
}
}
$this->setRedirect('index.php?option=com_contact&view=contacts');
}
示例15: load
/**
* Load transactions from database.
*
* <code>
* $options = array(
* "ids" => array(1,2,3),
* "txn_status" => "completed"
* );
*
* $transactions = new Crowdfunding\Transactions(\JFactory::getDbo());
* $transactions->load($options);
*
* foreach($transactions as $transaction) {
* echo $transaction->txn_id;
* echo $transaction->txn_amount;
* }
*
* </code>
*
* @param array $options
*
* @throws \UnexpectedValueException
*/
public function load($options = array())
{
$ids = !array_key_exists('ids', $options) ? array() : (array) $options['ids'];
$ids = ArrayHelper::toInteger($ids);
$results = array();
if (count($ids) > 0) {
// Load project data
$query = $this->db->getQuery(true);
$query->select('a.id, a.txn_date, a.txn_id, a.txn_amount, a.txn_currency, a.txn_status, ' . 'a.extra_data, a.status_reason, a.project_id, a.reward_id, a.investor_id, ' . 'a.receiver_id, a.service_provider, a.service_alias, a.reward_state')->from($this->db->quoteName('#__crowdf_transactions', 'a'))->where('a.id IN ( ' . implode(',', $ids) . ' )');
// Filter by status.
$status = ArrayHelper::getValue($options, 'txn_status', null, 'cmd');
if ($status !== null) {
$query->where('a.txn_status = ' . $this->db->quote($status));
}
$this->db->setQuery($query);
$results = (array) $this->db->loadAssocList();
// Convert JSON string into an array.
if (count($results) > 0) {
foreach ($results as $key => &$result) {
if (!empty($result['extra_data'])) {
$result['extra_data'] = json_decode($result['extra_data'], true);
}
}
unset($result);
}
}
$this->items = $results;
}