本文整理汇总了PHP中Joomla\Utilities\ArrayHelper类的典型用法代码示例。如果您正苦于以下问题:PHP ArrayHelper类的具体用法?PHP ArrayHelper怎么用?PHP ArrayHelper使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ArrayHelper类的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: 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');
}
示例3: load
/**
* Load data about updates from database by project ID.
*
* <code>
* $options = array(
* "project_id" => 1, // It can also be an array with IDs.
* "period" => 7, // Period in days
* "limit" => 10 // Limit the results
* );
*
* $updates = new Crowdfunding\Updates(\JFactory::getDbo());
* $updates->load($options);
*
* foreach($updates as $item) {
* echo $item->title;
* echo $item->record_date;
* }
* </code>
*
* @param array $options
*/
public function load(array $options = array())
{
$query = $this->db->getQuery(true);
$query->select('a.id, a.title, a.description, a.record_date, a.project_id')->from($this->db->quoteName('#__crowdf_updates', 'a'));
// Filter by IDs.
$ids = ArrayHelper::getValue($options, 'ids', array(), 'array');
if (count($ids) > 0) {
$query->where('a.ids IN (' . implode(',', $ids) . ')');
}
// Filter by project ID.
$projectId = ArrayHelper::getValue($options, 'project_id', 0, 'int');
if ($projectId > 0) {
$query->where('a.project_id = ' . (int) $projectId);
}
// Filter by period.
$period = ArrayHelper::getValue($options, 'period', 0, 'int');
if ($period > 0) {
$query->where('a.record_date >= DATE_SUB(NOW(), INTERVAL ' . $period . ' DAY)');
}
// Set limit.
$limit = ArrayHelper::getValue($options, 'limit', 0, 'int');
if ($limit > 0) {
$this->db->setQuery($query, 0, $limit);
} else {
$this->db->setQuery($query);
}
$this->items = (array) $this->db->loadAssocList();
}
示例4: 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);
}
示例5: 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);
}
示例6: array
/**
* Get the lists that contain events
*
* @return array
*/
public function &getEventLists()
{
if (is_null($this->eventLists)) {
$this->eventLists = array();
$db = FabrikWorker::getDbo(true);
$params = $this->getParams();
$lists = (array) $params->get('calendar_table');
$lists = ArrayHelper::toInteger($lists);
$dateFields = (array) $params->get('calendar_startdate_element');
$dateFields2 = (array) $params->get('calendar_enddate_element');
$labels = (array) $params->get('calendar_label_element');
$stati = (array) $params->get('status_element');
$colours = (array) $params->get('colour');
$query = $db->getQuery(true);
$query->select('id AS value, label AS text')->from('#__{package}_lists')->where('id IN (' . implode(',', $lists) . ')');
$db->setQuery($query);
$rows = $db->loadObjectList();
for ($i = 0; $i < count($rows); $i++) {
if (!isset($colours[$i])) {
$colours[$i] = '';
}
if (!isset($stati[$i])) {
$stati[$i] = '';
}
$rows[$i]->startdate_element = $dateFields[$i];
$rows[$i]->enddate_element = FArrayHelper::getValue($dateFields2, $i);
$rows[$i]->label_element = $labels[$i];
$rows[$i]->status = FArrayHelper::getValue($stati, $i, '');
$rows[$i]->colour = $colours[$i];
}
$this->eventLists = $rows;
}
return $this->eventLists;
}
示例7: publish
/**
* Method to set the publishing state for a row or list of rows in the database
* table. The method respects checked out rows by other users and will attempt
* to checkin rows that it can after adjustments are made.
*
* @param mixed $pks An array of primary key values to update. If not
* set the instance property value is used. [optional]
* @param integer $state The publishing state. eg. [0 = unpublished, 1 = published] [optional]
* @param integer $userId The user id of the user performing the operation. [optional]
*
* @return boolean True on success.
*
* @since 2.5
*/
public function publish($pks = null, $state = 1, $userId = 0)
{
$k = $this->_tbl_key;
// Sanitize input.
$pks = ArrayHelper::toInteger($pks);
$state = (int) $state;
// If there are no primary keys set check to see if the instance key is set.
if (empty($pks)) {
if ($this->{$k}) {
$pks = array($this->{$k});
} else {
$this->setError(JText::_('JLIB_DATABASE_ERROR_NO_ROWS_SELECTED'));
return false;
}
}
// Build the WHERE clause for the primary keys.
$where = $k . '=' . implode(' OR ' . $k . '=', $pks);
// Update the publishing state for rows with the given primary keys.
$query = $this->_db->getQuery(true)->update($this->_db->quoteName($this->_tbl))->set($this->_db->quoteName('state') . ' = ' . (int) $state)->where($where);
$this->_db->setQuery($query);
try {
$this->_db->execute();
} catch (RuntimeException $e) {
$this->setError($e->getMessage());
return false;
}
// If the JTable instance value is in the list of primary keys that were set, set the instance.
if (in_array($this->{$k}, $pks)) {
$this->state = $state;
}
$this->setError('');
return true;
}
示例8: fkData
/**
* Get the foreign keys value.
*
* @return mixed string|int
*/
protected function fkData()
{
if (!isset($this->fkData)) {
/** @var FabrikFEModelForm $formModel */
$formModel = $this->getModel();
$params = $this->getParams();
$this->fkData = array();
// Get the foreign key element
$fkElement = $this->fkElement();
if ($fkElement) {
$fkElementKey = $fkElement->getFullName();
$this->fkData = json_decode(FArrayHelper::getValue($formModel->formData, $fkElementKey));
if (is_object($this->fkData)) {
$this->fkData = ArrayHelper::fromObject($this->fkData);
}
$fkEval = $params->get('foreign_key_eval', '');
if ($fkEval !== '') {
$fkData = $this->fkData;
$eval = eval($fkEval);
if ($eval !== false) {
$this->fkData = $eval;
}
}
}
}
return $this->fkData;
}
示例9: 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;
}
示例10: changeBlock
/**
* Method to change the block status on a record.
*
* @return void
*
* @since 1.6
*/
public function changeBlock()
{
// Check for request forgeries.
JSession::checkToken() or jexit(JText::_('JINVALID_TOKEN'));
$ids = $this->input->get('cid', array(), 'array');
$values = array('block' => 1, 'unblock' => 0);
$task = $this->getTask();
$value = ArrayHelper::getValue($values, $task, 0, 'int');
if (empty($ids)) {
JError::raiseWarning(500, JText::_('COM_USERS_USERS_NO_ITEM_SELECTED'));
} else {
// Get the model.
$model = $this->getModel();
// Change the state of the records.
if (!$model->block($ids, $value)) {
JError::raiseWarning(500, $model->getError());
} else {
if ($value == 1) {
$this->setMessage(JText::plural('COM_USERS_N_USERS_BLOCKED', count($ids)));
} elseif ($value == 0) {
$this->setMessage(JText::plural('COM_USERS_N_USERS_UNBLOCKED', count($ids)));
}
}
}
$this->setRedirect('index.php?option=com_users&view=users');
}
示例11: setFieldSets
/**
* Set which fieldsets should be used
*
* @since 3.0.7
*
* @return array fieldset names
*/
private function setFieldSets()
{
$input = $this->app->input;
// From list data view in admin
$id = $input->getInt('listid', 0);
// From list of lists checkbox selection
$cid = $input->get('cid', array(0), 'array');
$cid = ArrayHelper::toInteger($cid);
if ($id === 0) {
$id = $cid[0];
}
if ($id !== 0) {
$db = FabrikWorker::getDbo();
$query = $db->getQuery(true);
$query->select('label')->from('#__{package}_lists')->where('id = ' . $id);
$db->setQuery($query);
$this->listName = $db->loadResult();
}
$fieldsets = array('details');
if ($this->model->canEmpty()) {
$fieldsets[] = 'drop';
}
$fieldsets[] = $id === 0 ? 'creation' : 'append';
$fieldsets[] = 'format';
return $fieldsets;
}
示例12: getOptions
/**
* Method to get the field options.
*
* @return array The field option objects.
*
* @since 3.6.0
*/
public function getOptions()
{
$lang = JFactory::getLanguage();
$options = array();
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select($db->quoteName('id', 'value'))->select($db->quoteName('title', 'text'))->from($db->quoteName('#__finder_types'));
// Get the options.
$db->setQuery($query);
try {
$contentTypes = $db->loadObjectList();
} catch (RuntimeException $e) {
JError::raiseWarning(500, $db->getMessage());
}
// Translate.
foreach ($contentTypes as $contentType) {
$key = FinderHelperLanguage::branchSingular($contentType->text);
$contentType->translatedText = $lang->hasKey($key) ? JText::_($key) : $contentType->text;
}
// Order by title.
$contentTypes = ArrayHelper::sortObjects($contentTypes, 'translatedText', 1, true, true);
// Convert the values to options.
foreach ($contentTypes as $contentType) {
$options[] = JHtml::_('select.option', $contentType->value, $contentType->translatedText);
}
// Merge any additional options in the XML definition.
$options = array_merge(parent::getOptions(), $options);
return $options;
}
示例13: association
/**
* Render the list of associated items
*
* @param integer $catid Category identifier to search its associations
* @param string $extension Category Extension
*
* @return string The language HTML
*
* @since 3.2
* @throws Exception
*/
public static function association($catid, $extension = 'com_content')
{
// Defaults
$html = '';
// Get the associations
if ($associations = CategoriesHelper::getAssociations($catid, $extension)) {
$associations = ArrayHelper::toInteger($associations);
// Get the associated categories
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select('c.id, c.title')->select('l.sef as lang_sef')->select('l.lang_code')->from('#__categories as c')->where('c.id IN (' . implode(',', array_values($associations)) . ')')->join('LEFT', '#__languages as l ON c.language=l.lang_code')->select('l.image')->select('l.title as language_title');
$db->setQuery($query);
try {
$items = $db->loadObjectList('id');
} catch (RuntimeException $e) {
throw new Exception($e->getMessage(), 500, $e);
}
if ($items) {
foreach ($items as &$item) {
$text = $item->lang_sef ? strtoupper($item->lang_sef) : 'XX';
$url = JRoute::_('index.php?option=com_categories&task=category.edit&id=' . (int) $item->id . '&extension=' . $extension);
$classes = 'hasPopover label label-association label-' . $item->lang_sef;
$item->link = '<a href="' . $url . '" title="' . $item->language_title . '" class="' . $classes . '" data-content="' . $item->title . '" data-placement="top">' . $text . '</a>';
}
}
JHtml::_('bootstrap.popover');
$html = JLayoutHelper::render('joomla.content.associations', $items);
}
return $html;
}
示例14: mapslist
/**
* Creates a list of maps.
*
* @return array An array containing the maps that can be selected.
*
* @since 2.5
*/
public static function mapslist()
{
$lang = JFactory::getLanguage();
// Load the finder types.
$db = JFactory::getDbo();
$query = $db->getQuery(true)->select($db->quoteName('title', 'text'))->select($db->quoteName('id', 'value'))->from($db->quoteName('#__finder_taxonomy'))->where($db->quoteName('parent_id') . ' = 1');
$db->setQuery($query);
try {
$branches = $db->loadObjectList();
} catch (RuntimeException $e) {
JError::raiseWarning(500, $db->getMessage());
}
// Translate.
foreach ($branches as $branch) {
$key = FinderHelperLanguage::branchPlural($branch->text);
$branch->translatedText = $lang->hasKey($key) ? JText::_($key) : $branch->text;
}
// Order by title.
$branches = ArrayHelper::sortObjects($branches, 'translatedText', 1, true, true);
// Compile the options.
$options = array();
$options[] = JHtml::_('select.option', '', JText::_('COM_FINDER_MAPS_SELECT_BRANCH'));
// Convert the values to options.
foreach ($branches as $branch) {
$options[] = JHtml::_('select.option', $branch->value, $branch->translatedText);
}
return $options;
}
示例15: 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;
}