コード例 #1
0
ファイル: ImportController.php プロジェクト: im286er/ent
 /**
  * 初始化函数
  *
  * @see \My\Common\ActionController::init()
  */
 public function init()
 {
     resetTimeMemLimit();
     $this->_project_id = isset($_REQUEST['__PROJECT_ID__']) ? trim($_REQUEST['__PROJECT_ID__']) : '';
     if (empty($this->_project_id)) {
         throw new \Exception('$this->_project_id值未设定');
     }
     $this->_collection = $this->model('Project\\Model\\Collection');
     $this->_collection_id = isset($_REQUEST['__COLLECTION_ID__']) ? trim($_REQUEST['__COLLECTION_ID__']) : '';
     if (empty($this->_collection_id)) {
         throw new \Exception('$this->_collection_id值未设定');
     }
     $this->_collection_id = $this->getCollectionIdByName($this->_collection_id);
     $this->_collection_name = 'idatabase_collection_' . $this->_collection_id;
     $this->_data = $this->collection($this->_collection_name);
     $this->_structure = $this->model('Project\\Model\\Structure');
     $this->getSchema();
 }
コード例 #2
0
ファイル: DataController.php プロジェクト: im286er/ent
 /**
  * 初始化函数
  *
  * @see \My\Common\ActionController::init()
  */
 public function init()
 {
     resetTimeMemLimit();
     // 特殊处理包含点的变量,将__DOT__转换为.
     convertVarNameWithDot($_POST);
     convertVarNameWithDot($_FILES);
     convertVarNameWithDot($_REQUEST);
     // 获取传递参数
     $this->_project_id = isset($_REQUEST['__PROJECT_ID__']) ? trim($_REQUEST['__PROJECT_ID__']) : '';
     $this->_collection_id = isset($_REQUEST['__COLLECTION_ID__']) ? trim($_REQUEST['__COLLECTION_ID__']) : '';
     // 初始化model
     $this->_collection = $this->model('Project\\Model\\Collection');
     $this->_structure = $this->model('Project\\Model\\Structure');
     $this->_plugin_structure = $this->model('Project\\Model\\PluginStructure');
     $this->_order = $this->model('Project\\Model\\Order');
     $this->_mapping = $this->model('Project\\Model\\Mapping');
     $this->_statistic = $this->model('Project\\Model\\Statistic');
     // 检查必要的参数
     if (empty($this->_project_id)) {
         throw new \Exception('$this->_project_id值未设定');
     }
     if (empty($this->_collection_id)) {
         throw new \Exception('$this->_collection_id值未设定');
     }
     // 进行内部私有变量的赋值
     $this->_collection_alias = $this->getCollectionAliasById($this->_collection_id);
     $this->_collection_id = $this->getCollectionIdByAlias($this->_collection_id);
     $this->_collection_name = 'idatabase_collection_' . $this->_collection_id;
     // 进行访问权限验证
     if (!$_SESSION['acl']['admin']) {
         if (!in_array($this->_collection_id, $_SESSION['acl']['collection'], true)) {
             return $this->deny();
         }
     }
     // 一次性获取当前集合的完整的文档结构信息
     $this->_schema = $this->getSchema();
     // 获取映射关系,初始化数据集合model
     $mapCollection = $this->_mapping->findOne(array('project_id' => $this->_project_id, 'collection_id' => $this->_collection_id, 'active' => true));
     if ($mapCollection != null) {
         $this->_data = $this->collection($mapCollection['collection'], $mapCollection['database'], $mapCollection['cluster']);
     } else {
         $this->_data = $this->collection($this->_collection_name);
     }
 }
コード例 #3
0
ファイル: function.php プロジェクト: im286er/ent
/**
 * 导出excel表格
 *
 * @param $datas 二维数据            
 * @param $name excel表格的名称,不包含.xlsx
 *            填充表格的数据
 * @example $datas['title'] = array('col1','col2','col3','col4');
 *          $datas['result'] = array(array('v11','v12','v13','v14')
 *          array('v21','v22','v23','v24'));
 * @return 直接浏览器输出excel表格 注意这个函数前不能有任何形式的输出
 *        
 */
