Skip to content

Instantly share code, notes, and snippets.

@vgrish

vgrish/export_users.php

Last active Jun 29, 2018
Embed
What would you like to do?
<?php
$c = $modx->newQuery('modUser');
$c->InnerJoin('modUserProfile', 'Profile');
$c->InnerJoin('msOrder', 'msOrder', 'modUser.id = msOrder.user_id');
$c->InnerJoin('msOrderAddress', 'msOrderAddress','msOrder.address = msOrderAddress.id');
$c->where(array(
'modUser.active' => 1,
));
$c->groupby('modUser.id');
$c->select($modx->getSelectColumns('modUser', 'modUser', '', array('id')));
$c->select($modx->getSelectColumns('modUserProfile', 'Profile', '', array('fullname')));
$c->select($modx->getSelectColumns('modUserProfile', 'msOrderAddress', '', array('city')));
$fp = fopen(MODX_BASE_PATH.'users.csv', 'w');
fputcsv($fp, array('id', 'name', 'city'));
if ($c->prepare() && $c->stmt->execute()) {
while($row = $c->stmt->fetch(PDO::FETCH_ASSOC)) {
fputcsv($fp, $row);
}
}
fclose($fp);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment