1
0
mirror of https://github.com/e107inc/e107.git synced 2025-08-03 13:17:24 +02:00

Closes #2309 - AdminUI Batch Export option added.

This commit is contained in:
Cameron
2017-01-27 18:02:57 -08:00
parent 2b6ba2920f
commit ff38b2ad07
9 changed files with 122 additions and 27 deletions

View File

@@ -154,6 +154,7 @@ class page_chapters_ui extends e_admin_ui
protected $batchDelete = false; protected $batchDelete = false;
protected $batchCopy = true; protected $batchCopy = true;
protected $batchLink = true; protected $batchLink = true;
protected $batchExport = true;
protected $listQry = "SELECT a. *, CASE WHEN a.chapter_parent = 0 THEN a.chapter_order ELSE b.chapter_order + (( a.chapter_order)/1000) END AS Sort FROM `#page_chapters` AS a LEFT JOIN `#page_chapters` AS b ON a.chapter_parent = b.chapter_id "; protected $listQry = "SELECT a. *, CASE WHEN a.chapter_parent = 0 THEN a.chapter_order ELSE b.chapter_order + (( a.chapter_order)/1000) END AS Sort FROM `#page_chapters` AS a LEFT JOIN `#page_chapters` AS b ON a.chapter_parent = b.chapter_id ";
protected $listOrder = 'Sort,chapter_order '; protected $listOrder = 'Sort,chapter_order ';
@@ -527,7 +528,8 @@ class page_admin_ui extends e_admin_ui
protected $batchDelete = true; protected $batchDelete = true;
protected $batchCopy = true; protected $batchCopy = true;
protected $batchLink = true; protected $batchLink = true;
protected $batchFeaturebox = true; protected $batchExport = true;
protected $batchFeaturebox = true;
protected $sortField = 'page_order'; protected $sortField = 'page_order';
protected $orderStep = 10; protected $orderStep = 10;
//protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided. //protected $url = array('profile'=>'page/view', 'name' => 'page_title', 'description' => '', 'link'=>'{e_BASE}page.php?id=[id]'); // 'link' only needed if profile not provided.

View File