function arrayToExcel($datas, $name = '', $output = 'php://output')
{
    resetTimeMemLimit();
    if (empty($name)) {
        $name = 'export_' . date("Y_m_d_H_i_s");
    }
    // 便于处理大的大型excel表格,存储在磁盘缓存中
    $cacheMethod = PHPExcel_CachedObjectStorageFactory::cache_to_discISAM;
    PHPExcel_Settings::setCacheStorageMethod($cacheMethod);
    $objPHPExcel = new PHPExcel();
    $objPHPExcel->getProperties()->setCreator('icc');
    $objPHPExcel->getProperties()->setLastModifiedBy('icc');
    $objPHPExcel->getProperties()->setTitle($name);
    $objPHPExcel->getProperties()->setSubject($name);
    $objPHPExcel->getProperties()->setDescription($name);
    $objPHPExcel->setActiveSheetIndex(0);
    $total = count($datas['title']);
    for ($i = 0; $i < $total; $i++) {
        $objPHPExcel->getActiveSheet()->getColumnDimension(excelTitle($i))->setAutoSize(true);
        $objPHPExcel->getActiveSheet()->SetCellValue(excelTitle($i) . '1', $datas['title'][$i]);
    }
    $i = 2;
    foreach ($datas['result'] as $data) {
        $j = 0;
        foreach ($data as $cell) {
            // 判断是否为图片,如果是图片,那么绘制图片
            if (is_array($cell) && isset($cell['type']) && $cell['type'] == 'image') {
                $coordinate = excelTitle($j) . $i;
                $cellName = isset($cell['name']) ? $cell['name'] : '';
                $cellDesc = isset($cell['desc']) ? $cell['desc'] : '';
                $cellType = isset($cell['type']) ? $cell['type'] : '';
                $cellUrl = isset($cell['url']) ? $cell['url'] : '';
                $cellHeight = isset($cell['height']) ? intval($cell['height']) : 0;
                if ($cellType == 'image') {
                    if ($cellHeight == 0) {
                        $cellHeight = 20;
                    }
                    $image = imagecreatefromstring(file_get_contents($cellUrl));
                    $objDrawing = new PHPExcel_Worksheet_MemoryDrawing();
                    $objDrawing->setName($cellName);
                    $objDrawing->setDescription($cellDesc);
                    $objDrawing->setImageResource($image);
                    $objDrawing->setRenderingFunction(PHPExcel_Worksheet_MemoryDrawing::RENDERING_JPEG);
                    $objDrawing->setMimeType(PHPExcel_Worksheet_MemoryDrawing::MIMETYPE_DEFAULT);
                    $objDrawing->setHeight($cellHeight);
                    $objDrawing->setCoordinates($coordinate);
                    // 填充到某个单元格
                    $objDrawing->setWorksheet($objPHPExcel->getActiveSheet());
                    $objPHPExcel->getActiveSheet()->getRowDimension($i)->setRowHeight($cellHeight);
                } else {
                    $objPHPExcel->getActiveSheet()->setCellValueExplicit($coordinate, $cellName, PHPExcel_Cell_DataType::TYPE_STRING);
                }
                // 添加链接
                $objPHPExcel->getActiveSheet()->getCell($coordinate)->getHyperlink()->setUrl($cellUrl);
                $objPHPExcel->getActiveSheet()->getCell($coordinate)->getHyperlink()->setTooltip($cellName . ':' . $cellDesc);
            } else {
                if (is_array($cell)) {
                    $objPHPExcel->getActiveSheet()->setCellValueExplicit(excelTitle($j) . $i, json_encode($cell), PHPExcel_Cell_DataType::TYPE_STRING);
                } else {
                    $objPHPExcel->getActiveSheet()->setCellValueExplicit(excelTitle($j) . $i, $cell, PHPExcel_Cell_DataType::TYPE_STRING);
                }
            }
            $j++;
        }
        $i++;
    }
    $objPHPExcel->getActiveSheet()->setTitle('Sheet1');
    $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
    if ($output === 'php://output') {
        header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
        header('Content-Disposition: attachment;filename="' . $name . '.xlsx"');
        header('Cache-Control: max-age=0');
        $objWriter->save($output);
        exit;
    }
    $objWriter->save($output);
    return true;
}
コード例 #4
0
ファイル: ProjectController.php プロジェクト: im286er/ent
 /**
  * 复制一个项目
  */
 public function cloneAction()
 {
     try {
         $projectId = $this->params()->fromQuery("projectId", '');
         $targetProjectId = $this->params()->fromQuery("targetProjectId", '');
         // 获取复制项目表
         $source_formIds = $this->params()->fromQuery('forms', array());
         // 是否复制数据
         $isCopyData = intval($this->params()->fromQuery("isCopyData", 0));
         // 是否是同一个数据库
         $isSameProject = $projectId == $targetProjectId;
         if (!empty($projectId)) {
             $projectInfo = $this->_project->findOne(array('_id' => myMongoId($projectId)));
             if (empty($projectInfo)) {
                 return $this->msg(false, '源项目不存在,无法复制');
             }
             $checkProject = $this->_project->findOne(array('_id' => myMongoId($targetProjectId)));
             if (empty($checkProject)) {
                 return $this->msg(false, '目标项目不存在,无法复制');
             }
             resetTimeMemLimit();
             // 获取该项目下的所有表,循环复制
             $formIds = array();
             $query = array();
             $query['projectId'] = $projectId;
             if (count($source_formIds) > 0) {
                 foreach ($source_formIds as $k => &$v) {
                     $v = myMongoId($v);
                 }
             }
             $query['_id'] = array('$in' => $source_formIds);
             $collection = $this->model('Idatabase\\Model\\Collection');
             $cursor = $collection->find($query);
             while ($cursor->hasNext()) {
                 $formInfo = $cursor->getNext();
                 // 复制表
                 $newFormInfo = $this->cloneForm($targetProjectId, $formInfo, $isCopyData);
                 // 返回旧表的ID和新表ID的对应数组
                 $formIds[$formInfo['_id']->__toString()] = $newFormInfo['newFormID'];
             }
             // 更新结构表的外键关联信息及数据关系
             $this->updateRshDataForm($formIds);
             return $this->msg(true, '复制项目成功');
         } else {
             return $this->msg(false, '请提交你要复制的项目');
         }
     } catch (\Exception $e) {
         $exceptMsg = exceptionMsg($e);
         return $this->msg(false, $exceptMsg);
     }
 }
