* Code for export.
This commit is contained in:
@@ -3,11 +3,17 @@ $config->port = new stdclass();
|
||||
|
||||
$config->port->fieldList['title'] = '';
|
||||
$config->port->fieldList['width'] = '';
|
||||
$config->port->fieldList['required'] = '';
|
||||
$config->port->fieldList['required'] = 'no';
|
||||
$config->port->fieldList['fixed'] = '';
|
||||
$config->port->fieldList['control'] = '';
|
||||
$config->port->fieldList['control'] = 'input';
|
||||
$config->port->fieldList['values'] = '';
|
||||
$config->port->fieldList['class'] = '';
|
||||
$config->port->fieldList['sort'] = '';
|
||||
$config->port->fieldList['foreignKey'] = '';
|
||||
$config->port->fieldList['foreignKeySource'] = array('module' => '', 'method' => '', 'params' => '', 'pairs' => '', 'sql' => '');
|
||||
|
||||
|
||||
$config->port->dateFeilds = ',estStarted,realStarted,deadline,openedDate,assignedDate,finishedDate,canceledDate,closedDate,lastEditedDate,';
|
||||
$config->port->datetimeFeilds = '';
|
||||
$config->port->sysLangField = ',pri,status,type,mode,';
|
||||
$config->port->sysDataField = '';
|
||||
$config->port->initFunction = 'title,control,required,';
|
||||
|
||||
+66
-25
@@ -9,44 +9,85 @@ class port extends control
|
||||
*/
|
||||
public function export($model = '', $params = '')
|
||||
{
|
||||
$fieldList = $this->initFieldList($model);
|
||||
$params = explode(',', $params);
|
||||
$params['executionID'] = 1;
|
||||
$params['orderBy'] = 'id_desc';
|
||||
|
||||
extract($params);
|
||||
|
||||
/* save params to session. */
|
||||
$this->session->set(($model.'ExportParams'), $params);
|
||||
|
||||
/* Init config fieldList */
|
||||
$fieldList = $this->port->initFieldList($model);
|
||||
|
||||
$queryCondition = $this->session->{$model . 'QueryCondition'};
|
||||
$onlyCondition = $this->session->{$model . 'OnlyCondition'};
|
||||
|
||||
$modelDatas = array();
|
||||
if($onlyCondition and $queryCondition)
|
||||
{
|
||||
$table = zget($this->config->objectTables, $model);;
|
||||
if(isset($this->config->$model->port->table)) $table = $this->config->$model->port->table;
|
||||
$modelDatas = $this->dao->select('*')->from($table)->where($queryCondition)->fetchAll('id');
|
||||
}
|
||||
elseif($queryCondition)
|
||||
{
|
||||
$stmt = $this->dbh->query($queryCondition . ($this->post->exportType == 'selected' ? " AND t1.id IN({$this->cookie->checkedItem})" : '') . " ORDER BY " . strtr($orderBy, '_', ' '));
|
||||
while($row = $stmt->fetch()) $modelDatas[$row->id] = $row;
|
||||
}
|
||||
|
||||
$exportDatas = $this->getExportDatas($fieldList, $modelDatas);
|
||||
$exportDatas['kind'] = $model;
|
||||
|
||||
$exportFields= isset($this->config->$model->exportFields) ? $this->config->$model->exportFields : '';
|
||||
$exportFields = explode(',', $exportFields);
|
||||
$exportDatas['exportFields'] = array_keys($exportDatas['fields']);
|
||||
$exportDatas['fileType'] = 'xlsx';
|
||||
$exportDatas['fileName'] = '企业网站第一期-所有任务';
|
||||
|
||||
$exportDatas['typeList'] = join(',', $exportDatas['typeList']);
|
||||
$exportDatas['priList'] = join(',', $exportDatas['priList']);
|
||||
$_POST = $exportDatas;
|
||||
//a($exportDatas);die;
|
||||
$this->fetch('file', 'export2' . $_POST['fileType'], $POST);
|
||||
}
|
||||
|
||||
/**
|
||||
* Init FieldList .
|
||||
* Get ExportDatas.
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $fieldList
|
||||
* @param int $modelDatas
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initFieldList($model)
|
||||
public function getExportDatas($fieldList, $modelDatas)
|
||||
{
|
||||
$portFieldList = $this->config->port->fieldList;
|
||||
|
||||
$this->loadModel($model);
|
||||
$fields = isset($this->config->$model->exportFields) ? $this->config->$model->exportFields : '';
|
||||
|
||||
if(empty($fields)) return false;
|
||||
|
||||
$fields = explode(',', $fields);
|
||||
|
||||
/* build module fieldList. */
|
||||
foreach ($fields as $field)
|
||||
$exportDatas = array();
|
||||
$foreignKeyList = array();
|
||||
foreach ($fieldList as $key => $field)
|
||||
{
|
||||
$field = trim($field);
|
||||
|
||||
$modelFieldList = isset($this->config->$model->fieldList[$field]) ? $this->config->$model->fieldList[$field] : array();
|
||||
|
||||
foreach ($portFieldList as $portField => $value)
|
||||
$exportDatas['fields'][$key] = $field['title'];
|
||||
if($field['foreignKey'])
|
||||
{
|
||||
$funcName = 'init' . ucfirst($portField);
|
||||
if(!array_key_exists($portField, $modelFieldList)) $modelFieldList[$portField] = $this->port->$funcName($model, $field);
|
||||
$exportDatas['listStyle'][] = $key;
|
||||
$exportDatas[$key.'List'] = $field['values'];
|
||||
$foreignKeyList[] = $key;
|
||||
}
|
||||
|
||||
$this->config->$model->fieldList[$field] = $modelFieldList;
|
||||
}
|
||||
|
||||
a($this->config->$model->fieldList);
|
||||
foreach ($modelDatas as $id => $values)
|
||||
{
|
||||
foreach($values as $field => $value)
|
||||
{
|
||||
if(in_array($field, $foreignKeyList))
|
||||
{
|
||||
$modelDatas[$id]->$field = zget($exportDatas[$field.'List'], $value);
|
||||
}
|
||||
}
|
||||
}
|
||||
$exportDatas['rows'] = array_values($modelDatas);
|
||||
return $exportDatas;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+124
-19
@@ -1,7 +1,50 @@
|
||||
<?php
|
||||
|
||||
class portModel extends model
|
||||
{
|
||||
/**
|
||||
* Init FieldList .
|
||||
*
|
||||
* @param int $model
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initFieldList($model)
|
||||
{
|
||||
$portFieldList = $this->config->port->fieldList;
|
||||
|
||||
$this->loadModel($model);
|
||||
$fields = isset($this->config->$model->exportFields) ? $this->config->$model->exportFields : '';
|
||||
|
||||
if(empty($fields)) return false;
|
||||
|
||||
$fields = explode(',', $fields);
|
||||
|
||||
/* build module fieldList. */
|
||||
foreach ($fields as $field)
|
||||
{
|
||||
$field = trim($field);
|
||||
|
||||
if(!isset($this->config->$model->fieldList[$field])) $this->config->$model->fieldList[$field] = array();
|
||||
$modelFieldList = $this->config->$model->fieldList[$field];
|
||||
|
||||
foreach ($portFieldList as $portField => $value)
|
||||
{
|
||||
$funcName = 'init' . ucfirst($portField);
|
||||
if(!array_key_exists($portField, $modelFieldList))
|
||||
{
|
||||
$modelFieldList[$portField] = $this->config->port->fieldList[$portField];
|
||||
if(strpos($this->config->port->initFunction, $portField) !== false) $modelFieldList[$portField] = $this->$funcName($model, $field);
|
||||
}
|
||||
}
|
||||
|
||||
$modelFieldList['values'] = $this->initValues($model, $field, $modelFieldList);
|
||||
$modelFieldList = $this->initForeignKey($model, $field, $modelFieldList);
|
||||
|
||||
$this->config->$model->fieldList[$field] = $modelFieldList;
|
||||
}
|
||||
|
||||
return $this->config->$model->fieldList;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Title.
|
||||
@@ -20,9 +63,9 @@ class portModel extends model
|
||||
{
|
||||
$title = $this->lang->$model->$field;
|
||||
}
|
||||
elseif(array_key_exists($field . 'AB', $this->lang->$model))
|
||||
elseif(array_key_exists(($field . 'AB'), $this->lang->$model))
|
||||
{
|
||||
$title = $this->lang->$model->$field . 'AB';
|
||||
$title = $this->lang->$model->{$field . 'AB'};
|
||||
}
|
||||
elseif(array_key_exists($field, $this->lang->port->reservedWord))
|
||||
{
|
||||
@@ -32,25 +75,84 @@ class portModel extends model
|
||||
return $title;
|
||||
}
|
||||
|
||||
public function initWidth($model, $field)
|
||||
{
|
||||
return '120px';
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Control .
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $field
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initControl($model, $field)
|
||||
{
|
||||
return 'select';
|
||||
if(isset($this->lang->$model->{$field.'List'})) return 'select';
|
||||
if(strpos($this->config->port->selectParis, $field) !== false) return 'select';
|
||||
return $this->config->port->fieldList['control'];
|
||||
}
|
||||
|
||||
public function initValues($model, $field)
|
||||
/**
|
||||
* Init Values .
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $field
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initValues($model, $field, $fieldValue = '')
|
||||
{
|
||||
return 'value';
|
||||
extract($fieldValue['foreignKeySource']); // $module, $method, $params, $paris, $sql
|
||||
|
||||
if($fieldValue['foreignKey'] and $module and $method)
|
||||
{
|
||||
$getParams = $this->session->{$model.'ExportParams'};
|
||||
|
||||
if($params)
|
||||
{
|
||||
$sourceParams = explode(',', $params);
|
||||
foreach($sourceParams as $key => $param)
|
||||
{
|
||||
if(strpos($param, '$') !== false) $sourceParams[$key] = $getParams[ltrim($param, '$')];
|
||||
}
|
||||
$params = join(',', $sourceParams);
|
||||
}
|
||||
|
||||
$values = $this->loadModel($module)->$method($params);
|
||||
if(!empty($pairs))
|
||||
{
|
||||
$valuePairs = array();
|
||||
foreach ($values as $key => $value)
|
||||
{
|
||||
if(is_object($value)) $value = get_object_vars($value);
|
||||
|
||||
$valuePairs[$key] = $value[$pairs[1]];
|
||||
if(!empty($pairs[0])) $valuePairs[$value[$pairs[0]]] = $value[$pairs[1]];
|
||||
}
|
||||
$values = $valuePairs;
|
||||
}
|
||||
return $values;
|
||||
}
|
||||
|
||||
return $this->config->port->fieldList['values'];
|
||||
}
|
||||
|
||||
public function initSort($model, $field)
|
||||
/**
|
||||
* Init ForeignKey .
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $field
|
||||
* @param int $fieldContent
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initForeignKey($model, $field, $fieldContent)
|
||||
{
|
||||
return 'no';
|
||||
if(strpos($this->config->port->langList, $field) and !$fieldContent['foreignKey'] and isset($this->lang->$model->{$field.'List'}))
|
||||
{
|
||||
$fieldContent['foreignKey'] = true;
|
||||
$fieldContent['values'] = $this->lang->$model->{$field.'List'};
|
||||
}
|
||||
|
||||
return $fieldContent;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -71,11 +173,14 @@ class portModel extends model
|
||||
return 'no';
|
||||
}
|
||||
|
||||
public function initFixed($model, $field)
|
||||
{
|
||||
return 'left';
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Class.
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $field
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initClass($model, $field)
|
||||
{
|
||||
return '';
|
||||
|
||||
@@ -38,6 +38,14 @@ $config->task->exportFields = '
|
||||
lastEditedBy, lastEditedDate, activatedDate, files
|
||||
';
|
||||
|
||||
$config->task->fieldList['module']['control'] = 'select';
|
||||
$config->task->fieldList['module']['foreignKey'] = true;
|
||||
$config->task->fieldList['module']['foreignKeySource'] = array('module' => 'tree', 'method' => 'getTaskOptionMenu', 'params' => 'task');
|
||||
|
||||
$config->task->fieldList['story']['control'] = 'select';
|
||||
$config->task->fieldList['story']['foreignKey'] = true;
|
||||
$config->task->fieldList['story']['foreignKeySource'] = array('module' => 'story', 'method' => 'getExecutionStories', 'params' => '$executionID', 'pairs' => array('id', 'title'));
|
||||
|
||||
$config->task->customCreateFields = 'story,estStarted,deadline,mailto,pri,estimate';
|
||||
$config->task->customBatchCreateFields = 'module,story,assignedTo,estimate,estStarted,deadline,desc,pri';
|
||||
$config->task->customBatchEditFields = 'module,assignedTo,status,pri,estimate,record,left,estStarted,deadline,finishedBy,canceledBy,closedBy,closedReason';
|
||||
|
||||
Reference in New Issue
Block a user