魔改!讓“禪道”擁有 抄送列表


禪道是第一款國產的開源項目管理軟件,她的核心管理思想基於敏捷方法scrum,內置了產品管理和項目管理。
官方傳送門:https://www.zentao.net/
禪道有多個版本:專業版、企業版、集團版、開源版。
在使用禪道開源版的過程中,發現了一個問題(不確定是不是使用方式不對),就是禪道的抄送數據並沒有在列表中可以展現。

所以摸索了一下實現了以下功能:

  1. 產品->需求列表加入“抄送給我”的需求列表
  2. 測試->BUG列表加入“抄送給我”的BUG列表

1. 參考文檔

禪道使用自主開發的zentaophp框架開發,內置了完整的擴展機制(非簡單的鈎子),用戶可以非常方便的對禪道進行徹底的二次開發。
zentaophp開發手冊地址:https://devel.easycorp.cn/book/zentaophphelp/about-10.html
zentaophp二次開發文檔地址:https://devel.easycorp.cn/book/extension/intro-45.html

2. 流程分析

zentaophp的請求分發是按url地址來划分的,比如/product-browse-1.html這個請求。
其中:product是一個模塊,而browse是這個模塊control的一個接口。
以BUG列表為例:
control的browse接口接收到http請求后調用model的getBugs方法拉取bugs數據,然后將數據填充到/view/browse.html.php視圖中顯示出來。

bug

需求的流程大致是一樣的,不過需求的入口是product模塊,然后通過調用story拉取數據。

3. 拓展功能

zentaoPHP框架每個模塊按照mvc進行划分,有自己的control(控制層)、 model(模型層)和view(視圖層),並且提供了非常便利的拓展方式。
想要拓展自己的功能只需要將拓展代碼放在每個模塊的ext目錄下即可,可以看一下效果圖:
拓展前:
old
拓展后:
new

a. 對視圖層進行拓展

為了不改變禪道的源碼,對視圖層的拓展鈎子進行擴展,鈎子腳本的命名規則為方法名. 擴展名.html.hook.php。
所以對應的拓展頁面名稱為:browse.mailto.html.hook.php,存放路徑為:module/bug/ext/view。內容如下:

<script>
  <?php
  $mail_to_type = 'mailtome';
  $mail_to_label = "<span class='text'>抄送給我</span>";
  $mail_to_active = $mail_to_type == $browseType ? 'btn-active-text' : '';
  $mail_to_uri = html::a($this->createLink('bug', 'browse', "productid=$productID&branch=$branch&browseType=$mail_to_type"), $mail_to_label, "", "class='btn btn-link $mail_to_active'");
  $mail_to_uri = str_replace(array("\r", "\n", "\r\n"), "", $mail_to_uri);
  ?>
  $('#bysearchTab')
    .parent()
    .find('a:eq(3)')
    .after("<?php echo $mail_to_uri ?>");
</script>

通過zentaoPHP的js模塊生成a標簽,如果將a標簽用jQuery插入到指定的位置。

b. 對模型層進行拓展

上面視圖層拓展中,“抄送給我”調用的還是bug模塊的browse接口,所以不需要對control進行拓展,只需要重寫model的getBugs方法,添加對browseType=‘mailtome’的數據進行處理即可。

重寫getBugs方法,拓展文件名稱以getBugs方法名稱命名,路徑為module/bug/ext/model/,內容如下:

<?php
public function getBugs($productID, $projects, $branch, $browseType, $moduleID, $queryID, $sort, $pager)
{
  if($browseType == 'mailtome')
  {
    /* Set modules and browse type. */
    $modules    = $moduleID ? $this->loadModel('tree')->getAllChildId($moduleID) : '0';
    $browseType = ($browseType == 'bymodule' and $this->session->bugBrowseType and $this->session->bugBrowseType != 'bysearch') ? $this->session->bugBrowseType : $browseType;
    $bugs = array();
    $bugs = $this->getMailToMeBugs($productID, $branch, $modules, $projects, $sort, $pager);
    return $this->checkDelayBugs($bugs);
  } 
  else 
  {
    return parent::getBugs($productID, $projects, $branch, $browseType, $moduleID, $queryID, $sort, $pager);
  }
}
?>

這里,如果$browseType='mailtome'的話,就調用getMailToMeBugs這個方法,否則調用父級的getBugs方法。
getMailToMeBug這個方法是自己拓展的,所有需要在module/bug/ext/model/路徑下創建對應的php,內容如下:

<?php
public function getMailToMeBugs($productID, $branch, $modules, $projects, $orderBy, $pager)
{
    return $this->dao->select('*')->from(TABLE_BUG)
      ->where('project')->in(array_keys($projects))
      ->andWhere('product')->eq($productID)
      ->beginIF($branch)->andWhere('branch')->in($branch)->fi()
      ->beginIF($modules)->andWhere('module')->in($modules)->fi()
      ->andWhere('deleted')->eq(0)
      ->andWhere('mailto', true)->like('%,' . $this->app->user->account . ',%')
      ->orWhere('mailto')->like('%,' . $this->app->user->account)
      ->markRight(1)
      ->andWhere('status')->eq('active')
      ->orderBy($orderBy)->page($pager)->fetchAll();
}
?>

根據禪道的抄送入庫規則“,賬號”,只需要查詢“,賬號,”“,賬號”的數據即可,這里只查詢狀態為激活的BUG。

c. 拓展需求“抄送給我”列表

需求“抄送給我”的拓展方式跟BUG“抄送給我”的拓展方式是一樣的,需要注意的是需求入口是product模塊,拉取的數據是story模塊。

story拓展的model代碼:

<?php
public function getByMailTo($productID, $branch, $modules, $orderBy, $pager)
{
  $stories = $this->dao->select('*')->from(TABLE_STORY)
    ->where('product')->in($productID)
    ->andWhere('deleted')->eq(0)
    ->beginIF($branch)->andWhere("branch")->eq($branch)->fi()
    ->beginIF($modules)->andWhere("module")->in($modules)->fi()
    ->andWhere('mailto', true)->like('%,' . $this->app->user->account . ',%')
    ->orWhere('mailto')->like('%,' . $this->app->user->account)
    ->markRight(1)
    ->andWhere('stage')->ne('closed')
    ->orderBy($orderBy)
    ->page($pager)
    ->fetchAll();
  return $this->mergePlanTitle($productID, $stories, $branch);
}
?>

下面是拓展后的效果:

story

至此,就可以在禪道上查看“抄送給我”的需求和BUG了。

我是寫java的,不會php代碼,這里的代碼都是根據開發手冊依葫蘆畫瓢的。

=========================================================
源碼可關注公眾號 “HiIT青年” 發送 “zentao” 獲取。(如果沒有收到回復,可能是你之前取消過關注。)

HiIT青年
關注公眾號,閱讀更多文章。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM