public static function writeCSV($type, $query, $totalItems, $from, $fileHash = '', $filename, $customFields = null) { $db = JFactory::getDBO(); $db->setQuery($query, $from, 10); $data = $db->loadObjectList(); $fileContent = RSMembershipExport::buildCSV($type, $data, $fileHash, $customFields); // build the file hash if not already created if ($fileHash == '') { $now = JHtml::date('now', 'D, d M Y H:i:s'); $date = JHtml::date('now', 'Y-m-d_H-i-s'); $filename = $filename . '-' . $date . '.csv'; $fileHash = md5($filename . $now); } // create or append the hashed file and put content $path = JPATH_ADMINISTRATOR . '/components/com_rsmembership/'; $success = false; if ($fileContent != '') { $test = file_put_contents($path . 'tmp/' . $fileHash, $fileContent, FILE_APPEND); if ($test) { $success = true; } } $response = new stdClass(); if ($success) { $newFrom = $from + 10; $checkRemaining = $totalItems - $newFrom; $response->success = $success; $response->newFrom = $checkRemaining > 0 ? $newFrom : $totalItems; $response->fileHash = $fileHash; } $response->success = $success; return $response; }
public function exportcsv() { require_once JPATH_COMPONENT . '/helpers/export.php'; $model = $this->getModel('Subscribers'); $filename = JText::_('COM_RSMEMBERSHIP_SUBSCRIBERS'); RSMembershipExport::buildCSVHeaders($filename); $input = JFactory::getApplication()->input; $fileHash = $input->get('filehash'); echo RSMembershipExport::getCSV($fileHash); JFactory::getApplication()->close(); }
public function writeCSV($from, $fileHash = '') { require_once JPATH_COMPONENT . '/helpers/export.php'; // setting the function arguments $query = $this->getListQuery(); $totalItems = (int) $this->getTotalItems(); $filename = JText::_('COM_RSMEMBERSHIP_SUBSCRIPTIONS'); $type = 'subscriptions'; return RSMembershipExport::writeCSV($type, $query, $totalItems, $from, $fileHash, $filename); }
public function writeCSV($from, $fileHash = '') { require_once JPATH_COMPONENT . '/helpers/export.php'; // setting the function arguments $query = $this->getListQuery(); $totalItems = (int) $this->getTotalItems(); $customFields = RSMembership::getCustomFields(array('showinsubscribers' => 1)); $filename = JText::_('COM_RSMEMBERSHIP_SUBSCRIBERS'); $type = 'subscribers'; return RSMembershipExport::writeCSV($type, $query, $totalItems, $from, $fileHash, $filename, $customFields); }