1981 lines
57 KiB
PHP
1981 lines
57 KiB
PHP
<?php
|
|
|
|
/**
|
|
* SOTESHOP/stAdminGeneratorPlugin
|
|
*
|
|
* Ten plik należy do aplikacji stAdminGeneratorPlugin opartej na licencji (Open License SOTE) Otwarta Licencja SOTE.
|
|
* Nie zmieniaj tego pliku, jeśli chcesz korzystać z automatycznych aktualizacji oprogramowania.
|
|
* Jeśli chcesz wprowadzać swoje modyfikacje do programu, zapoznaj się z dokumentacją, jak zmieniać
|
|
* oprogramowanie bez zmiany kodu bazowego http://www.sote.pl/modifications
|
|
*
|
|
* @package stAdminGeneratorPlugin
|
|
* @subpackage helpers
|
|
* @copyright SOTE (www.sote.pl)
|
|
* @license http://www.sote.pl/license/open (Open License SOTE) Otwarta Licencja SOTE
|
|
* @version $Id: stAdminGeneratorHelper.php 17502 2012-03-22 15:35:51Z marcin $
|
|
*/
|
|
use_helper('Tag', 'Asset', 'nifty', 'Validation', 'stBackend', 'stPrice', 'Form');
|
|
|
|
/**
|
|
* Sprawdza czy dane pole jest usunięte
|
|
*
|
|
* @param string $name
|
|
* @return bool
|
|
*/
|
|
function st_admin_is_field_removed($name)
|
|
{
|
|
$context = sfContext::getInstance();
|
|
$user = $context->getUser();
|
|
$module = $context->getModuleName();
|
|
|
|
return $user->getParameter($name, false, 'soteshop/stAdminGenerator/removed') || $user->getParameter('hide', false, "{$module}/edit/fields/{$name}");
|
|
}
|
|
|
|
/**
|
|
* Sprawdza czy dane pole jest ukryte
|
|
*
|
|
* @param string $name
|
|
* @return bool
|
|
*/
|
|
function st_admin_is_field_hidden($name)
|
|
{
|
|
return sfContext::getInstance()->getUser()->getParameter($name, false, 'soteshop/stAdminGenerator/hidden');
|
|
}
|
|
|
|
/**
|
|
* Sprawdza czy akcja o podnej nazwie jest ukryta
|
|
*
|
|
* @param string $name
|
|
* @return bool
|
|
*/
|
|
function st_admin_is_action_hidden($name)
|
|
{
|
|
return sfContext::getInstance()->getUser()->getParameter($name, false, 'soteshop/stAdminGenerator/actions/hidden');
|
|
}
|
|
|
|
/**
|
|
* Zwraca sciężkę do szablonu wygenerowanego przez generator
|
|
*
|
|
* @param string $templatePath Scieżka do szablonu
|
|
* @param string $moduleName Opcjonalna nazwa modułu
|
|
* @return string
|
|
*/
|
|
function st_admin_get_template_path(string $templatePath, ?string $moduleName = null)
|
|
{
|
|
$fileName = basename($templatePath);
|
|
|
|
if (null === $moduleName)
|
|
{
|
|
$moduleName = basename(dirname(dirname($templatePath)));
|
|
}
|
|
|
|
$path = sfConfig::get('sf_module_cache_dir') . '/auto' . ucfirst($moduleName) . '/templates/' . $fileName;
|
|
|
|
if (!is_file($path))
|
|
{
|
|
throw new sfException(sprintf('Template "%s" doest not exist', $path));
|
|
}
|
|
|
|
return $path;
|
|
}
|
|
|
|
/**
|
|
* Zwraca tekst automatycznie przycięty do zawartości w której się znajduje
|
|
*
|
|
* @param string $text Tekst do przycięcia
|
|
* @param int $maxLines Maksymalna ilość linii do jakiej ma zostać przycięty tekst (domyślnie 2)
|
|
* @param bool $expandable Określa czy tekst można rozwijać
|
|
* @return string
|
|
*/
|
|
function st_admin_truncate_text($text, $maxLines = null, $expandable = false, $stripTags = true)
|
|
{
|
|
$params = [
|
|
'style' => null !== $maxLines ? '--truncate-text-lines: '.$maxLines .';' : '',
|
|
'class' => 'truncate-text-container',
|
|
];
|
|
|
|
if (1 == $maxLines)
|
|
{
|
|
$params['style'] .= 'word-break: break-all';
|
|
}
|
|
|
|
$content = content_tag('span', $stripTags ? strip_tags($text, 'b') : $text, $params);
|
|
|
|
if ($expandable) {
|
|
$content .= st_get_admin_button('expand', null, '#', ['class' => 'truncate-text-expand-button', 'size' => 'small']);
|
|
}
|
|
|
|
return content_tag('span', $content, ['class' => $expandable ? 'truncate-text expandable' : 'truncate-text']);
|
|
}
|
|
|
|
function st_admin_get_viewport_width_button()
|
|
{
|
|
return content_tag('a', st_admin_get_icon('expand-h', ['class' => 'viewport-expand']) . st_admin_get_icon('shrink-h', ['class' => 'viewport-shrink']), [
|
|
'href' => st_url_for('stBackend/changeContentViewport'),
|
|
'id' => 'viewport-width',
|
|
'class' => st_admin_get_configuration_param('viewport.expanded') ? "viewport-expanded" : "",
|
|
]);
|
|
}
|
|
|
|
function st_admin_get_viewport_force_width()
|
|
{
|
|
return javascript_tag('jQuery("#content-viewport").addClass("content-viewport-force-width")');
|
|
}
|
|
|
|
function st_admin_get_favorites()
|
|
{
|
|
$config = stAdminGeneratorUserConfiguration::getDefault(sfContext::getInstance());
|
|
|
|
$favorites = $config->getParameter('favorites');
|
|
|
|
if (null === $favorites)
|
|
{
|
|
$favorites = array(
|
|
'stOrder/list' => __('Zamówienia', null, 'stOrder'),
|
|
'stProduct/list' => __('Produkty', null, 'stProduct'),
|
|
'stCategory/manager' => __('Kategorie', null, 'stCategory'),
|
|
'stUser/list' => __('Klienci', null, 'stUser'),
|
|
);
|
|
|
|
$config->setParameter('favorites', $favorites);
|
|
$config->save();
|
|
}
|
|
|
|
asort($favorites, SORT_NATURAL);
|
|
|
|
return $favorites;
|
|
}
|
|
|
|
function st_admin_get_configuration_param($name, $default = null)
|
|
{
|
|
$config = stAdminGeneratorUserConfiguration::getDefault(sfContext::getInstance());
|
|
|
|
return $config->getParameter($name, $default);
|
|
}
|
|
|
|
function st_admin_form_tag_start($url, array $options = array())
|
|
{
|
|
$options['class'] = isset($options['class']) ? $options['class'] . ' admin_form' : 'admin_form';
|
|
$options['multipart'] = true;
|
|
|
|
return form_tag($url, $options);
|
|
}
|
|
|
|
function st_admin_form_tag_end()
|
|
{
|
|
return '</form>';
|
|
}
|
|
|
|
function st_admin_object_plain_field_tag(BaseObject $object, string $methodName, array $options = [])
|
|
{
|
|
$value = _get_object_value($object, $methodName);
|
|
|
|
return st_admin_plain_field_tag($value, $options);
|
|
}
|
|
|
|
function st_admin_plain_field_tag($value, array $options = [])
|
|
{
|
|
$type = null;
|
|
$options['class'] = isset($options['class']) ? $options['class'].' plain-field' : 'plain-field';
|
|
|
|
if (isset($options['format_type']))
|
|
{
|
|
$type = $options['type'];
|
|
unset($options['type']);
|
|
}
|
|
|
|
if (null !== $type && $type == 'bool')
|
|
{
|
|
$value = !empty($value) ? __('Tak', null, 'stAdminGeneratorPlugin') : __('Nie', null, 'stAdminGeneratorPlugin');
|
|
}
|
|
|
|
return content_tag('div', $value, $options);
|
|
}
|
|
|
|
function st_admin_yesno_select_tag($name, $value, array $options = array())
|
|
{
|
|
$itemOptions = array();
|
|
|
|
if (isset($options['include_custom']))
|
|
{
|
|
$itemOptions['include_custom'] = $options['include_custom'];
|
|
unset($options['include_custom']);
|
|
}
|
|
|
|
$selectItems = array(
|
|
1 => __('tak', null, 'stAdminGeneratorPlugin'),
|
|
0 => __('nie', null, 'stAdminGeneratorPlugin'),
|
|
);
|
|
|
|
return select_tag($name, options_for_select($selectItems, $value, $itemOptions), $options);
|
|
}
|
|
|
|
function st_admin_input_file_tag($name, $value = null, array $options = array())
|
|
{
|
|
static $init = false;
|
|
$files = array();
|
|
$script = null;
|
|
$image = false;
|
|
$remove = null;
|
|
$request = sfContext::getInstance()->getRequest();
|
|
$withUploadDir = false;
|
|
|
|
if (!isset($options['upload_dir']))
|
|
{
|
|
throw new Exception('upload_dir option is mandatory');
|
|
}
|
|
|
|
if (isset($options['image']) && $options['image'])
|
|
{
|
|
$image = true;
|
|
|
|
if (!isset($options['accept']))
|
|
{
|
|
$options['accept'] = 'image/jpeg,image/gif,image/png,image/webp,image/apng';
|
|
}
|
|
|
|
unset($options['image']);
|
|
}
|
|
|
|
if (isset($options['allow_remove']))
|
|
{
|
|
$remove = is_string($options['allow_remove']) ? $options['allow_remove'] : 'usuń';
|
|
unset($options['allow_remove']);
|
|
}
|
|
|
|
if (isset($options['with_upload_dir']))
|
|
{
|
|
$withUploadDir = $options['with_upload_dir'];
|
|
unset($options['with_upload_dir']);
|
|
}
|
|
|
|
if (is_array($options['accept']))
|
|
{
|
|
$options['accept'] = implode(',', $options['accept']);
|
|
}
|
|
|
|
$uploadDir = $options['upload_dir'];
|
|
unset($options['upload_dir']);
|
|
|
|
$content = input_file_tag(isset($options['multiple']) ? $name.'[]' : $name, $options);
|
|
|
|
if ($value)
|
|
{
|
|
$files = is_array($value) ? $value : array($value);
|
|
}
|
|
|
|
$filesContent = '';
|
|
|
|
foreach ($files as $file)
|
|
{
|
|
$filepath = $withUploadDir ? '/' . $file : '/' . sfConfig::get('sf_upload_dir_name') . '/' . $uploadDir . '/' . $file;
|
|
|
|
if (is_file(sfConfig::get('sf_web_dir').$filepath))
|
|
{
|
|
$filename = basename($file);
|
|
|
|
$actions = st_get_admin_button('download', $image ? null : $filename, $filepath, array('target' => '_blank', 'download' => $filename, 'class' => 'action action-download', 'size' => 'small'));
|
|
|
|
if ($remove)
|
|
{
|
|
$actions .= st_get_admin_button('delete', null, '#', array('class' => 'action action-delete', 'size' => 'small', 'icon' => 'close'));
|
|
}
|
|
|
|
$fileContent = content_tag('div', $actions, array('class' => 'actions'));
|
|
|
|
if ($file)
|
|
{
|
|
if ($image)
|
|
{
|
|
$fileContent .= image_tag($filepath, array('alt' => $file));
|
|
}
|
|
}
|
|
|
|
$filesContent .= content_tag('div', $fileContent, array('class' => 'file', 'data-filename' => $filename));
|
|
}
|
|
}
|
|
|
|
$content .= content_tag('div', $filesContent, array('class' => "files"));
|
|
|
|
$containerOptions = array('class' => 'st-admin-input-file-tag');
|
|
|
|
if ($image)
|
|
{
|
|
$containerOptions['class'] .= ' image-preview';
|
|
}
|
|
|
|
$removeName = strpos($name, ']') !== false ? substr($name, 0, -1).'_remove]' : $name.'_remove';
|
|
$orderName = strpos($name, ']') !== false ? substr($name, 0, -1).'_order]' : $name.'_order';
|
|
|
|
$content .= input_hidden_tag($orderName, implode("::", $files), array('class' => 'file-order'));
|
|
|
|
foreach ($request->getParameter($removeName, array()) as $removeFile)
|
|
{
|
|
$content .= input_hidden_tag($removeName.'[]', $removeFile);
|
|
}
|
|
|
|
if (!$init)
|
|
{
|
|
$confirmDeleteMessage = __('Zamierzasz usunąć plik. Jesteś pewien?');
|
|
|
|
$init = true;
|
|
|
|
$script =<<<JS
|
|
jQuery(function($) {
|
|
$(document).ready(function() {
|
|
let = container = $('.st-admin-input-file-tag');
|
|
container.on("click", ".action-delete", function() {
|
|
if (window.confirm("{$confirmDeleteMessage}"))
|
|
{
|
|
let action = $(this);
|
|
let file = action.closest('.file');
|
|
action.closest('.file').hide();
|
|
container.append('<input name="{$removeName}[]" type="hidden" value="'+file.data('filename')+'">');
|
|
}
|
|
return false;
|
|
});
|
|
});
|
|
});
|
|
JS;
|
|
$script = javascript_tag($script);
|
|
}
|
|
|
|
return content_tag('div', $content, $containerOptions).$script;
|
|
}
|
|
|
|
function object_st_admin_input_file_tag($object, $method, $options = array(), $default_value = null)
|
|
{
|
|
$options = _parse_attributes($options);
|
|
$value = _get_object_value($object, $method, $default_value);
|
|
$name = _convert_method_to_name($method, $options);
|
|
|
|
return st_admin_input_file_tag($name, $value, $options);
|
|
}
|
|
|
|
function st_admin_table_record_manager($namespace, array $fields, array $values, array $options = array())
|
|
{
|
|
$version = stApplication::getApplicationVersion('stBase');
|
|
use_javascript('/jQueryTools/stTableRecordManager/js/script.js?v'.$version);
|
|
use_stylesheet('/jQueryTools/stTableRecordManager/css/style.css?v'.$version);
|
|
$labels = array();
|
|
$templateFields = array();
|
|
$disabled = false;
|
|
|
|
if (isset($options['disabled']))
|
|
{
|
|
$disabled = $options['disabled'];
|
|
unset($options['disabled']);
|
|
}
|
|
|
|
$id = 'st_trm_'.get_id_from_name($namespace);
|
|
$confirmMsg = __('Jesteś pewien?', null, 'stAdminGeneratorPlugin');
|
|
$removeAction = link_to(st_admin_get_icon('delete-circle', array('size' => 'medium')), '#', array('class' => 'remove'));
|
|
$createAction = link_to(st_admin_get_icon('add-circle', array('size' => 'medium')), '#', array('class' => 'create'));
|
|
|
|
foreach ($fields as $name => $field)
|
|
{
|
|
$fieldOptions = isset($field['options']) ? $field['options'] : array();
|
|
$type = isset($field['type']) ? $field['type'] : null;
|
|
$value = isset($field['value']) ? $field['value'] : null;
|
|
$label = array('label' => $field['label'], 'options' => array('class' => 'st_trm_field_'.$name));
|
|
|
|
if (isset($field['width']))
|
|
{
|
|
$label['options']['width'] = $field['width'];
|
|
}
|
|
|
|
$labels[] = $label;
|
|
|
|
if ($type == 'checkbox_tag')
|
|
{
|
|
$fieldOptions['checked'] = $value;
|
|
$value = 1;
|
|
}
|
|
|
|
$fieldOptions['id'] = $id . '_' . $name;
|
|
|
|
$templateField = array(
|
|
'label' => st_admin_get_form_field($name, false, $value, $type, $fieldOptions),
|
|
'options' => array('class' => 'st_trm_field_'.$name),
|
|
);
|
|
|
|
$templateFields[] = $templateField;
|
|
}
|
|
|
|
if (!$disabled)
|
|
{
|
|
$labels[] = array('label' => '', 'options' => array('class' => 'actions'));
|
|
$templateFields[] = array('label' => $createAction.$removeAction, 'options' => array('class' => 'actions'));
|
|
}
|
|
|
|
ob_start();
|
|
|
|
$rows = array(
|
|
array('columns' => $labels),
|
|
);
|
|
|
|
if (!$disabled)
|
|
{
|
|
$rows[1] = array(
|
|
'columns' => $templateFields,
|
|
'options' => array('class' => 'template')
|
|
);
|
|
}
|
|
|
|
st_admin_table_start(array('rows' => $rows), array_merge($options, array('class' => 'st_record_manager', 'id' => $id)));
|
|
|
|
echo "<tbody>";
|
|
|
|
foreach ($values as $index => $current)
|
|
{
|
|
echo "<tr>";
|
|
|
|
foreach ($fields as $name => $field)
|
|
{
|
|
$type = isset($field['type']) ? $field['type'] : null;
|
|
|
|
$value = isset($current[$name]) ? $current[$name] : null;
|
|
$fieldOptions = isset($field['options']) ? $field['options'] : array();
|
|
|
|
|
|
if ($type == 'checkbox_tag')
|
|
{
|
|
$fieldOptions['checked'] = $value;
|
|
$value = 1;
|
|
}
|
|
|
|
echo content_tag('td', st_admin_get_form_field("{$namespace}[$index][$name]", false, $value, $type, $fieldOptions));
|
|
}
|
|
|
|
if (!$disabled)
|
|
{
|
|
echo content_tag('td', $removeAction, array('class' => 'actions'));
|
|
}
|
|
|
|
echo "</tr>";
|
|
}
|
|
|
|
echo '</tbody>';
|
|
|
|
st_admin_table_end();
|
|
|
|
if (!$disabled)
|
|
{
|
|
echo javascript_tag("jQuery(function(\$) { \$('#{$id}').stTableRecordManager({ namespace: '$namespace', confirmMsg: '$confirmMsg' }); });");
|
|
}
|
|
|
|
return ob_get_clean();
|
|
}
|
|
|
|
/**
|
|
* Rozpoczyna tabele
|
|
*
|
|
* @param array $options Opcjonalne atrybuty html
|
|
* @return void
|
|
*/
|
|
function st_admin_table_start(array $columns = array(), array $options = array())
|
|
{
|
|
$options['class'] = isset($options['class']) ? 'st_record_list record_list ' . $options['class'] : 'st_record_list record_list';
|
|
$options['cellpadding'] = 0;
|
|
$options['cellspacing'] = 0;
|
|
|
|
if (!isset($options['style']))
|
|
{
|
|
$options['style'] = '';
|
|
}
|
|
|
|
if (isset($options['stretch']))
|
|
{
|
|
$options['class'] .= ' st-responsive';
|
|
unset($options['stretch']);
|
|
}
|
|
|
|
if (isset($options['align']))
|
|
{
|
|
$options['class'] .= ' text-' . $options['align'];
|
|
unset($options['align']);
|
|
}
|
|
|
|
if (isset($options['min_width']))
|
|
{
|
|
$options['style'] .= '; min-width: ' . (false === $options['min_width'] ? 0 : $options['min_width']);
|
|
unset($options['min_width']);
|
|
}
|
|
|
|
if (isset($options['highlight']) && false === $options['highlight'])
|
|
{
|
|
$options['class'] .= ' st_no_highlight';
|
|
unset($options['highlight']);
|
|
}
|
|
|
|
if (isset($options['compact']) && $options['compact'])
|
|
{
|
|
$options['class'] .= ' st_compact';
|
|
}
|
|
|
|
echo tag('table', $options, true);
|
|
|
|
if ($columns)
|
|
{
|
|
$rows = isset($columns['rows']) ? $columns['rows'] : array(
|
|
array('columns' => $columns),
|
|
);
|
|
|
|
echo '<thead>';
|
|
|
|
foreach ($rows as $row)
|
|
{
|
|
$rowOptions = isset($row['options']) ? $row['options'] : array();
|
|
|
|
echo tag('tr', $rowOptions, false);
|
|
|
|
foreach ($row['columns'] as $column)
|
|
{
|
|
$options = isset($column['options']) ? $column['options'] : array('style' => '');
|
|
|
|
if (isset($column['align']))
|
|
{
|
|
$options['class'] = isset($options['class']) ? $options['class'] . ' text-' . $column['align'] : 'text-' . $column['align'];
|
|
unset($column['align']);
|
|
}
|
|
|
|
if (isset($column['width']))
|
|
{
|
|
$options['style'] = 'width: ' . $column['width'];
|
|
unset($column['width']);
|
|
}
|
|
|
|
if (isset($column['min_width']))
|
|
{
|
|
$options['style'] = ' min-width: ' . $column['min_width'];
|
|
unset($column['min_width']);
|
|
}
|
|
|
|
echo content_tag('th', $column['label'], $options);
|
|
}
|
|
|
|
echo '</tr>';
|
|
}
|
|
|
|
echo '</thead>';
|
|
}
|
|
}
|
|
|
|
function st_admin_table_body(array $rows = array())
|
|
{
|
|
echo '<tbody>';
|
|
|
|
foreach ($rows as $row)
|
|
{
|
|
$rowContent = '';
|
|
|
|
foreach ($rows['columns'] as $column)
|
|
{
|
|
$columnOptions = is_array($column) ? $column : ['content' => $column];
|
|
|
|
$rowContent .= content_tag('td', $columnOptions['content'], isset($columnOptions['options']) ? $columnOptions['options'] : []);
|
|
}
|
|
|
|
echo content_tag('tr', $rowContent, isset($row['row']) ? $row['options'] : []);
|
|
}
|
|
|
|
echo '</tbody>';
|
|
}
|
|
|
|
/**
|
|
* Kończy tabele
|
|
*
|
|
* @return void
|
|
*/
|
|
function st_admin_table_end(array $columns = array())
|
|
{
|
|
if ($columns)
|
|
{
|
|
echo '<tfoot>';
|
|
echo '<tr>';
|
|
|
|
foreach ($columns as $column)
|
|
{
|
|
echo content_tag('td', $column['label'], isset($column['options']) ? $column['options'] : array());
|
|
}
|
|
|
|
echo '</tr>';
|
|
echo '</tfoot>';
|
|
}
|
|
echo '</table>';
|
|
}
|
|
|
|
/**
|
|
* Rozpoczyna sekcję formularza
|
|
*
|
|
* @param string $title Opcjonalny tytuł sekcji
|
|
* @param array $options Opcjonalne atrybuty dla sekcji
|
|
* @return void
|
|
*/
|
|
function st_admin_section_start($title = null, array $options = array())
|
|
{
|
|
$options['class'] = isset($options['class']) ? $options['class'] . ' fieldset' : 'fieldset';
|
|
|
|
echo tag('fieldset', $options, true);
|
|
|
|
if ($title)
|
|
{
|
|
echo content_tag('h2', $title);
|
|
}
|
|
|
|
echo tag('div', array('class' => 'content'), true);
|
|
}
|
|
|
|
/**
|
|
* Kończy sekcje formularza
|
|
*
|
|
* @return void
|
|
*/
|
|
function st_admin_section_end()
|
|
{
|
|
echo '</div></fieldset>';
|
|
}
|
|
|
|
function st_admin_table_column_message($message, $colspan)
|
|
{
|
|
return content_tag('td', $message, array('class' => 'text-center bs-p-4 st_admin_table_column_message', 'colspan' => $colspan));
|
|
}
|
|
|
|
/**
|
|
* Tworzy zewnętrzny link do modułu
|
|
*
|
|
* @param string $name Nazwa linku
|
|
* @param string $internal_uri Wewnętrzny adres linku (np. 'stDemo/list')
|
|
* @param array $options Dodatkowe parametry linku
|
|
* @return string HTML
|
|
*/
|
|
function st_external_link_to($name = '', $internal_uri = '', $options = array())
|
|
{
|
|
$options = _parse_attributes($options);
|
|
|
|
$options['class'] = 'st_admin_external_link';
|
|
|
|
$options['target'] = '_blank';
|
|
|
|
return link_to($name, $internal_uri, $options);
|
|
}
|
|
|
|
function st_replace_forward_parameters($value, $forward_parameters = array())
|
|
{
|
|
foreach ($forward_parameters as $name => $forward_parameter)
|
|
{
|
|
$value = str_replace('%%forward_parameters.' . $name . '%%', $forward_parameter, $value);
|
|
}
|
|
|
|
return $value;
|
|
}
|
|
|
|
function st_get_admin_culture_picker($params = array())
|
|
{
|
|
$languages = LanguagePeer::doSelectLanguages();
|
|
|
|
$params['query_div'] = strpos($params['url'], '?') !== false ? '&' : '?';
|
|
|
|
$params['url'] = st_url_for($params['url']);
|
|
|
|
$content = '';
|
|
|
|
foreach ($languages as $language)
|
|
{
|
|
if ($language->getOriginalLanguage() == $params['culture'])
|
|
{
|
|
$current = _culture_picker_flag($language, $params);
|
|
}
|
|
else
|
|
{
|
|
$content .= '<li>' . _culture_picker_flag($language, $params) . '</li>';
|
|
}
|
|
}
|
|
|
|
return <<<HTML
|
|
<li class="expandable backend-language-picker">
|
|
<span>$current</span>
|
|
<ul>
|
|
$content
|
|
</ul>
|
|
</li>
|
|
HTML;
|
|
}
|
|
|
|
function st_admin_get_large_icon($icon)
|
|
{
|
|
$content = null;
|
|
|
|
if ($icon && $icon[0] == '/')
|
|
{
|
|
$content = tag('img', array('src' => $icon));
|
|
}
|
|
else
|
|
{
|
|
$path = '/images/backend/applications/large/' . $icon . '.png';
|
|
|
|
if (is_file(sfConfig::get('sf_web_dir') . $path))
|
|
{
|
|
$content = tag('img', array('src' => $path));
|
|
}
|
|
else
|
|
{
|
|
$content = tag('img', array('src' => get_app_icon($icon), 'style' => 'width: 100px'));
|
|
}
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
|
|
function st_get_admin_hideable_picker(array $fields)
|
|
{
|
|
$content = '';
|
|
|
|
$context = sfContext::getInstance();
|
|
|
|
$user = sfContext::getInstance()->getUser();
|
|
|
|
foreach ($fields as $name => $params)
|
|
{
|
|
$label = is_array($params) ? $params['label'] : $params;
|
|
$content .= '<div>' . st_admin_checkbox_tag('view_fields[' . $name . ']', 1, !$user->getParameter($name, false, 'soteshop/stAdminGenerator/hidden'), array('label' => $label, 'data-field' => $name)) . '</div>';
|
|
}
|
|
|
|
if (!$content)
|
|
{
|
|
return '';
|
|
}
|
|
|
|
$action = st_url_for($context->getModuleName() . '/setConfiguration?params[]=view_fields&for_action=' . $context->getActionName());
|
|
|
|
$dotsHorizontalIcon = st_admin_get_icon('dots-horizontal');
|
|
|
|
return <<<HTML
|
|
<li class="expandable align-right" id="backend-view-field-picker">
|
|
<span>$dotsHorizontalIcon</span>
|
|
<ul>
|
|
<li>
|
|
<form action="$action" method="post">
|
|
$content
|
|
</form>
|
|
<script>
|
|
jQuery(function($) {
|
|
|
|
$('#backend-view-field-picker form').on('change', 'input', function() {
|
|
var input = $(this);
|
|
|
|
var field = input.data('field');
|
|
|
|
var editForm = $('#admin_edit_form,#admin_config_form');
|
|
|
|
if (editForm.length) {
|
|
if (input.prop('checked')) {
|
|
editForm.find('.row_' + field + ', #sf_fieldset_' + field).removeClass('hidden').removeClass('always');
|
|
} else {
|
|
editForm.find('.row_' + field + ', #sf_fieldset_' + field).addClass('hidden').addClass('always');
|
|
}
|
|
|
|
editForm.trigger('update:fieldsetVisibility');
|
|
} else {
|
|
var listForm = $('#record_list_form');
|
|
if (input.prop('checked')) {
|
|
listForm.find('.column_' + field + ', #sf_admin_list_th_' + field).removeClass('hidden');
|
|
} else {
|
|
listForm.find('.column_' + field + ', #sf_admin_list_th_' + field).addClass('hidden');
|
|
}
|
|
}
|
|
|
|
var form = input.closest('form');
|
|
|
|
$.post(form.prop('action'), form.serialize(), function() {
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</li>
|
|
</ul>
|
|
</li>
|
|
HTML;
|
|
}
|
|
|
|
|
|
function st_get_admin_culture_flag($culture = null)
|
|
{
|
|
static $languages = array();
|
|
|
|
if (!isset($languages[$culture]))
|
|
{
|
|
foreach (LanguagePeer::doSelectLanguages() as $language)
|
|
{
|
|
if ($language->getOriginalLanguage() == $culture)
|
|
{
|
|
$languages[$culture] = $language;
|
|
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
return _culture_picker_flag($languages[$culture], array('culture' => $culture));
|
|
}
|
|
|
|
function _culture_picker_flag(Language $language, $params)
|
|
{
|
|
$culture = $language->getOriginalLanguage();
|
|
|
|
$icon = '/images/backend/icons/flags/' . $language->getShortcut() . '.svg';
|
|
|
|
$image = is_file(sfConfig::get('sf_web_dir') . $icon) ? image_tag($icon) : $language->getShortcut();
|
|
|
|
if ($culture == $params['culture'])
|
|
{
|
|
return $image . '<span>' . $language->getName() . '</span>';
|
|
}
|
|
else
|
|
{
|
|
return '<a href="' . $params['url'] . '/culture/' . $culture . '">' . $image . '<span>' . $language->getName() . '</span></a>';
|
|
}
|
|
}
|
|
|
|
function object_st_admin_checkbox_tag($object, $method, $options = array(), $default_value = null)
|
|
{
|
|
$options = _parse_attributes($options);
|
|
|
|
$checked = (bool) _get_object_value($object, $method, $default_value);
|
|
|
|
return st_admin_checkbox_tag(_convert_method_to_name($method, $options), isset($options['value']) ? $options['value'] : 1, $checked, $options);
|
|
}
|
|
|
|
function st_admin_checkbox_tag($name, $value = '1', $checked = false, $params = array())
|
|
{
|
|
$size = '';
|
|
|
|
if (isset($params['size']) && $params['size'] == 'small')
|
|
{
|
|
$size = ' p-small';
|
|
}
|
|
|
|
$label = isset($params['label']) ? $params['label'] : '';
|
|
return '<div class="pretty p-image p-plain' . $size . '">' . checkbox_tag($name, $value, $checked, $params) . '<div class="state"><img class="image" src="' . st_admin_get_icon_path('checkbox') . '"><label>' . $label . '</label></div></div>';
|
|
}
|
|
|
|
function st_admin_select_day_of_week_tag($name, $value, $params = array())
|
|
{
|
|
$days = [
|
|
1 => __("Poniedziałek"),
|
|
2 => __("Wtorek"),
|
|
3 => __("Środa"),
|
|
4 => __("Czwartek"),
|
|
5 => __("Piątek"),
|
|
6 => __("Sobota"),
|
|
7 => __("Niedziela"),
|
|
];
|
|
|
|
$params['selected'] = $value;
|
|
|
|
return select_tag($name, $days, $params);
|
|
}
|
|
|
|
function st_admin_input_time_tag($name, $value, $params = array())
|
|
{
|
|
$id = get_id_from_name($name);
|
|
|
|
$flatpikrOptions = [
|
|
'enableTime' => true,
|
|
'noCalendar' => true,
|
|
'dateFormat' => "H:i",
|
|
'time_24hr' => true
|
|
];
|
|
|
|
$options = json_encode($flatpikrOptions, JSON_UNESCAPED_UNICODE);
|
|
|
|
return input_tag($name, $value, $params) . javascript_tag("flatpickr('#$id', $options)");
|
|
}
|
|
|
|
function st_admin_radio_tag($name, $value = '1', $checked = false, $params = array())
|
|
{
|
|
$size = '';
|
|
|
|
if (isset($params['size']) && $params['size'] == 'small')
|
|
{
|
|
$size = ' p-small';
|
|
}
|
|
|
|
$label = isset($params['label']) ? $params['label'] : '';
|
|
return '<div class="pretty p-default p-round' . $size . '">' . radiobutton_tag($name, $value, $checked, $params) . '<div class="state"><label>' . $label . '</label></div></div>';
|
|
}
|
|
|
|
/**
|
|
* Zwraca kontrolkę wyboru
|
|
*
|
|
* @param string $name Nazwa pola
|
|
* @param array $choices Opcje wyboru
|
|
* @param string|array $selected Wartość wybranej|wybranych opcji
|
|
* @param array $options Dodatkowe opcje kontrolki HTML
|
|
* @return string Kod HTML kontrolki
|
|
*/
|
|
function st_admin_select_tag(string $name, array $choices, $selected, array $options = array())
|
|
{
|
|
$options['selected'] = $selected;
|
|
|
|
return select_tag($name, $choices, $options);
|
|
}
|
|
|
|
function st_admin_optional_input($name, $value, $options)
|
|
{
|
|
static $init = false;
|
|
|
|
$options['class'] = isset($options['class']) ? $options['class'] . ' bs-ms-2' : 'bs-ms-2';
|
|
|
|
if (isset($options['enabled']))
|
|
{
|
|
$options['disabled'] = !boolval($options['enabled']);
|
|
unset($options['enabled']);
|
|
}
|
|
elseif (!isset($options['disabled']))
|
|
{
|
|
$options['disabled'] = null === $value || "" === $value;
|
|
}
|
|
else
|
|
{
|
|
$options['disabled'] = boolval($options['disabled']);
|
|
}
|
|
|
|
$content = content_tag('div', st_admin_checkbox_tag($name, $value, !$options['disabled']) . input_tag('', $value, $options), array('class' => 'st_admin_optional_input bs-d-inline-block'));
|
|
|
|
if (!$init)
|
|
{
|
|
$content .= "
|
|
<script>
|
|
jQuery(function($) {
|
|
$(document).ready(function() {
|
|
$('.st_admin_optional_input').on('change', function(e) {
|
|
let container = $(this);
|
|
let input = $(e.target);
|
|
if (input.prop('type') == 'checkbox') {
|
|
let textInput = container.find('input[type=text]');
|
|
textInput.prop('disabled', !input.prop('checked'));
|
|
textInput.focus();
|
|
|
|
if (input.prop('checked')) {
|
|
textInput.val(input.val());
|
|
}
|
|
} else {
|
|
let checkbox = container.find('input[type=checkbox]');
|
|
checkbox.val(input.val());
|
|
checkbox.change();
|
|
}
|
|
})
|
|
});
|
|
});
|
|
</script>
|
|
";
|
|
|
|
$init = true;
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
|
|
function object_st_admin_optional_input($object, $method, $options = array(), $default_value = null)
|
|
{
|
|
$options = _parse_attributes($options);
|
|
$value = _get_object_value($object, $method, $default_value);
|
|
$name = _convert_method_to_name($method, $options);
|
|
|
|
return st_admin_optional_input($name, $value, $options);
|
|
}
|
|
|
|
function st_admin_get_icon_path($name)
|
|
{
|
|
return st_backend_get_icon_path($name);
|
|
}
|
|
|
|
function st_admin_get_icon($name, array $options = array())
|
|
{
|
|
return st_backend_get_icon($name, $options);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML rozpoczynający aplikację
|
|
*
|
|
* @param string $name Tytuł aplikacji
|
|
* @param string $icon Ikona aplikacji (nazwa lub pełna ścieżka)
|
|
* @param string $url Link do aplikacji (@nazwaRoutingu)
|
|
* @param string $title Tytuł dla aktualnie wyświetlanej podstrony aplikacji
|
|
* @param array $options Dodatkowe opcje
|
|
* @return string
|
|
*/
|
|
function st_admin_application_start($name, $icon, $url, $title = '', array $options = array())
|
|
{
|
|
return st_get_admin_head(array($url, $name, $icon), $title, $options);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML kończący aplikację
|
|
*
|
|
* @return string
|
|
*/
|
|
function st_admin_application_end()
|
|
{
|
|
return st_get_admin_foot();
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML dla menu aplikacji
|
|
*
|
|
* @return string
|
|
*/
|
|
function st_admin_get_menu(array $items)
|
|
{
|
|
return st_get_component('stAdminGenerator', 'menu', array('items' => $items));
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML otwierający aplikację
|
|
*
|
|
* @param mixed $app_name Nazwa aplikacji np. stOrder
|
|
* @param string $title Dodatkowy tytuł dla aplikacji
|
|
* @param array $options
|
|
* @param array $applications Lista aplikacji np. array('stOrder', 'stUser', ...) (deprecated use options instead)
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_head($app_name, $title = '', $options = array(), $shortcuts = array())
|
|
{
|
|
$context = sfContext::getInstance();
|
|
$routing = sfRouting::getInstance();
|
|
|
|
$context->getI18N()->setFallbackCatalogue('stAdminGeneratorPlugin');
|
|
|
|
if (is_array($options))
|
|
{
|
|
if (isset($options['shortcuts']))
|
|
{
|
|
$shortcuts = $options['shortcuts'];
|
|
|
|
unset($options['shortcuts']);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$options = array();
|
|
}
|
|
|
|
if (is_array($app_name) && $app_name[0] != $app_name[1])
|
|
{
|
|
list($route, $label) = $app_name;
|
|
|
|
if (isset($app_name[2]))
|
|
{
|
|
$icon = get_app_icon($app_name[2]);
|
|
}
|
|
else
|
|
{
|
|
$icon = get_app_icon($route);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
if (is_array($app_name))
|
|
{
|
|
$app_name = $app_name[0];
|
|
}
|
|
|
|
if (stMenuModifier::hasHeadApplications($app_name))
|
|
{
|
|
$shortcuts = stMenuModifier::getHeadApplications($app_name, $shortcuts);
|
|
}
|
|
|
|
$route = stApplication::getAppRoute($app_name);
|
|
|
|
$icon = get_app_icon($app_name);
|
|
|
|
$route_info = $routing->getRouteByName($route);
|
|
|
|
$label = $context->getI18N()->__(stApplication::getAppName($app_name), null, $route_info[4]['module']);
|
|
}
|
|
|
|
$adminGeneratorUserConfiguration = new stAdminGeneratorUserConfiguration($context, 'stAdminGenerator', 'default');
|
|
|
|
$favorites = $adminGeneratorUserConfiguration->getParameter('favorites', array());
|
|
|
|
$favorite = isset($options['favorite']) ? $options['favorite'] : array();
|
|
|
|
if (false !== $favorite)
|
|
{
|
|
$favoriteLabel = isset($favorite['label']) ? $favorite['label'] : (!isset($favorite['add_title']) && in_array($context->getActionName(), array('list', 'index')) || isset($favorite['add_title']) && !$favorite['add_title'] ? $label : $label . ' - ' . $title);
|
|
|
|
$internalUrl = isset($favorite['url']) ? $favorite['url'] : $routing->getCurrentInternalUri();
|
|
|
|
list($favoriteUrl) = explode("?", $internalUrl);
|
|
|
|
$showFavorite = (false === strpos($internalUrl, '?') || strpos($internalUrl, '?filters_clear=1')) && !in_array($internalUrl, array('stBackend/additionalApplicationsList'));
|
|
}
|
|
else
|
|
{
|
|
$showFavorite = false;
|
|
}
|
|
|
|
$header = st_get_partial('stAdminGenerator/header', array(
|
|
'route' => $route,
|
|
'icon' => $icon,
|
|
'label' => $label,
|
|
'title' => $title,
|
|
'options' => $options,
|
|
'is_favorite' => $showFavorite ? isset($favorites[$favoriteUrl]) : null,
|
|
'favorite' => $showFavorite ? base64_encode($favoriteUrl . ':' . $favoriteLabel) : null,
|
|
'show_favorite' => $showFavorite,
|
|
));
|
|
|
|
return tag('div', array('id' => 'sf_admin_container', 'class' => 'admin_container'), true) . $header;
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający aplikację
|
|
*
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_foot()
|
|
{
|
|
return "</div>";
|
|
}
|
|
|
|
function _st_head_menu_item($app_name)
|
|
{
|
|
$routing = sfRouting::getInstance();
|
|
|
|
$real_name = stApplication::getMenuElementName($app_name);
|
|
|
|
$image_content = image_tag('backend/main/icons/' . $app_name . '.png', array('id' => 'app_' . $app_name, 'width' => '40px', 'height' => '40px'));
|
|
|
|
$para_content = content_tag('p', $real_name);
|
|
|
|
return content_tag('li', st_link_to($image_content, $routing->hasRouteName($app_name . 'Default') ? '@' . $app_name . 'Default' : '@' . $app_name) . $para_content);
|
|
}
|
|
|
|
function _st_head_application_icon($app_name, $params)
|
|
{
|
|
$routing = sfRouting::getInstance();
|
|
return content_tag('div', st_link_to(image_tag('backend/main/icons/' . $app_name . '.png'), $routing->hasRouteName($app_name . 'Default') ? '@' . $app_name . 'Default' : '@' . $app_name . $params), 'id=st_application-head-package');
|
|
}
|
|
|
|
function st_admin_sort_st_link_to($label, $field_name)
|
|
{
|
|
$content = '';
|
|
$sf_user = sfContext::getInstance()->getUser();
|
|
if ($sf_user->getAttribute('sort', null, 'sf_admin/order/sort') == $field_name)
|
|
{
|
|
// $content .= st_link_to($label, 'order/list?sort=' . $field_name . '&type=' . ($sf_user->getAttribute('type', 'asc', 'sf_admin/order/sort') == 'asc' ? 'desc' : 'asc'));
|
|
$content .= $label;
|
|
$content .= image_tag('/images/backend/icons/' . $sf_user->getAttribute('type', 'asc', 'sf_admin/order/sort') . '.png', array('align' => 'absmiddle'));
|
|
}
|
|
else
|
|
{
|
|
// $content .= st_link_to($label, 'order/list?sort=' . $field_name . '&type=asc');
|
|
$content .= $label;
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
|
|
function st_admin_row_highlight()
|
|
{
|
|
static $i;
|
|
return !fmod(++$i, 2);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML otwierający nagłówek dla komponentu
|
|
* Postać zwracanego kodu
|
|
* <div class="st_admin-component" $html_options>
|
|
* <h2>$label</h2>
|
|
* <br class="st_clear_all" />
|
|
*
|
|
* @param string $label Tytuł nagłówka
|
|
* @param mixed $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_component_head($label, $html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
if (isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'st_admin-component ' . $html_options['class'];
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] = 'st_admin-component';
|
|
}
|
|
|
|
$content = tag('div', $html_options, true);
|
|
$content .= content_tag('h2', $label);
|
|
$content .= tag('br', array('class' => 'st_clear_all'));
|
|
return $content;
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający nagłówek dla komponentu
|
|
* Postać zwracanego kodu
|
|
* </div>
|
|
*
|
|
* @return unknown
|
|
*/
|
|
function st_get_admin_component_foot()
|
|
{
|
|
return '</div>';
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML otwierający układ horyzontalny
|
|
* Postać zwracanego kodu
|
|
* <ul class="st_admin-horizontal-look" $html_options>
|
|
*
|
|
* @param mixed $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_horizontal_look_head($html_options = array())
|
|
{
|
|
$same_height = '';
|
|
|
|
$html_options = _parse_attributes($html_options);
|
|
|
|
if (isset($html_options['id']))
|
|
{
|
|
$same_height = javascript_tag(nifty_round_elements('ul#' . $html_options['id'] . ' > li', 'none same-height'));
|
|
}
|
|
|
|
if (isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'st_admin-horizontal-look ' . $html_options['class'];
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] = 'st_admin-horizontal-look';
|
|
}
|
|
|
|
return $same_height . tag('ul', $html_options, true);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML otwierający element dla układu horyzontalnego
|
|
* Postać zwracanego kodu
|
|
* <li $html_options>
|
|
*
|
|
* @param mixed $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_horizontal_element_head($html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
if (isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'st_admin-horizontal-look-element ' . $html_options['class'];
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] = 'st_admin-horizontal-look-element';
|
|
}
|
|
|
|
return tag('li', $html_options, true);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający element dla układu horyzontalnego
|
|
* Postać zwracanego kodu
|
|
* </li>
|
|
*
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_horizontal_element_foot()
|
|
{
|
|
return '</li>';
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający układ horyzontalny
|
|
* Postać zwracanego kodu
|
|
* </ul><br class="st_clear_all" />
|
|
*
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_horizontal_look_foot()
|
|
{
|
|
return content_tag('li', '', 'class="st_clear_all"') . '</ul>';
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML otwierający listę
|
|
* Postać zwracanego kodu
|
|
* <ul class="st_admin-item-list">
|
|
*
|
|
* @param mixed $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_item_list_head($html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
if (isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'st_admin-item-list ' . $html_options['class'];
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] = 'st_admin-item-list';
|
|
}
|
|
|
|
return tag('ul', $html_options, true);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML elementu listy
|
|
* Postać zwracanego kodu:
|
|
* <li $html_options>
|
|
* <span>$label</span>
|
|
* $value albo <strong>$value</strong> (gdy flaga is_imported jest ustawiona)
|
|
* </li>
|
|
*
|
|
* @param string $label Tytuł elementu
|
|
* @param string $value Wartość elementu
|
|
* @param bool $is_important Określa czy element ma być oznaczony jako ważny
|
|
* @param array $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_item_list_element($label, $value, $is_important = false, $html_options = array())
|
|
{
|
|
$label_content = content_tag('span', $label . ':');
|
|
|
|
if ($is_important)
|
|
{
|
|
$value_content = content_tag('strong', $value);
|
|
}
|
|
else
|
|
{
|
|
$value_content = $value;
|
|
}
|
|
|
|
return content_tag('li', $label_content . $value_content, $html_options);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający listę
|
|
* Postać zwracanego kodu:
|
|
* </ul><br class="st_clear_all" />
|
|
*
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_item_list_foot()
|
|
{
|
|
return '</ul>' . tag('br', array('class' => 'st_clear_all'));
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML otwierający separator zawartości
|
|
* Postać zwracanego kodu:
|
|
* <div class="st_admin-content-separator" $html_options>
|
|
*
|
|
* @param mixed $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_content_separator_head($html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
if (isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'st_admin-content-separator ' . $html_options['class'];
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] = 'st_admin-content-separator';
|
|
}
|
|
|
|
return tag('div', $html_options, true);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający separator zawartości
|
|
* Postać zwracanego kodu
|
|
* </div>
|
|
*
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_content_separator_foot()
|
|
{
|
|
return '</div>';
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML przycisku dla danej akcji
|
|
*
|
|
* @param string $type Typ akcji (dostepne: save, save_and_add, save_and_list, delete, list, edit)
|
|
* @param string $label Etykieta przycisku
|
|
* @param string $action Akcja przycisku (np. category/index)
|
|
* @param mixed $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_action($type, $label, $action = null, $html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
|
|
if ($type == 'create' || $type == 'add')
|
|
{
|
|
$type = 'add';
|
|
}
|
|
elseif ($type == 'save_and_list' || $type == 'save_and_add' || $type == 'save')
|
|
{
|
|
$type = 'save';
|
|
}
|
|
|
|
$content = st_get_admin_button($type, $label, $action, $html_options);
|
|
|
|
return content_tag('li', $content, array('class' => 'action-' . $type));
|
|
}
|
|
|
|
function st_get_admin_button($type = 'default', $label = null, $action = null, $html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
$color = null;
|
|
$icon = $type;
|
|
|
|
if (isset($html_options['show_preloader']))
|
|
{
|
|
$html_options['data-admin-action'] = null;
|
|
$html_options['data-admin-action-show-preloader'] = intval($html_options['show_preloader']);
|
|
unset($html_options['show_preloader']);
|
|
}
|
|
|
|
if ($type == 'create' || $type == 'add')
|
|
{
|
|
$type = 'add';
|
|
$icon = 'add';
|
|
}
|
|
elseif ($type == 'save_and_list' || $type == 'save_and_add' || $type == 'save')
|
|
{
|
|
$type = 'save';
|
|
$icon = 'check';
|
|
}
|
|
elseif ($type != 'delete')
|
|
{
|
|
$color = 'default';
|
|
}
|
|
|
|
if (isset($html_options['icon']))
|
|
{
|
|
$icon = $html_options['icon'];
|
|
unset($html_options['icon']);
|
|
}
|
|
|
|
if (!isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'button button-' . $type;
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] .= ' button button-' . $type;
|
|
}
|
|
|
|
if (null !== $label)
|
|
{
|
|
$label = content_tag('span', $label, array('class' => 'button-label'));
|
|
$html_options['class'] .= ' with-label';
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] .= ' no-label';
|
|
}
|
|
|
|
if (isset($html_options['size']))
|
|
{
|
|
$html_options['class'] .= ' button-size-' . $html_options['size'];
|
|
unset($html_options['size']);
|
|
}
|
|
|
|
if (isset($html_options['color']))
|
|
{
|
|
$color = $html_options['color'];
|
|
unset($html_options['color']);
|
|
}
|
|
|
|
if ($color)
|
|
{
|
|
$html_options['class'] .= ' button-color-' . $color;
|
|
}
|
|
|
|
if ($icon != 'default')
|
|
{
|
|
$icon_image = st_admin_get_icon($icon, array('default' => false));
|
|
|
|
if ($icon_image)
|
|
{
|
|
$label = $icon_image . $label;
|
|
$html_options['class'] .= ' with-icon';
|
|
}
|
|
}
|
|
|
|
// $html_options['style'] = 'background-image: url(/images/backend/icons/'.$icon.'.png?v2)';
|
|
|
|
if (is_null($action))
|
|
{
|
|
if (!isset($html_options['type']))
|
|
{
|
|
$html_options['type'] = 'submit';
|
|
}
|
|
|
|
if (isset($html_options['confirm']))
|
|
{
|
|
$html_options['data-admin-confirm'] = $html_options['confirm'];
|
|
$html_options['data-admin-action-post'] = true;
|
|
unset($html_options['confirm']);
|
|
}
|
|
|
|
return content_tag('button', $label, $html_options);
|
|
}
|
|
else
|
|
{
|
|
// return st_button_to($label, $action, $html_options);
|
|
if (isset($html_options['confirm']))
|
|
{
|
|
$html_options['data-admin-confirm'] = $html_options['confirm'];
|
|
unset($html_options['confirm']);
|
|
}
|
|
|
|
// if (isset($html_options['target']))
|
|
// {
|
|
// if ($html_options['target'] == '_blank')
|
|
// {
|
|
// $html_options['data-admin-action-blank'] = 1;
|
|
// }
|
|
|
|
// unset($html_options['target']);
|
|
// }
|
|
|
|
return st_link_to($label, $action, $html_options);
|
|
}
|
|
}
|
|
|
|
function st_button_to($name, $internal_uri = '', $options = array())
|
|
{
|
|
$html_options = _parse_attributes($options);
|
|
$html_options['value'] = $name;
|
|
|
|
if (isset($html_options['confirm']))
|
|
{
|
|
$html_options['data-admin-confirm'] = $html_options['confirm'];
|
|
unset($html_options['confirm']);
|
|
}
|
|
|
|
if (isset($html_options['post']) && $html_options['post'])
|
|
{
|
|
if (isset($html_options['popup']))
|
|
{
|
|
throw new sfConfigurationException('You can\'t use "popup" and "post" together');
|
|
}
|
|
$html_options['type'] = 'submit';
|
|
unset($html_options['post']);
|
|
$html_options = _convert_options_to_javascript($html_options);
|
|
|
|
return form_tag($internal_uri, array('method' => 'post', 'class' => 'button_to')) . content_tag('div', tag('input', $html_options)) . '</form>';
|
|
}
|
|
|
|
$url = $internal_uri && $internal_uri[0] == '/' ? $internal_uri : url_for($internal_uri);
|
|
if (isset($html_options['query_string']))
|
|
{
|
|
$url = $url . '?' . $html_options['query_string'];
|
|
unset($html_options['query_string']);
|
|
}
|
|
|
|
$html_options['type'] = 'button';
|
|
|
|
if (isset($html_options['popup']))
|
|
{
|
|
$url = "'" . $url . "'";
|
|
$html_options = _convert_options_to_javascript($html_options, $url);
|
|
unset($html_options['popup']);
|
|
}
|
|
else
|
|
{
|
|
$html_options['data-admin-action-url'] = $url;
|
|
}
|
|
|
|
if (isset($html_options['target']))
|
|
{
|
|
if ($html_options['target'] == '_blank')
|
|
{
|
|
$html_options['data-admin-action-blank'] = 1;
|
|
}
|
|
|
|
unset($html_options['target']);
|
|
}
|
|
|
|
$html_options['data-admin-action'] = isset($html_options['type']) ? $html_options['type'] : 'none';
|
|
|
|
return tag('input', $html_options);
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
* Zwraca HTML otwierający definiowanie akcji
|
|
*
|
|
* @param string $html_options opcje HTML
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_actions_head($html_options = array())
|
|
{
|
|
$html_options = _parse_attributes($html_options);
|
|
if (isset($html_options['class']))
|
|
{
|
|
$html_options['class'] = 'admin_actions ' . $html_options['class'];
|
|
}
|
|
else
|
|
{
|
|
$html_options['class'] = 'admin_actions';
|
|
}
|
|
|
|
return tag('ul', $html_options, true);
|
|
}
|
|
|
|
/**
|
|
* Zwraca HTML zamykający definiowanie akcji
|
|
*
|
|
* @return string HTML
|
|
*/
|
|
function st_get_admin_actions_foot()
|
|
{
|
|
return '</ul><div class="clr"></div>';
|
|
}
|
|
|
|
function st_get_admin_actions($actions)
|
|
{
|
|
$html = st_get_admin_actions_head();
|
|
|
|
foreach ($actions as $action)
|
|
{
|
|
if (!isset($action['type']))
|
|
{
|
|
throw new sfException('Parameter "type" is mandatory');
|
|
}
|
|
|
|
if (!isset($action['label']))
|
|
{
|
|
throw new sfException('Parameter "label" is mandatory');
|
|
}
|
|
|
|
$html .= st_get_admin_action($action['type'], $action['label'], isset($action['action']) ? $action['action'] : null, isset($action['params']) ? $action['params'] : array());
|
|
}
|
|
|
|
return $html . st_get_admin_actions_foot();
|
|
}
|
|
|
|
function st_admin_get_filters_list($module, $action, $page)
|
|
{
|
|
$user = sfContext::getInstance()->getUser();
|
|
|
|
$c = new Criteria();
|
|
|
|
$c->add(AdminGeneratorFilterPeer::MODULE_NAMESPACE, $module . '/' . $action);
|
|
|
|
$c1 = $c->getNewCriterion(AdminGeneratorFilterPeer::GUARD_USER_ID, $user->getGuardUser()->getId());
|
|
|
|
$c1->addOr($c->getNewCriterion(AdminGeneratorFilterPeer::IS_GLOBAL, true));
|
|
|
|
$c->add($c1);
|
|
|
|
$c->addAscendingOrderByColumn(AdminGeneratorFilterPeer::NAME);
|
|
|
|
$filters = AdminGeneratorFilterPeer::doSelect($c);
|
|
|
|
$options = array();
|
|
|
|
foreach ($filters as $filter)
|
|
{
|
|
$options[$filter->getId()] = $filter->getName();
|
|
}
|
|
|
|
$selected = $user->getAttribute($action . '.filter', null, 'soteshop/stAdminGenerator/' . $module . '/config');
|
|
|
|
$url = st_url_for($module . '/setFilter?for_action=' . $action . '&page=' . $page . '&id=');
|
|
|
|
$js = <<<JS
|
|
<script type="text/javascript">
|
|
$('filter_control').observe('change', function() {
|
|
window.location = '$url/' + this.options[this.selectedIndex].value;
|
|
});
|
|
</script>
|
|
JS;
|
|
|
|
$label = label_for('filter_control', __('Aktywny filtr', null, 'stAdminGeneratorPlugin') . ':');
|
|
|
|
$select = select_tag('filter_control', options_for_select($options, $selected ? $selected['id'] : null, array('include_custom' => '---')));
|
|
|
|
return $label . $select . $js;
|
|
}
|
|
|
|
function st_admin_get_assigned_filter($filters)
|
|
{
|
|
return select_tag('filters[assigned]', options_for_select(array(1 => __('tak', array(), 'stAdminGeneratorPlugin'), 0 => __('nie', array(), 'stAdminGeneratorPlugin')), isset($filters['assigned']) ? $filters['assigned'] : null, array(
|
|
'include_custom' => __("---"),
|
|
)));
|
|
}
|
|
|
|
function st_admin_get_current_filter($var, $module, $action)
|
|
{
|
|
$selected = sfContext::getInstance()->getUser()->getAttribute($action . '.filter', null, 'soteshop/stAdminGenerator/' . $module . '/config');
|
|
|
|
return isset($selected[$var]) ? $selected[$var] : null;
|
|
}
|
|
|
|
function st_admin_show_form_fields($fields, $values, $order)
|
|
{
|
|
foreach ($order as $name)
|
|
{
|
|
$attr = isset($fields[$name]['attr']) ? $fields[$name]['attr'] : array();
|
|
|
|
$type = isset($fields[$name]['type']) ? $fields[$name]['type'] : 'input_tag';
|
|
|
|
$value = isset($values[$name]) ? $values[$name] : null;
|
|
|
|
if ($type == 'select_tag')
|
|
{
|
|
$attr['selected'] = $value;
|
|
|
|
$value = $fields[$name]['options'];
|
|
}
|
|
elseif ($type == 'checkbox_tag')
|
|
{
|
|
$attr['checked'] = $value;
|
|
|
|
$type == 'st_admin_checkbox_tag';
|
|
|
|
$value = $fields[$name]['value'];
|
|
}
|
|
|
|
echo st_admin_get_form_field($name, __($fields[$name]['label']), $value, $type, $attr);
|
|
}
|
|
}
|
|
|
|
function st_admin_generator_filter_form(\stAdminGeneratorFilterForm $form, $action = null)
|
|
{
|
|
if (null !== $action)
|
|
{
|
|
$form->setAction($action);
|
|
}
|
|
|
|
return st_get_partial('stAdminGenerator/filter_form', array('form' => $form));
|
|
}
|
|
|
|
function st_admin_get_filter_type(\stAdminGeneratorFilter $filter)
|
|
{
|
|
$mapping = array(
|
|
'boolean' => 'st_admin_yesno_select_tag',
|
|
'date' => 'st_gadget_date_select_tag',
|
|
);
|
|
|
|
return isset($mapping[$filter->getType()]) ? $mapping[$filter->getType()] : $filter->getType();
|
|
}
|
|
|
|
function st_admin_get_filter_attr(\stAdminGeneratorFilter $filter)
|
|
{
|
|
$attr = $filter->getOption('attr');
|
|
|
|
if ($filter->getType() == 'boolean')
|
|
{
|
|
$attr = array_merge(array('include_custom' => '---'), $attr);
|
|
}
|
|
|
|
return $attr;
|
|
}
|
|
|
|
function st_admin_get_form_field($name, $label, $value = null, $type = null, array $params = array())
|
|
{
|
|
$label_params = array();
|
|
$row_attr = array();
|
|
|
|
if (null === $type)
|
|
{
|
|
$type = 'input_tag';
|
|
}
|
|
|
|
if ($label)
|
|
{
|
|
$label = rtrim($label, ':');
|
|
}
|
|
|
|
if (isset($params['help']))
|
|
{
|
|
$label .= ' <a href="#" class="help" tabindex="-1" title="' . htmlspecialchars($params['help']) . '"></a>';
|
|
}
|
|
|
|
if (isset($params['required']))
|
|
{
|
|
if ($params['required'])
|
|
{
|
|
$label_params['class'] = 'required';
|
|
}
|
|
|
|
unset($params['required']);
|
|
}
|
|
|
|
if (isset($params['clipboard']) && $params['clipboard'])
|
|
{
|
|
$clipboard = true;
|
|
unset($params['clipboard']);
|
|
}
|
|
else
|
|
{
|
|
$clipboard = false;
|
|
}
|
|
|
|
if (isset($params['postfix']) && $params['postfix'])
|
|
{
|
|
$postfix = ' ' . $params['postfix'];
|
|
unset($params['postfix']);
|
|
}
|
|
else
|
|
{
|
|
$postfix = '';
|
|
}
|
|
|
|
if (isset($params['row_attr']))
|
|
{
|
|
$row_attr = $params['row_attr'];
|
|
unset($params['row_attr']);
|
|
}
|
|
|
|
$id = isset($params['id']) ? $params['id'] : get_id_from_name($name);
|
|
|
|
$row_attr['class'] = 'row ' . $id;
|
|
|
|
switch ($type)
|
|
{
|
|
case 'partial':
|
|
$params['value'] = $value;
|
|
$params['name'] = $name;
|
|
|
|
$field_content = st_get_partial($params['partial'], $params);
|
|
break;
|
|
|
|
case 'component':
|
|
$params['value'] = $value;
|
|
$params['name'] = $name;
|
|
|
|
if (!isset($params['module']))
|
|
{
|
|
$params['module'] = sfContext::getInstance()->getModuleName();
|
|
}
|
|
|
|
$field_content = st_get_component($params['module'], $params['component'], $params);
|
|
break;
|
|
|
|
case 'checkbox_tag':
|
|
case 'radiobutton_tag':
|
|
if (array_key_exists('checked', $params))
|
|
{
|
|
$checked = $params['checked'];
|
|
|
|
unset($params['checked']);
|
|
}
|
|
else
|
|
{
|
|
$checked = false;
|
|
}
|
|
|
|
if ($type == "checkbox_tag")
|
|
{
|
|
$type = 'st_admin_checkbox_tag';
|
|
}
|
|
|
|
$field_content = $type($name, $value, $checked, $params);
|
|
$params['type'] = 'plain';
|
|
|
|
break;
|
|
case 'select_tag':
|
|
if (isset($params['include_custom']))
|
|
{
|
|
$custom = array('include_custom' => $params['include_custom']);
|
|
unset($params['include_custom']);
|
|
}
|
|
else
|
|
{
|
|
$custom = array();
|
|
}
|
|
|
|
if (!isset($params['choices']))
|
|
{
|
|
if (array_key_exists('selected', $params))
|
|
{
|
|
$selected = $params['selected'];
|
|
|
|
unset($params['selected']);
|
|
}
|
|
else
|
|
{
|
|
$selected = '';
|
|
}
|
|
|
|
$field_content = $type($name, options_for_select($value, $selected, $custom), $params);
|
|
}
|
|
else
|
|
{
|
|
$choices = $params['choices'];
|
|
unset($params['choices']);
|
|
$field_content = $type($name, options_for_select($choices, $value, $custom), $params);
|
|
}
|
|
break;
|
|
case 'select_number_tag':
|
|
$field_content = $type($name, $value, $params, isset($params['html']) ? $params['html'] : array());
|
|
break;
|
|
case 'plain':
|
|
$field_content = $value;
|
|
break;
|
|
default:
|
|
if ($type[0] == '_')
|
|
{
|
|
$partial = substr($type, 1);
|
|
|
|
$field_content = st_get_partial($partial, array('value' => $value, 'name' => $name, 'params' => $params));
|
|
}
|
|
else
|
|
{
|
|
$field_content = $type($name, $value, $params);
|
|
|
|
if ($clipboard)
|
|
{
|
|
$field_content .= '<button type="button" class="clipboard-btn list_tooltip" data-clipboard-target="#' . $id . '" title="' . __('Kopiuj', null, 'stBackend') . '"></button>';
|
|
}
|
|
}
|
|
}
|
|
|
|
$error_name = str_replace(array('[', ']'), array('{', '}'), $name);
|
|
|
|
$row_attr['class'] .= ' row_type_' . (isset($params['type']) ? $params['type'] : $type);
|
|
|
|
if ($label)
|
|
{
|
|
if (form_has_error($error_name))
|
|
{
|
|
$error_msg = content_tag('div', form_error($error_name), array('class' => 'form-error-msg'));
|
|
|
|
$result = content_tag('div', label_for($id, $label, $label_params) . content_tag('div', $error_msg . $field_content . $postfix . content_tag('div', '', array('class' => 'clr')), array('class' => 'field form-error')), $row_attr);
|
|
}
|
|
else
|
|
{
|
|
$result = content_tag('div', label_for($id, $label, $label_params) . content_tag('div', $field_content . $postfix . content_tag('div', '', array('class' => 'clr')), array('class' => 'field')), $row_attr);
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$result = $field_content . $postfix;
|
|
}
|
|
|
|
$dispatcher = stEventDispatcher::getInstance();
|
|
$context = sfContext::getInstance();
|
|
|
|
if ($dispatcher->getListeners("st_admin_get_form_field.{$context->getModuleName()}.$id"))
|
|
{
|
|
|
|
return $dispatcher->filter(new sfEvent($context, "st_admin_get_form_field.{$context->getModuleName()}.$id", array('label' => $label, 'name' => $name, 'id' => $id, 'value' => $value, 'params' => $params)), $result)->getReturnValue();
|
|
}
|
|
|
|
return $result;
|
|
}
|