105 lines
3.2 KiB
PHP
105 lines
3.2 KiB
PHP
<?php
|
|
|
|
function _get_propel_object_list_for_import_export($object, $method, $options)
|
|
{
|
|
// get the lists of objects
|
|
$through_class = _get_option($options, 'through_class');
|
|
|
|
$c = new Criteria();
|
|
$c->add(ExportFieldPeer::MODEL, $object->getModel());
|
|
$c->add(ExportFieldPeer::IS_KEY, 0);
|
|
|
|
$objects = sfPropelManyToMany::getAllObjects($object, $through_class, $c);
|
|
|
|
if (sfContext::getInstance()->getRequest()->hasErrors())
|
|
{
|
|
$ids = sfContext::getInstance()->getRequest()->getParameterHolder()->get('associated_field', 0);
|
|
$c = new Criteria();
|
|
$c->add(ExportFieldPeer::ID, $ids, Criteria::IN);
|
|
$objects_associated = ExportFieldPeer::doSelect($c);
|
|
}
|
|
else
|
|
{
|
|
$objects_associated = sfPropelManyToMany::getRelatedObjects($object, $through_class, $c);
|
|
}
|
|
|
|
|
|
$ids = array_map(create_function('$o', 'return $o->getPrimaryKey();'), $objects_associated);
|
|
|
|
return array($objects, $objects_associated, $ids);
|
|
}
|
|
|
|
function st_export_type_picker($name, $value, array $options = array())
|
|
{
|
|
$content = '';
|
|
|
|
foreach ($options['types'] as $type => $label)
|
|
{
|
|
$label = __($label, array(), 'stImportExportBackend');
|
|
$radio = radiobutton_tag($name, $type, $value == $type);
|
|
$content .= content_tag('li', content_tag('label', $radio . ' ' . $label, array(
|
|
'style' => 'float: none; width: auto'
|
|
)));
|
|
}
|
|
|
|
return content_tag('ul', $content);
|
|
}
|
|
|
|
function st_export_profile_picker($name, $value, array $options = array())
|
|
{
|
|
$module = $options['module'];
|
|
$model = $options['model'];
|
|
$profiles = $options['profiles'];
|
|
|
|
$url = 'stImportExportBackend/list?model='.$model.'&for_module='.$module;
|
|
|
|
$forwardParameters = stAdminGeneratorHelper::filterAdditionalParameters($options['forward_parameters']);
|
|
|
|
foreach ($forwardParameters as $forwardParameterName => $value)
|
|
{
|
|
$url .= "&$forwardParameterName=$value";
|
|
}
|
|
|
|
if (!empty($forwardParameters))
|
|
{
|
|
$url .= '¶meters=' . implode(',', array_keys($forwardParameters));
|
|
}
|
|
|
|
$select = select_tag($name, options_for_select($profiles, $value));
|
|
$link = st_get_admin_button('default', __('Zarządzaj profilami', array(), 'stImportExportBackend'), $url, array('size' => 'small', 'class' => 'bs-mt-2', 'icon' => 'stImportExportPlugin'));
|
|
|
|
return $select . '<br>' . $link;
|
|
}
|
|
|
|
function st_export_custom_parameter($name, $value, array $options = array())
|
|
{
|
|
$parameters = $options['parameters'];
|
|
$parameterName = $options['parameter_name'];
|
|
|
|
$type = isset($parameters['type']) ? $parameters['type'] : 'input_tag';
|
|
$default = isset($parameters['default']) ? $parameters['default'] : null;
|
|
|
|
switch ($type)
|
|
{
|
|
case 'checkbox_tag':
|
|
$content = st_admin_checkbox_tag($name, 1, $default);
|
|
break;
|
|
|
|
case 'select_tag':
|
|
if (!isset($parameters['choices']))
|
|
{
|
|
throw new Exception(sprintf('Missing choices parameter for %s', $parameterName));
|
|
}
|
|
$content = select_tag($name, options_for_select($parameters['choices'], $default));
|
|
break;
|
|
|
|
default:
|
|
$content = $type($name, $default);
|
|
break;
|
|
|
|
}
|
|
|
|
return $content;
|
|
}
|
|
|