0

我对新想法感到空虚——我差点认输。教义只是不想和我玩..

我的程序是针对 MySQL 和 php 网络界面构建的,并且基于 www.qdpm.com。目前,我有一个公共函数来执行将表“任务”中的元素导出到 csv 文件。到目前为止,一切都很好。但我的目标也是从表“Tasks”相关的“Tasks_comments”表中导出评论,以及从“Users”表中创建评论的用户。这可以通过 SQL 查询轻松完成:

SELECT `tasks`.`description`, `tasks_comments`.`description`, `users`.`name`
FROM tasks, tasks_comments
INNER JOIN users on `tasks_comments`.`created_by` = `users`.`id`

困难的部分是将其纳入教义——并使其发挥作用。我一直在 Google 上搜索前 200 页,但失败的次数大致相同。如果不是更多的话。

我有一个 action.class.php 模块,其中包括我的公共函数 executeExport(完整代码:http ://pastebin.com/uWqfd4WC )和 components.class.php(完整代码:http ://pastebin.com/ NAJRvaBp )。

公共函数执行导出:

public function executeExport(sfWebRequest $request)
  {
    /*check access*/
    if($request->hasParameter('projects_id'))
    {
      $this->forward404Unless($this->projects = Doctrine_Core::getTable('Projects')->createQuery()->addWhere('id=?',$request->getParameter('projects_id'))->fetchOne(), sprintf('Object projects does not exist (%s).', $request->getParameter('projects_id')));

      $this->checkProjectsAccess($this->projects);
      $this->checkTasksAccess('view',false,$this->projects);
    }
    else
    {
      $this->checkTasksAccess('view');
    }

    /*Form with checklist on what I want to export*/  
    $this->columns = array(
                           'Projects'       => t::__('Project Name'),
                           'id'             => t::__('Id'),
                           'TasksGroups'    => t::__('Group'),
                           'Versions'        => t::__('Version'),
                           'ProjectsPhases' => t::__('Phase'),                 
                           'TasksPriority'  => t::__('Priority'),
                           'TasksLabels'     => t::__('Label'),                                  
                           'name'     => t::__('Name'),
                           'TasksStatus'    => t::__('Status'),
                           'TasksTypes'      => t::__('Type'),                 
                           'assigned_to'    => t::__('Assigned To'),
                           'Users'     => t::__('Created By'),
                           'estimated_time' => t::__('Est. Time'),
                           'work_hours'     => t::__('Work Hours'),                                                      
                           'start_date'     => t::__('Start Date'),
                           'due_date'       => t::__('Due Date'),
                           'progress'       => t::__('Progress'),
                           'created_at'     => t::__('Created At'),
                           'description'    => t::__('Description'),

                          );

    $extra_fields = ExtraFieldsList::getFieldsByType('tasks',$this->getUser(),false,array('all'=>true));

    foreach($extra_fields as $v)
    {
      $this->columns['extra_field_' . $v['id']]=$v['name'];
    }   




    $this->columns['url']=t::__('Url');

    if($fields = $request->getParameter('fields'))
    {
      $separator = "\t";
      $format = $request->getParameter('format','.csv');
      $filename = $request->getParameter('filename','tasks');

            header("Content-type: Application/octet-stream");      
            header("Content-disposition: attachment; filename=" . $filename . "." . $format);
            header("Pragma: no-cache");
            header("Expires: 0");

      $content = '';
      foreach($fields as $f)
      {
        $content .= str_replace(array("\n\r","\r","\n",$separator),' ',$this->columns[$f]) . $separator;
      }
      $content .= "\n";

      if($format=='csv')
      {
        echo chr( 0xFF ) . chr( 0xFE ) . mb_convert_encoding( $content, 'UTF-16LE', 'UTF-8' );
      }
      else
      {
        echo $content;
      }

      if(strlen($request->getParameter('selected_items')==0)) exit();

/*Query at the time*/      
$q = Doctrine_Core::getTable('Tasks')->createQuery('t')
          ->leftJoin('t.TasksPriority tp')
          ->leftJoin('t.TasksStatus ts')
          ->leftJoin('t.TasksLabels tl')
          ->leftJoin('t.TasksTypes tt')
          ->leftJoin('t.TasksGroups tg')
          ->leftJoin('t.ProjectsPhases pp')
          ->leftJoin('t.Versions v')
          ->leftJoin('t.Projects p')
          ->leftJoin('t.Users')  
          ->leftJoin('t.TasksComments')                            
          ->whereIn('t.id',explode(',',$request->getParameter('selected_items')));

架构.yml:

Tasks:
  connection: doctrine
  tableName: tasks
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    projects_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      default: '0'
      notnull: true
      autoincrement: false
    tasks_status_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tasks_priority_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tasks_type_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tasks_label_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tasks_groups_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    projects_phases_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    versions_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    created_by:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    name:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      default: ''
      notnull: true
      autoincrement: false
    description:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    assigned_to:
      type: string(255)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    estimated_time:
      type: float()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    due_date:
      type: date(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    created_at:
      type: timestamp(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tickets_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    closed_date:
      type: date(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    discussion_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    start_date:
      type: date(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    progress:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Projects:
      local: projects_id
      foreign: id
      type: one
    Tickets:
      local: tickets_id
      foreign: id
      type: one
    TasksStatus:
      local: tasks_status_id
      foreign: id
      type: one
    TasksPriority:
      local: tasks_priority_id
      foreign: id
      type: one
    TasksTypes:
      local: tasks_type_id
      foreign: id
      type: one
    TasksLabels:
      local: tasks_label_id
      foreign: id
      type: one
    TasksGroups:
      local: tasks_groups_id
      foreign: id
      type: one
    ProjectsPhases:
      local: projects_phases_id
      foreign: id
      type: one
    Versions:
      local: versions_id
      foreign: id
      type: one
    Users:
      local: created_by
      foreign: id
      type: one
    TasksComments:
      local: id
      foreign: tasks_id
      type: many
TasksComments:
  connection: doctrine
  tableName: tasks_comments
  columns:
    id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: true
      autoincrement: true
    tasks_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      default: '0'
      notnull: true
      autoincrement: false
    created_by:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tasks_status_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    tasks_priority_id:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    due_date:
      type: date(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    worked_hours:
      type: float()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    description:
      type: string()
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    created_at:
      type: timestamp(25)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
    progress:
      type: integer(4)
      fixed: false
      unsigned: false
      primary: false
      notnull: false
      autoincrement: false
  relations:
    Tasks:
      local: tasks_id
      foreign: id
      type: one
    Users:
      local: created_by
      foreign: id
      type: one
    TasksStatus:
      local: tasks_status_id
      foreign: id
      type: one
    TasksPriority:
      local: tasks_priority_id
      foreign: id
      type: one

我要使用的三个表是:

  1. 任务(图片来自phpadmin:s2.postimg.org/3sf75m055/web16_meebox_net_db16_meebox_net_commissi_qd.png)

  2. task_comments(图片来自phpadmin:s11.postimg.org/lfrtdnw9v/web16_meebox_net_db16_meebox_net_commissi_qd.png)

  3. 用户

这可能与子查询有关吗?或者你有我需要添加的神奇代码行吗?刚刚有个主意,我是游戏!

谢谢你。

4

1 回答 1

1

好的,我用另一种方式解决了。

  1. 在程序配置文件中找到连接文件。
  2. 使用连接选项创建 php 文件
  3. 使用组合框创建 php 文件,其中包含获取项目名称的查询
  4. 创建了 php f 好的,我用另一种方式解决了它。

  5. 在程序配置文件中找到连接文件。

  6. 使用连接选项创建 php 文件
  7. 使用组合框创建 php 文件,其中包含获取项目名称的查询
  8. 创建了一个 php 文件,该文件使用组合框的 where 语句将查询导出到 csv,该文件使用组合框的 where 语句将查询导出到 csv
于 2013-10-03T15:22:10.780 回答