Projekt

Obecné

Profil

« Předchozí | Další » 

Revize 1463

Přidáno uživatelem Ondřej Fibich před více než 12 roky(ů)

Upravy:
- vylepseni exportu

Zobrazit rozdíly:

freenetis/branches/network/application/models/member.php
* @param $filter_values used for filtering
* @return Mysql_Result
*/
public function get_all_members($limit_from = 0, $limit_results = 50, $order_by = 'id',
$order_by_direction = 'asc', $filter_sql = "")
public function get_all_members($limit_from = 0, $limit_results = 50,
$order_by = 'id', $order_by_direction = 'asc', $filter_sql = '')
{
$where = '';
if ($filter_sql != '')
......
LIMIT " . intval($limit) . ", " . intval($limit_results) ."
");
}
/**
* Function gets all members to export.
*
......
birthday, login, comment, membership_interrupt
FROM
(
SELECT
SELECT
m.id, m.registration, m.name,
s.street, ap.street_number, t.town, t.quarter,
s.street, ap.street_number, t.town, t.quarter,
vs.variable_symbol, m.type, m.entrance_date,
m.leaving_date,
u.birthday, u.login, m.comment, m.membership_interrupt
FROM
(
SELECT m.id,
m.name,
m.address_point_id,
IF(m.registration = 1, ?, ?) AS registration,
IFNULL(t.translated_term, e.value) AS type,
FROM
(
SELECT m.id,
m.name,
m.address_point_id,
IF(m.registration = 1, ?, ?) AS registration,
IFNULL(t.translated_term, e.value) AS type,
IF(mi.id IS NOT NULL, 1, 0) AS membership_interrupt,
m.comment, m.entrance_date, m.leaving_date
FROM members m
LEFT JOIN enum_types e ON m.type = e.id
LEFT JOIN translations t ON e.value = t.original_term AND lang = ?
LEFT JOIN
(
SELECT mi.id, mi.member_id
FROM membership_interrupts mi
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id
WHERE mf.activation_date <= CURDATE() AND mf.deactivation_date >= CURDATE()
) mi ON mi.member_id = m.id
) AS m
LEFT JOIN address_points ap ON m.address_point_id = ap.id
LEFT JOIN streets s ON ap.street_id = s.id
LEFT JOIN towns t ON ap.town_id = t.id
LEFT JOIN accounts a ON a.member_id = m.id AND m.id <> 1
LEFT JOIN variable_symbols vs ON vs.account_id = a.id
LEFT JOIN users u ON u.member_id = m.id AND u.type = ?
FROM members m
LEFT JOIN enum_types e ON m.type = e.id
$filter_sql
) AS q
GROUP BY q.id
LEFT JOIN translations t ON e.value = t.original_term AND lang = ?
LEFT JOIN
(
SELECT mi.id, mi.member_id
FROM membership_interrupts mi
LEFT JOIN members_fees mf ON mi.members_fee_id = mf.id
WHERE mf.activation_date <= CURDATE() AND mf.deactivation_date >= CURDATE()
) mi ON mi.member_id = m.id
) AS m
LEFT JOIN address_points ap ON m.address_point_id = ap.id
LEFT JOIN streets s ON ap.street_id = s.id
LEFT JOIN towns t ON ap.town_id = t.id
LEFT JOIN accounts a ON a.member_id = m.id AND m.id <> 1
LEFT JOIN variable_symbols vs ON vs.account_id = a.id
LEFT JOIN users u ON u.member_id = m.id AND u.type = ?
LEFT JOIN enum_types e ON m.type = e.id
$filter_sql
) AS q
GROUP BY q.id
ORDER BY q.id
) AS q
", array
freenetis/branches/network/application/controllers/export.php
'utf-8' => 'UTF-8',
'windows-1250' => 'WINDOWS-1250'
);
// display form only if required
$form_display = !isset($encodings[$encoding]);
......
// empty result?
if (!count($items))
{
die(__('Invalid data'));
status::error('Invalid data - no data available');
}
else
{
/* Generate file */
/* Generate file */
// set content header
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
// set content header
header('Content-type: application/csv');
header('Content-Disposition: attachment; filename="' . $filename . '"');
// get headers
foreach ($items[0] as $key => $value)
{
// translation of column titles
$field = __(utf8::ucfirst(inflector::humanize($key)));
// file cannot start with ID, otherwise excel
// and openoffice think that the file is invalid
if ($field == 'ID')
// get headers
foreach ($items[0] as $key => $value)
{
$field = __('Number');
}
// character encoding
if ($encoding != 'utf-8')
{
$field = iconv('utf-8', $encoding, $value);
}
// output
echo '"' . $field . '";';
}
echo "\n";
// for each data row
foreach ($items as $line)
{
// this foreach writes line
foreach ($line as $key => $value)
{
// translation of column titles
$field = __(utf8::ucfirst(inflector::humanize($key)));
// file cannot start with ID, otherwise excel
// and openoffice think that the file is invalid
if ($field == 'ID')
{
$field = __('Number');
}
// character encoding
if ($encoding != 'utf-8')
{
$field = iconv('utf-8', $encoding, $value);
}
// output
echo '"' . $value . '";';
echo '"' . $field . '";';
}
echo "\n";
// for each data row
foreach ($items as $line)
{
// this foreach writes line
foreach ($line as $key => $value)
{
// character encoding
if ($encoding != 'utf-8')
{
$field = iconv('utf-8', $encoding, $value);
}
// output
echo '"' . $value . '";';
}
echo "\n";
}
// do not display view
die();
}
}
else
{
$title = __('Export');
$title = __('Export');
$view = new View('main');
$view->title = $title;
$view->content = new View('form');
$view->content->headline = $title;
$view->content->form = $form;
$view->render(TRUE);
}
$view = new View('main');
$view->title = $title;
$view->content = new View('form');
$view->content->headline = $title;
$view->content->form = $form;
$view->render(TRUE);
}
}

Také k dispozici: Unified diff