コード例 #5
0
ファイル: IndexController.php プロジェクト: im286er/ent
 /**
  * 初始化函数
  *
  * @see \My\Common\ActionController::init()
  */
 public function init()
 {
     resetTimeMemLimit();
     // 特殊处理包含点的变量,将__DOT__转换为.
     convertVarNameWithDot($_POST);
     convertVarNameWithDot($_FILES);
     convertVarNameWithDot($_REQUEST);
     $this->_data = $this->model('User\\Model\\User');
     // 一次性获取当前集合的完整的文档结构信息
     $this->_schema = $this->getSchema();
     //$this->_data = $this->collection($this->_collection_name);
 }
コード例 #6
0
ファイル: DataController.php プロジェクト: im286er/ent
 /**
  * 清空某个数据结合
  * 注意,为了确保数据安全,需要输入当前用户的登录密码
  */
 public function dropAction()
 {
     resetTimeMemLimit();
     $password = $this->params()->fromPost('password', null);
     if ($password == null) {
         return $this->msg(false, '请输入当前用户的登录密码');
     }
     if (empty($_SESSION['account']['password'])) {
         return $this->msg(false, '当前会话已经过期,请重新登录');
     }
     if ($_SESSION['account']['password'] !== sha1($password)) {
         return $this->msg(false, '您输入的登录密码错误,请重新输入');
     }
     $rst = $this->_data->drop();
     if ($rst['ok'] == 1) {
         return $this->msg(true, '清空数据成功');
     } else {
         fb($rst, \FirePHP::LOG);
         return $this->msg(false, '清空数据失败' . Json::encode($rst));
     }
 }