Files
EasySoft-ZenTaoPMS/module/product/control.php
T
2023-05-11 21:01:52 +08:00

1134 lines
45 KiB
PHP
Executable File

<?php
/**
* The control file of product module of ZenTaoPMS.
*
* @copyright Copyright 2009-2015 禅道软件(青岛)有限公司(ZenTao Software (Qingdao) Co., Ltd. www.cnezsoft.com)
* @license ZPL(http://zpl.pub/page/zplv12.html) or AGPL(https://www.gnu.org/licenses/agpl-3.0.en.html)
* @author Chunsheng Wang <chunsheng@cnezsoft.com>
* @package product
* @version $Id: control.php 5144 2013-07-15 06:37:03Z chencongzhi520@gmail.com $
* @link http://www.zentao.net
*/
class product extends control
{
public $products = array();
/**
* Construct function.
*
* @param string moduleName
* @param string methodName
* @access public
* @return void
*/
public function __construct(string $moduleName = '', string $methodName = '')
{
parent::__construct($moduleName, $methodName);
if(!isset($this->app->user)) return;
/* Load need modules. */
$this->loadModel('story');
$this->loadModel('release');
$this->loadModel('tree');
$this->loadModel('user');
/* Get all products, if no, goto the create page. */
$this->products = $this->product->getPairs('nocode', 0, '', 'all');
if($this->product->checkLocateCreate($this->products)) $this->locate($this->createLink('product', 'create'));
$this->view->products = $this->products;
}
/**
* Index page, to browse.
*
* @param string $productID
* @access public
* @return void
*/
public function index(string $productID = '0')
{
/* Check product id and get product branch. */
$productID = (int)$productID;
$productID = $this->product->saveVisitState($productID, $this->products);
$branch = (int)$this->cookie->preBranch;
/* Set Menu. */
if($this->app->getViewType() != 'mhtml') unset($this->lang->product->menu->index);
if($this->app->viewType == 'mhtml') $this->product->setMenu($productID, $branch);
/* Add create product button for view. */
if(common::hasPriv('product', 'create')) $this->lang->TRActions = html::a($this->createLink('product', 'create'), "<i class='icon icon-sm icon-plus'></i> " . $this->lang->product->create, '', "class='btn btn-primary'");
$this->view->title = $this->lang->product->index;
$this->display();
}
/**
* The projects which linked the product.
*
* @param string $status
* @param string $productID
* @param string $branch
* @param string $involved
* @param string $orderBy
* @param string $recTotal
* @param string $recPerPage
* @param string $pageID
* @access public
* @return void
*/
public function project(string $status = 'all', string $productID = '0', string $branch = '', string $involved = '0', string $orderBy = 'order_desc', string $recTotal = '0', string $recPerPage = '20', string $pageID = '1')
{
$productID = (int)$productID;
$involved = ($this->cookie->involved or $involved);
$this->productZen->setProjectMenu($productID, $branch, $this->cookie->preBranch);
/* Load pager. */
$this->app->loadClass('pager', true);
$pager = new pager((int)$recTotal, (int)$recPerPage, (int)$pageID);
/* Set view variables and display. */
$this->productZen->displayProjectPage($productID, $branch, $status, $involved, $orderBy, $pager);
}
/**
* 产品研发需求列表。
* Browse requirements list of product.
*
* @param int $productID
* @param int|stirng $branch all|''|0
* @param string $browseType
* @param int $param Story Module ID
* @param string $storyType requirement|story
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @param int $projectID
* @access public
* @return void
*/
public function browse(string $productID = '0', string $branch = '', string $browseType = '', string $param = '0', string $storyType = 'story', string $orderBy = '', string $recTotal = '0', string $recPerPage = '20', $pageID = '1', $projectID = '0')
{
$productID = (int)$productID;
$param = (int)$param;
$recTotal = (int)$recTotal;
$recPerPage = (int)$recPerPage;
$pageID = (int)$pageID;
$projectID = (int)$projectID;
$browseType = strtolower($browseType);
/* Pre process. */
$isProjectStory = $this->app->rawModule == 'projectstory';
$this->loadModel('datatable');
$this->loadModel('execution');
/* Generate data. */
$showModule = !empty($this->config->datatable->productBrowse->showModule) ? $this->config->datatable->productBrowse->showModule : '';
$productID = $this->app->tab != 'project' ? $this->product->saveVisitState($productID, $this->products) : $productID;
$product = $this->productZen->getBrowseProduct($productID);
$project = $this->loadModel('project')->getByID($projectID);
list($branch, $branchID) = $this->productZen->getBranchAndBranchID($product, $branch);
$orderBy = $orderBy ?? ($this->cookie->productStoryOrder ? $this->cookie->productStoryOrder : 'id_desc');
/* ATTENTION: be careful to change the order of follow sentencies. */
$this->productZen->setMenu4Browse($projectID, $productID, $branch, $storyType);
$this->productZen->saveAndModifyCookie4Browse($productID, $branch, $param, $browseType, $orderBy);
/* Generate data. */
$moduleID = $this->productZen->getModuleId4Browse($param, $browseType);
$moduleTree = $this->productZen->getModuleTree4Browse($projectID, $productID, $branch, $param, $storyType, $browseType);
$showBranch = $this->productZen->getShowBranch4Browse($projectID, $productID, $storyType, $isProjectStory);
$projectProducts = $this->productZen->getProjectProducts4Browse($projectID, $storyType, $isProjectStory);
$productPlans = $this->productZen->getProductPlans4Browse($projectProducts, $projectID, $storyType, $isProjectStory);
list($stories, $pager) = $this->productZen->getStoriesAndPager4Browse($projectID, $productID, $branchID, $moduleID, $param, $storyType, $browseType, $orderBy, $recTotal, $recPerPage, $pageID);
/* Process the sql, get the conditon partion, save it to session. */
$queryCondition = $this->story->dao->get();
$this->loadModel('common')->saveQueryCondition($queryCondition, 'story', (strpos('bysearch,reviewbyme,bymodule', $browseType) === false and !$isProjectStory));
/* Collect story ID list. */
$storyIdList = $this->productZen->getStoryIdList($stories);
/* Generate data. */
list($branchOpt, $branchTagOpt) = $this->productZen->getBranchAndTagOption4Browse($projectID, $product, $isProjectStory);
$branchOptions = (empty($product) && $isProjectStory) ? $this->productZen->getBranchOptions4Browse($projectProducts, $projectID) : array();
$storyTasks = $this->loadModel('task')->getStoryTaskCounts($storyIdList);
$storyBugs = $this->loadModel('bug')->getStoryBugCounts($storyIdList);
$storyCases = $this->loadModel('testcase')->getStoryCaseCounts($storyIdList);
$productName = ($isProjectStory and empty($productID)) ? $this->lang->product->all : $this->products[$productID];
/* Save session. */
$this->productZen->saveSession4Browse($product, $storyType, $browseType, $isProjectStory);
/* Build search form. */
$this->productZen->buildSearchForm4Browse($project, $projectID, $productID, $branch, $param, $storyType, $browseType, $isProjectStory);
/* Assign. */
$this->view->title = $productName . $this->lang->colon . ($storyType === 'story' ? $this->lang->product->browse : $this->lang->product->requirement);
$this->view->position[] = $productName;
$this->view->position[] = $this->lang->product->browse;
$this->view->productID = $productID;
$this->view->product = $product;
$this->view->productName = $productName;
$this->view->moduleID = $moduleID;
$this->view->stories = $stories;
$this->view->plans = $this->loadModel('productplan')->getPairs($productID, ($branch === 'all' or empty($branch)) ? '' : $branch, 'unexpired,noclosed', true);
$this->view->productPlans = !empty($productPlans) ? array(0 => '') + $productPlans : array();
$this->view->summary = $this->product->summary($stories, $storyType);
$this->view->moduleTree = $moduleTree;
$this->view->parentModules = $this->tree->getParents($moduleID);
$this->view->pager = $pager;
$this->view->users = $this->user->getPairs('noletter|pofirst|nodeleted');
$this->view->orderBy = $orderBy;
$this->view->browseType = $browseType;
$this->view->modules = $this->tree->getOptionMenu($productID, 'story', 0, $branchID);
$this->view->moduleID = $moduleID;
$this->view->moduleName = ($moduleID and $moduleID !== 'all') ? $this->tree->getById($moduleID)->name : $this->lang->tree->all;
$this->view->branch = $branch;
$this->view->branchID = $branchID;
$this->view->branchOptions = $branchOptions;
$this->view->branchOption = $branchOpt;
$this->view->branchTagOption = $branchTagOpt;
$this->view->showBranch = $showBranch;
$this->view->storyStages = $this->product->batchGetStoryStage($stories);
$this->view->setModule = true;
$this->view->storyTasks = $storyTasks;
$this->view->storyBugs = $storyBugs;
$this->view->storyCases = $storyCases;
$this->view->param = $param;
$this->view->projectID = $projectID;
$this->view->products = $this->products;
$this->view->projectProducts = !empty($projectProducts) ? $projectProducts : array();
$this->view->storyType = $storyType;
$this->view->from = $this->app->tab;
$this->view->modulePairs = $showModule ? $this->tree->getModulePairs($productID, 'story', $showModule) : array();
$this->view->project = $project;
$this->view->recTotal = $pager->recTotal;
$this->display();
}
/**
* Create a product.
* 创建产品。可以是顶级产品,也可以是项目集下的产品。
*
* @param string $programID
* @param string $extra
* @access public
* @return void
*/
public function create(string $programID = '0', string $extra = '')
{
$programID = (int)$programID;
if(!empty($_POST))
{
$formConfig = $this->productZen->appendFlowFields($this->config->product->form->create);
$data = form::data($formConfig);
$product = $this->productZen->prepareCreateExtras($data, $this->post->acl, $this->post->uid);
$productID = $this->product->create($product, $this->post->uid, zget($_POST, 'lineName', ''));
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$response = $this->productZen->responseAfterCreate($productID, (int)$product->program);
$this->send($response);
}
$this->productZen->setCreateMenu($programID);
$this->productZen->buildCreateForm($programID, $extra);
}
/**
* Edit a product.
*
* @param int $productID
* @param string $action
* @param string $extra
* @param int $programID
* @access public
* @return void
*/
public function edit(string $productID, string $action = 'edit', string $extra = '', string $programID = '0')
{
$productID = (int)$productID;
$programID = (int)$programID;
if(!empty($_POST))
{
$formConfig = $this->productZen->appendFlowFields($this->config->product->form->edit);
$data = form::data($formConfig);
$product = $this->productZen->prepareEditExtras($data, $this->post->acl, $this->post->uid);
$changes = $this->product->update($productID, $product, $this->post->uid);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
if($action == 'undelete') $this->loadModel('action')->undelete((int)$extra);
$response = $this->productZen->responseAfterEdit($productID, $programID, $changes);
$this->send($response);
}
$this->productZen->setEditMenu($productID, $programID);
$product = $this->product->getByID($productID);
$productID = $this->product->saveVisitState($productID, $this->products);
$this->productZen->buildEditForm($product);
}
/**
* 根据POST过来的ID列表,批量编辑相应产品。
* Batch edit products.
*
* @param string $programID
* @access public
* @return void
*/
public function batchEdit(string $programID = '0')
{
$programID = (int)$programID;
if($this->post->name)
{
/* 从POST中获取数据,并预处理数据。 */
$formConfig = $this->productZen->appendFlowFields($this->config->product->form->batchEdit, 'batch');
$data = form::data($formConfig);
$products = $this->productZen->prepareBatchEditExtras($data);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$result = $this->product->batchUpdate($products);
if(dao::isError()) $this->send($result);
$response = $this->productZen->responseAfterBatchEdit($result, $programID);
return $this->send($response);
}
/* 获取要修改的产品ID列表。*/
$productIdList = $this->post->productIDList;
if(empty($productIdList)) return print(js::locate($this->session->productList, 'parent'));
/* Set menu when page come from program. */
if($this->app->tab == 'program') $this->loadModel('program')->setMenu(0);
/* 构造批量编辑页面表单配置数据。*/
$this->productZen->buildBatchEditForm($programID, explode(',', $productIdList));
}
/**
* Close product.
*
* @param string $productID
* @access public
* @return void
*/
public function close(string $productID)
{
$productID = (int)$productID;
if(!empty($_POST))
{
$formConfig = $this->productZen->appendFlowFields($this->config->product->form->close);
$data = form::data($formConfig);
$product = $this->productZen->prepareCloseExtras($data);
$changes = $this->product->close($productID, $product);
if(dao::isError()) $this->send(array('result' => 'fail', 'message' => dao::getError()));
$response = $this->productZen->responseAfterClose($productID, $changes, $this->post->comment);
$this->send($response);
}
$this->product->setMenu($productID);
$this->productZen->buildCloseForm($productID);
}
/**
* 查看产品。
* View a product.
*
* @param int $productID
* @access public
* @return void
*/
public function view(string $productID)
{
$productID = (int)$productID;
/* Get product. */
$product = $this->product->getStatByID($productID);
if(!$product) return $this->productZen->responseNotFound4View();
$product->desc = $this->loadModel('file')->setImgSize($product->desc);
/* Set navigation menu. */
$this->product->setMenu($productID);
/* Execute hooks. */
$this->executeHooks($productID);
$this->view->title = $product->name . $this->lang->colon . $this->lang->product->view;
$this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name);
$this->view->position[] = $this->lang->product->view;
$this->view->product = $product;
$this->view->actions = $this->loadModel('action')->getList('product', $productID);
$this->view->users = $this->user->getPairs('noletter');
$this->view->groups = $this->loadModel('group')->getPairs();
$this->view->branches = $this->loadModel('branch')->getPairs($productID);
$this->view->reviewers = explode(',', $product->reviewer);
$this->display();
}
/**
* 删除产品。
* Delete a product.
*
* @param int $productID
* @param string $confirm yes|no
* @access public
* @return void
*/
public function delete(string $productID, string $confirm = 'no')
{
$productID = (int)$productID;
/* Not confirm. */
if($confirm == 'no')
{
print(js::confirm($this->lang->product->confirmDelete, $this->createLink('product', 'delete', "productID=$productID&confirm=yes")));
return;
}
/* Delete product. */
$this->product->deleteById($productID);
/* Reset session. */
$this->session->set('product', '');
/* Response JSON message. */
$message = $this->executeHooks($productID);
if($message) $this->lang->saveSuccess = $message;
if($this->viewType == 'json') return $this->send(array('result' => 'success', 'message' => $this->lang->saveSuccess));
print(js::locate($this->createLink('product', 'all'), 'parent'));
}
/**
* 产品路线图。
* Road map of a product.
*
* @param int $productID
* @param int|string $branch
* @access public
* @return void
*/
public function roadmap(string $productID, string $branch = 'all')
{
$productID = (int)$productID;
/* Set env viriables. */
$this->product->setMenu($productID, $branch);
$this->productZen->saveSession4Roadmap();
/* Generate data. */
$product = $this->product->getByID($productID);
if(empty($product)) $this->locate($this->createLink('product', 'showErrorNone', 'fromModule=product'));
$roadmaps = $this->product->getRoadmap($productID, $branch);
$branches = $product->type == 'normal' ? array(0 => '') : $this->loadModel('branch')->getPairs($productID);
/* Assign view data. */
$this->view->title = $product->name . $this->lang->colon . $this->lang->product->roadmap;
$this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name);
$this->view->position[] = $this->lang->product->roadmap;
$this->view->product = $product;
$this->view->roadmaps = $roadmaps;
$this->view->branches = $branches;
$this->display();
}
/**
* 产品动态。
* Product dynamic.
*
* @param int $productID
* @param string $type
* @param string $param
* @param int $recTotal
* @param string $date
* @param string $direction next|pre
* @access public
* @return void
*/
public function dynamic(string $productID = '0', string $type = 'today', string $param = '', string $recTotal = '0', string $date = '', string $direction = 'next')
{
$productID = (int)$productID;
$recTotal = (int)$recTotal;
$param = (int)$param;
$this->loadModel('action');
/* Save env data. */
$this->productZen->saveBackUriSession4Dynamic();
$this->product->setMenu($productID, 0, $type);
/* Generate order by string. */
$orderBy = $direction == 'next' ? 'date_desc' : 'date_asc';
/* Get user account. */
$account = 'all';
if($type == 'account')
{
$user = $this->loadModel('user')->getById($param, 'id');
if($user) $account = $user->account;
}
/* Get actions. */
list($actions, $pager) = $this->getActions4Dynamic($account, $orderBy, $productID, $type, $recTotal, $date, $direction);
if(empty($recTotal)) $recTotal = count($actions);
/* Assign. */
$this->view->title = $this->products[$productID] . $this->lang->colon . $this->lang->product->dynamic;
$this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $this->products[$productID]);
$this->view->position[] = $this->lang->product->dynamic;
$this->view->userIdPairs = $this->loadModel('user')->getPairs('noletter|nodeleted|noclosed|useid');
$this->view->accountPairs = $this->user->getPairs('noletter|nodeleted|noclosed');
$this->view->productID = $productID;
$this->view->type = $type;
$this->view->orderBy = $orderBy;
$this->view->account = $account;
$this->view->user = isset($user) ? $user : '';
$this->view->param = $param;
$this->view->pager = $pager;
$this->view->dateGroups = $this->action->buildDateGroup($actions, $direction, $type);
$this->view->direction = $direction;
$this->view->recTotal = $recTotal;
$this->display();
}
/**
* Product dashboard.
*
* @param int $productID
* @access public
* @return void
*/
public function dashboard(string $productID = '0')
{
$productID = (int)$productID;
/* Check and get product ID. */
$productID = $this->product->saveVisitState($productID, $this->products);
/* Get product. */
$product = $this->product->getStatByID($productID);
if(!$product) return print(js::locate('product', 'all'));
$product->desc = $this->loadModel('file')->setImgSize($product->desc);
/* Save env data. */
$this->productZen->saveBackUriSession4Dashboard();
$this->product->setMenu($productID);
/* Assign. */
$this->view->title = $product->name . $this->lang->colon . $this->lang->product->view;
$this->view->position[] = html::a($this->createLink($this->moduleName, 'browse'), $product->name);
$this->view->position[] = $this->lang->product->view;
$this->view->product = $product;
$this->view->actions = $this->loadModel('action')->getList('product', $productID);
$this->view->users = $this->user->getPairs('noletter');
$this->view->lines = array('') + $this->product->getLinePairs();
$this->view->dynamics = $this->productZen->getActions4Dashboard($productID);
$this->view->roadmaps = $this->product->getRoadmap($productID, 0, 6);
$this->display();
}
/**
* Update order.
*
* @access public
* @return void
*/
public function updateOrder()
{
/* Init vars. */
$idList = explode(',', trim($this->post->products, ','));
$orderBy = $this->post->orderBy;
if(strpos($orderBy, 'program') === false) return false;
/* Remove programID. */
foreach($idList as $i => $id)
{
if(!is_numeric($id)) unset($idList[$i]);
}
/* Update order. */
$products = $this->dao->select('t1.`order`, t1.id')->from(TABLE_PRODUCT)->alias('t1')
->leftJoin(TABLE_PROGRAM)->alias('t2')->on('t1.program = t2.id')
->where('t1.id')->in($idList)
->orderBy('t2.order_asc, t1.line_desc, t1.order_asc')
->fetchPairs('order', 'id');
foreach($products as $order => $id)
{
$newID = array_shift($idList);
if($id == $newID) continue;
$this->dao->update(TABLE_PRODUCT)->set('`order`')->eq($order)->where('id')->eq($newID)->exec();
}
}
/**
* 访问与测试相关模块或方法时,又没有相关产品,或者没有产品,会跳转到该方法。例如:qa。
* Show error no product when visit qa.
*
* @param string $moduleName project|qa|execution
* @param string $activeMenu
* @param string $objectID The format of this parameter should be integer.
* @access public
* @return void
*/
public function showErrorNone(string $moduleName = 'qa', string $activeMenu = 'index', string $objectID = '')
{
$objectID = (int)$objectID;
$this->productZen->setShowErrorNoneMenu($moduleName, $activeMenu, $objectID);
$this->view->title = $this->lang->$moduleName->common;
$this->view->objectID = $objectID;
$this->display();
}
/**
* Products under project set.
*
* @param string $browseType
* @param string $orderBy
* @param int $param
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @param int $programID
* @access public
* @return void
*/
public function all(string $browseType = 'noclosed', string $orderBy = 'program_asc', string $param = '0', string $recTotal = '0', string $recPerPage = '20', string $pageID = '1', string $programID = '0')
{
/* Convert string to int. */
$param = (int)$param;
$recTotal = (int)$recTotal;
$recPerPage = (int)$recPerPage;
$pageID = (int)$pageID;
$programID = (int)$programID;
/* Set env data. */
$this->productZen->setMenu4All();
/* Generate statistics of products and program. */
$this->app->loadClass('pager', true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$queryID = ($browseType == 'bySearch' or !empty($param)) ? $param : 0;
if($this->config->systemMode == 'light' and $orderBy == 'program_asc') $orderBy = 'order_asc';
$productStats = $this->product->getStats($orderBy, $pager, $browseType, 0, 'story', 0, $queryID);
$productStructure = $this->productZen->statisticProgram($productStats);
/* Save search form. */
$actionURL = $this->createLink('product', 'all', "browseType=bySearch&orderBy=order_asc&queryID=myQueryID");
$this->product->buildProductSearchForm($param, $actionURL);
/* Get product lines. */
list($productLines, $programLines) = $this->productZen->getProductLines();
$this->view->title = $this->lang->productCommon;
$this->view->position[] = $this->lang->productCommon;
$this->view->recTotal = $pager->recTotal;
$this->view->productStats = $productStats;
$this->view->productStructure = $productStructure;
$this->view->productLines = $productLines;
$this->view->programLines = $programLines;
$this->view->users = $this->user->getPairs('noletter');
$this->view->userIdPairs = $this->user->getPairs('noletter|showid');
$this->view->usersAvatar = $this->user->getAvatarPairs('');
$this->view->orderBy = $orderBy;
$this->view->browseType = $browseType;
$this->view->pager = $pager;
$this->view->showBatchEdit = $this->cookie->showProductBatchEdit;
$this->view->param = $param;
$this->view->recPerPage = $recPerPage;
$this->view->pageID = $pageID;
$this->view->programID = $programID;
$this->display();
}
/**
* 产品看板。
* Product kanban.
*
* @access public
* @return void
*/
public function kanban()
{
/* Save back URI to session. */
$this->productZen->saveBackUriSession4Kanban();
/* Generate data. */
list( , $productList, $planList, $projectList, $executionList, $projectProduct, $projectLatestExecutions, $hourList, $releaseList) = $this->product->getStats4Kanban();
$programPairs = $this->loadModel('program')->getPairs(true);
$kanbanList = $this->productZen->getProductList4Kanban($productList);
$emptyHour = $this->productZen->getEmptyHour();
/* Assign. */
$this->view->title = $this->lang->product->kanban;
$this->view->kanbanList = $kanbanList;
$this->view->programList = array($this->lang->product->emptyProgram) + $programPairs;
$this->view->productList = $productList;
$this->view->planList = $planList;
$this->view->projectList = $projectList;
$this->view->projectProduct = $projectProduct;
$this->view->latestExecutions = $projectLatestExecutions;
$this->view->executionList = $executionList;
$this->view->hourList = $hourList;
$this->view->emptyHour = $emptyHour;
$this->view->releaseList = $releaseList;
$this->display();
}
/**
* Manage product line.
*
* @access public
* @return void
*/
public function manageLine()
{
$this->app->loadLang('tree');
if($_POST)
{
$this->product->manageLine();
if(dao::isError()) return print(js::error(dao::getError()));
return print(js::reload('parent'));
}
$this->view->title = $this->lang->product->line;
$this->view->position[] = $this->lang->product->line;
$this->view->programs = array('') + $this->loadModel('program')->getTopPairs('', 'withDeleted');
$this->view->lines = $this->product->getLines();
$this->display();
}
/**
* Get white list personnel.
*
* @param int $productID
* @param string $module
* @param string $objectType
* @param string $orderBy
* @param int $recTotal
* @param int $recPerPage
* @param int $pageID
* @access public
* @return void
*/
public function whitelist($productID = 0, $module = 'product', $objectType = 'product', $orderBy = 'id_desc', $recTotal = 0, $recPerPage = 20, $pageID = 1)
{
$this->product->setMenu($productID, 0);
$this->lang->modulePageNav = '';
echo $this->fetch('personnel', 'whitelist', "objectID=$productID&module=$module&browseType=$objectType&orderBy=$orderBy&recTotal=$recTotal&recPerPage=$recPerPage&pageID=$pageID");
}
/**
* Adding users to the white list.
*
* @param int $productID
* @param int $deptID
* @param int $copyID
* @param string $branch
* @access public
* @return void
*/
public function addWhitelist($productID = 0, $deptID = 0, $copyID = 0)
{
$this->product->setMenu($productID);
$this->lang->modulePageNav = '';
echo $this->fetch('personnel', 'addWhitelist', "objectID=$productID&dept=$deptID&copyID=$copyID&objectType=product&module=product");
}
/*
* Removing users from the white list.
*
* @param int $id
* @param string $confirm
* @access public
* @return void
*/
public function unbindWhitelist($id = 0, $confirm = 'no')
{
echo $this->fetch('personnel', 'unbindWhitelist', "id=$id&confirm=$confirm");
}
/**
* Export product.
*
* @param string $status
* @param string $orderBy
* @access public
* @return void
*/
public function export(string $status, string $orderBy)
{
if($_POST)
{
/* 获取导出字段和数据。 */
$fields = $this->productZen->getExportFields();
$productStats = $this->productZen->getExportData($status, $orderBy);
$rowspan = $this->productZen->getExportRowspan($productStats);
/* 如果只导出选中产品,删除非选中产品。 */
if($this->post->exportType == 'selected')
{
$checkedItem = $this->cookie->checkedItem;
foreach($productStats as $i => $product)
{
if(strpos(",$checkedItem,", ",{$product->id},") === false) unset($productStats[$i]);
}
}
if($this->config->edition != 'open') list($fields, $productStats) = $this->loadModel('workflowfield')->appendDataFromFlow($fields, $productStats);
$this->post->set('rowspan', $rowspan);
$this->post->set('fields', $fields);
$this->post->set('rows', $productStats);
$this->post->set('kind', 'product');
$this->fetch('file', 'export2' . $this->post->fileType, $_POST);
}
$this->display();
}
/**
* Story track.
*
* @param string $productID
* @param int|string $branch
* @param string $projectID
* @param string $recTotal
* @param string $recPerPage
* @param string $pageID
* @access public
* @return void
*/
public function track(string $productID, string $branch = '', string $projectID = '0', string $recTotal = '0', string $recPerPage = '20', string $pageID = '1')
{
$productID = (int)$productID;
$projectID = (int)$projectID;
$branch = ($this->cookie->preBranch !== '' and $branch === '') ? $this->cookie->preBranch : $branch;
/* Set menu. The projectstory module does not execute. */
$this->productZen->setTrackMenu($productID, $branch, $projectID);
/* Load pager and get tracks. */
$this->app->loadClass('pager', true);
$pager = new pager($recTotal, $recPerPage, $pageID);
$tracks = $this->story->getTracks($productID, $branch, $projectID, $pager);
/* Get project products. */
$projectProducts = array();
if($projectID) $projectProducts = $this->product->getProducts($projectID);
$this->view->title = $this->lang->story->track;
$this->view->tracks = $tracks;
$this->view->pager = $pager;
$this->view->productID = $productID;
$this->view->projectProducts = $projectProducts;
$this->display();
}
/**
* Ajax set show setting.
*
* @access public
* @return void
*/
public function ajaxSetShowSetting()
{
$data = fixer::input('post')->get();
$this->loadModel('setting')->updateItem("{$this->app->user->account}.product.showAllProjects", $data->showAllProjects);
}
/**
* Ajax get products.
*
* @param int $executionID
* @access public
* @return void
*/
public function ajaxGetProducts($executionID)
{
$this->loadModel('build');
if(!$executionID) return print(html::select('product', array(), '', "class='form-control chosen' required"));
$status = empty($this->config->CRProduct) ? 'noclosed' : '';
$products = $this->product->getProductPairsByProject($executionID, $status);
if(empty($products))
{
return printf($this->lang->build->noProduct, $this->createLink('execution', 'manageproducts', "executionID=$executionID&from=buildCreate", '', 'true'), 'project');
}
return print(html::select('product', $products, '', "onchange='loadBranches(this.value);' class='form-control chosen' required data-toggle='modal' data-type='iframe'"));
}
/**
* Ajax get product by id.
*
* @param int $productID
* @access public
* @return void
*/
public function ajaxGetProductById($productID)
{
$product = $this->product->getById($productID);
$product->branchSourceName = sprintf($this->lang->product->branch, $this->lang->product->branchName[$product->type]);
$product->branchName = $this->lang->product->branchName[$product->type];
echo json_encode($product);
}
/**
* AJAX: get projects of a product in html select.
*
* @param int $productID
* @param int $branch
* @param int $projectID
* @access public
* @return void
*/
public function ajaxGetProjects($productID, $branch = 0, $projectID = 0)
{
$projects = array('' => '');
$projects += $this->product->getProjectPairsByProduct($productID, $branch);
if($this->app->getViewType() == 'json') return print(json_encode($projects));
return print(html::select('project', $projects, $projectID, "class='form-control' onchange='loadProductExecutions({$productID}, this.value)'"));
}
/**
* AJAX: get projects of a product in html select.
*
* @param int $productID
* @param int $branch
* @param int $number
* @access public
* @return void
*/
public function ajaxGetProjectsByBranch($productID, $branch = 0, $number = 0)
{
$projects = array('' => '');
$projects += $this->product->getProjectPairsByProduct($productID, $branch);
return print(html::select('projects' . "[$number]", array('' => '') + $projects, 0, "class='form-control' onchange='loadProductExecutionsByProject($productID, this.value, $number)'"));
}
/**
* AJAX: get executions of a product in html select.
*
* @param int $productID
* @param int $projectID
* @param int $branch
* @param string $number
* @param int $executionID
* @param string $from showImport
* @param string mode
* @access public
* @return void
*/
public function ajaxGetExecutions($productID, $projectID = 0, $branch = 0, $number = '', $executionID = 0, $from = '', $mode = '')
{
if($this->app->tab == 'execution' and $this->session->execution)
{
$execution = $this->loadModel('execution')->getByID($this->session->execution);
if($execution->type == 'kanban') $projectID = $execution->project;
}
if($projectID) $project = $this->loadModel('project')->getById($projectID);
$mode .= ($from == 'bugToTask' or empty($this->config->CRExecution)) ? 'noclosed' : '';
$mode .= !$projectID ? ',multiple' : '';
$executions = $from == 'showImport' ? $this->product->getAllExecutionPairsByProduct($productID, $branch, $projectID) : $this->product->getExecutionPairsByProduct($productID, $branch, $projectID, $mode);
if($this->app->getViewType() == 'json') return print(json_encode($executions));
if($number === '')
{
$event = $from == 'bugToTask' ? '' : " onchange='loadExecutionRelated(this.value)'";
$datamultiple = !empty($project) ? "data-multiple={$project->multiple}" : '';
return print(html::select('execution', array('' => '') + $executions, $executionID, "class='form-control' $datamultiple $event"));
}
else
{
$executions = empty($executions) ? array('' => '') : $executions;
$executionsName = $from == 'showImport' ? "execution[$number]" : "executions[$number]";
$misc = $from == 'showImport' ? "class='form-control' onchange='loadImportExecutionRelated(this.value, $number)'" : "class='form-control' onchange='loadExecutionBuilds($productID, this.value, $number)'";
return print(html::select($executionsName, $executions, '', $misc));
}
}
/**
* AJAX: get executions of a product in html select.
*
* @param int $productID
* @param int $projectID
* @param int $branch
* @param int $number
* @access public
* @return void
*/
public function ajaxGetExecutionsByProject($productID, $projectID = 0, $branch = 0, $number = 0)
{
$noMultipleExecutionID = $projectID ? $this->loadModel('execution')->getNoMultipleID($projectID) : '';
$executions = $this->product->getExecutionPairsByProduct($productID, $branch, $projectID, 'multiple,stagefilter');
$disabled = $noMultipleExecutionID ? "disabled='disabled'" : '';
$html = html::select("executions[{$number}]", array('' => '') + $executions, 0, "class='form-control' onchange='loadExecutionBuilds($productID, this.value, $number)' $disabled");
if($noMultipleExecutionID) $html .= html::hidden("executions[{$number}]", $noMultipleExecutionID, "id=executions{$number}");
return print($html);
}
/**
* AJAX: get plans of a product in html select.
*
* @param int $productID
* @param int $planID
* @param bool $needCreate
* @param string $expired
* @param string $param
* @access public
* @return void
*/
public function ajaxGetPlans($productID, $branch = 0, $planID = 0, $fieldID = '', $needCreate = false, $expired = '', $param = '')
{
$param = strtolower($param);
if(strpos($param, 'forstory') === false)
{
$plans = $this->loadModel('productplan')->getPairs($productID, empty($branch) ? 'all' : $branch, $expired, strpos($param, 'skipparent') !== false);
}
else
{
$plans = $this->loadModel('productplan')->getPairsForStory($productID, $branch == '0' ? 'all' : $branch, $param);
}
$field = $fieldID !== '' ? "plans[$fieldID]" : 'plan';
$multiple = strpos($param, 'multiple') === false ? '' : 'multiple';
$output = html::select($field, $plans, $planID, "class='form-control chosen' $multiple");
if($branch == 0 and strpos($param, 'edit') and (strpos($param, 'forstory') === false)) $output = html::select($field, $plans, $planID, "class='form-control chosen' multiple");
if(count($plans) == 1 and $needCreate and $needCreate !== 'false')
{
$output .= "<div class='input-group-btn'>";
$output .= html::a($this->createLink('productplan', 'create', "productID=$productID&branch=$branch", '', true), "<i class='icon icon-plus'></i>", '', "class='btn btn-icon' data-toggle='modal' data-type='iframe' data-width='95%' title='{$this->lang->productplan->create}'");
$output .= '</div>';
$output .= "<div class='input-group-btn'>";
$output .= html::a("javascript:void(0)", "<i class='icon icon-refresh'></i>", '', "class='btn btn-icon refresh' data-toggle='tooltip' title='{$this->lang->refresh}' onclick='loadProductPlans($productID)'");
$output .= '</div>';
}
echo $output;
}
/**
* Ajax get product lines.
*
* @param int $programID
* @param int $productID
* @access public
* @return void
*/
public function ajaxGetLine($programID, $productID = 0)
{
$lines = array();
if(empty($productID) or $programID) $lines = $this->product->getLinePairs($programID);
if($productID) return print(html::select("lines[$productID]", array('' => '') + $lines, '', "class='form-control picker-select'"));
if(!$productID) return print(html::select('line', array('' => '') + $lines, '', "class='form-control picker-select'"));
}
/**
* Ajax get reviewers.
*
* @param int $productID
* @param int $storyID
* @access public
* @return void
*/
public function ajaxGetReviewers($productID, $storyID = 0)
{
/* Get product reviewers. */
$product = $this->product->getByID($productID);
$productReviewers = $product->reviewer;
if(!$productReviewers and $product->acl != 'open') $productReviewers = $this->loadModel('user')->getProductViewListUsers($product, '', '', '', '');
$storyReviewers = '';
if($storyID)
{
$story = $this->loadModel('story')->getByID($storyID);
$storyReviewers = $this->story->getReviewerPairs($story->id, $story->version);
$storyReviewers = implode(',', array_keys($storyReviewers));
}
$reviewers = $this->loadModel('user')->getPairs('noclosed|nodeleted', $storyReviewers, 0, $productReviewers);
echo html::select("reviewer[]", $reviewers, $storyReviewers, "class='form-control chosen' multiple");
}
/**
* Drop menu page.
*
* @param int $productID
* @param string $module
* @param string $method
* @param string $extra
* @param string $from
* @access public
* @return void
*/
public function ajaxGetDropMenu(string $productID, string $module, string $method, string $extra = '', string $from = '')
{
$productID = (int)$productID;
$shadow = '0';
if($from == 'qa') $shadow = 'all';
$products = $this->productZen->getProducts4DropMenu($shadow);
$programProducts = array();
foreach($products as $product) $programProducts[$product->program][] = $product;
$this->view->link = $this->product->getProductLink($module, $method, $extra);
$this->view->productID = $productID;
$this->view->module = $module;
$this->view->method = $method;
$this->view->extra = $extra;
$this->view->products = $programProducts;
$this->view->projectID = $this->app->tab == 'project' ? $this->session->project : 0;
$this->view->programs = $this->loadModel('program')->getPairs(true);
$this->view->lines = $this->product->getLinePairs();
$this->display();
}
/**
* Set product id to session in ajax
*
* @param int $productID
* @access public
* @return void
*/
public function ajaxSetState(string $productID)
{
$this->session->set('product', (int)$productID, $this->app->tab);
$this->send(array('result' => 'success', 'productID' => $this->session->product));
}
}