@@ -1735,7 +1735,7 @@ function exportXmlFile($prefs,$tables=array(),$plugPrefs, $package=FALSE,$debug=
} }
} }
$mode = ($debug === true) ? "debug" : false; $mode = ($debug === true) ? array( "debug" =>1) : null;
if($xml->e107Export($prefs,$tables,$plugPrefs, $mode)) if($xml->e107Export($prefs,$tables,$plugPrefs, $mode))
{ {

View File

@@ -887,7 +887,7 @@ class links_admin_form_ui extends e_admin_form_ui
'fields' => $controller->getFields(), // see e_admin_ui::$fields 'fields' => $controller->getFields(), // see e_admin_ui::$fields
'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref 'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref
'table_pre' => '', // markup to be added before opening table element 'table_pre' => '', // markup to be added before opening table element
'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy()) : '', 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch(array('delete'=>$controller->getBatchDelete(),'copy'=>$controller->getBatchCopy())) : '',
'fieldset_pre' => '', // markup to be added before opening fieldset element 'fieldset_pre' => '', // markup to be added before opening fieldset element
'fieldset_post' => '', // markup to be added after closing fieldset element 'fieldset_post' => '', // markup to be added after closing fieldset element
'perPage' => $controller->getPerPage(), // if 0 - no next/prev navigation 'perPage' => $controller->getPerPage(), // if 0 - no next/prev navigation

View File

@@ -120,6 +120,7 @@ class news_cat_ui extends e_admin_ui
protected $pid = "category_id"; protected $pid = "category_id";
protected $perPage = 0; //no limit protected $perPage = 0; //no limit
protected $batchDelete = false; protected $batchDelete = false;
protected $batchExport = true;
protected $sortField = 'category_order'; protected $sortField = 'category_order';
protected $listOrder = "category_order ASC"; protected $listOrder = "category_order ASC";
@@ -407,6 +408,7 @@ class news_admin_ui extends e_admin_ui
protected $pid = "news_id"; protected $pid = "news_id";
protected $perPage = 10; //no limit protected $perPage = 10; //no limit
protected $batchDelete = true; protected $batchDelete = true;
protected $batchExport = true;
protected $batchCopy = true; protected $batchCopy = true;
protected $batchLink = true; protected $batchLink = true;
protected $listQry = "SELECT n.*,u.user_id,u.user_name FROM `#news` AS n LEFT JOIN `#user` AS u ON n.news_author = u.user_id "; // without any Order or Limit. protected $listQry = "SELECT n.*,u.user_id,u.user_name FROM `#news` AS n LEFT JOIN `#user` AS u ON n.news_author = u.user_id "; // without any Order or Limit.

View File

@@ -3658,7 +3658,8 @@ class ".$table." extends e_admin_ui
protected \$pid = '".$vars['pid']."'; protected \$pid = '".$vars['pid']."';
protected \$perPage = 10; protected \$perPage = 10;
protected \$batchDelete = true; protected \$batchDelete = true;
// protected \$batchCopy = true; protected \$batchExport = true;
protected \$batchCopy = true;
// protected \$sortField = 'somefield_order'; // protected \$sortField = 'somefield_order';
// protected \$orderStep = 10; // protected \$orderStep = 10;
// protected \$tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the \$fields below to enable. // protected \$tabs = array('Tabl 1','Tab 2'); // Use 'tab'=>0 OR 'tab'=>1 in the \$fields below to enable.

View File

@@ -2478,6 +2478,11 @@ class e_admin_controller_ui extends e_admin_controller
*/ */
protected $batchFeaturebox = false; protected $batchFeaturebox = false;
/**
* @var boolean
*/
protected $batchExport = false;
/** /**
* @var array * @var array
*/ */
@@ -2559,6 +2564,11 @@ class e_admin_controller_ui extends e_admin_controller
return $this->batchFeaturebox; return $this->batchFeaturebox;
} }
public function getBatchExport()
{
return $this->batchExport;
}
public function getBatchOptions() public function getBatchOptions()
{ {
return $this->batchOptions; return $this->batchOptions;
@@ -3126,6 +3136,16 @@ class e_admin_controller_ui extends e_admin_controller
switch($trigger[0]) switch($trigger[0])
{ {
case 'export':
$method = 'handle'.$this->getRequest()->getActionName().'ExportBatch';
if(method_exists($this, $method)) // callback handling
{
$this->$method($selected);
}
break;
case 'delete': //FIXME - confirmation popup case 'delete': //FIXME - confirmation popup
//method handleListDeleteBatch(); for custom handling of 'delete' batch //method handleListDeleteBatch(); for custom handling of 'delete' batch
// if(empty($selected)) return $this; // if(empty($selected)) return $this;
@@ -4523,7 +4543,7 @@ class e_admin_ui extends e_admin_controller_ui
//$this->redirect(); //$this->redirect();
} }
/** TODO /**
* Batch copy trigger * Batch copy trigger
* @param array $selected * @param array $selected
* @return void * @return void
@@ -4542,6 +4562,28 @@ class e_admin_ui extends e_admin_controller_ui
$this->redirect(); $this->redirect();
} }
/**
* Batch Export trigger
* @param array $selected
* @return void
*/
protected function handleListExportBatch($selected)
{
// Batch Copy
$res = $this->getTreeModel()->export($selected);
// callback
// $this->afterCopy($res, $selected);
// move messages to default stack
$this->getTreeModel()->setMessages();
// send messages to session
e107::getMessage()->moveToSession();
// redirect
$this->redirect();
}
/** /**
* Batch URL trigger * Batch URL trigger
* @param array $selected * @param array $selected
@@ -5951,7 +5993,14 @@ class e_admin_form_ui extends e_form
// ------------------------------------------ // ------------------------------------------
$coreBatchOptions = array(
'delete' => $controller->getBatchDelete(),
'copy' => $controller->getBatchCopy(),
'url' => $controller->getBatchLink(),
'featurebox' => $controller->getBatchFeaturebox(),
'export' => $controller->getBatchExport()
);
$options[$id] = array( $options[$id] = array(
@@ -5969,7 +6018,9 @@ class e_admin_form_ui extends e_form
'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref 'fieldpref' => $controller->getFieldPref(), // see e_admin_ui::$fieldpref
'table_pre' => '', // markup to be added before opening table element 'table_pre' => '', // markup to be added before opening table element
// 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy(),$controller->getBatchLink(),$controller->getBatchFeaturebox()) : '', // 'table_post' => !$tree[$id]->isEmpty() ? $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy(),$controller->getBatchLink(),$controller->getBatchFeaturebox()) : '',
'table_post' => $this->renderBatch($controller->getBatchDelete(),$controller->getBatchCopy(),$controller->getBatchLink(),$controller->getBatchFeaturebox(), $controller->getBatchOptions()),
'table_post' => $this->renderBatch($coreBatchOptions, $controller->getBatchOptions()),
'fieldset_pre' => '', // markup to be added before opening fieldset element 'fieldset_pre' => '', // markup to be added before opening fieldset element
'fieldset_post' => '', // markup to be added after closing fieldset element 'fieldset_post' => '', // markup to be added after closing fieldset element
@@ -6264,15 +6315,17 @@ class e_admin_form_ui extends e_form
// FIXME - use e_form::batchoptions(), nice way of buildig batch dropdown - news administration show_batch_options() // FIXME - use e_form::batchoptions(), nice way of buildig batch dropdown - news administration show_batch_options()
function renderBatch($allow_delete = false,$allow_copy= false, $allow_url=false, $allow_featurebox=false, $customBatchOptions=array())
/**
* @param array $options array of flags for copy, delete, url, featurebox, batch
* @param array $customBatchOptions
* @return string
*/
function renderBatch($options, $customBatchOptions=array())
{ {
// $allow_copy = TRUE;
$fields = $this->getController()->getFields(); $fields = $this->getController()->getFields();
if(!varset($fields['checkboxes'])) if(!varset($fields['checkboxes']))
{ {
$mes = e107::getMessage(); $mes = e107::getMessage();
@@ -6283,7 +6336,7 @@ class e_admin_form_ui extends e_form
// FIX - don't show FB option if plugin not installed // FIX - don't show FB option if plugin not installed
if(!e107::isInstalled('featurebox')) if(!e107::isInstalled('featurebox'))
{ {
$allow_featurebox = false; $options['featurebox'] = false;
} }
// TODO - core ui-batch-option class!!! REMOVE INLINE STYLE! // TODO - core ui-batch-option class!!! REMOVE INLINE STYLE!
@@ -6302,10 +6355,11 @@ class e_admin_form_ui extends e_form
if(!$this->getController()->getTreeModel()->isEmpty()) if(!$this->getController()->getTreeModel()->isEmpty())
{ {
$selectOpt .= ($allow_copy ? $this->option(LAN_COPY, 'copy', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); $selectOpt .= !empty($options['copy']) ? $this->option(LAN_COPY, 'copy', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : '';
$selectOpt .= ($allow_delete ? $this->option(LAN_DELETE, 'delete', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); $selectOpt .= !empty($options['delete']) ? $this->option(LAN_DELETE, 'delete', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : '';
$selectOpt .= ($allow_url ? $this->option(LAN_UI_BATCH_CREATELINK, 'url', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); $selectOpt .= !empty($options['export']) ? $this->option(LAN_UI_BATCH_EXPORT, 'export', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : '';
$selectOpt .= ($allow_featurebox ? $this->option(LAN_PLUGIN_FEATUREBOX_BATCH, 'featurebox', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : ''); $selectOpt .= !empty($options['url']) ? $this->option(LAN_UI_BATCH_CREATELINK, 'url', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : '';
$selectOpt .= !empty($options['featurebox']) ? $this->option(LAN_PLUGIN_FEATUREBOX_BATCH, 'featurebox', false, array('class' => 'ui-batch-option class', 'other' => 'style="padding-left: 15px"')) : '';
if(!empty($customBatchOptions)) if(!empty($customBatchOptions))
{ {

View File

@@ -1711,6 +1711,10 @@ class e_model extends e_object
return e107::getParser()->parseTemplate($template, $parsesc, $this, $eVars); return e107::getParser()->parseTemplate($template, $parsesc, $this, $eVars);
} }
/**
* Export a Model configuration
* @return string
*/
public function toXML() public function toXML()
{ {
$ret = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n"; $ret = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
@@ -3706,4 +3710,32 @@ class e_admin_tree_model extends e_front_tree_model
} }
return $ret; return $ret;
} }
/**
* Export Selected Data
* @param $ids
* @return null
*/
public function export($ids)
{
$ids = e107::getParser()->filter($ids,'int');
if(empty($ids))
{
return false;
}
$idstr = implode(', ', $ids);
$table = array($this->getModelTable());
$filename = "e107Export_" .$this->getModelTable()."_". date("YmdHi").".xml";
$query = $this->getFieldIdName().' IN ('.$idstr.') '; // ORDER BY '.$this->getParam('db_order') ;
e107::getXML()->e107Export(null,$table,null,array('file'=>$filename,'query'=>$query));
return null;
}
} }

View File

@@ -869,10 +869,10 @@ class xmlClass
* *
* @param array $prefs - see e_core_pref $aliases (eg. core, ipool etc) * @param array $prefs - see e_core_pref $aliases (eg. core, ipool etc)
* @param array $tables - table names without the prefix * @param array $tables - table names without the prefix
* @param boolean $debug [optional] * @param array $options [optional] debug, return, query
* @return string text / file for download * @return string text / file for download
*/ */
public function e107Export($xmlprefs, $tables, $plugPrefs, $mode = false) public function e107Export($xmlprefs, $tables, $plugPrefs, $options = array())
{ {
// error_reporting(0); // error_reporting(0);
$e107info = array(); $e107info = array();
@@ -904,7 +904,7 @@ class xmlClass
{ {
continue; continue;
} }
elseif($mode === 'debug') elseif(!empty($options['debug']))
{ {
echo "<div>Original/Modiied <b>".$key."</b>"; echo "<div>Original/Modiied <b>".$key."</b>";
var_dump($default[$key],$val); var_dump($default[$key],$val);
@@ -947,13 +947,14 @@ class xmlClass
if(varset($tables)) if(!empty($tables))
{ {
$text .= "\t<database>\n"; $text .= "\t<database>\n";
foreach($tables as $tbl) foreach($tables as $tbl)
{ {
$eTable= str_replace(MPREFIX,"",$tbl); $eTable= str_replace(MPREFIX,"",$tbl);
e107::getDB()->select($eTable, "*"); $eQry = (!empty($options['query'])) ? $options['query'] : null;
e107::getDB()->select($eTable, "*", $eQry);
$text .= "\t<dbTable name=\"".$eTable."\">\n"; $text .= "\t<dbTable name=\"".$eTable."\">\n";
$count = 1; $count = 1;
while($row = e107::getDB()->fetch()) while($row = e107::getDB()->fetch())
@@ -985,12 +986,12 @@ class xmlClass
$text .= "</e107Export>"; $text .= "</e107Export>";
if($mode === 'return') if(!empty($options['return']))
{ {
return $text; return $text;
} }
if($mode === 'debug') if(!empty($options['debug']))
{ {
echo "<pre>".htmlentities($text)."</pre>"; echo "<pre>".htmlentities($text)."</pre>";
return null; return null;
@@ -1016,8 +1017,10 @@ class xmlClass
return true; return true;
} }
$fileName = (!empty($options['file'])) ? $options['file'] : "e107Export_" . date("Y-m-d").".xml";
header('Content-type: application/xml', TRUE); header('Content-type: application/xml', TRUE);
header("Content-disposition: attachment; filename= e107Export_" . date("Y-m-d").".xml"); header("Content-disposition: attachment; filename= ".$fileName);
header("Cache-Control: max-age=30"); header("Cache-Control: max-age=30");
header("Pragma: public"); header("Pragma: public");
echo $text; echo $text;

View File

@@ -453,7 +453,8 @@ define("LAN_UI_DELETE_LABEL", "Confirm Delete");
define("LAN_UI_DELETE_WARNING", "You are about to delete [x] records. Please confirm to continue."); define("LAN_UI_DELETE_WARNING", "You are about to delete [x] records. Please confirm to continue.");
define("LAN_UI_BATCH_CREATELINK", "Create Link"); define("LAN_UI_BATCH_CREATELINK", "Create Link");
define("LAN_UI_DELETED", "[x] record(s) successfully deleted!"); define("LAN_UI_DELETED", "[x] record(s) successfully deleted!");
define("LAN_UI_DELETED_FAILED", "[x] records not found and not deleted!"); define("LAN_UI_DELETED_FAILED", "[x] records not found and not deleted!");\
define("LAN_UI_BATCH_EXPORT", "Export");
define("LAN_UI_USING_DATABASE_TABLE", "Using [x] database table"); define("LAN_UI_USING_DATABASE_TABLE", "Using [x] database table");
define("LAN_UI_TOTAL_RECORDS", "Total Records: [x]"); define("LAN_UI_TOTAL_RECORDS", "Total Records: [x]");