* Code for import.
This commit is contained in:
@@ -9,8 +9,11 @@ $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' => '', 'lang' => '');
|
||||
$config->port->fieldList['dataSource'] = array('module' => '', 'method' => '', 'params' => '', 'pairs' => '', 'sql' => '', 'lang' => '');
|
||||
|
||||
$config->port->table['mainTable']['name'] = '';
|
||||
$config->port->table['mainTable']['fields'] = explode(',', "");
|
||||
$config->port->table['mainTable']['foreignKey'] = '';
|
||||
|
||||
$config->port->initFunction = 'title,control,required,';
|
||||
$config->port->dateFeilds = 'estStarted,realStarted,deadline,openedDate,assignedDate,finishedDate,canceledDate,closedDate,lastEditedDate,';
|
||||
|
||||
+28
-163
@@ -4,44 +4,17 @@ class port extends control
|
||||
/**
|
||||
* Export datas.
|
||||
*
|
||||
* @param string $model
|
||||
* @param string $params
|
||||
* @param array $rows
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function export($model = '', $params = '', $rows = array())
|
||||
{
|
||||
/* Split parameters into variables (executionID=1,status=open).*/
|
||||
$params = explode(',', $params);
|
||||
foreach($params as $key => $param)
|
||||
{
|
||||
$param = explode('=', $param);
|
||||
$params[$param[0]] = $param[1];
|
||||
unset($params[$key]);
|
||||
}
|
||||
extract($params);
|
||||
|
||||
/* save params to session. */
|
||||
$this->session->set(($model.'PortParams'), $params);
|
||||
if($_POST)
|
||||
{
|
||||
$this->config->port->sysDataList = $this->port->initSysDataFields();
|
||||
|
||||
$fields = $this->post->exportFields;
|
||||
|
||||
/* Init config fieldList */
|
||||
$fieldList = $this->port->initFieldList($model, $fields);
|
||||
|
||||
$rows = $this->getRows($model, $fieldList);
|
||||
|
||||
$list = $this->setListValue($model, $fieldList);
|
||||
if($list) foreach($list as $listName => $listValue) $this->post->set($listName, $listValue);
|
||||
|
||||
/* Get export rows and fields datas */
|
||||
$exportDatas = $this->getExportDatas($fieldList, $rows);
|
||||
|
||||
$this->post->set('rows', $exportDatas['rows']);
|
||||
$this->post->set('fields', $exportDatas['fields']);
|
||||
$this->post->set('kind', $model);
|
||||
|
||||
$this->port->export($model, $params, $rows);
|
||||
$this->fetch('file', 'export2' . $_POST['fileType'], $_POST);
|
||||
}
|
||||
}
|
||||
@@ -76,10 +49,10 @@ class port extends control
|
||||
/* Init config fieldList */
|
||||
$fieldList = $this->port->initFieldList($model, $fields);
|
||||
|
||||
$list = $this->setListValue($model, $fieldList);
|
||||
$list = $this->port->setListValue($model, $fieldList);
|
||||
if($list) foreach($list as $listName => $listValue) $this->post->set($listName, $listValue);
|
||||
|
||||
$fields = $this->getExportDatas($fieldList);
|
||||
$fields = $this->port->getExportDatas($fieldList);
|
||||
$this->post->set('fields', $fields['fields']);
|
||||
$this->post->set('kind', $model);
|
||||
$this->post->set('rows', array());
|
||||
@@ -92,143 +65,35 @@ class port extends control
|
||||
$this->display();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ExportDatas.
|
||||
*
|
||||
* @param int $fieldList
|
||||
* @param array $rows
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getExportDatas($fieldList, $rows = array())
|
||||
{
|
||||
$exportDatas = array();
|
||||
$foreignKeyList = array();
|
||||
foreach ($fieldList as $key => $field)
|
||||
{
|
||||
$exportDatas['fields'][$key] = $field['title'];
|
||||
if($field['foreignKey'])
|
||||
{
|
||||
$exportDatas[$key] = $field['values'];
|
||||
$foreignKeyList[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($rows)) return $exportDatas;
|
||||
|
||||
$exportDatas['user'] = $this->loadModel('user')->getPairs('devfirst|noclosed|nodeleted');
|
||||
|
||||
foreach ($rows as $id => $values)
|
||||
{
|
||||
foreach($values as $field => $value)
|
||||
{
|
||||
if(in_array($field, $foreignKeyList))
|
||||
{
|
||||
$rows[$id]->$field = zget($exportDatas[$field], $value);
|
||||
}
|
||||
elseif(strpos($this->config->port->userFields, $field) !== false)
|
||||
{
|
||||
$rows[$id]->$field = zget($exportDatas['user'], $value);
|
||||
}
|
||||
|
||||
/* if value = 0 or value = 0000:00:00 set value = ''*/
|
||||
if(!$value or helper::isZeroDate($value))
|
||||
{
|
||||
$rows[$id]->$field = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$exportDatas['rows'] = array_values($rows);
|
||||
return $exportDatas;
|
||||
}
|
||||
|
||||
/**
|
||||
* setListValue
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $fieldList
|
||||
* @access public
|
||||
* @return void/array
|
||||
*/
|
||||
public function setListValue($model, $fieldList)
|
||||
{
|
||||
$lists = array();
|
||||
|
||||
if(!empty($this->config->$model->listFields))
|
||||
{
|
||||
$listFields = $this->config->$model->listFields;
|
||||
foreach($listFields as $field)
|
||||
{
|
||||
$listName = $field . 'List';
|
||||
if(!empty($fieldList[$field]))
|
||||
{
|
||||
$lists[$listName] = $fieldList[$field]['values'];
|
||||
if(strpos($this->config->$model->sysLangFields, $field)) $lists[$listName] = join(',', $fieldList[$field]['values']);
|
||||
}
|
||||
}
|
||||
|
||||
$lists['listStyle'] = $listFields;
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rows .
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $fieldList
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getRows($model, $fieldList)
|
||||
{
|
||||
$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)->alias('t1')
|
||||
->where($queryCondition)
|
||||
->beginIF($this->post->exportType == 'selected')->andWhere('t1.id')->in($this->cookie->checkedItem)->fi()
|
||||
->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;
|
||||
}
|
||||
|
||||
if(array_key_exists('files', $fieldList))
|
||||
{
|
||||
$modelDatas = $this->port->getFiles($model, $modelDatas);
|
||||
}
|
||||
|
||||
$rows = !empty($_POST['rows']) ? $_POST['rows'] : '';
|
||||
if($rows)
|
||||
{
|
||||
foreach($rows as $id => $row)
|
||||
{
|
||||
$modelDatas[$id] = (object) array_merge((array)$modelDatas[$id], (array)$row);
|
||||
}
|
||||
}
|
||||
return $modelDatas;
|
||||
}
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* Import.
|
||||
*
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function import()
|
||||
public function import($params = '')
|
||||
{
|
||||
if($_FILES)
|
||||
{
|
||||
$file = $this->loadModel('file')->getUpload('file');
|
||||
$file = $file[0];
|
||||
$extension = $file['extension'];
|
||||
|
||||
$fileName = $this->file->savePath . $this->file->getSaveName($file['pathname']);
|
||||
move_uploaded_file($file['tmpname'], $fileName);
|
||||
|
||||
$phpExcel = $this->app->loadClass('phpexcel');
|
||||
$phpReader = new PHPExcel_Reader_Excel2007();
|
||||
if(!$phpReader->canRead($fileName))
|
||||
{
|
||||
$phpReader = new PHPExcel_Reader_Excel5();
|
||||
if(!$phpReader->canRead($fileName))die(js::alert($this->lang->excel->canNotRead));
|
||||
}
|
||||
$this->session->set('fileImportFileName', $fileName);
|
||||
$this->session->set('fileImportExtension', $extension);
|
||||
die(js::locate(inlink('showImport', "executionID=$executionID"), 'parent.parent'));
|
||||
}
|
||||
$this->display();
|
||||
|
||||
}
|
||||
|
||||
|
||||
+212
-23
@@ -32,6 +32,88 @@ class portModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* export
|
||||
*
|
||||
* @param string $model
|
||||
* @param string $params
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function export($model = '', $params = '')
|
||||
{
|
||||
/* Split parameters into variables (executionID=1,status=open).*/
|
||||
$params = explode(',', $params);
|
||||
foreach($params as $key => $param)
|
||||
{
|
||||
$param = explode('=', $param);
|
||||
$params[$param[0]] = $param[1];
|
||||
unset($params[$key]);
|
||||
}
|
||||
extract($params);
|
||||
|
||||
/* save params to session. */
|
||||
$this->session->set(($model.'PortParams'), $params);
|
||||
|
||||
$this->config->port->sysDataList = $this->initSysDataFields();
|
||||
|
||||
$fields = $this->post->exportFields;
|
||||
|
||||
/* Init config fieldList */
|
||||
$fieldList = $this->initFieldList($model, $fields);
|
||||
|
||||
$rows = $this->getRows($model, $fieldList);
|
||||
|
||||
$list = $this->setListValue($model, $fieldList);
|
||||
if($list) foreach($list as $listName => $listValue) $this->post->set($listName, $listValue);
|
||||
|
||||
/* Get export rows and fields datas */
|
||||
$exportDatas = $this->getExportDatas($fieldList, $rows);
|
||||
|
||||
$this->post->set('rows', $exportDatas['rows']);
|
||||
$this->post->set('fields', $exportDatas['fields']);
|
||||
$this->post->set('kind', $model);
|
||||
}
|
||||
|
||||
/**
|
||||
* createFromImport
|
||||
*
|
||||
* @param int $model
|
||||
* @param string $params
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function createFromImport($model, $params = '')
|
||||
{
|
||||
$this->loadModel('action');
|
||||
$this->loadModel('file');
|
||||
$now = helper::now();
|
||||
$datas = fixer::input('post')->get();
|
||||
$table = zget($this->config->objectTables, $model);
|
||||
|
||||
if(!empty($_POST['id']))
|
||||
{
|
||||
$oldObjects = $this->dao->select('*')->from($table)->where('id')->in(($_POST['id']))->fetchAll('id');
|
||||
}
|
||||
|
||||
$objects = array();
|
||||
$objectData = array();
|
||||
foreach ($datas as $field => $data)
|
||||
{
|
||||
if(is_array($data))
|
||||
{
|
||||
foreach($data as $key => $value) $objectData[$key][$field] = $value;
|
||||
}
|
||||
}
|
||||
|
||||
a($objectData);
|
||||
|
||||
die;
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Init FieldList .
|
||||
*
|
||||
@@ -66,7 +148,6 @@ class portModel extends model
|
||||
}
|
||||
}
|
||||
|
||||
$modelFieldList = $this->initForeignKey($model, $field, $modelFieldList);
|
||||
$modelFieldList['values'] = $this->initValues($model, $field, $modelFieldList);
|
||||
$fieldList[$field] = $modelFieldList;
|
||||
}
|
||||
@@ -135,9 +216,9 @@ class portModel extends model
|
||||
return $this->portConfig->sysDataList[$values];
|
||||
}
|
||||
|
||||
if(!$fieldValue['foreignKey']) return $values;
|
||||
if(!$fieldValue['dataSource']) return $values;
|
||||
|
||||
extract($fieldValue['foreignKeySource']); // $module, $method, $params, $pairs, $sql, $lang
|
||||
extract($fieldValue['dataSource']); // $module, $method, $params, $pairs, $sql, $lang
|
||||
|
||||
if(!empty($module) and !empty($method))
|
||||
{
|
||||
@@ -164,26 +245,6 @@ class portModel extends model
|
||||
return $values;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init ForeignKey .
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $field
|
||||
* @param int $fieldContent
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function initForeignKey($model, $field, $fieldContent)
|
||||
{
|
||||
$modelConfig = $this->modelConfig;
|
||||
if((strpos($modelConfig->sysLangFields, $field) or strpos($modelConfig->sysDataFields, $field)) and empty($fieldContent['foreignKey']))
|
||||
{
|
||||
$fieldContent['foreignKey'] = true;
|
||||
}
|
||||
|
||||
return $fieldContent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Init Required.
|
||||
*
|
||||
@@ -320,6 +381,58 @@ class portModel extends model
|
||||
return $lang;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get ExportDatas.
|
||||
*
|
||||
* @param int $fieldList
|
||||
* @param array $rows
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getExportDatas($fieldList, $rows = array())
|
||||
{
|
||||
$exportDatas = array();
|
||||
$dataSourceList = array();
|
||||
|
||||
foreach ($fieldList as $key => $field)
|
||||
{
|
||||
$exportDatas['fields'][$key] = $field['title'];
|
||||
if($field['values'])
|
||||
{
|
||||
$exportDatas[$key] = $field['values'];
|
||||
$dataSourceList[] = $key;
|
||||
}
|
||||
}
|
||||
|
||||
if(empty($rows)) return $exportDatas;
|
||||
|
||||
$exportDatas['user'] = $this->loadModel('user')->getPairs('devfirst|noclosed|nodeleted');
|
||||
|
||||
foreach ($rows as $id => $values)
|
||||
{
|
||||
foreach($values as $field => $value)
|
||||
{
|
||||
if(in_array($field, $dataSourceList))
|
||||
{
|
||||
$rows[$id]->$field = zget($exportDatas[$field], $value);
|
||||
}
|
||||
elseif(strpos($this->config->port->userFields, $field) !== false)
|
||||
{
|
||||
$rows[$id]->$field = zget($exportDatas['user'], $value);
|
||||
}
|
||||
|
||||
/* if value = 0 or value = 0000:00:00 set value = ''*/
|
||||
if(!$value or helper::isZeroDate($value))
|
||||
{
|
||||
$rows[$id]->$field = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$exportDatas['rows'] = array_values($rows);
|
||||
return $exportDatas;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get files by model;
|
||||
*
|
||||
@@ -356,5 +469,81 @@ class portModel extends model
|
||||
return $datas;
|
||||
}
|
||||
|
||||
/**
|
||||
* setListValue
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $fieldList
|
||||
* @access public
|
||||
* @return void/array
|
||||
*/
|
||||
public function setListValue($model, $fieldList)
|
||||
{
|
||||
$lists = array();
|
||||
|
||||
if(!empty($this->config->$model->listFields))
|
||||
{
|
||||
$listFields = $this->config->$model->listFields;
|
||||
foreach($listFields as $field)
|
||||
{
|
||||
$listName = $field . 'List';
|
||||
if(!empty($fieldList[$field]))
|
||||
{
|
||||
$lists[$listName] = $fieldList[$field]['values'];
|
||||
if(strpos($this->config->$model->sysLangFields, $field)) $lists[$listName] = join(',', $fieldList[$field]['values']);
|
||||
}
|
||||
}
|
||||
|
||||
$lists['listStyle'] = $listFields;
|
||||
}
|
||||
|
||||
return $lists;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Rows .
|
||||
*
|
||||
* @param int $model
|
||||
* @param int $fieldList
|
||||
* @access public
|
||||
* @return void
|
||||
*/
|
||||
public function getRows($model, $fieldList, $orderBy = 'id_desc')
|
||||
{
|
||||
$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)->alias('t1')
|
||||
->where($queryCondition)
|
||||
->beginIF($this->post->exportType == 'selected')->andWhere('t1.id')->in($this->cookie->checkedItem)->fi()
|
||||
->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;
|
||||
}
|
||||
|
||||
if(array_key_exists('files', $fieldList))
|
||||
{
|
||||
$modelDatas = $this->getFiles($model, $modelDatas);
|
||||
}
|
||||
|
||||
$rows = !empty($_POST['rows']) ? $_POST['rows'] : '';
|
||||
if($rows)
|
||||
{
|
||||
foreach($rows as $id => $row)
|
||||
{
|
||||
$modelDatas[$id] = (object) array_merge((array)$modelDatas[$id], (array)$row);
|
||||
}
|
||||
}
|
||||
return $modelDatas;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -39,21 +39,18 @@ $config->task->exportFields = '
|
||||
';
|
||||
|
||||
$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['module']['dataSource'] = array('module' => 'tree', 'method' => 'getTaskOptionMenu', 'params' => '$executionID');
|
||||
|
||||
$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->fieldList['story']['dataSource'] = array('module' => 'story', 'method' => 'getExecutionStories', 'params' => '$executionID', 'pairs' => array('id', 'title'));
|
||||
|
||||
$config->task->fieldList['execution']['control'] = 'select';
|
||||
$config->task->fieldList['execution']['foreignKey'] = true;
|
||||
$config->task->fieldList['execution']['foreignKeySource'] = array('module' => 'execution', 'method' => 'getPairs');
|
||||
$config->task->fieldList['execution']['dataSource'] = array('module' => 'execution', 'method' => 'getPairs');
|
||||
|
||||
$config->task->fieldList['assignedTo']['values'] = 'user';
|
||||
$config->task->fieldList['assignedTo']['title'] = 'assignTo';
|
||||
$config->task->fieldList['closedReason']['foreignKey'] = true;
|
||||
$config->task->fieldList['closedReason']['foreignKeySource'] = array('lang' => 'reasonList');
|
||||
|
||||
$config->task->fieldList['closedReason']['dataSource'] = array('lang' => 'reasonList');
|
||||
|
||||
$config->task->customCreateFields = 'story,estStarted,deadline,mailto,pri,estimate';
|
||||
$config->task->customBatchCreateFields = 'module,story,assignedTo,estimate,estStarted,deadline,desc,pri';
|
||||
|
||||
Reference in New Issue
Block a user