zen.php 172 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576
  1. <?php
  2. class blockZen extends block
  3. {
  4. /**
  5. * 初始化用户某个仪表盘下的区块数据。
  6. * Init block when account use first.
  7. *
  8. * @param string $dashboard
  9. * @access public
  10. * @return bool
  11. */
  12. public function initBlock($dashboard)
  13. {
  14. if(!$dashboard) return false;
  15. $flow = isset($this->config->global->flow) ? $this->config->global->flow : 'full';
  16. $account = $this->app->user->account;
  17. $vision = $this->config->vision;
  18. /* 获取该仪表盘下的初始化默认布局。 */
  19. $blocks = $dashboard == 'my' ? $this->lang->block->default[$flow][$dashboard] : $this->lang->block->default[$dashboard];
  20. $closedBlock = isset($this->config->block->closed) ? $this->config->block->closed : '';
  21. foreach($blocks as $block)
  22. {
  23. if(strpos(",{$closedBlock},", ",{$block['module']}|{$block['code']},") !== false) continue;
  24. /* 根据module和code生成区块的宽度和高度。 */
  25. $sizeConfig = !empty($this->config->block->size[$block['module']][$block['code']]) ? $this->config->block->size[$block['module']][$block['code']] : $this->config->block->defaultSize;
  26. if(empty($block['width'])) $block['width'] = reset(array_keys($sizeConfig));
  27. $block['height'] = zget($sizeConfig, $block['width'], reset($sizeConfig));
  28. $block['account'] = $account; // 所属用户。
  29. $block['dashboard'] = $dashboard; // 所属仪表盘。
  30. $block['params'] = isset($block['params']) ? helper::jsonEncode($block['params']) : ''; // 配置项信息。
  31. $block['vision'] = $this->config->vision; // 所属用户界面。
  32. $block['left'] = $block['width'] == 1 ? 2 : 0; // 距左侧宽度。
  33. $block['top'] = $this->block->computeBlockTop((object)$block); // 距顶部高度。
  34. $this->block->create((object)$block);
  35. }
  36. if(dao::isError()) return false;
  37. /* 保存当前区块已经被初始化过的记录。 */
  38. $this->loadModel('setting')->setItem("$account.$dashboard.common.blockInited@$vision", '1');
  39. $this->loadModel('setting')->setItem("$account.$dashboard.block.initVersion", (string)$this->config->block->version);
  40. return true;
  41. }
  42. /**
  43. * 根据仪表盘获取可使用的模块列表。
  44. * Get module options when adding or editing blocks.
  45. *
  46. * @param string $dashboard
  47. * @access protected
  48. * @return string[]
  49. */
  50. protected function getAvailableModules($dashboard)
  51. {
  52. /* 只有在我的地盘仪表盘中添加区块才会选择对应模块,否则直接使用对应仪表盘所在的模块。*/
  53. /* Only when adding blocks to my dashboard can I select the corresponding module, otherwise I will directly use the module where the corresponding dashboard is located.*/
  54. if($dashboard != 'my') return array();
  55. $modules = $this->lang->block->moduleList;
  56. /* Unable to display the doc module on my dashboard. */
  57. unset($modules['doc']);
  58. if($this->config->global->flow != 'full') unset($modules['guide']);
  59. if($this->config->vision != 'rnd') unset($modules['contribute']);
  60. /* 从配置项中取出不同模块的首页对应的控制器方法。*/
  61. /* Retrieve the controller method corresponding to the homepage of different modules from the configuration item.*/
  62. list($programModule, $programMethod) = explode('-', $this->config->programLink);
  63. list($productModule, $productMethod) = explode('-', $this->config->productLink);
  64. list($projectModule, $projectMethod) = explode('-', $this->config->projectLink);
  65. list($executionModule, $executionMethod) = explode('-', $this->config->executionLink);
  66. $closedBlock = isset($this->config->block->closed) ? $this->config->block->closed : '';
  67. foreach($modules as $moduleKey => $moduleName)
  68. {
  69. if($moduleKey == 'todo') continue;
  70. /* Determine if the user has permission for the current module. */
  71. if(in_array($moduleKey, $this->app->user->rights['acls'])) unset($modules[$moduleKey]);
  72. $method = 'index';
  73. if($moduleKey == 'program') $method = $programMethod;
  74. if($moduleKey == 'product') $method = $productMethod;
  75. if($moduleKey == 'project') $method = $projectMethod;
  76. if($moduleKey == 'execution') $method = $executionMethod;
  77. /* After obtaining module permissions, it is necessary to verify whether there is permission for the module homepage. */
  78. if(in_array($moduleKey, array('product', 'project', 'execution', 'qa')) && !common::hasPriv($moduleKey, $method)) unset($modules[$moduleKey]);
  79. /* 被永久关闭的区块删除对应选项。 */
  80. /* Delete corresponding options for blocks that have been permanently closed. */
  81. if(strpos(",$closedBlock,", ",$moduleKey|$moduleKey,") !== false) unset($modules[$moduleKey]);
  82. if(isset($this->lang->block->modules[$moduleKey]) && !$this->getAvailableCodes($moduleKey)) unset($modules[$moduleKey]);
  83. }
  84. return $modules;
  85. }
  86. /**
  87. * 根据模块获取可使用的区块列表。
  88. * Get block options when adding or editing blocks.
  89. *
  90. * @param string $module
  91. * @access protected
  92. * @return string[]|true
  93. */
  94. protected function getAvailableCodes($module)
  95. {
  96. $blocks = array();
  97. /* 获取当前模块下的所有区块列表。 */
  98. if($module && isset($this->lang->block->modules[$module]))
  99. {
  100. $blocks = $this->lang->block->modules[$module]->availableBlocks;
  101. }
  102. /* 过滤掉永久关闭的区块。 */
  103. if(isset($this->config->block->closed))
  104. {
  105. foreach($blocks as $blockKey => $blockName)
  106. {
  107. if(strpos(",{$this->config->block->closed},", ",{$module}|{$blockKey},") !== false) unset($blocks[$blockKey]);
  108. }
  109. }
  110. return $blocks;
  111. }
  112. /**
  113. * 根据区块获取区块相关可配置参数列表。
  114. * Get other form items when adding or editing blocks.
  115. *
  116. * @param string $module
  117. * @param string $code
  118. * @access protected
  119. * @return array
  120. */
  121. protected function getAvailableParams($module = '', $code = '')
  122. {
  123. /* 特殊的模块对code特殊处理。 */
  124. if($code == 'todo' || $code == 'list' || $module == 'assigntome')
  125. {
  126. $code = $module;
  127. }
  128. elseif($code == 'statistic')
  129. {
  130. $code = $module . $code;
  131. }
  132. $params = zget($this->config->block->params, $code, array());
  133. $params = json_decode(json_encode($params), true);
  134. return $params;
  135. }
  136. /**
  137. * 自动生成区块的默认标题。
  138. * Get block default title.
  139. *
  140. * @param mixed[] $modules
  141. * @param string $module
  142. * @param array $codes
  143. * @param string $code
  144. * @param array $params
  145. * @access protected
  146. * @return string
  147. */
  148. protected function getBlockTitle($modules, $module, $codes, $code, $params)
  149. {
  150. $blockTitle = zget($codes, $code, ''); // 标快的标题默认是区块列表下拉选中的内容。
  151. /* scrumtest以外的区块标题前面要根据选中的类型填充标题内容。 如:产品列表 => 已关闭的产品列表。 */
  152. if($module != 'scrumtest' || $code == 'all')
  153. {
  154. $options = isset($params['type']['options']) ? $params['type']['options'] : array();
  155. if(!empty($options)) $blockTitle = vsprintf($this->lang->block->blockTitle, array(reset($options), $blockTitle));
  156. if(empty($blockTitle) && !in_array($module, array('product', 'project', 'execution', 'qa'))) $blockTitle = zget($modules, $module, ''); // 特殊的区块标题使用模块列表选中的文本内容。 如:欢迎总览区块。
  157. }
  158. return $blockTitle;
  159. }
  160. /**
  161. * 处理每个区块以渲染 UI。
  162. * Process each block for render UI.
  163. *
  164. * @param array $blocks
  165. * @param int $projectID
  166. * @access protected
  167. * @return array
  168. */
  169. protected function processBlockForRender($blocks, $projectID)
  170. {
  171. /* 根据用户的权限,和当前系统开启的权限 处理区块列表。*/
  172. $acls = $this->app->user->rights['acls'];
  173. foreach($blocks as $key => $block)
  174. {
  175. /* 将没有开启功能区块过虑。 */
  176. if(!helper::hasFeature('project_risk') && ($block->code == 'waterfallrisk' || $block->code == 'scrumrisk'))
  177. {
  178. unset($blocks[$key]);
  179. continue;
  180. }
  181. if(!helper::hasFeature('project_issue') && ($block->code == 'waterfallissue' || $block->code == 'scrumissue'))
  182. {
  183. unset($blocks[$key]);
  184. continue;
  185. }
  186. /* 过滤目前已经不存在的区块。 */
  187. if(!isset($this->lang->block->moduleList[$block->code]) && !isset($this->lang->block->modules[$block->module]->availableBlocks[$block->code]))
  188. {
  189. unset($blocks[$key]);
  190. continue;
  191. }
  192. /* 将没有视图权限的区块过滤。 */
  193. $module = $block->module;
  194. if(in_array($module, array('scrumproject', 'waterfallproject', 'waterfallplusproject', 'agileplusproject', 'ipdproject'))) $module = 'project';
  195. if($module == 'singleproduct') $module = 'product';
  196. if(!empty($module) && !in_array($module, array('welcome', 'guide', 'assigntome', 'zentaodynamic', 'teamachievement', 'dynamic', 'html')) && !empty($acls['views']) && !isset($acls['views'][$module]))
  197. {
  198. unset($blocks[$key]);
  199. continue;
  200. }
  201. /* 处理 params 信息中 count 的值,当没有 count 字段时 ,将 num 字段赋值给 count。 */
  202. $block->params = json_decode($block->params);
  203. if(isset($block->params->num) && !isset($block->params->count)) $block->params->count = $block->params->num;
  204. /* 生成更多链接。 */
  205. $this->createMoreLink($block, $projectID);
  206. $sizeConfig = !empty($this->config->block->size[$block->module][$block->code]) ? $this->config->block->size[$block->module][$block->code] : $this->config->block->defaultSize;
  207. /* 设置区块的默认宽度和高度。 */
  208. if(empty($block->width)) $block->width = reset(array_keys($sizeConfig));
  209. if(empty($block->height)) $block->height = zget($sizeConfig, $block->width, reset($sizeConfig));
  210. /* 设置区块距离左侧的宽度和距离顶部的高度。 */
  211. if($block->left === '') $block->left = $block->width == 1 ? 2 : 0;
  212. if($block->top === 0) $block->top = -1; // -1 将会自动计算高度。
  213. $block->width = (int)$block->width;
  214. $block->height = (int)$block->height;
  215. $block->left = (int)$block->left;
  216. $block->top = (int)$block->top;
  217. }
  218. return $blocks;
  219. }
  220. /**
  221. * 补全区块的加载更多链接。
  222. * Get the more link of the block.
  223. *
  224. * @param object $block
  225. * @param int $projectID
  226. * @access protected
  227. * @return object
  228. */
  229. protected function createMoreLink($block, $projectID)
  230. {
  231. $module = empty($block->module) ? 'common' : $block->module;
  232. $params = helper::safe64Encode("module={$block->module}&projectID={$projectID}");
  233. $block->blockLink = $this->createLink('block', 'printBlock', "id=$block->id&params=$params");
  234. $block->moreLink = '';
  235. if(isset($this->config->block->modules[$module]->moreLinkList->{$block->code}))
  236. {
  237. list($moduleName, $method, $vars) = explode('|', sprintf($this->config->block->modules[$module]->moreLinkList->{$block->code}, isset($block->params->type) ? $block->params->type : ''));
  238. /* The list assigned to me jumps to the work page when click more button. */
  239. $block->moreLink = $this->createLink($moduleName, $method, $vars);
  240. if($moduleName == 'my' && strpos($this->config->block->workMethods, $method) !== false)
  241. {
  242. /* 处理研发需求或任务列表区块点击更多后的跳转连接。 */
  243. if($moduleName == 'my' && $method == 'task' && $block->params->type != 'assignedTo' || $moduleName == 'my' && $method == 'story' && $block->params->type != 'assignedTo' && $block->params->type != 'reviewBy')
  244. {
  245. $block->moreLink = $this->createLink('my', 'contribute', "module={$method}&type={$block->params->type}");
  246. }
  247. else
  248. {
  249. $block->moreLink = $this->createLink($moduleName, 'work', 'mode=' . $method . '&' . $vars);
  250. }
  251. }
  252. elseif($moduleName == 'project' && $method == 'dynamic')
  253. {
  254. $block->moreLink = $this->createLink('project', 'dynamic', "projectID=$projectID&type=all");
  255. }
  256. elseif($moduleName == 'project' && $method == 'execution')
  257. {
  258. $block->moreLink = $this->createLink('project', 'execution', "status=all&projectID=$projectID");
  259. }
  260. elseif($moduleName == 'project' && $method == 'testtask')
  261. {
  262. $block->moreLink = $this->createLink('project', 'testtask', "projectID=$projectID");
  263. }
  264. elseif($moduleName == 'testtask' && $method == 'browse')
  265. {
  266. $block->moreLink = $this->createLink('testtask', 'browse', 'productID=0&branch=0&type=all,totalStatus');
  267. }
  268. elseif($block->code == 'recentproject' || $block->code == 'project')
  269. {
  270. $block->moreLink = $this->config->vision == 'or' ? $this->createLink('marketresearch', 'all') : $this->createLink('project', 'browse');
  271. }
  272. }
  273. elseif($block->code == 'dynamic')
  274. {
  275. $block->moreLink = $this->createLink('my', 'dynamic');
  276. }
  277. return $block;
  278. }
  279. /**
  280. * 打印动态区块。
  281. * latest dynamic.
  282. *
  283. * @access protected
  284. * @return void
  285. */
  286. protected function printDynamicBlock()
  287. {
  288. $this->view->actions = $this->loadModel('action')->getDynamic('all', 'today', 'date_desc', 30);
  289. $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all', '', 0, array_unique(array_column($this->view->actions, 'actor')));
  290. }
  291. /**
  292. * 打印禅道官网最新动态。
  293. * Latest dynamic by zentao official.
  294. *
  295. * @access protected
  296. * @return void
  297. */
  298. protected function printZentaoDynamicBlock()
  299. {
  300. $this->view->dynamics = array();
  301. $this->app->loadModuleConfig('admin');
  302. /* 检查服务端是否联网。 */
  303. $hasInternet = $this->session->hasInternet;
  304. if(empty($hasInternet))
  305. {
  306. $hasInternet = $this->loadModel('admin')->checkInternet();
  307. $this->session->set('hasInternet', $hasInternet);
  308. if(!$hasInternet) return;
  309. }
  310. if($this->session->isSlowNetwork) return;
  311. /* 调取接口获取数据。 */
  312. $startTime = microtime(true);
  313. $result = json_decode(preg_replace('/[[:cntrl:]]/mu', '', common::http(sprintf($this->config->admin->dynamicAPIURL, $this->config->version))));
  314. /* 请求超过一定时间后判断为网络请求缓慢。 */
  315. if(microtime(true) - $startTime > $this->config->timeout / 1000) $this->session->set('isSlowNetwork', true);
  316. $dynamics = array();
  317. if(!empty($result->data))
  318. {
  319. $data = $result->data;
  320. /* 如果存在活动时间大于当前时间的禅道中国行的动态,则优先展示此类动态。 */
  321. if(!empty($data->zentaosalon) && time() < strtotime($data->zentaosalon->time))
  322. {
  323. $data->zentaosalon->title = $this->lang->block->zentaodynamic->zentaosalon;
  324. $data->zentaosalon->label = formatTime($data->zentaosalon->time, DT_DATE4) . ' ' . $data->zentaosalon->name;
  325. $data->zentaosalon->linklabel = $this->lang->block->zentaodynamic->registration;
  326. $dynamics[] = $data->zentaosalon;
  327. }
  328. /* 如果存在活动时间大于当前时间的禅道公开课的动态,则次优先展示此类动态。 */
  329. if(!empty($data->publicclass) && time() < strtotime($data->zentaosalon->time))
  330. {
  331. $data->publicclass->title = $this->lang->block->zentaodynamic->publicclass;
  332. $data->publicclass->label = formatTime($data->publicclass->time, DT_DATE4) . ' ' . $this->lang->datepicker->dayNames[date('w', strtotime($data->publicclass->time))] . ' ' . formatTime($data->publicclass->time, 'H:i');
  333. $data->publicclass->linklabel = $this->lang->block->zentaodynamic->reservation;
  334. $dynamics[] = $data->publicclass;
  335. }
  336. /* 啥都没有就展示禅道的发布动态。 */
  337. if(!empty($data->release))
  338. {
  339. foreach($data->release as $release)
  340. {
  341. $releaseLength = strpos($release->content, $this->lang->release->common);
  342. $release->title = $this->lang->block->zentaodynamic->release;
  343. $release->label = $releaseLength > 0 && $releaseLength <= 30 ? mb_strcut($release->content, 0, $releaseLength + 8) : formatTime($release->time, DT_DATE4) . ' ' . $this->lang->datepicker->dayNames[date('w', strtotime($release->time))];
  344. $release->linklabel = false;
  345. $dynamics[] = $release;
  346. }
  347. }
  348. }
  349. $this->view->dynamics = $dynamics;
  350. }
  351. /**
  352. * 打印欢迎总览区块。
  353. * Welcome block.
  354. *
  355. * @access protected
  356. * @return void
  357. */
  358. protected function printWelcomeBlock()
  359. {
  360. /* 计算当前时间是早上还是中午还是下午还是晚上。 */
  361. $time = date('H:i');
  362. $welcomeType = '19:00';
  363. foreach($this->lang->block->welcomeList as $type => $name) $welcomeType = $time >= $type ? $type : $welcomeType;
  364. $usageDays = '';
  365. $dateUsed = $this->loadModel('admin')->genDateUsed();
  366. if(!empty($dateUsed->year)) $usageDays .= $dateUsed->year . ' ' . $this->lang->year . ' ';
  367. if(!empty($dateUsed->month)) $usageDays .= $dateUsed->month . ' ' . $this->lang->month . ' ';
  368. if(!empty($dateUsed->day)) $usageDays .= $dateUsed->day . ' ' . $this->lang->day . ' ';
  369. if(!$usageDays) $usageDays = "0 {$this->lang->day}";
  370. if(strpos($this->app->getClientLang(), 'zh') !== false) $usageDays = str_replace(' ', '', $usageDays);
  371. $yesterday = strtotime("-1 day");
  372. $year = date('Y', $yesterday);
  373. $month = date('m', $yesterday);
  374. $day = date('d', $yesterday);
  375. /* 获取昨日完成的任务数。 */
  376. $finishTask = 0;
  377. $finishTaskGroup = $this->loadModel('metric')->getResultByCodeWithArray('count_of_daily_finished_task_in_user', array('user' => $this->app->user->account, 'year' => $year, 'month' => $month, 'day' => $day), 'cron', null, $this->config->vision);
  378. if(!empty($finishTaskGroup))
  379. {
  380. foreach($finishTaskGroup as $finishTaskData)
  381. {
  382. if($finishTaskData['user'] == $this->app->user->account && $year == $finishTaskData['year'] && $month == $finishTaskData['month'] && $day == $finishTaskData['day'])
  383. {
  384. $finishTask = $finishTaskData['value'];
  385. break;
  386. }
  387. }
  388. }
  389. /* 获取昨日解决的Bug数。 */
  390. $fixBug = 0;
  391. $fixBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_fixed_bug_in_user', array('user' => $this->app->user->account, 'year' => $year, 'month' => $month, 'day' => $day), 'cron', null, $this->config->vision);
  392. if(!empty($fixBugGroup))
  393. {
  394. foreach($fixBugGroup as $fixBugData)
  395. {
  396. if($fixBugData['user'] == $this->app->user->account && $year == $fixBugData['year'] && $month == $fixBugData['month'] && $day == $fixBugData['day'])
  397. {
  398. $fixBug = $fixBugData['value'];
  399. break;
  400. }
  401. }
  402. }
  403. /* 根据完成任务和修复bug的数量给与称号。 */
  404. $honorary = '';
  405. if($finishTask || $fixBug)
  406. {
  407. $honorary = $finishTask > $fixBug ? 'task' : 'bug';
  408. $honorary = zget($this->lang->block->honorary, $honorary, '');
  409. }
  410. /* 生成指派给我的数据。 */
  411. $assignToMe = array();
  412. foreach($this->lang->block->welcome->assignList as $field => $label)
  413. {
  414. $type = 'assignedTo';
  415. if($field == 'testcase') $type = 'assigntome';
  416. if($field == 'ticket') $type = 'assignedtome';
  417. /* 根据不同的模块生成不同的度量项查询码。 */
  418. $code = "assigned_{$field}";
  419. if($field == 'story') $code = "pending_story";
  420. if($field == 'testcase') $code = "assigned_case";
  421. /* 查询当前指派给当前用户的不同数据。 */
  422. $assignedGroup = $this->metric->getResultByCode("count_of_{$code}_in_user", array('user' => $this->app->user->account), 'realtime', null, $field != 'feedback' ? $this->config->vision : '');
  423. $count = 0;
  424. if(!empty($assignedGroup))
  425. {
  426. $assignedGroup = reset($assignedGroup);
  427. $count = zget($assignedGroup, 'value', 0);
  428. }
  429. $assignToLink = '';
  430. if(common::hasPriv('my', 'work') && $this->config->vision != 'lite') $assignToLink = helper::createLink('my', 'work', "mode=$field&type=$type");
  431. if(common::hasPriv('my', 'contribute') && $this->config->vision == 'lite') $assignToLink = helper::createLink('my', 'contribute', "mode=$field&type=$type");
  432. $assignToMe[$field] = array('number' => $count, 'href' => $assignToLink);
  433. }
  434. /* 生成待我审批的数据。 */
  435. $reviewList = $this->loadModel('my')->getReviewingList('all');
  436. $reviewByMe['reviewByMe'] = array('number' => count($reviewList), 'href' => common::hasPriv('my', 'audit') && $this->config->vision != 'lite' ? helper::createLink('my', 'audit') : '');
  437. $isEn = $this->app->getClientLang() == 'en';
  438. /* 生成欢迎语。 */
  439. $yesterdaySummary = '';
  440. if($finishTask || $fixBug)
  441. {
  442. $separator = $isEn ? ', ' : '、';
  443. $comma = $isEn ? ' ' : $this->lang->comma;
  444. if($finishTask) $yesterdaySummary .= sprintf($this->lang->block->summary->finishTask, $finishTask) . ($fixBug ? $separator : $comma);
  445. if($isEn)
  446. {
  447. if($finishTask && $fixBug) $yesterdaySummary .= sprintf($this->lang->block->summary->fixBugEn, $fixBug) ;
  448. if($fixBug && !$finishTask) $yesterdaySummary .= sprintf($this->lang->block->summary->fixBug, $fixBug);
  449. }
  450. else
  451. {
  452. if($fixBug) $yesterdaySummary .= sprintf($this->lang->block->summary->fixBug, $fixBug) . $this->lang->comma;
  453. }
  454. }
  455. else
  456. {
  457. $yesterdaySummary .= $this->lang->block->summary->noWork;
  458. }
  459. if($isEn)
  460. {
  461. $yesterdaySummary = $yesterdaySummary . ' ' . $this->lang->block->summary->yesterday;
  462. }
  463. else
  464. {
  465. $yesterdaySummary = $this->lang->block->summary->yesterday . $yesterdaySummary;
  466. }
  467. $welcomeSummary = sprintf($this->lang->block->summary->welcome, $usageDays, $yesterdaySummary);
  468. $this->view->todaySummary = date(DT_DATE3, time()) . ' ' . $this->lang->datepicker->dayNames[date('w', time())]; // 当前年月日 星期几。
  469. $this->view->welcomeType = $welcomeType;
  470. $this->view->usageDays = $usageDays;
  471. $this->view->finishTask = $finishTask;
  472. $this->view->fixBug = $fixBug;
  473. $this->view->honorary = $honorary;
  474. $this->view->assignToMe = $assignToMe;
  475. $this->view->reviewByMe = $reviewByMe;
  476. $this->view->welcomeSummary = $welcomeSummary;
  477. }
  478. /**
  479. * 打印任务列表区块。
  480. * Print task block.
  481. *
  482. * @params object $block
  483. * @access protected
  484. * @return void
  485. * @param object $block
  486. */
  487. protected function printTaskBlock($block)
  488. {
  489. $this->session->set('taskList', $this->createLink('my', 'index'), 'execution');
  490. if(preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  491. $account = $this->app->user->account;
  492. $type = $block->params->type;
  493. $this->app->loadLang('execution');
  494. $this->view->tasks = $this->loadModel('task')->getUserTasks($account, $type, $this->viewType == 'json' ? 0 : (int)$block->params->count, null, $block->params->orderBy);;
  495. }
  496. /**
  497. * 打印Bug列表区块。
  498. * Print bug block.
  499. *
  500. * @params object $block
  501. * @access protected
  502. * @return void
  503. * @param object $block
  504. */
  505. protected function printBugBlock($block)
  506. {
  507. $this->session->set('bugList', $this->createLink('my', 'index'), 'qa');
  508. if(preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  509. /* 如果是我的地盘则展示所有项目, 否则展示当前项目数据。 */
  510. $projectID = $this->lang->navGroup->qa == 'project' ? $this->session->project : 0;
  511. $projectID = $block->dashboard == 'my' ? 0 : $projectID;
  512. $this->view->bugs = $this->loadModel('bug')->getUserBugs($this->app->user->account, $block->params->type, $block->params->orderBy, $this->viewType == 'json' ? 0 : (int)$block->params->count, null, $projectID);
  513. }
  514. /**
  515. * 打印用例列表区块。
  516. * Print case block.
  517. *
  518. * @params object $block
  519. * @access protected
  520. * @return void
  521. * @param object $block
  522. */
  523. protected function printCaseBlock($block)
  524. {
  525. $this->session->set('caseList', $this->createLink('my', 'index'), 'qa');
  526. $this->app->loadLang('testcase');
  527. $this->app->loadLang('testtask');
  528. /* 如果是我的地盘则展示所有项目, 否则展示当前项目数据。 */
  529. $projectID = $this->lang->navGroup->qa == 'project' ? $this->session->project : 0;
  530. $projectID = $block->dashboard == 'my' ? 0 : $projectID;
  531. $cases = array();
  532. if($block->params->type == 'assigntome')
  533. {
  534. $cases = $this->dao->select('t1.assignedTo AS assignedTo, t2.*')->from(TABLE_TESTRUN)->alias('t1')
  535. ->leftJoin(TABLE_CASE)->alias('t2')->on('t1.case = t2.id')
  536. ->leftJoin(TABLE_TESTTASK)->alias('t3')->on('t1.task = t3.id')
  537. ->Where('t1.assignedTo')->eq($this->app->user->account)
  538. ->andWhere('t1.status')->ne('done')
  539. ->andWhere('t3.status')->ne('done')
  540. ->andWhere('t3.deleted')->eq(0)
  541. ->andWhere('t2.deleted')->eq(0)
  542. ->beginIF($projectID)->andWhere('t2.project')->eq($projectID)->fi()
  543. ->orderBy($block->params->orderBy)
  544. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  545. ->fetchAll();
  546. }
  547. elseif($block->params->type == 'openedbyme')
  548. {
  549. $cases = $this->dao->findByOpenedBy($this->app->user->account)->from(TABLE_CASE)
  550. ->andWhere('deleted')->eq(0)
  551. ->beginIF($projectID)->andWhere('project')->eq($projectID)->fi()
  552. ->orderBy($block->params->orderBy)
  553. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  554. ->fetchAll();
  555. }
  556. $this->view->cases = $cases;
  557. }
  558. /**
  559. * 打印测试单区块。
  560. * Print testtask block.
  561. *
  562. * @params object $block
  563. * @access public
  564. * @return void
  565. * @param object $block
  566. */
  567. public function printTesttaskBlock($block)
  568. {
  569. $this->app->loadLang('testtask');
  570. $uri = $this->createLink('my', 'index');
  571. $this->session->set('productList', $uri, 'product');
  572. $this->session->set('testtaskList', $uri, 'qa');
  573. $this->session->set('buildList', $uri, 'execution');
  574. if(preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  575. $this->view->projects = $this->loadModel('project')->getPairsByProgram();
  576. $this->view->testtasks = $this->dao->select("DISTINCT t1.*,t2.name as productName,t2.shadow,t3.name as buildName,t4.name as projectName, CONCAT(t4.name, '/', t3.name) as executionBuild")->from(TABLE_TESTTASK)->alias('t1')
  577. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  578. ->leftJoin(TABLE_BUILD)->alias('t3')->on('t1.build=t3.id')
  579. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t1.execution=t4.id')
  580. ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t5')->on('t1.execution=t5.project')
  581. ->where('t1.deleted')->eq('0')
  582. ->andWhere('t1.auto')->ne('unit')
  583. ->beginIF(!$this->app->user->admin)->andWhere('t1.product')->in($this->app->user->view->products)->fi()
  584. ->beginIF(!$this->app->user->admin)->andWhere('t1.execution')->in($this->app->user->view->sprints)->fi()
  585. ->andWhere('t1.product = t5.product')
  586. ->beginIF($block->params->type != 'all')->andWhere('t1.status')->eq($block->params->type)->fi()
  587. ->orderBy('t1.id desc')
  588. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  589. ->fetchAll();
  590. }
  591. /**
  592. * 打印研发需求区块。
  593. * Print story block.
  594. *
  595. * @params object $block
  596. * @access protected
  597. * @return void
  598. * @param object $block
  599. */
  600. protected function printStoryBlock($block)
  601. {
  602. $this->session->set('storyList', $this->createLink('my', 'index'), 'product');
  603. if(preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  604. $this->app->loadClass('pager', true);
  605. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  606. $pager = pager::init(0, $count , 1);
  607. $type = isset($block->params->type) ? $block->params->type : 'assignedTo';
  608. $orderBy = isset($block->params->type) ? $block->params->orderBy : 'id_asc';
  609. $this->view->stories = $this->loadModel('story')->getUserStories($this->app->user->account, $type, $orderBy, $this->viewType != 'json' ? $pager : '', 'story');
  610. }
  611. /**
  612. * 打印产品计划列表区块。
  613. * Print plan block.
  614. *
  615. * @param object $block
  616. * @access protected
  617. * @return bool
  618. */
  619. protected function printPlanBlock($block)
  620. {
  621. $uri = $this->createLink('my', 'index');
  622. $this->session->set('productList', $uri, 'product');
  623. $this->session->set('productPlanList', $uri, 'product');
  624. $this->app->loadClass('pager', true);
  625. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  626. $pager = pager::init(0, $count , 1);
  627. $this->view->products = $this->loadModel('product')->getPairs();
  628. $this->view->plans = $this->loadModel('productplan')->getList(0, 0, 'all', $pager, 'begin_desc', 'noproduct|' . zget($block->params, 'type', ''));
  629. }
  630. /**
  631. * 打印产品发布列表区块数据。
  632. * Print releases block.
  633. *
  634. * @param object $block
  635. * @access protected
  636. * @return void
  637. */
  638. protected function printReleaseBlock($block)
  639. {
  640. $uri = $this->createLink('my', 'index');
  641. $this->session->set('releaseList', $uri, 'product');
  642. $this->session->set('buildList', $uri, 'execution');
  643. $type = $block->params->type;
  644. $this->app->loadLang('release');
  645. $this->view->releases = $this->dao->select('t1.*,t2.name as productName')->from(TABLE_RELEASE)->alias('t1')
  646. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  647. ->where('t1.deleted')->eq('0')
  648. ->andWhere('t2.shadow')->eq(0)
  649. ->beginIF(strpos($type, 'noclosed') !== false)->andWhere('t2.status')->ne('closed')->fi()
  650. ->beginIF(strpos("|$type|", '|closed|') !== false)->andWhere('t2.status')->eq('closed')->fi()
  651. ->beginIF(!$this->app->user->admin)->andWhere('t1.product')->in($this->app->user->view->products)->fi()
  652. ->orderBy('t1.id desc')
  653. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  654. ->fetchAll();
  655. $this->view->builds = $this->dao->select('id,name')->from(TABLE_BUILD)->where('deleted')->eq(0)->fetchPairs();
  656. }
  657. /**
  658. * 打印产品路线图区块数据。
  659. * Print roadmap block.
  660. *
  661. * @param object $block
  662. * @access protected
  663. * @return void
  664. */
  665. protected function printRoadmapBlock($block)
  666. {
  667. $productID = $this->session->product;
  668. $product = $this->loadModel('product')->getByID($productID);
  669. $roadmaps = $this->product->getRoadmap($productID, 'all');
  670. $branches = $product->type == 'normal' ? array(0 => '') : $this->loadModel('branch')->getPairs($productID, 'active');
  671. /* Assign view data. */
  672. $this->view->title = $product->name . $this->lang->hyphen . $this->lang->product->roadmap;
  673. $this->view->product = $product;
  674. $this->view->roadmaps = $roadmaps;
  675. $this->view->branches = $branches;
  676. }
  677. /**
  678. * 打印产品发布统计区块数据。
  679. * Print product release statistic block.
  680. *
  681. * @param object $block
  682. * @access protected
  683. * @return void
  684. */
  685. protected function printReleaseStatisticBlock($block)
  686. {
  687. /* 获取最近六个月的年月数组。 */
  688. $years = array();
  689. $months = array();
  690. $dates = array();
  691. for($i = 5; $i >= 0; $i --)
  692. {
  693. $years[] = date('Y', strtotime("first day of -{$i} month"));
  694. $months[] = date('m', strtotime("first day of -{$i} month"));
  695. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  696. }
  697. /* 从度量项获取所有产品的月度发布次数的数据。 */
  698. $monthRelease = $this->loadModel('metric')->getResultByCodeWithArray('count_of_monthly_created_release', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron');
  699. /* 获取各个产品的年度(今年)发布次数。 */
  700. $products = $this->loadModel('product')->getOrderedProducts('all', 0, 0, 'all');
  701. $productIdList = array_keys($products);
  702. $releaseGroup = $this->metric->getResultByCodeWithArray('count_of_annual_created_release_in_product', array('product' => join(',', $productIdList), 'year' => date('Y')), 'cron');
  703. foreach($dates as $date)
  704. {
  705. $releaseData[$date] = 0;
  706. if(!empty($monthRelease))
  707. {
  708. foreach($monthRelease as $release)
  709. {
  710. if($date == "{$release['year']}-{$release['month']}") $releaseData[$date] = $release['value'];
  711. }
  712. }
  713. }
  714. /* 组装成由产品名称和发布次数组成的数组。 */
  715. $releases = array();
  716. foreach($products as $product)
  717. {
  718. $releases[$product->name] = 0;
  719. if(!empty($releaseGroup))
  720. {
  721. foreach($releaseGroup as $release)
  722. {
  723. if($product->id == $release['product'] && date('Y') == $release['year']) $releases[$product->name] = $release['value'];
  724. }
  725. }
  726. }
  727. arsort($releases); // 按发布次数从高到低排序。
  728. $this->view->releaseData = $releaseData;
  729. $this->view->releases = $releases;
  730. }
  731. /**
  732. * 打印版本区块。
  733. * Print Build block.
  734. *
  735. * @param object $block
  736. * @access protected
  737. * @return void
  738. */
  739. protected function printBuildBlock($block)
  740. {
  741. $this->session->set('buildList', $this->createLink('my', 'index'), 'execution');
  742. $this->app->loadLang('build');
  743. $builds = $this->dao->select('t1.*, t2.name AS productName, t2.shadow, t3.name AS projectName')->from(TABLE_BUILD)->alias('t1')
  744. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  745. ->leftJoin(TABLE_PROJECT)->alias('t3')->on('t1.project=t3.id')
  746. ->where('t1.deleted')->eq('0')
  747. ->beginIF(!$this->app->user->admin)->andWhere('t1.execution')->in($this->app->user->view->sprints)->fi()
  748. ->beginIF($block->dashboard != 'my' && $this->session->project)->andWhere('t1.project')->eq((int)$this->session->project)->fi()
  749. ->orderBy('t1.id desc')
  750. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  751. ->fetchAll();
  752. $this->view->builds = $builds;
  753. }
  754. /**
  755. * 打印项目列表区块。
  756. * Print project block.
  757. *
  758. * @param object $block
  759. * @access protected
  760. * @return void
  761. */
  762. protected function printProjectBlock($block)
  763. {
  764. $this->app->loadLang('execution');
  765. $this->app->loadLang('task');
  766. $count = isset($block->params->count) ? $block->params->count : 15;
  767. $type = isset($block->params->type) ? $block->params->type : 'all';
  768. $orderBy = isset($block->params->orderBy) ? $block->params->orderBy : 'id_desc';
  769. $this->view->projects = $this->loadModel('project')->getOverviewList($type, 0, $orderBy, $count);
  770. $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(array_column($this->view->projects, 'PM')));
  771. }
  772. /**
  773. * 打印产品列表区块。
  774. * Print product block.
  775. *
  776. * @param object $block
  777. * @access protected
  778. * @return void
  779. */
  780. protected function printProductListBlock($block)
  781. {
  782. $this->app->loadClass('pager', true);
  783. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  784. $type = isset($block->params->type) ? $block->params->type : '';
  785. $pager = pager::init(0, $count , 1);
  786. $products = $this->loadModel('product')->getList(0, $type);
  787. $productStats = $this->product->getStats(array_keys($products), 'order_desc', $this->viewType != 'json' ? $pager : '');
  788. $this->view->productStats = $productStats;
  789. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  790. $this->view->avatarList = $this->user->getAvatarPairs();
  791. }
  792. /**
  793. * 打印项目概况区块。
  794. * Get data of the project overview block.
  795. *
  796. * @param object $block
  797. * @access protected
  798. * @return void
  799. */
  800. protected function printProjectOverviewBlock($block)
  801. {
  802. $this->loadModel('metric');
  803. /* 通过度量项获取项目总量数据。 */
  804. $projectCount = 0;
  805. $projectCountGroup = $this->metric->getResultByCodeWithArray('count_of_project', array(), 'cron');
  806. if(!empty($projectCountGroup))
  807. {
  808. $projectCountGroup = reset($projectCountGroup);
  809. $projectCount = zget($projectCountGroup, 'value', 0);
  810. }
  811. /* 通过度量项获取最近三年完成的项目数据。 */
  812. $years = array();
  813. $i = 3;
  814. foreach(array('lastTwoYear', 'lastYear', 'thisYear') as $year)
  815. {
  816. $i --;
  817. $years[$year] = date('Y', strtotime("first day of -{$i} year"));
  818. }
  819. $finishedProjectGroup = $this->metric->getResultByCodeWithArray('count_of_annual_finished_project', array('year' => join(',', $years)), 'cron');
  820. if($finishedProjectGroup) $finishedProjectGroup = array_column($finishedProjectGroup, null, 'year');
  821. /* 组装前台所需的cards数组。 */
  822. $cards = array();
  823. $cards[0] = new stdclass();
  824. $cards[0]->value = $projectCount;
  825. $cards[0]->class = 'text-primary';
  826. $cards[0]->label = $this->lang->block->projectoverview->totalProject;
  827. $cards[0]->url = common::hasPriv('project', 'browse') ? helper::createLink('project', 'browse', 'programID=0&browseType=all') : null;
  828. $cards[1] = new stdclass();
  829. $cards[1]->value = isset($finishedProjectGroup[date('Y')]['value']) ? $finishedProjectGroup[date('Y')]['value'] : 0;
  830. $cards[1]->label = $this->lang->block->projectoverview->thisYear;
  831. $cardGroup = new stdclass();
  832. $cardGroup->type = 'cards';
  833. $cardGroup->cards = $cards;
  834. /* 获取最近三年最多完成的项目数量。 */
  835. $maxCount = 0;
  836. if($finishedProjectGroup)
  837. {
  838. foreach($finishedProjectGroup as $data)
  839. {
  840. if($maxCount < $data['value']) $maxCount = $data['value'];
  841. }
  842. }
  843. /* 组将前台柱状图所需的bars数组。 */
  844. $bars = array();
  845. foreach($years as $code => $year)
  846. {
  847. $bar = new stdclass();
  848. $bar->label = $year;
  849. $bar->value = isset($finishedProjectGroup[$year]['value']) ? $finishedProjectGroup[$year]['value'] : 0;;
  850. $bar->rate = $maxCount ? round($bar->value / $maxCount * 100) . '%' : '0%';
  851. $bars[] = $bar;
  852. }
  853. $barGroup = new stdclass();
  854. $barGroup->type = 'barChart';
  855. $barGroup->title = $this->lang->block->projectoverview->lastThreeYear;
  856. $barGroup->bars = $bars;
  857. $this->view->groups = array($cardGroup, $barGroup);
  858. }
  859. /**
  860. * 打印项目统计区块。
  861. * Print project statistic block.
  862. *
  863. * @param object $block
  864. * @access protected
  865. * @return void
  866. */
  867. protected function printProjectStatisticBlock($block)
  868. {
  869. if(!empty($block->params->type) && preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  870. /* Set project status and count. */
  871. $status = isset($block->params->type) ? $block->params->type : 'all';
  872. $count = isset($block->params->count) ? (int)$block->params->count : 15;
  873. /* Get projects. */
  874. $excludedModel = ($this->config->edition == 'max' or $this->config->edition == 'ipd') ? '' : 'waterfall,waterfallplus';
  875. $projects = $this->loadModel('project')->getProjectList($status, 'order_asc', $count, '');
  876. $projectIdList = array_keys($projects);
  877. /* Get metric data. */
  878. $data = $this->getProjectsStatisticData($projectIdList);
  879. /* 将获取的度量数据塞入项目列表数据中。 */
  880. $this->app->loadClass('pager', true);
  881. $pager = pager::init(0, 3, 1);
  882. foreach($projects as $project) $project = $this->buildProjectStatistic($project, $data, $pager);
  883. $this->view->projects = $projects;
  884. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  885. }
  886. /**
  887. * 打印产品统计区块。
  888. * Print product statistic block.
  889. *
  890. * @param object $block
  891. * @access protected
  892. * @return bool
  893. */
  894. protected function printProductStatisticBlock($block)
  895. {
  896. /* 获取需要统计的产品列表。 */
  897. /* Obtain a list of products that require statistics. */
  898. $status = isset($block->params->type) ? $block->params->type : '';
  899. $count = isset($block->params->count) ? $block->params->count : '';
  900. $products = $this->loadModel('product')->getOrderedProducts($status, (int)$count, 0, 'all');
  901. $productIdList = array_keys($products);
  902. $this->loadModel('metric');
  903. /* 按照产品分组获取产品需求交付率度量项。 */
  904. $storyDeliveryRate = $this->metric->getResultByCodeWithArray('rate_of_delivery_story_in_product', array('product' => join(',', $productIdList)), 'cron');
  905. /* 按照产品分组获取产品有效需求数度量项。 */
  906. $totalStories = $this->metric->getResultByCodeWithArray('count_of_valid_story_in_product', array('product' => join(',', $productIdList)), 'cron');
  907. /* 按照产品分组获取产品已交付需求数度量项。 */
  908. $closedStories = $this->metric->getResultByCodeWithArray('count_of_delivered_story_in_product', array('product' => join(',', $productIdList)), 'cron');
  909. /* 按照产品分组获取产品未关闭需求数度量项。 */
  910. $unclosedStories = $this->metric->getResultByCodeWithArray('count_of_unclosed_story_in_product', array('product' => join(',', $productIdList)), 'cron');
  911. if(!empty($storyDeliveryRate)) $storyDeliveryRate = array_column($storyDeliveryRate, null, 'product');
  912. if(!empty($totalStories)) $totalStories = array_column($totalStories, null, 'product');
  913. if(!empty($closedStories)) $closedStories = array_column($closedStories, null, 'product');
  914. if(!empty($unclosedStories)) $unclosedStories = array_column($unclosedStories, null, 'product');
  915. /* 按照产品和日期分组获取产品每月新增和完成的需求数度量项。 */
  916. $years = array();
  917. $months = array();
  918. $dates = array();
  919. for($i = 5; $i >= 0; $i --)
  920. {
  921. $years[] = date('Y', strtotime("first day of -{$i} month"));
  922. $months[] = date('m', strtotime("first day of -{$i} month"));
  923. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  924. }
  925. $monthFinish = $this->metric->getResultByCodeWithArray('count_of_monthly_finished_story_in_product', array('product' => join(',', $productIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron');
  926. $monthCreated = $this->metric->getResultByCodeWithArray('count_of_monthly_created_story_in_product', array('product' => join(',', $productIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron');
  927. /* 根据产品列表获取预计开始日期距离现在最近且预计开始日期大于当前日期的未开始状态计划。 */
  928. /* Obtain an unstarted status plan based on the product list, with an expected start date closest to the current date and an expected start date greater than the current date. */
  929. $newPlan = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)
  930. ->where('deleted')->eq('0')
  931. ->andWhere('product')->in($productIdList)
  932. ->andWhere('begin')->ge(date('Y-m-d'))
  933. ->andWhere('status')->eq('wait')
  934. ->orderBy('begin_desc,id_desc')
  935. ->fetchGroup('product');
  936. /* 根据产品列表获取实际开始日期距离当前最近的进行中状态的执行。 */
  937. /* Obtain the execution of the current in progress status closest to the actual start date based on the product list. */
  938. $newExecution = $this->dao->select('execution.*,relation.product')->from(TABLE_EXECUTION)->alias('execution')
  939. ->leftJoin(TABLE_PROJECTPRODUCT)->alias('relation')->on('execution.id=relation.project')
  940. ->where('execution.deleted')->eq('0')
  941. ->andWhere('execution.type')->eq('sprint')
  942. ->andWhere('relation.product')->in($productIdList)
  943. ->andWhere('execution.status')->eq('doing')
  944. ->orderBy('realBegan_desc,id_desc')
  945. ->fetchGroup('product');
  946. /* 根据产品列表获取发布日期距离现在最近且发布日期小于当前日期的发布。 */
  947. /* Retrieve releases with the latest release date from the product list and a release date earlier than the current date. */
  948. $newRelease = $this->dao->select('*')->from(TABLE_RELEASE)
  949. ->where('deleted')->eq('0')
  950. ->andWhere('product')->in($productIdList)
  951. ->andWhere('date')->le(date('Y-m-d'))
  952. ->orderBy('date_desc,id_desc')
  953. ->fetchGroup('product');
  954. /* 将按照产品分组的统计数据放入产品列表中。 */
  955. /* Place statistical data grouped by product into the product list. */
  956. foreach($products as $productID => $product)
  957. {
  958. $product->storyDeliveryRate = isset($storyDeliveryRate[$productID]['value']) ? $storyDeliveryRate[$productID]['value'] * 100 : 0;
  959. $product->totalStories = isset($totalStories[$productID]['value']) ? $totalStories[$productID]['value'] : 0;
  960. $product->closedStories = isset($closedStories[$productID]['value']) ? $closedStories[$productID]['value'] : 0;
  961. $product->unclosedStories = isset($unclosedStories[$productID]['value']) ? $unclosedStories[$productID]['value'] : 0;
  962. $product->newPlan = isset($newPlan[$productID]) ? current($newPlan[$productID]) : '';
  963. $product->newExecution = isset($newExecution[$productID]) ? current($newExecution[$productID]) : '';
  964. $product->newRelease = isset($newRelease[$productID]) ? current($newRelease[$productID]) : '';
  965. foreach($dates as $date)
  966. {
  967. if(strtotime($date) < strtotime(substr($product->createdDate, 0, 7))) continue;
  968. $product->monthFinish[$date] = 0;
  969. $product->monthCreated[$date] = 0;
  970. if(!empty($monthFinish))
  971. {
  972. foreach($monthFinish as $story)
  973. {
  974. if($date == "{$story['year']}-{$story['month']}" && $productID == $story['product']) $product->monthFinish[$date] = $story['value'];
  975. }
  976. }
  977. if(!empty($monthCreated))
  978. {
  979. foreach($monthCreated as $story)
  980. {
  981. if($date == "{$story['year']}-{$story['month']}" && $productID == $story['product']) $product->monthCreated[$date] = $story['value'];
  982. }
  983. }
  984. }
  985. }
  986. $this->view->products = $products;
  987. }
  988. /**
  989. * 打印执行统计区块。
  990. * Print execution statistic block.
  991. *
  992. * @param object $block
  993. * @param array $params
  994. * @access protected
  995. * @return void
  996. */
  997. protected function printExecutionStatisticBlock($block, $params = array())
  998. {
  999. if(!empty($block->params->type) && preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  1000. $status = isset($block->params->type) ? $block->params->type : 'undone';
  1001. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  1002. /* Get projects. */
  1003. $projectID = $block->dashboard == 'my' ? 0 : (int)$this->session->project;
  1004. if(isset($params['project'])) $projectID = (int)$params['project'];
  1005. $executions = $this->loadModel('execution')->getOrderedExecutions($projectID, $status, $count, 'skipparent');
  1006. $projectIdList = $this->loadModel('project')->getProjectExecutionPairs('1', $status);
  1007. if(empty($executions))
  1008. {
  1009. $this->view->chartData = array('labels' => array(), 'baseLine' => array(), 'burnLine' => array());
  1010. $this->view->executions = array();
  1011. $this->view->projects = $this->project->getPairsByIdList(array_keys($projectIdList));
  1012. $this->view->currentProjectID = $projectID;
  1013. return;
  1014. }
  1015. $executionID = isset($params['active']) && isset($executions[$params['active']]) ? $params['active'] : key($executions);
  1016. $execution = $executions[$executionID];
  1017. $this->loadModel('metric');
  1018. $estimateGroup = $this->metric->getResultByCodeWithArray('estimate_of_task_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的预计工时。
  1019. $consumeGroup = $this->metric->getResultByCodeWithArray('consume_of_task_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的消耗工时。
  1020. $leftGroup = $this->metric->getResultByCodeWithArray('left_of_task_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的剩余工时。
  1021. $developedStoryGroup = $this->metric->getResultByCodeWithArray('count_of_developed_story_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的已完成需求。
  1022. $totalStoryGroup = $this->metric->getResultByCodeWithArray('count_of_story_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的总需求数量。
  1023. $yesterday = strtotime("-1 day");
  1024. $totalTaskGroup = $this->metric->getResultByCodeWithArray('count_of_task_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的任务总数。
  1025. $unfinishedTaskGroup = $this->metric->getResultByCodeWithArray('count_of_unfinished_task_in_execution', array('execution' => $executionID), 'cron'); // 从度量项获取执行的未完成任务。
  1026. $dailyFinishedGroup = $this->metric->getResultByCodeWithArray('count_of_daily_finished_task_in_execution ', array('execution' => $executionID, 'year' => date('Y', $yesterday), 'month' => date('m', $yesterday), 'day' => date('d', $yesterday)), 'cron'); // 从度量项获取执行的昨日完成任务数。
  1027. if(!empty($estimateGroup)) $estimateGroup = array_column($estimateGroup, null, 'execution');
  1028. if(!empty($consumeGroup)) $consumeGroup = array_column($consumeGroup, null, 'execution');
  1029. if(!empty($leftGroup)) $leftGroup = array_column($leftGroup, null, 'execution');
  1030. if(!empty($developedStoryGroup)) $developedStoryGroup = array_column($developedStoryGroup, null, 'execution');
  1031. if(!empty($totalStoryGroup)) $totalStoryGroup = array_column($totalStoryGroup, null, 'execution');
  1032. if(!empty($totalTaskGroup)) $totalTaskGroup = array_column($totalTaskGroup, null, 'execution');
  1033. if(!empty($unfinishedTaskGroup)) $unfinishedTaskGroup = array_column($unfinishedTaskGroup, null, 'execution');
  1034. if(!empty($dailyFinishedGroup)) $dailyFinishedGroup = array_column($dailyFinishedGroup, null, 'execution');
  1035. /* 将从度量项获取的数据塞入执行列表中。 */
  1036. $execution->totalEstimate = 0;
  1037. $execution->totalConsumed = 0;
  1038. $execution->totalLeft = 0;
  1039. $execution->doneStory = 0;
  1040. $execution->totalStory = 0;
  1041. $execution->totalTask = 0;
  1042. $execution->undoneTask = 0;
  1043. $execution->yesterdayDoneTask = 0;
  1044. if(!empty($estimateGroup[$executionID])) $execution->totalEstimate = zget($estimateGroup[$executionID], 'value', 0);
  1045. if(!empty($consumeGroup[$executionID])) $execution->totalConsumed = zget($consumeGroup[$executionID], 'value', 0);
  1046. if(!empty($leftGroup[$executionID])) $execution->totalLeft = zget($leftGroup[$executionID], 'value', 0);
  1047. if(!empty($developedStoryGroup[$executionID])) $execution->doneStory = zget($developedStoryGroup[$executionID], 'value', 0);
  1048. if(!empty($totalStoryGroup[$executionID])) $execution->totalStory = zget($totalStoryGroup[$executionID], 'value', 0);
  1049. if(!empty($totalTaskGroup[$executionID])) $execution->totalTask = zget($totalTaskGroup[$executionID], 'value', 0);
  1050. if(!empty($unfinishedTaskGroup[$executionID])) $execution->undoneTask = zget($unfinishedTaskGroup[$executionID], 'value', 0);
  1051. if(!empty($dailyFinishedGroup[$executionID])) $execution->yesterdayDoneTask = zget($dailyFinishedGroup[$executionID], 'value', 0);
  1052. $execution->totalHours = $execution->totalLeft + $execution->totalConsumed;
  1053. if($execution->type == 'kanban')
  1054. {
  1055. /* Process the cfd. */
  1056. $this->app->loadClass('date');
  1057. list($begin, $end) = $this->execution->getBeginEnd4CFD($execution);
  1058. $dateList = date::getDateList($begin, $end, 'Y-m-d', 'noweekend');
  1059. $chartData = $this->execution->buildCFDData($executionID, $dateList, 'task');
  1060. if(isset($chartData['line'])) $chartData['line'] = array_reverse($chartData['line']);
  1061. $this->view->chartData = $chartData;
  1062. }
  1063. else
  1064. {
  1065. /* Process the burns. */
  1066. $execution->burns = array();
  1067. $burnData = isset($burns[$execution->id]) ? $burns[$execution->id] : array();
  1068. $deadline = $execution->status == 'closed' ? substr($execution->closedDate, 0, 10) : $execution->suspendedDate;
  1069. $today = helper::today();
  1070. if(strpos('closed,suspended', $execution->status) === false) $deadline = $today > $execution->end ? $today : $execution->end;
  1071. list($dateList, $interval) = $this->execution->getDateList($execution->begin, $deadline, 'noweekend', 0, 'Y-m-d', $execution->end);
  1072. foreach($burnData as $data) $execution->burns[] = $data->value;
  1073. $this->view->chartData = $this->execution->buildBurnData($executionID, $dateList, 'left', $execution->end);
  1074. }
  1075. $this->view->executions = $executions;
  1076. $this->view->projects = $this->project->getPairsByIdList(array_keys($projectIdList));
  1077. $this->view->currentProjectID = $projectID;
  1078. }
  1079. /**
  1080. * 打印瀑布项目统计区块。
  1081. * Print waterfall report block.
  1082. *
  1083. * @access protected
  1084. * @return void
  1085. */
  1086. protected function printWaterfallReportBlock()
  1087. {
  1088. $this->app->loadLang('programplan');
  1089. $project = $this->loadModel('project')->getByID(common::isTutorialMode() ? 2 : $this->session->project);
  1090. /* Get metric data. */
  1091. $data = $this->getProjectsStatisticData(array($project->id));
  1092. $project = $this->buildProjectStatistic($project, $data);
  1093. $this->view->project = $project;
  1094. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  1095. }
  1096. /**
  1097. * 打印瀑布项目统计区块。
  1098. * Print waterfall general report block.
  1099. *
  1100. * @access protected
  1101. * @return void
  1102. */
  1103. protected function printWaterfallGeneralReportBlock()
  1104. {
  1105. $this->app->loadLang('programplan');
  1106. $this->loadModel('project');
  1107. $this->loadModel('weekly');
  1108. $data = $this->project->getWaterfallPVEVAC($this->session->project);
  1109. $this->view->pv = (float)$data['PV'];
  1110. $this->view->ev = (float)$data['EV'];
  1111. $this->view->ac = sprintf("%.2f", (float)$data['AC']);
  1112. $this->view->sv = $this->weekly->getSV($this->view->ev, $this->view->pv);
  1113. $this->view->cv = $this->weekly->getCV($this->view->ev, $this->view->ac);
  1114. $left = (float)$data['left'];
  1115. $progress = (!empty($this->view->ac) || !empty($left)) ? floor($this->view->ac / ($this->view->ac + $left) * 1000) / 1000 * 100 : 0;
  1116. $this->view->progress = $progress > 100 ? 100 : $progress;
  1117. }
  1118. /**
  1119. * 打印瀑布项目计划甘特图区块。
  1120. * Print waterfall gantt block.
  1121. *
  1122. * @param object $block
  1123. * @param array $params
  1124. * @access protected
  1125. * @return void
  1126. */
  1127. protected function printWaterfallGanttBlock($block, $params = array())
  1128. {
  1129. $products = $this->loadModel('product')->getProductPairsByProject($this->session->project);
  1130. $productID = $this->session->product ? $this->session->product : 0;
  1131. if(isset($params['productID'])) $productID = (int)$params['productID'];
  1132. $productID = isset($products[$productID]) ? $productID : key($products);
  1133. $productID = !empty($productID) ? $productID : 0;
  1134. /* Get program plans. */
  1135. $plans = $this->loadModel('programplan')->getStage($this->session->project, $productID, 'all', 'order');
  1136. $plans = $this->programplan->initGanttPlans($plans);
  1137. $plansProgress = $this->loadModel('metric')->getResultByCodeWithArray('progress_of_task_in_execution', array('execution' => implode(',', $plans['planIdList'])), 'cron'); // Get plan progress by metric.
  1138. $plans = $plans['datas'] ? $plans['datas']['data'] : array();
  1139. /* Set progress from metric. */
  1140. foreach($plansProgress as $metric)
  1141. {
  1142. if(isset($plans[$metric['execution']])) $plans[$metric['execution']]->taskProgress = ($metric['value'] * 100) . '%';
  1143. }
  1144. $project = $this->loadModel('project')->getByID(common::isTutorialMode() ? 2 : $this->session->project);
  1145. $this->view->plans = $plans ? $plans : array();
  1146. $this->view->products = $project->hasProduct ? $products : array();
  1147. $this->view->productID = $productID;
  1148. }
  1149. /**
  1150. * 打印瀑布项目问题列表区块。
  1151. * Print waterfall issue block.
  1152. *
  1153. * @access protected
  1154. * @param object $block
  1155. * @return void
  1156. */
  1157. protected function printWaterfallIssueBlock($block)
  1158. {
  1159. $this->printIssueBlock($block);
  1160. }
  1161. /**
  1162. * 打印瀑布项目风险列表区块。
  1163. * Print waterfall risk block.
  1164. *
  1165. * @access protected
  1166. * @param object $block
  1167. * @return void
  1168. */
  1169. protected function printWaterfallRiskBlock($block)
  1170. {
  1171. $this->printRiskBlock($block);
  1172. }
  1173. /**
  1174. * 打印瀑布项目工时统计区块。
  1175. * Print waterfall estimate block.
  1176. *
  1177. * @access protected
  1178. * @return void
  1179. */
  1180. protected function printWaterfallEstimateBlock()
  1181. {
  1182. $this->app->loadLang('durationestimation');
  1183. $this->loadModel('project');
  1184. $projectID = $this->session->project;
  1185. $members = $this->loadModel('user')->getTeamMemberPairs($projectID, 'project');
  1186. $budget = $this->loadModel('workestimation')->getBudget($projectID);
  1187. $workhour = $this->loadModel('project')->getWorkhour($projectID);
  1188. if(empty($budget)) $budget = new stdclass();
  1189. $consumed = $this->dao->select('sum(consumed) as consumed')->from(TABLE_TASK)->where('project')->eq($projectID)->andWhere('deleted')->eq(0)->andWhere('isParent')->eq('0')->fetch('consumed');
  1190. $this->view->people = $this->dao->select('sum(people) as people')->from(TABLE_DURATIONESTIMATION)->where('project')->eq($this->session->project)->fetch('people');
  1191. $this->view->members = count($members) ? count($members) - 1 : 0;
  1192. $this->view->consumed = sprintf("%.2f", $consumed);
  1193. $this->view->budget = $budget;
  1194. $this->view->totalLeft = (float)$workhour->totalLeft;
  1195. }
  1196. /**
  1197. * 打印瀑布项目进度区块。
  1198. * Print waterfall progress block.
  1199. *
  1200. * @access protected
  1201. * @return void
  1202. */
  1203. protected function printWaterfallProgressBlock()
  1204. {
  1205. $this->loadModel('milestone');
  1206. $this->loadModel('weekly');
  1207. $this->app->loadLang('execution');
  1208. $projectID = $this->session->project;
  1209. $projectWeekly = $this->dao->select('*')->from(TABLE_WEEKLYREPORT)->where('project')->eq($projectID)->orderBy('weekStart_asc')->fetchAll('weekStart');
  1210. $charts = array('pv' => array(), 'ev' => array(), 'ac' => array());
  1211. foreach($projectWeekly as $weekStart => $data)
  1212. {
  1213. $charts['pv'][$weekStart] = $data->pv;
  1214. $charts['ev'][$weekStart] = $data->ev;
  1215. $charts['ac'][$weekStart] = $data->ac;
  1216. }
  1217. $this->view->charts = $charts;
  1218. }
  1219. /**
  1220. * 打印敏捷项目概况区块。
  1221. * Print srcum project block.
  1222. *
  1223. * @access protected
  1224. * @return void
  1225. */
  1226. protected function printScrumOverviewBlock()
  1227. {
  1228. $projectID = $this->session->project;
  1229. $this->app->loadLang('bug');
  1230. /* Get metric data. */
  1231. $projectIdList = array($projectID);
  1232. $data = $this->getProjectsStatisticData($projectIdList);
  1233. /* Get base project. */
  1234. $project = $this->loadModel('project')->getByID(common::isTutorialMode() ? 2 : $projectID);
  1235. /* Build project statistic data. */
  1236. $this->app->loadClass('pager', true);
  1237. $pager = pager::init(0, 3, 1);
  1238. $project = $project ? $this->buildProjectStatistic($project, $data, $pager) : new stdclass();
  1239. $this->view->projectID = $projectID;
  1240. $this->view->project = $project;
  1241. }
  1242. /**
  1243. * 打印敏捷项目列表区块。
  1244. * Print srcum project list block.
  1245. *
  1246. * @param object $block
  1247. * @access protected
  1248. * @return void
  1249. */
  1250. protected function printScrumListBlock($block)
  1251. {
  1252. if(!empty($block->params->type) && preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  1253. $count = isset($block->params->count) ? (int)$block->params->count : 15;
  1254. $type = isset($block->params->type) ? $block->params->type : 'undone';
  1255. $this->app->loadClass('pager', true);
  1256. $pager = pager::init(0, $count, 1);
  1257. $this->loadModel('execution');
  1258. $this->view->executionStats = !commonModel::isTutorialMode() ? $this->execution->getStatData($this->session->project, $type, 0, 0, false, '', '', $pager) : array($this->loadModel('tutorial')->getExecution());
  1259. }
  1260. /**
  1261. * 打印敏捷项目产品概况。
  1262. * Print srcum product block.
  1263. *
  1264. * @param object $block
  1265. * @access protected
  1266. * @return void
  1267. */
  1268. protected function printScrumProductBlock($block)
  1269. {
  1270. $stories = array();
  1271. $bugs = array();
  1272. $releases = array();
  1273. $count = isset($block->params->count) ? (int)$block->params->count : 15;
  1274. $products = $this->dao->select('id, name')->from(TABLE_PRODUCT)->where('program')->eq($this->session->program)->limit($count)->fetchPairs();
  1275. $productIdList = array_keys($products);
  1276. if(!empty($productIdList))
  1277. {
  1278. $fields = 'product, COUNT(1) AS total';
  1279. $stories = $this->dao->select($fields)->from(TABLE_STORY)->where('product')->in($productIdList)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs();
  1280. $bugs = $this->dao->select($fields)->from(TABLE_BUG)->where('product')->in($productIdList)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs();
  1281. $releases = $this->dao->select($fields)->from(TABLE_RELEASE)->where('product')->in($productIdList)->andWhere('deleted')->eq('0')->groupBy('product')->fetchPairs();
  1282. }
  1283. $this->view->products = $products;
  1284. $this->view->stories = $stories;
  1285. $this->view->bugs = $bugs;
  1286. $this->view->releases = $releases;
  1287. }
  1288. /**
  1289. * 打印敏捷项目问题列表区块。
  1290. * Print scrum issue block.
  1291. *
  1292. * @access protected
  1293. * @param object $block
  1294. * @return void
  1295. */
  1296. protected function printScrumIssueBlock($block)
  1297. {
  1298. $this->printIssueBlock($block);
  1299. }
  1300. /**
  1301. * 打印敏捷项目风险列表区块。
  1302. * Print scrum risk block.
  1303. *
  1304. * @access protected
  1305. * @param object $block
  1306. * @return void
  1307. */
  1308. protected function printScrumRiskBlock($block)
  1309. {
  1310. $this->printRiskBlock($block);
  1311. }
  1312. /**
  1313. * 打印问题列表区块。
  1314. * Print issue block.
  1315. *
  1316. * @param object $block
  1317. * @access protected
  1318. * @return void
  1319. */
  1320. private function printIssueBlock($block)
  1321. {
  1322. $uri = $this->app->tab == 'my' ? $this->createLink('my', 'index') : $this->server->http_referer;
  1323. $this->session->set('issueList', $uri, 'project');
  1324. if(preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  1325. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  1326. $this->view->issues = $this->loadModel('issue')->getBlockIssues($this->session->project, $block->params->type, $this->viewType == 'json' ? 0 : (int)$block->params->count, $block->params->orderBy);
  1327. }
  1328. /**
  1329. * 打印风险列表区块。
  1330. * Print risk block.
  1331. *
  1332. * @param object $block
  1333. * @access protected
  1334. * @return void
  1335. */
  1336. private function printRiskBlock($block)
  1337. {
  1338. $uri = $this->app->tab == 'my' ? $this->createLink('my', 'index') : $this->server->http_referer;
  1339. $this->session->set('riskList', $uri, 'project');
  1340. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  1341. $this->view->risks = $this->loadModel('risk')->getBlockRisks($this->session->project, $block->params->type, $this->viewType == 'json' ? 0 : (int)$block->params->count, $block->params->orderBy);
  1342. }
  1343. /**
  1344. * 打印单个项目下的迭代总览区块。
  1345. * Print sprint block.
  1346. *
  1347. * @param object $block
  1348. * @access protected
  1349. * @return void
  1350. */
  1351. protected function printSprintBlock($block)
  1352. {
  1353. $this->printExecutionOverviewBlock($block, array(), 'sprint', (int)$this->session->project, true);
  1354. }
  1355. /**
  1356. * 打印项目动态区块。
  1357. * Print project dynamic block.
  1358. *
  1359. * @param object $block
  1360. * @access protected
  1361. * @return void
  1362. */
  1363. protected function printProjectDynamicBlock($block)
  1364. {
  1365. $projectID = $this->session->project;
  1366. $count = isset($block->params->count) ? (int)$block->params->count : 10;
  1367. $this->view->actions = $this->loadModel('action')->getDynamic('all', 'all', 'date_desc', $count, 'all', $projectID);
  1368. $this->view->users = $this->loadModel('user')->getPairs('noletter', '', 0, array_unique(array_column($this->view->actions, 'actor')));
  1369. }
  1370. /**
  1371. * 打印敏捷项目路线图区块。
  1372. * Print srcum road map block.
  1373. *
  1374. * @param int $productID
  1375. * @param int $roadMapID
  1376. * @access protected
  1377. * @return void
  1378. */
  1379. protected function printScrumRoadMapBlock($productID = 0, $roadMapID = 0)
  1380. {
  1381. $uri = $this->app->tab == 'my' ? $this->createLink('my', 'index') : $this->server->http_referer;
  1382. $this->session->set('releaseList', $uri, 'product');
  1383. $this->session->set('productPlanList', $uri, 'product');
  1384. $products = $this->loadModel('product')->getPairs('', $this->session->project);
  1385. if(!is_numeric($productID)) $productID = key($products);
  1386. $this->view->roadmaps = $this->product->getRoadmap($productID, 0, 6);
  1387. $this->view->productID = $productID;
  1388. $this->view->roadMapID = $roadMapID;
  1389. $this->view->products = $products;
  1390. $this->view->sync = 1;
  1391. if($_POST)
  1392. {
  1393. $this->view->sync = 0;
  1394. $this->display('block', 'scrumroadmapblock');
  1395. }
  1396. }
  1397. /**
  1398. * 打印敏捷项目的测试统计区块。
  1399. * Print srcum test block.
  1400. *
  1401. * @param object $block
  1402. * @access public
  1403. * @return void
  1404. */
  1405. public function printScrumTestBlock($block)
  1406. {
  1407. $uri = $this->app->tab == 'my' ? $this->createLink('my', 'index') : $this->server->http_referer;
  1408. $this->session->set('testtaskList', $uri, 'qa');
  1409. $this->session->set('productList', $uri, 'product');
  1410. $this->session->set('projectList', $uri, 'project');
  1411. $this->session->set('buildList', $uri, 'execution');
  1412. $this->app->loadLang('testtask');
  1413. $this->view->project = $this->loadModel('project')->getByID($this->session->project);
  1414. $this->view->testtasks = $this->dao->select("DISTINCT t1.*,t2.name as productName,t2.shadow,t3.name as buildName,t4.name as executionName, CONCAT(t4.name, '/', t3.name) as executionBuild")->from(TABLE_TESTTASK)->alias('t1')
  1415. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  1416. ->leftJoin(TABLE_BUILD)->alias('t3')->on('t1.build=t3.id')
  1417. ->leftJoin(TABLE_PROJECT)->alias('t4')->on('t1.execution=t4.id')
  1418. ->leftJoin(TABLE_PROJECTPRODUCT)->alias('t5')->on('t1.project=t5.project')
  1419. ->where('t1.deleted')->eq('0')
  1420. ->andWhere('t1.auto')->ne('unit')
  1421. ->beginIF(!$this->app->user->admin)->andWhere('t1.product')->in($this->app->user->view->products)->fi()
  1422. ->beginIF(!$this->app->user->admin)->andWhere('t1.execution')->in($this->app->user->view->sprints)->fi()
  1423. ->andWhere('t1.project')->eq($this->session->project)->fi()
  1424. ->andWhere('t1.product = t5.product')
  1425. ->beginIF($block->params->type != 'all')->andWhere('t1.status')->eq($block->params->type)->fi()
  1426. ->orderBy('t1.id desc')
  1427. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  1428. ->fetchAll();
  1429. }
  1430. /**
  1431. * 打印测试统计区块。
  1432. * Print qa statistic block.
  1433. *
  1434. * @param object $block
  1435. * @access protected
  1436. * @return void
  1437. */
  1438. protected function printQaStatisticBlock($block)
  1439. {
  1440. if(!empty($block->params->type) && preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  1441. $this->app->loadLang('bug');
  1442. $status = isset($block->params->type) ? $block->params->type : '';
  1443. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  1444. /* 测试统计是按产品分组统计的。 */
  1445. $products = $this->loadModel('product')->getOrderedProducts($status, $count, 0, 'all');
  1446. $shadowProductList = array();
  1447. foreach($products as $productID => $product) if($product->shadow) $shadowProductList[] = $productID;
  1448. $productProject = $this->dao->select('t1.product, t1.project')->from(TABLE_PROJECTPRODUCT)->alias('t1')
  1449. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  1450. ->where('t1.product')->in(array_values($shadowProductList))
  1451. ->andWhere('t2.type')->eq('project')
  1452. ->fetchPairs();
  1453. $productIdList = array_keys($products);
  1454. $projectIdList = array_values($productProject);
  1455. /* 计算昨日和今日可能包含的日期情况。 */
  1456. $years = array();
  1457. $months = array();
  1458. for($i = 0; $i <= 1; $i ++)
  1459. {
  1460. $years[] = date('Y', strtotime("-{$i} day"));
  1461. $months[] = date('m', strtotime("-{$i} day"));
  1462. }
  1463. $this->loadModel('metric');
  1464. $createdBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_created_bug_in_product', array('product' => join(',', $productIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 获取昨日和今日新增的Bug数。
  1465. $shadowCreatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_created_bug_in_project', array('project' => join(',', $projectIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 获取昨日和今日新增的Bug数。
  1466. $resolvedBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_resolved_bug_in_product', array('product' => join(',', $productIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 获取昨日和今日解决的Bug数。
  1467. $shadowResolvedBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_resolved_bug_in_project', array('project' => join(',', $projectIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 获取影子产品昨日和今日解决的Bug数。
  1468. $closedBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_closed_bug_in_product', array('product' => join(',', $productIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 获取昨日和今日关闭的Bug数。
  1469. $shadowClosedBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_closed_bug_in_project', array('project' => join(',', $projectIdList), 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 获取影子产品昨日和今日关闭的Bug数。
  1470. $bugFixRate = $this->metric->getResultByCodeWithArray('rate_of_fixed_bug_in_product', array('product' => join(',', $productIdList)), 'cron'); // 获取Bug修复率。
  1471. $shadowBugFixRate = $this->metric->getResultByCodeWithArray('rate_of_fixed_bug_in_project', array('project' => join(',', $projectIdList)), 'cron'); // 获取影子产品Bug修复率。
  1472. $effectiveBug = $this->metric->getResultByCodeWithArray('count_of_effective_bug_in_product', array('product' => join(',', $productIdList)), 'cron'); // 获取有效Bug总数。
  1473. $shadowEffectiveBug = $this->metric->getResultByCodeWithArray('count_of_effective_bug_in_project', array('project' => join(',', $projectIdList)), 'cron'); // 获取影子产品有效Bug总数。
  1474. $fixedBug = $this->metric->getResultByCodeWithArray('count_of_fixed_bug_in_product', array('product' => join(',', $productIdList)), 'cron'); // 获取Bug修复数。
  1475. $shadowFixedBug = $this->metric->getResultByCodeWithArray('count_of_fixed_bug_in_project', array('project' => join(',', $projectIdList)), 'cron'); // 获取影子产品Bug修复数。
  1476. $activatedBug = $this->metric->getResultByCodeWithArray('count_of_activated_bug_in_product', array('product' => join(',', $productIdList)), 'cron'); // 获取Bug激活数。
  1477. $shadowActivatedBug = $this->metric->getResultByCodeWithArray('count_of_activated_bug_in_project', array('project' => join(',', $projectIdList)), 'cron'); // 获取影子产品Bug激活数。
  1478. if(!empty($bugFixRate)) $bugFixRate = array_column($bugFixRate, null, 'product');
  1479. if(!empty($shadowBugFixRate)) $shadowBugFixRate = array_column($shadowBugFixRate, null, 'project');
  1480. if(!empty($effectiveBug)) $effectiveBug = array_column($effectiveBug, null, 'product');
  1481. if(!empty($shadowEffectiveBug)) $shadowEffectiveBug = array_column($shadowEffectiveBug, null, 'project');
  1482. if(!empty($fixedBug)) $fixedBug = array_column($fixedBug, null, 'product');
  1483. if(!empty($shadowFixedBug)) $shadowFixedBug = array_column($shadowFixedBug, null, 'project');
  1484. if(!empty($activatedBug)) $activatedBug = array_column($activatedBug, null, 'product');
  1485. if(!empty($shadowActivatedBug)) $shadowActivatedBug = array_column($shadowActivatedBug, null, 'project');
  1486. $productIdList = array_keys($products);
  1487. $unclosedTesttasks = $this->dao->select('product,id,name')->from(TABLE_TESTTASK)
  1488. ->where('product')->in($productIdList)
  1489. ->andWhere('project')->ne(0)
  1490. ->andWhere('status')->ne('done')
  1491. ->andWhere('deleted')->eq(0)
  1492. ->orderBy('id_desc')
  1493. ->fetchGroup('product');
  1494. /* 将获取出的度量项数据塞入产品列表数据中。 */
  1495. foreach($products as $productID => $product)
  1496. {
  1497. $isShadow = $product->shadow;
  1498. $useObjectID = !$isShadow ? $productID : (isset($productProject[$productID]) ? $productProject[$productID] : $productID); // 如果是影子产品,用项目查询
  1499. $useDataKey = !$isShadow ? 'product' : 'project';
  1500. $product->addToday = 0;
  1501. $product->addYesterday = 0;
  1502. $product->resolvedToday = 0;
  1503. $product->resolvedYesterday = 0;
  1504. $product->closedToday = 0;
  1505. $product->closedYesterday = 0;
  1506. $useCreatedBug = !$isShadow ? 'createdBugGroup' : 'shadowCreatedBugGroup';
  1507. if(!empty($$useCreatedBug))
  1508. {
  1509. foreach($$useCreatedBug as $data)
  1510. {
  1511. $objectEQ = $useObjectID == $data[$useDataKey];
  1512. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  1513. if($currentDay == date('Y-m-d') && $objectEQ) $product->addToday = $data['value'];
  1514. if($currentDay == date('Y-m-d', strtotime("-1 day")) && $objectEQ) $product->addYesterday = $data['value'];
  1515. }
  1516. }
  1517. $useResolvedBug = !$isShadow ? 'resolvedBugGroup' : 'shadowResolvedBugGroup';
  1518. if(!empty($$useResolvedBug))
  1519. {
  1520. foreach($$useResolvedBug as $data)
  1521. {
  1522. $objectEQ = $useObjectID == $data[$useDataKey];
  1523. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  1524. if($currentDay == date('Y-m-d') && $objectEQ) $product->resolvedToday = $data['value'];
  1525. if($currentDay == date('Y-m-d', strtotime("-1 day")) && $objectEQ) $product->resolvedYesterday = $data['value'];
  1526. }
  1527. }
  1528. $useClosedBug = !$isShadow ? 'closedBugGroup' : 'shadowClosedBugGroup';
  1529. if(!empty($$useClosedBug))
  1530. {
  1531. foreach($$useClosedBug as $data)
  1532. {
  1533. $objectEQ = $useObjectID == $data[$useDataKey];
  1534. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  1535. if($currentDay == date('Y-m-d') && $objectEQ) $product->closedToday = $data['value'];
  1536. if($currentDay == date('Y-m-d', strtotime("-1 day")) && $objectEQ) $product->closedYesterday = $data['value'];
  1537. }
  1538. }
  1539. $useBugFixRate = !$isShadow ? 'bugFixRate' : 'shadowBugFixRate';
  1540. $useEffectiveBug = !$isShadow ? 'effectiveBug' : 'shadowEffectiveBug';
  1541. $useFixedBug = !$isShadow ? 'fixedBug' : 'shadowFixedBug';
  1542. $useActivatedBug = !$isShadow ? 'activatedBug' : 'shadowActivatedBug';
  1543. $product->fixedBugRate = isset($$useBugFixRate[$useObjectID]['value']) ? $$useBugFixRate[$useObjectID]['value'] * 100 : 0;
  1544. $product->totalBug = isset($$useEffectiveBug[$useObjectID]['value']) ? $$useEffectiveBug[$useObjectID]['value'] : 0;
  1545. $product->fixedBug = isset($$useFixedBug[$useObjectID]['value']) ? $$useFixedBug[$useObjectID]['value'] : 0;
  1546. $product->activatedBug = isset($$useActivatedBug[$useObjectID]['value']) ? $$useActivatedBug[$useObjectID]['value'] : 0;
  1547. $product->unclosedTesttasks = isset($unclosedTesttasks[$productID]) ? $unclosedTesttasks[$productID] : '';
  1548. }
  1549. $this->view->products = $products;
  1550. }
  1551. /**
  1552. * 传递产品总览区块页面数据。
  1553. * Transfer product overview block page data.
  1554. *
  1555. * @param object $block
  1556. * @param array $params
  1557. * @access protected
  1558. * @return bool
  1559. */
  1560. protected function printProductOverviewBlock($block, $params = array())
  1561. {
  1562. if($block->width == 1) $this->printShortProductOverview();
  1563. if($block->width == 3) $this->printLongProductOverview($params);
  1564. }
  1565. /**
  1566. * 传递产品总览短区块页面数据。
  1567. * Transfer short product overview block page data.
  1568. *
  1569. * @access protected
  1570. * @return void
  1571. */
  1572. protected function printShortProductOverview()
  1573. {
  1574. $data = new stdclass();
  1575. $data->productCount = 0;
  1576. $data->releaseCount = 0;
  1577. $data->milestoneCount = 0;
  1578. $this->loadModel('metric');
  1579. /* 从度量项获取产品总数量。 */
  1580. $productCount = $this->metric->getResultByCodeWithArray('count_of_product', array(), 'cron', null, $this->config->vision == 'or' ? 'rnd,or' : 'rnd');
  1581. if(!empty($productCount))
  1582. {
  1583. $productCount = reset($productCount);
  1584. $data->productCount = zget($productCount, 'value', 0);
  1585. }
  1586. /* 从度量项获取发布次数。 */
  1587. $releaseCount = $this->metric->getResultByCodeWithArray('count_of_annual_created_release', array('year' => date('Y')), 'cron');
  1588. if(!empty($releaseCount))
  1589. {
  1590. $releaseCount = reset($releaseCount);
  1591. $data->releaseCount = zget($releaseCount, 'value', 0);
  1592. }
  1593. /* 从度量项获取发布里程碑数。 */
  1594. $milestoneCount = $this->metric->getResultByCodeWithArray('count_of_marker_release', array(), 'cron');
  1595. if(!empty($milestoneCount))
  1596. {
  1597. $milestoneCount = reset($milestoneCount);
  1598. $data->milestoneCount = zget($milestoneCount, 'value', 0);
  1599. }
  1600. $this->view->data = $data;
  1601. }
  1602. /**
  1603. * 传递产品总览长区块页面数据。
  1604. * Transfer long product overview block page data.
  1605. *
  1606. * @param array $params
  1607. * @access protected
  1608. * @return void
  1609. */
  1610. protected function printLongProductOverview($params = array())
  1611. {
  1612. $year = isset($params['year']) ? (int)$params['year'] : date('Y');
  1613. /* 初始化报表数据为0。 */
  1614. $data = new stdclass();
  1615. $data->productLineCount = 0;
  1616. $data->productCount = 0;
  1617. $data->unfinishedPlanCount = 0;
  1618. $data->unclosedStoryCount = 0;
  1619. $data->activeBugCount = 0;
  1620. $data->finishedReleaseCount['year'] = 0;
  1621. $data->finishedReleaseCount['week'] = 0;
  1622. $data->finishedStoryCount['year'] = 0;
  1623. $data->finishedStoryCount['week'] = 0;
  1624. $data->finishedStoryPoint['year'] = 0;
  1625. $data->finishedStoryPoint['week'] = 0;
  1626. $this->loadModel('metric');
  1627. $productLineCount = $this->metric->getResultByCodeWithArray('count_of_line', array(), 'cron'); // 产品线总量。
  1628. if(!empty($productLineCount))
  1629. {
  1630. $productLineCount = reset($productLineCount);
  1631. $data->productLineCount = zget($productLineCount, 'value', 0);
  1632. }
  1633. $productCount = $this->metric->getResultByCodeWithArray('count_of_product', array(), 'cron'); // 产品总量。
  1634. if(!empty($productCount))
  1635. {
  1636. $productCount = reset($productCount);
  1637. $data->productCount = zget($productCount, 'value', 0);
  1638. }
  1639. $unfinishedPlanCount = $this->metric->getResultByCodeWithArray('count_of_unfinished_productplan', array(), 'cron'); // 未完成计划数。
  1640. if(!empty($unfinishedPlanCount))
  1641. {
  1642. $unfinishedPlanCount = reset($unfinishedPlanCount);
  1643. $data->unfinishedPlanCount = zget($unfinishedPlanCount, 'value', 0);
  1644. }
  1645. $unclosedStoryCount = $this->metric->getResultByCodeWithArray('count_of_unclosed_story', array(), 'cron'); // 未关闭需求数。
  1646. if(!empty($unclosedStoryCount))
  1647. {
  1648. $unclosedStoryCount = reset($unclosedStoryCount);
  1649. $data->unclosedStoryCount = zget($unclosedStoryCount, 'value', 0);
  1650. }
  1651. $activeBugCount = $this->metric->getResultByCodeWithArray('count_of_activated_bug', array(), 'cron'); // 激活Bug数。
  1652. if(!empty($activeBugCount))
  1653. {
  1654. $activeBugCount = reset($activeBugCount);
  1655. $data->activeBugCount = zget($activeBugCount, 'value', 0);
  1656. }
  1657. $createdReleaseGroup = $this->metric->getResultByCodeWithArray('count_of_annual_created_release', array(), 'cron'); // 已完成发布数。
  1658. $finishedStoryGroup = $this->metric->getResultByCodeWithArray('count_of_annual_finished_story', array(), 'cron'); // 已完成需求数。
  1659. $storyScaleGroup = $this->metric->getResultByCodeWithArray('scale_of_annual_finished_story', array(), 'cron'); // 已完成需求规模。
  1660. if($createdReleaseGroup) $createdReleaseGroup = array_column($createdReleaseGroup, null, 'year');
  1661. if($finishedStoryGroup) $finishedStoryGroup = array_column($finishedStoryGroup, null, 'year');
  1662. if($storyScaleGroup) $storyScaleGroup = array_column($storyScaleGroup, null, 'year');
  1663. if(!empty($createdReleaseGroup[$year])) $data->finishedReleaseCount['year'] = zget($createdReleaseGroup[$year], 'value', 0);
  1664. if(!empty($finishedStoryGroup[$year])) $data->finishedStoryCount['year'] = zget($finishedStoryGroup[$year], 'value', 0);
  1665. if(!empty($storyScaleGroup[$year])) $data->finishedStoryPoint['year'] = zget($storyScaleGroup[$year], 'value', 0);
  1666. /* 获取有数据的年份,默认显示今年。 */
  1667. $years = array(date('Y') => 0);
  1668. if($createdReleaseGroup || $finishedStoryGroup || $storyScaleGroup) $years = $years + $createdReleaseGroup + $finishedStoryGroup + $storyScaleGroup;
  1669. $years = array_keys($years);
  1670. rsort($years);
  1671. $this->view->years = $years;
  1672. $this->view->currentYear = $year;
  1673. $this->view->data = $data;
  1674. }
  1675. /**
  1676. * 打印迭代总览区块。
  1677. * Print execution overview block.
  1678. *
  1679. * @param object $block
  1680. * @param array $params
  1681. * @param string $code executionoverview|sprint
  1682. * @param int $project
  1683. * @param bool $showClosed true|false
  1684. * @access protected
  1685. * @return void
  1686. */
  1687. protected function printExecutionOverviewBlock($block, $params = array(), $code = 'executionoverview', $project = 0, $showClosed = false)
  1688. {
  1689. $this->loadModel('metric');
  1690. /* 通过度量项获取迭代总量。 */
  1691. $executionCount = 0;
  1692. $executionCountGroup = $project ? $this->metric->getResultByCodeWithArray('count_of_execution_in_project', array('project' => $project)) : $this->metric->getResultByCodeWithArray('count_of_execution', array(), 'cron', null, $this->config->vision);
  1693. if(!empty($executionCountGroup))
  1694. {
  1695. $executionCountGroup = reset($executionCountGroup);
  1696. $executionCount = zget($executionCountGroup, 'value', 0);
  1697. }
  1698. /* 通过度量项获取今年完成的迭代数量。 */
  1699. $finishedExecution = 0;
  1700. $finishedExecutionGroup = $project ? $this->metric->getResultByCodeWithArray('count_of_annual_finished_execution_in_project', array('project' => $project, 'year' => date('Y')), 'cron') : $this->metric->getResultByCodeWithArray('count_of_annual_finished_execution', array('year' => date('Y')), 'cron', null, $this->config->vision);
  1701. if(!empty($finishedExecutionGroup))
  1702. {
  1703. $finishedExecutionGroup = reset($finishedExecutionGroup);
  1704. $finishedExecution = zget($finishedExecutionGroup, 'value', 0);
  1705. }
  1706. /* 通过度量项获取未开始的迭代数量。 */
  1707. $waitExecution = 0;
  1708. $waitExecutionGroup = $project ? $this->metric->getResultByCodeWithArray('count_wait_execution_in_project', array('project' => $project), 'cron') : $this->metric->getResultByCodeWithArray('count_of_wait_execution', array(), 'cron', null, $this->config->vision);
  1709. if(!empty($waitExecutionGroup))
  1710. {
  1711. $waitExecutionGroup = reset($waitExecutionGroup);
  1712. $waitExecution = zget($waitExecutionGroup, 'value', 0);
  1713. }
  1714. /* 通过度量项获取进行中的迭代数量。 */
  1715. $doingExecution = 0;
  1716. $doingExecutionGroup = $project ? $this->metric->getResultByCodeWithArray('count_of_doing_execution_in_project', array('project' => $project), 'cron') : $this->metric->getResultByCodeWithArray('count_of_doing_execution', array(), 'cron', null, $this->config->vision);
  1717. if(!empty($doingExecutionGroup))
  1718. {
  1719. $doingExecutionGroup = reset($doingExecutionGroup);
  1720. $doingExecution = zget($doingExecutionGroup, 'value', 0);
  1721. }
  1722. /* 通过度量项获取已挂起的迭代数量。 */
  1723. $suspendedExecution = 0;
  1724. $suspendedExecutionGroup = $project ? $this->metric->getResultByCodeWithArray('count_of_suspended_execution_in_project', array('project' => $project), 'cron') : $this->metric->getResultByCodeWithArray('count_of_suspended_execution', array(), 'cron', null, $this->config->vision);
  1725. if(!empty($suspendedExecutionGroup))
  1726. {
  1727. $suspendedExecutionGroup = reset($suspendedExecutionGroup);
  1728. $suspendedExecution = zget($suspendedExecutionGroup, 'value', 0);
  1729. }
  1730. /* 如果是地盘下的区块跳转到执行列表,如果是单项目下的区块跳转到项目的迭代列表。 */
  1731. $url = common::hasPriv('execution', 'all') && $this->config->vision != 'lite' ? helper::createLink('execution', 'all', 'status=all') : null;
  1732. if($project) $url = common::hasPriv('project', 'execution') ? helper::createLink('project', 'execution', "status=all&projectID=$project") : null;
  1733. /* 组装区块左侧的数据。 */
  1734. $cards = array();
  1735. $cards[0] = new stdclass();
  1736. $cards[0]->value = $executionCount;
  1737. $cards[0]->class = 'text-primary';
  1738. $cards[0]->label = $this->lang->block->{$code}->totalExecution;
  1739. $cards[0]->url = $url;
  1740. $cards[1] = new stdclass();
  1741. $cards[1]->value = $finishedExecution;
  1742. $cards[1]->label = $this->lang->block->{$code}->thisYear;
  1743. $cardGroup = new stdclass();
  1744. $cardGroup->type = 'cards';
  1745. $cardGroup->cards = $cards;
  1746. /* 组装区块右侧的柱状图数据。 */
  1747. $max = max($waitExecution, $doingExecution, $suspendedExecution);
  1748. $bars = array();
  1749. $bars[0] = new stdclass();
  1750. $bars[0]->label = $this->lang->block->typeList->projectAll['wait'];
  1751. $bars[0]->value = $waitExecution;
  1752. $bars[0]->rate = $max ? round($waitExecution / $max, 4) * 100 . '%' : '0%';
  1753. $bars[1] = new stdclass();
  1754. $bars[1]->label = $this->lang->block->typeList->projectAll['doing'];
  1755. $bars[1]->value = $doingExecution;
  1756. $bars[1]->rate = $max ? round($doingExecution / $max, 4) * 100 . '%' : '0%';
  1757. $bars[2] = new stdclass();
  1758. $bars[2]->label = $this->lang->block->typeList->projectAll['suspended'];
  1759. $bars[2]->value = $suspendedExecution;
  1760. $bars[2]->rate = $max ? round($suspendedExecution / $max, 4) * 100 . '%' : '0%';
  1761. $barGroup = new stdclass();
  1762. $barGroup->type = 'barChart';
  1763. $barGroup->title = $this->lang->block->{$code}->statusCount;
  1764. $barGroup->bars = $bars;
  1765. $this->view->groups = array($cardGroup, $barGroup);
  1766. }
  1767. /**
  1768. * 打印测试概况区块。
  1769. * Print qa overview block.
  1770. *
  1771. * @param object $block
  1772. * @access protected
  1773. * @return void
  1774. */
  1775. protected function printQaOverviewBlock($block)
  1776. {
  1777. $casePairs = $this->dao->select('lastRunResult, COUNT(1) AS count')->from(TABLE_CASE)
  1778. ->where('1=1')
  1779. ->beginIF($block->module != 'my' && $this->session->project)->andWhere('project')->eq((int)$this->session->project)->fi()
  1780. ->groupBy('lastRunResult')
  1781. ->fetchPairs();
  1782. $total = array_sum($casePairs);
  1783. $this->app->loadLang('testcase');
  1784. foreach($this->lang->testcase->resultList as $result => $label)
  1785. {
  1786. if(!isset($casePairs[$result])) $casePairs[$result] = 0;
  1787. }
  1788. $casePercents = array();
  1789. foreach($casePairs as $result => $count)
  1790. {
  1791. $casePercents[$result] = $total ? round($count / $total * 100, 2) : 0;
  1792. }
  1793. $this->view->total = $total;
  1794. $this->view->casePairs = $casePairs;
  1795. $this->view->casePercents = $casePercents;
  1796. }
  1797. /**
  1798. * 打印执行列表区块。
  1799. * Print execution block.
  1800. *
  1801. * @param object $block
  1802. * @access protected
  1803. * @return void
  1804. */
  1805. protected function printExecutionListBlock($block)
  1806. {
  1807. if(!empty($block->params->type) && preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  1808. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  1809. $status = isset($block->params->type) ? $block->params->type : 'all';
  1810. $this->loadModel('execution');
  1811. $this->app->loadClass('pager', true);
  1812. $pager = pager::init(0, $count, 1);
  1813. $projectID = $block->dashboard == 'my' ? 0 : (int)$this->session->project;
  1814. $executions = $this->execution->getStatData($projectID, $status, 0, 0, false, 'skipParent', 'id_asc', $pager);
  1815. if($executions)
  1816. {
  1817. foreach($executions as $execution)
  1818. {
  1819. $execution->totalEstimate = !empty($execution->hours) ? $execution->hours->totalEstimate : 0;
  1820. $execution->totalLeft = !empty($execution->hours) ? $execution->hours->totalLeft : 0;
  1821. $execution->progress = !empty($execution->hours) ? $execution->hours->progress : 0;
  1822. $execution->burns = !empty($execution->burns) ? join(',', $execution->burns) : array();
  1823. }
  1824. }
  1825. $this->view->executions = $executions ? $executions : array();
  1826. }
  1827. /**
  1828. * 打印指派给的我区块。
  1829. * Print assign to me block.
  1830. *
  1831. * @param object $block
  1832. * @access protected
  1833. * @return array
  1834. */
  1835. protected function printAssignToMeBlock($block)
  1836. {
  1837. $hasIssue = helper::hasFeature('issue');
  1838. $hasRisk = helper::hasFeature('risk');
  1839. $hasMeeting = helper::hasFeature('meeting');
  1840. $hasViewPriv = array();
  1841. $count = array();
  1842. $params = $block->params;
  1843. $limitCount = zget($params, 'count', $this->config->block->params['assigntome']->count['default']);
  1844. $shadowProducts = $this->dao->select('id')->from(TABLE_PRODUCT)->where('deleted')->eq('0')->andWhere('shadow')->eq(1)->fetchPairs();
  1845. $this->app->loadClass('pager', true);
  1846. $pager = new pager(0, $limitCount, 1);
  1847. $reviews = $this->loadModel('my')->getReviewingList('all', 'time_desc', $pager);
  1848. if($reviews)
  1849. {
  1850. $hasViewPriv['review'] = true;
  1851. $count['review'] = count($reviews);
  1852. foreach($reviews as $review)
  1853. {
  1854. if($review->type == 'story') $review->isShadowProduct = isset($shadowProducts[$review->product]) ? 1 : 0;
  1855. }
  1856. $this->view->reviews = $reviews;
  1857. if($this->config->edition != 'open')
  1858. {
  1859. $this->app->loadLang('approval');
  1860. $this->app->loadLang('projectchange');
  1861. $this->view->flows = $this->dao->select('module,name')->from(TABLE_WORKFLOW)->where('buildin')->eq(0)->fetchPairs('module', 'name');
  1862. }
  1863. }
  1864. if(common::hasPriv('todo', 'view')) $hasViewPriv['todo'] = true;
  1865. if(common::hasPriv('demand', 'view') && $this->config->edition == 'ipd' && $this->config->vision == 'or') $hasViewPriv['demand'] = true;
  1866. if((common::hasPriv('task', 'view') && $this->config->vision == 'rnd') || (common::hasPriv('researchtask', 'view') && $this->config->vision == 'or')) $hasViewPriv['task'] = true;
  1867. if(common::hasPriv('story', 'view') && $this->config->vision != 'lite') $hasViewPriv['story'] = true;
  1868. if($this->config->URAndSR && common::hasPriv('story', 'view') && $this->config->vision != 'lite') $hasViewPriv['requirement'] = true;
  1869. if(common::hasPriv('bug', 'view') && !in_array($this->config->vision, array('lite', 'or'))) $hasViewPriv['bug'] = true;
  1870. if(common::hasPriv('testcase', 'view') && !in_array($this->config->vision, array('lite', 'or'))) $hasViewPriv['testcase'] = true;
  1871. if(common::hasPriv('testtask', 'cases') && !in_array($this->config->vision, array('lite', 'or'))) $hasViewPriv['testtask'] = true;
  1872. if(common::hasPriv('risk', 'view') && in_array($this->config->edition, array('max', 'ipd')) && !in_array($this->config->vision, array('lite', 'or')) && $hasRisk) $hasViewPriv['risk'] = true;
  1873. if(common::hasPriv('reviewissue', 'view') && in_array($this->config->edition, array('max', 'ipd')) && !in_array($this->config->vision, array('lite', 'or')) && $hasRisk) $hasViewPriv['reviewissue'] = true;
  1874. if(common::hasPriv('issue', 'view') && in_array($this->config->edition, array('max', 'ipd')) && !in_array($this->config->vision, array('lite', 'or')) && $hasIssue) $hasViewPriv['issue'] = true;
  1875. if(common::hasPriv('meeting', 'view') && in_array($this->config->edition, array('max', 'ipd')) && !in_array($this->config->vision, array('lite', 'or')) && $hasMeeting) $hasViewPriv['meeting'] = true;
  1876. if((common::hasPriv('feedback', 'view') || common::hasPriv('feedback', 'adminView')) && in_array($this->config->edition, array('max', 'biz', 'ipd'))) $hasViewPriv['feedback'] = true;
  1877. if(common::hasPriv('ticket', 'view') && in_array($this->config->edition, array('max', 'biz', 'ipd')) && $this->config->vision != 'or') $hasViewPriv['ticket'] = true;
  1878. $objectList = array('todo' => 'todos', 'task' => 'tasks', 'bug' => 'bugs', 'story' => 'stories', 'requirement' => 'requirements');
  1879. if($this->config->edition == 'max' or $this->config->edition == 'ipd')
  1880. {
  1881. if($hasRisk) $objectList += array('risk' => 'risks');
  1882. if($hasIssue) $objectList += array('issue' => 'issues');
  1883. $objectList += array('feedback' => 'feedbacks', 'ticket' => 'tickets', 'reviewissue' => 'reviewissues');
  1884. if($this->config->edition == 'ipd' && $this->config->vision == 'or') $objectList += array('demand' => 'demands');
  1885. }
  1886. if($this->config->edition == 'biz') $objectList += array('feedback' => 'feedbacks', 'ticket' => 'tickets');
  1887. $tasks = $this->loadModel('task')->getUserSuspendedTasks($this->app->user->account);
  1888. foreach(array_keys($objectList) as $objectType)
  1889. {
  1890. if(!isset($hasViewPriv[$objectType])) continue;
  1891. $table = $objectType == 'requirement' ? TABLE_STORY : $this->config->objectTables[$objectType];
  1892. $orderBy = $objectType == 'todo' ? '`date` desc' : 'id_desc';
  1893. $objects = $this->dao->select('t1.*')->from($table)->alias('t1')
  1894. ->beginIF($objectType == 'story' || $objectType == 'requirement')->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')->fi()
  1895. ->beginIF($objectType == 'bug')->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')->fi()
  1896. ->beginIF($objectType == 'task')->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.execution=t2.id')->fi()
  1897. ->beginIF(in_array($objectType, array('issue', 'risk', 'reviewissue')))->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project=t2.id')->fi()
  1898. ->beginIF($objectType == 'ticket')->leftJoin(TABLE_USER)->alias('t2')->on('t1.openedBy = t2.account')->fi()
  1899. ->beginIF($objectType == 'demand')->leftJoin(TABLE_DEMANDPOOL)->alias('t2')->on('t1.pool = t2.id')->fi()
  1900. ->where('t1.deleted')->eq(0)
  1901. ->andWhere('t1.assignedTo')->eq($this->app->user->account)->fi()
  1902. ->beginIF($objectType == 'story')->andWhere('t1.type')->eq('story')->andWhere('t2.deleted')->eq('0')->andWhere('t1.vision')->eq($this->config->vision)->fi()
  1903. ->beginIF($objectType == 'requirement')->andWhere('t1.type')->eq('requirement')->andWhere('t2.deleted')->eq('0')->andWhere("FIND_IN_SET('{$this->config->vision}', t1.vision)")->fi()
  1904. ->beginIF($objectType == 'bug')->andWhere('t2.deleted')->eq('0')->fi()
  1905. ->beginIF($objectType == 'story' || $objectType == 'requirement')->andWhere('t2.deleted')->eq('0')->fi()
  1906. ->beginIF($objectType == 'todo')->andWhere('t1.cycle')->eq(0)->andWhere('t1.status')->eq('wait')->andWhere('t1.vision')->eq($this->config->vision)->fi()
  1907. ->beginIF($objectType != 'todo')->andWhere('t1.status')->ne('closed')->fi()
  1908. ->beginIF($objectType == 'feedback')->andWhere('t1.status')->in('wait, noreview')->fi()
  1909. ->beginIF(in_array($objectType, array('issue', 'risk', 'reviewissue')))->andWhere('t2.deleted')->eq(0)->fi()
  1910. ->beginIF($objectType == 'ticket')->andWhere('t1.status')->in('wait,doing,done')->fi()
  1911. ->beginIF($objectType == 'demand')->andWhere('t2.deleted')->eq(0)->fi()
  1912. ->orderBy($orderBy)
  1913. ->beginIF($limitCount)->limit($limitCount)->fi()
  1914. ->fetchAll('id', false);
  1915. if($objectType == 'todo')
  1916. {
  1917. $this->app->loadClass('date');
  1918. $this->app->loadLang('todo');
  1919. foreach($objects as $key => $todo)
  1920. {
  1921. if($todo->status == 'done' && $todo->finishedBy == $this->app->user->account)
  1922. {
  1923. unset($objects[$key]);
  1924. continue;
  1925. }
  1926. if($todo->type == 'task' && isset($tasks[$todo->objectID]))
  1927. {
  1928. unset($objects[$key]);
  1929. continue;
  1930. }
  1931. $todo->begin = date::formatTime($todo->begin);
  1932. $todo->end = date::formatTime($todo->end);
  1933. }
  1934. }
  1935. if($objectType == 'task')
  1936. {
  1937. $this->app->loadLang('task');
  1938. $this->app->loadLang('execution');
  1939. $objects = $this->loadModel('task')->getUserTasks($this->app->user->account, 'assignedTo');
  1940. foreach($objects as $k => $task)
  1941. {
  1942. if(in_array($task->status, array('closed', 'cancel'))) unset($objects[$k]);
  1943. if($task->deadline) $task->deadline = date('m-d', strtotime($task->deadline));
  1944. $task->estimate .= 'h';
  1945. $task->left .= 'h';
  1946. }
  1947. if($limitCount > 0) $objects = array_slice($objects, 0, $limitCount);
  1948. }
  1949. if($objectType == 'story')
  1950. {
  1951. foreach($objects as $key => $story)
  1952. {
  1953. $story->isShadowProduct = isset($shadowProducts[$story->product]) ? 1 : 0;
  1954. $story->storyType = $story->type;
  1955. }
  1956. }
  1957. if($objectType == 'bug') $this->app->loadLang('bug');
  1958. if($objectType == 'risk') $this->app->loadLang('risk');
  1959. if($objectType == 'reviewissue') $this->app->loadLang('reviewissue');
  1960. if($objectType == 'issue') $this->app->loadLang('issue');
  1961. if($objectType == 'feedback' || $objectType == 'ticket')
  1962. {
  1963. $this->app->loadLang('feedback');
  1964. $this->app->loadLang('ticket');
  1965. }
  1966. $count[$objectType] = count($objects);
  1967. $this->view->{$objectList[$objectType]} = $objects;
  1968. }
  1969. if(isset($hasViewPriv['testcase'])) $this->view->testcases = $this->loadModel('testcase')->getByAssignedTo($this->app->user->account, 'skip|run', 'id_desc', $pager);
  1970. if(isset($hasViewPriv['testtask'])) $this->view->testtasks = $this->loadModel('testtask')->getByUser($this->app->user->account, $pager, 'id_desc', 'wait');
  1971. if(isset($hasViewPriv['meeting']))
  1972. {
  1973. $this->app->loadLang('meeting');
  1974. $today = helper::today();
  1975. $now = date('H:i:s', strtotime(helper::now()));
  1976. $meetings = $this->dao->select('t1.*')->from(TABLE_MEETING)->alias('t1')
  1977. ->leftJoin(TABLE_PROJECT)->alias('t2')->on('t1.project = t2.id')
  1978. ->where('t1.deleted')->eq('0')
  1979. ->andWhere('t2.deleted')->eq('0')
  1980. ->andWhere('(t1.date')->gt($today)
  1981. ->orWhere('(t1.begin')->gt($now)
  1982. ->andWhere('t1.date')->eq($today)
  1983. ->markRight(2)
  1984. ->andwhere('(t1.host')->eq($this->app->user->account)
  1985. ->orWhere('t1.participant')->in($this->app->user->account)
  1986. ->markRight(1)
  1987. ->orderBy('t1.id_desc')
  1988. ->beginIF($limitCount)->limit($limitCount)->fi()
  1989. ->fetchAll();
  1990. $count['meeting'] = count($meetings);
  1991. $this->view->meetings = $meetings;
  1992. $this->view->depts = $this->loadModel('dept')->getOptionMenu();
  1993. }
  1994. /* Compatible with the logic of the back button on the old page. */
  1995. $this->session->set('demandList', $this->createLink('my', 'index'), 'my');
  1996. $this->view->users = $this->loadModel('user')->getPairs('all,noletter');
  1997. $this->view->isExternalCall = $this->isExternalCall();
  1998. $this->view->hasViewPriv = $hasViewPriv;
  1999. $this->view->products = $this->dao->select('id, name')->from(TABLE_PRODUCT)->where('deleted')->eq('0')->fetchPairs('id', 'name');
  2000. $this->view->projects = $this->dao->select('id, name')->from(TABLE_PROJECT)->where('deleted')->eq('0')->fetchPairs('id', 'name');
  2001. $this->view->count = $count;
  2002. return $count;
  2003. }
  2004. /**
  2005. * 打印最近项目区块。
  2006. * Print recent project block.
  2007. *
  2008. * @access protected
  2009. * @return void
  2010. */
  2011. protected function printRecentProjectBlock()
  2012. {
  2013. $this->app->loadLang('program');
  2014. /* load pager. */
  2015. $this->app->loadClass('pager', true);
  2016. $pager = new pager(0, 3, 1);
  2017. $projects = $this->loadModel('project')->getList('all', 'id_desc', true, $pager);
  2018. foreach($projects as $project)
  2019. {
  2020. $recentExecution = '';
  2021. $executions = $project->executions;
  2022. foreach($executions as $execution)
  2023. {
  2024. if($execution->status == 'doing' && (empty($recentExecution) || $execution->realBegan > $recentExecution->realBegan))
  2025. {
  2026. $recentExecution = $execution;
  2027. }
  2028. }
  2029. $project->recentExecution = $recentExecution;
  2030. }
  2031. $this->view->projects = $projects;
  2032. }
  2033. /**
  2034. * 打印项目团队区块。
  2035. * Print project team block.
  2036. *
  2037. * @param object $block
  2038. * @access protected
  2039. * @return void
  2040. */
  2041. protected function printProjectTeamBlock($block)
  2042. {
  2043. $count = isset($block->params->count) ? $block->params->count : 15;
  2044. $status = isset($block->params->type) ? $block->params->type : 'all';
  2045. $orderBy = isset($block->params->orderBy) ? $block->params->orderBy : 'id_desc';
  2046. /* Get projects. */
  2047. $this->app->loadLang('task');
  2048. $this->app->loadLang('program');
  2049. $this->app->loadLang('execution');
  2050. $this->view->projects = $this->loadModel('project')->getOverviewList($status, 0, $orderBy, $count);
  2051. }
  2052. /**
  2053. * 打印文档统计区块。
  2054. * Print document statistic block.
  2055. *
  2056. * @access protected
  2057. * @return void
  2058. */
  2059. protected function printDocStatisticBlock()
  2060. {
  2061. $this->view->statistic = $this->loadModel('doc')->getStatisticInfo();
  2062. }
  2063. /**
  2064. * 打印文档动态区块。
  2065. * Print document dynamic block.
  2066. *
  2067. * @access protected
  2068. * @return void
  2069. */
  2070. protected function printDocDynamicBlock()
  2071. {
  2072. /* Load pager. */
  2073. $this->app->loadClass('pager', true);
  2074. $pager = new pager(0, 30, 1);
  2075. $this->view->actions = $this->loadModel('doc')->getDynamic($pager);
  2076. $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all', '', 0, array_unique(array_column($this->view->actions, 'actor')));
  2077. }
  2078. /**
  2079. * 打印我创建的文档区块。
  2080. * Print my collection of documents block.
  2081. *
  2082. * @access protected
  2083. * @return void
  2084. */
  2085. protected function printDocMyCreatedBlock()
  2086. {
  2087. /* Load pager. */
  2088. $this->app->loadClass('pager', true);
  2089. $pager = new pager(0, 6, 1);
  2090. $docList = $this->loadModel('doc')->getDocsByBrowseType('openedbyme', 0, 0, 'addedDate_desc', $pager);
  2091. $libList = array();
  2092. foreach($docList as $doc)
  2093. {
  2094. $doc->editedDate = substr($doc->editedDate, 0, 10);
  2095. $doc->editInterval = helper::getDateInterval($doc->editedDate);
  2096. $libList[] = $doc->lib;
  2097. }
  2098. $this->view->docList = $docList;
  2099. }
  2100. /**
  2101. * 打印我关注的文档区块。
  2102. * Print my collection of documents block.
  2103. *
  2104. * @access protected
  2105. * @return void
  2106. */
  2107. protected function printDocMyCollectionBlock()
  2108. {
  2109. /* Load pager. */
  2110. $this->app->loadClass('pager', true);
  2111. $pager = new pager(0, 6, 1);
  2112. $docList = $this->loadModel('doc')->getDocsByBrowseType('collectedbyme', 0, 0, 'editedDate_desc', $pager);
  2113. $libList = array();
  2114. foreach($docList as $doc)
  2115. {
  2116. $doc->editedDate = substr($doc->editedDate, 0, 10);
  2117. $doc->editInterval = helper::getDateInterval($doc->editedDate);
  2118. $libList[] = $doc->lib;
  2119. }
  2120. $this->view->docList = $docList;
  2121. }
  2122. /**
  2123. * 打印最近更新的文档区块。
  2124. * Print recent update block.
  2125. *
  2126. * @access protected
  2127. * @return void
  2128. */
  2129. protected function printDocRecentUpdateBlock()
  2130. {
  2131. /* Load pager. */
  2132. $this->app->loadClass('pager', true);
  2133. $pager = new pager(0, 6, 1);
  2134. $docList = $this->loadModel('doc')->getDocsByBrowseType('byediteddate', 0, 0, 'editedDate_desc', $pager);
  2135. $libList = array();
  2136. foreach($docList as $doc)
  2137. {
  2138. $doc->editedDate = substr($doc->editedDate, 0, 10);
  2139. $doc->editInterval = helper::getDateInterval($doc->editedDate);
  2140. $libList[] = $doc->lib;
  2141. }
  2142. $this->view->docList = $docList;
  2143. }
  2144. /**
  2145. * 打印文档浏览排行区块。
  2146. * Print view list block.
  2147. *
  2148. * @access protected
  2149. * @return void
  2150. */
  2151. protected function printDocViewListBlock()
  2152. {
  2153. /* Load pager. */
  2154. $this->app->loadClass('pager', true);
  2155. $pager = new pager(0, 6, 1);
  2156. $this->view->docList = $this->loadModel('doc')->getDocsByBrowseType('all', 0, 0,'views_desc', $pager);
  2157. }
  2158. /**
  2159. * 打印文档关注排行区块。
  2160. * Print collect list block.
  2161. *
  2162. * @access protected
  2163. * @return void
  2164. */
  2165. protected function printDocCollectListBlock()
  2166. {
  2167. /* Load pager. */
  2168. $this->app->loadClass('pager', true);
  2169. $pager = new pager(0, 6, 1);
  2170. $docList = $this->loadModel('doc')->getDocsByBrowseType('all', 0, 0, 'collects_desc', $pager);
  2171. foreach($docList as $docID => $doc)
  2172. {
  2173. if(empty($doc->collects)) unset($docList[$docID]);
  2174. }
  2175. $this->view->docList = $docList;
  2176. }
  2177. /**
  2178. * 打拼产品文档统计区块。
  2179. * Print product's document block.
  2180. *
  2181. * @param object $block
  2182. * @param array $params
  2183. * @access protected
  2184. * @return void
  2185. */
  2186. protected function printProductDocBlock($block, $params = array())
  2187. {
  2188. $type = 'involved';
  2189. if(isset($params['type'])) $type = $params['type'];
  2190. $this->loadModel('doc');
  2191. $this->session->set('docList', $this->createLink('doc', 'index'), 'doc');
  2192. /* Set project status and count. */
  2193. $count = isset($block->params->count) ? (int)$block->params->count : 15;
  2194. $products = $this->loadModel('product')->getOrderedProducts('all', 0, 0, 'all');
  2195. $involveds = $this->product->getOrderedProducts('involved', 0, 0, 'all');
  2196. $productIdList = array_merge(array_keys($products), array_keys($involveds));
  2197. $stmt = $this->dao->select('id,product,lib,title,type,addedBy,addedDate,editedDate,status,acl,`groups`,readGroups,users,readUsers,deleted')->from(TABLE_DOC)->alias('t1')
  2198. ->where('deleted')->eq(0)
  2199. ->andWhere('product')->in($productIdList)
  2200. ->beginIF($this->config->doc->notArticleType)->andWhere('t1.type')->notIN($this->config->doc->notArticleType)->fi()
  2201. ->orderBy('product,status,editedDate_desc')
  2202. ->query();
  2203. $docGroup = array();
  2204. while($doc = $stmt->fetch())
  2205. {
  2206. if(!isset($docGroup[$doc->product])) $docGroup[$doc->product] = array();
  2207. if(count($docGroup[$doc->product]) >= $count) continue;
  2208. if($this->doc->checkPrivDoc($doc)) $docGroup[$doc->product][$doc->id] = $doc;
  2209. }
  2210. $hasDataProducts = $hasDataInvolveds = array();
  2211. foreach($products as $productID => $product)
  2212. {
  2213. if(isset($docGroup[$productID]) && count($docGroup[$productID]) > 0)
  2214. {
  2215. $hasDataProducts[$productID] = $product;
  2216. if(isset($involveds[$productID])) $hasDataInvolveds[$productID] = $product;
  2217. }
  2218. }
  2219. $this->view->type = $type;
  2220. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  2221. $this->view->products = $type == 'involved' ? $hasDataInvolveds : $hasDataProducts;
  2222. $this->view->docGroup = $docGroup;
  2223. }
  2224. /**
  2225. * 打印项目文档统计区块。
  2226. * Print project's document block.
  2227. *
  2228. * @param object $block
  2229. * @param array $params
  2230. * @access protected
  2231. * @return void
  2232. */
  2233. protected function printProjectDocBlock($block, $params = array())
  2234. {
  2235. $type = 'involved';
  2236. if(isset($params['type'])) $type = $params['type'];
  2237. $this->loadModel('doc');
  2238. $this->app->loadLang('project');
  2239. $this->session->set('docList', $this->createLink('doc', 'index'), 'doc');
  2240. /* Set project status and count. */
  2241. $count = isset($block->params->count) ? (int)$block->params->count : 15;
  2242. $projects = $this->dao->select('*')->from(TABLE_PROJECT)
  2243. ->where('deleted')->eq('0')
  2244. ->andWhere('vision')->eq($this->config->vision)
  2245. ->andWhere('type')->eq('project')
  2246. ->beginIF($this->config->vision == 'rnd')->andWhere('model')->ne('kanban')->fi()
  2247. ->beginIF(!$this->app->user->admin)->andWhere('id')->in($this->app->user->view->projects)->fi()
  2248. ->orderBy('order_asc,id_desc')
  2249. ->fetchAll('id');
  2250. $involveds = $this->dao->select('t1.*')->from(TABLE_PROJECT)->alias('t1')
  2251. ->leftJoin(TABLE_TEAM)->alias('t2')->on('t1.id=t2.root')
  2252. ->where('t1.deleted')->eq('0')
  2253. ->andWhere('t1.vision')->eq($this->config->vision)
  2254. ->andWhere('t1.type')->eq('project')
  2255. ->beginIF($this->config->vision == 'rnd')->andWhere('t1.model')->ne('kanban')->fi()
  2256. ->andWhere('t2.type')->eq('project')
  2257. ->beginIF(!$this->app->user->admin)->andWhere('t1.id')->in($this->app->user->view->projects)->fi()
  2258. ->andWhere('t1.openedBy', true)->eq($this->app->user->account)
  2259. ->orWhere('t1.PM')->eq($this->app->user->account)
  2260. ->orWhere('t2.account')->eq($this->app->user->account)
  2261. ->markRight(1)
  2262. ->orderBy('t1.order_asc,t1.id_desc')
  2263. ->fetchAll('id');
  2264. $projectIdList = array_keys($projects);
  2265. $stmt = $this->dao->select('t1.id,t1.lib,t1.title,t1.type,t1.addedBy,t1.addedDate,t1.editedDate,t1.status,t1.acl,t1.groups,t1.readGroups,t1.users,t1.readUsers,t1.deleted,if(t1.project = 0, t2.project, t1.project) as project')->from(TABLE_DOC)->alias('t1')
  2266. ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.execution=t2.id')
  2267. ->where('t1.deleted')->eq(0)
  2268. ->beginIF($this->config->doc->notArticleType)->andWhere('t1.type')->notIN($this->config->doc->notArticleType)->fi()
  2269. ->andWhere('t2.deleted', true)->eq(0)
  2270. ->orWhere('t2.deleted is null')
  2271. ->markRight(1)
  2272. ->andWhere('t1.project', true)->in($projectIdList)
  2273. ->orWhere('t2.project')->in($projectIdList)
  2274. ->markRight(1)
  2275. ->orderBy('project,t1.status,t1.editedDate_desc')
  2276. ->query();
  2277. $docGroup = array();
  2278. while($doc = $stmt->fetch())
  2279. {
  2280. if(!isset($docGroup[$doc->project])) $docGroup[$doc->project] = array();
  2281. if(count($docGroup[$doc->project]) >= $count) continue;
  2282. if($this->doc->checkPrivDoc($doc)) $docGroup[$doc->project][$doc->id] = $doc;
  2283. }
  2284. $hasDataProjects = $hasDataInvolveds = array();
  2285. foreach($projects as $projectID => $project)
  2286. {
  2287. if(isset($docGroup[$projectID]) && count($docGroup[$projectID]) > 0)
  2288. {
  2289. $hasDataProjects[$projectID] = $project;
  2290. if(isset($involveds[$projectID])) $hasDataInvolveds[$projectID] = $project;
  2291. }
  2292. }
  2293. $this->view->type = $type;
  2294. $this->view->users = $this->loadModel('user')->getPairs('noletter');
  2295. $this->view->projects = $type == 'involved' ? $hasDataInvolveds : $hasDataProjects;
  2296. $this->view->docGroup = $docGroup;
  2297. }
  2298. /**
  2299. * 打印帮助区块。
  2300. * Print guide block
  2301. *
  2302. * @param object $block
  2303. * @access protected
  2304. * @return void
  2305. */
  2306. protected function printGuideBlock($block)
  2307. {
  2308. $this->app->loadLang('custom');
  2309. $this->app->loadLang('my');
  2310. $this->loadModel('setting');
  2311. $this->view->blockID = $block->id;
  2312. $this->view->programs = $this->loadModel('program')->getTopPairs('noclosed', true);
  2313. $this->view->programID = isset($this->config->global->defaultProgram) ? $this->config->global->defaultProgram : 0;
  2314. $this->view->URSRList = $this->loadModel('custom')->getURSRPairs();
  2315. $this->view->URSR = $this->setting->getURSR();
  2316. $this->view->programLink = isset($this->config->programLink) ? $this->config->programLink : 'program-browse';
  2317. $this->view->productLink = isset($this->config->productLink) ? $this->config->productLink : 'product-all';
  2318. $this->view->projectLink = isset($this->config->projectLink) ? $this->config->projectLink : 'project-browse';
  2319. $this->view->executionLink = isset($this->config->executionLink) ? $this->config->executionLink : 'execution-task';
  2320. }
  2321. /**
  2322. * 打印产品月度推进分析区块。
  2323. * Print product monthly progress block.
  2324. *
  2325. * @access protected
  2326. * @return void
  2327. */
  2328. protected function printMonthlyProgressBlock()
  2329. {
  2330. /* 获取最近6个月的年月数组组合。 */
  2331. $years = array();
  2332. $months = array();
  2333. $dates = array();
  2334. for($i = 5; $i >= 0; $i --)
  2335. {
  2336. $years[] = date('Y', strtotime("first day of -{$i} month"));
  2337. $months[] = date('m', strtotime("first day of -{$i} month"));
  2338. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  2339. }
  2340. $this->loadModel('metric');
  2341. $monthFinishedScale = $this->metric->getResultByCodeWithArray('scale_of_monthly_finished_story', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取月度完成需求规模数。
  2342. $monthCreatedStory = $this->metric->getResultByCodeWithArray('count_of_monthly_created_story', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取月度新增需求数。
  2343. $monthFinishedStory = $this->metric->getResultByCodeWithArray('count_of_monthly_finished_story', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取月度完成需求数。
  2344. $monthCreatedBug = $this->metric->getResultByCodeWithArray('count_of_monthly_created_bug', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取月度新增Bug数。
  2345. $monthFinishedBug = $this->metric->getResultByCodeWithArray('count_of_monthly_fixed_bug', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取月度解决Bug数。
  2346. /* 重新组装度量项数据为年月和数据的数组。 */
  2347. foreach($dates as $date)
  2348. {
  2349. $doneStoryEstimate[$date] = 0;
  2350. $doneStoryCount[$date] = 0;
  2351. $createStoryCount[$date] = 0;
  2352. $fixedBugCount[$date] = 0;
  2353. $createBugCount[$date] = 0;
  2354. if(!empty($monthFinishedScale))
  2355. {
  2356. foreach($monthFinishedScale as $scale)
  2357. {
  2358. if($date == "{$scale['year']}-{$scale['month']}") $doneStoryEstimate[$date] = $scale['value'];
  2359. }
  2360. }
  2361. if(!empty($monthCreatedStory))
  2362. {
  2363. foreach($monthCreatedStory as $story)
  2364. {
  2365. if($date == "{$story['year']}-{$story['month']}") $doneStoryCount[$date] = $story['value'];
  2366. }
  2367. }
  2368. if(!empty($monthFinishedStory))
  2369. {
  2370. foreach($monthFinishedStory as $story)
  2371. {
  2372. if($date == "{$story['year']}-{$story['month']}") $createStoryCount[$date] = $story['value'];
  2373. }
  2374. }
  2375. if(!empty($monthCreatedBug))
  2376. {
  2377. foreach($monthCreatedBug as $bug)
  2378. {
  2379. if($date == "{$bug['year']}-{$bug['month']}") $fixedBugCount[$date] = $bug['value'];
  2380. }
  2381. }
  2382. if(!empty($monthFinishedBug))
  2383. {
  2384. foreach($monthFinishedBug as $bug)
  2385. {
  2386. if($date == "{$bug['year']}-{$bug['month']}") $createBugCount[$date] = $bug['value'];
  2387. }
  2388. }
  2389. }
  2390. $this->view->doneStoryEstimate = $doneStoryEstimate;
  2391. $this->view->doneStoryCount = $doneStoryCount;
  2392. $this->view->createStoryCount = $createStoryCount;
  2393. $this->view->fixedBugCount = $fixedBugCount;
  2394. $this->view->createBugCount = $createBugCount;
  2395. }
  2396. /**
  2397. * 打印产品年度工作量统计区块。
  2398. * Print product annual workload statisitc block.
  2399. *
  2400. * @access protected
  2401. * @return void
  2402. */
  2403. protected function printAnnualWorkloadBlock()
  2404. {
  2405. /* 获取产品列表, 按照产品分组展示数据。 */
  2406. $products = $this->loadModel('product')->getPairs();
  2407. $productIdList = array_keys($products);
  2408. $this->loadModel('metric');
  2409. $finishEstimateGroup = $this->metric->getResultByCodeWithArray('scale_of_annual_finished_story_in_product', array('product' => join(',', $productIdList), 'year' => date('Y')), 'cron'); // 从度量项获取今年各产品完成的需求规模数。
  2410. $doneStoryGroup = $this->metric->getResultByCodeWithArray('count_of_annual_finished_story_in_product', array('product' => join(',', $productIdList), 'year' => date('Y')), 'cron'); // 从度量项获取今年各产品完成的需求数。
  2411. $resolvedBugGroup = $this->metric->getResultByCodeWithArray('count_of_annual_fixed_bug_in_product', array('product' => join(',', $productIdList), 'year' => date('Y')), 'cron'); // 从度量项获取今年各产品修复的Bug数。
  2412. if(!empty($finishEstimateGroup)) $finishEstimateGroup = array_column($finishEstimateGroup, null, 'product');
  2413. if(!empty($doneStoryGroup)) $doneStoryGroup = array_column($doneStoryGroup, null, 'product');
  2414. if(!empty($resolvedBugGroup)) $resolvedBugGroup = array_column($resolvedBugGroup, null, 'product');
  2415. /* 组装数据成产品ID和度量数据的数组。*/
  2416. $doneStoryEstimate = array();
  2417. $doneStoryCount = array();
  2418. $resolvedBugCount = array();
  2419. foreach($products as $productID => $productName)
  2420. {
  2421. $doneStoryEstimate[$productID] = isset($finishEstimateGroup[$productID]['value']) ? $finishEstimateGroup[$productID]['value'] : 0;
  2422. $doneStoryCount[$productID] = isset($doneStoryGroup[$productID]['value']) ? $doneStoryGroup[$productID]['value'] : 0;
  2423. $resolvedBugCount[$productID] = isset($resolvedBugGroup[$productID]['value']) ? $resolvedBugGroup[$productID]['value'] : 0;
  2424. }
  2425. /* 从大到小排序。 */
  2426. arsort($doneStoryEstimate);
  2427. arsort($doneStoryCount);
  2428. arsort($resolvedBugCount);
  2429. $this->view->products = $products;
  2430. $this->view->doneStoryEstimate = $doneStoryEstimate;
  2431. $this->view->doneStoryCount = $doneStoryCount;
  2432. $this->view->resolvedBugCount = $resolvedBugCount;
  2433. /* 获取各个分组中最大的值, 用来计算各个值所占的比例。 */
  2434. $this->view->maxStoryEstimate = !empty($doneStoryEstimate) ? max($doneStoryEstimate) : 0;
  2435. $this->view->maxStoryCount = !empty($doneStoryCount) ? max($doneStoryCount) : 0;
  2436. $this->view->maxBugCount = !empty($resolvedBugCount) ? max($resolvedBugCount) : 0;
  2437. }
  2438. /**
  2439. * 打印产品的Bug数据区块。
  2440. * Print bug statistic block.
  2441. *
  2442. * @param object $block
  2443. * @param array $param
  2444. * @access protected
  2445. * @return void
  2446. * @param mixed[] $params
  2447. */
  2448. protected function printBugStatisticBlock($block, $params = array())
  2449. {
  2450. /* 获取需要统计的产品列表。 */
  2451. /* Obtain a list of products that require statistics. */
  2452. $status = isset($block->params->type) ? $block->params->type : '';
  2453. $count = isset($block->params->count) ? $block->params->count : '';
  2454. $products = $this->loadModel('product')->getOrderedProducts($status, (int)$count, 0, 'all');
  2455. $productID = !empty($params['active']) ? $params['active'] : key($products);
  2456. if(empty($productID)) $productID = 0;
  2457. $isShadow = $productID ? (bool)$products[$productID]->shadow : false;
  2458. $projectID = $isShadow ? $this->dao->select('project')->from(TABLE_PROJECTPRODUCT)->where('product')->eq($productID)->fetch('project') : 0;
  2459. $useObjectID = $isShadow ? $projectID : $productID;
  2460. $useDataKey = $isShadow ? 'project' : 'product';
  2461. $this->loadModel('metric');
  2462. $bugFixedRate = $this->metric->getResultByCodeWithArray('rate_of_fixed_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的Bug修复率。
  2463. $shadowBugFixRate = $this->metric->getResultByCodeWithArray('rate_of_fixed_bug_in_project', array('project' => $projectID), 'cron'); // 获取影子产品Bug修复率。
  2464. $effectiveBugGroup = $this->metric->getResultByCodeWithArray('count_of_effective_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的有效Bug数。
  2465. $shadowEffectiveBug = $this->metric->getResultByCodeWithArray('count_of_effective_bug_in_project', array('project' => $projectID), 'cron'); // 获取影子产品有效Bug总数。
  2466. $fixedBugGroup = $this->metric->getResultByCodeWithArray('count_of_fixed_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的Bug修复数。
  2467. $shadowFixedBugGroup = $this->metric->getResultByCodeWithArray('count_of_fixed_bug_in_project', array('project' => $projectID), 'cron'); // 获取影子产品Bug修复数。
  2468. $activatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_activated_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的Bug激活数。
  2469. $shadowActivatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_activated_bug_in_project', array('project' => $projectID), 'cron'); // 获取影子产品Bug激活数。
  2470. if(!empty($bugFixedRate)) $bugFixedRate = array_column($bugFixedRate, null, 'product');
  2471. if(!empty($shadowBugFixRate)) $shadowBugFixRate = array_column($shadowBugFixRate, null, 'project');
  2472. if(!empty($effectiveBugGroup)) $effectiveBugGroup = array_column($effectiveBugGroup, null, 'product');
  2473. if(!empty($shadowEffectiveBug)) $shadowEffectiveBug = array_column($shadowEffectiveBug, null, 'project');
  2474. if(!empty($fixedBugGroup)) $fixedBugGroup = array_column($fixedBugGroup, null, 'product');
  2475. if(!empty($shadowFixedBugGroup)) $shadowFixedBugGroup = array_column($shadowFixedBugGroup, null, 'project');
  2476. if(!empty($activatedBugGroup)) $activatedBugGroup = array_column($activatedBugGroup, null, 'product');
  2477. if(!empty($shadowActivatedBugGroup)) $shadowActivatedBugGroup = array_column($shadowActivatedBugGroup, null, 'project');
  2478. /* 按照产品和日期分组获取产品每月新增和完成的需求数度量项。 */
  2479. $years = array();
  2480. $months = array();
  2481. $dates = array();
  2482. for($i = 5; $i >= 0; $i --)
  2483. {
  2484. $years[] = date('Y', strtotime("first day of -{$i} month"));
  2485. $months[] = date('m', strtotime("first day of -{$i} month"));
  2486. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  2487. }
  2488. $monthCreatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_created_bug_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的激活Bug数。
  2489. $shadowMonthCreatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_created_bug_in_project', array('project' => $projectID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的激活Bug数。
  2490. $monthClosedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_closed_bug_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的关闭Bug数。
  2491. $shadowMonthClosedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_closed_bug_in_project', array('project' => $projectID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的关闭Bug数。
  2492. /* 组装页面所需的度量项数组。 */
  2493. $useClosedBug = $isShadow ? 'shadowFixedBugGroup' : 'fixedBugGroup';
  2494. $useUnresovledBugs = $isShadow ? 'shadowActivatedBugGroup' : 'activatedBugGroup';
  2495. $useTotalBugs = $isShadow ? 'shadowEffectiveBug' : 'effectiveBugGroup';
  2496. $useResolvedRate = $isShadow ? 'shadowBugFixRate' : 'bugFixedRate';
  2497. $closedBugs = isset($$useClosedBug[$useObjectID]['value']) ? $$useClosedBug[$useObjectID]['value'] : 0;
  2498. $unresovledBugs = isset($$useUnresovledBugs[$useObjectID]['value']) ? $$useUnresovledBugs[$useObjectID]['value'] : 0;
  2499. $totalBugs = isset($$useTotalBugs[$useObjectID]['value']) ? $$useTotalBugs[$useObjectID]['value'] : 0;
  2500. $resolvedRate = isset($$useResolvedRate[$useObjectID]['value']) ? $$useResolvedRate[$useObjectID]['value'] * 100 : 0;
  2501. $useMonthCreate = $isShadow ? 'shadowMonthCreatedBugGroup' : 'monthCreatedBugGroup';
  2502. $useMonthClose = $isShadow ? 'shadowMonthClosedBugGroup' : 'monthClosedBugGroup';
  2503. foreach($dates as $date)
  2504. {
  2505. $activateBugs[$date] = 0;
  2506. $resolveBugs[$date] = 0;
  2507. $closeBugs[$date] = 0;
  2508. if(!empty($$useMonthCreate))
  2509. {
  2510. foreach($$useMonthCreate as $data)
  2511. {
  2512. if($date == "{$data['year']}-{$data['month']}" && $useObjectID == $data[$useDataKey]) $activateBugs[$date] = $data['value'];
  2513. }
  2514. }
  2515. if(!empty($$useMonthClose))
  2516. {
  2517. foreach($$useMonthClose as $data)
  2518. {
  2519. if($date == "{$data['year']}-{$data['month']}" && $useObjectID == $data[$useDataKey]) $closeBugs[$date] = $data['value'];
  2520. }
  2521. }
  2522. }
  2523. $this->view->months = $months;
  2524. $this->view->products = $products;
  2525. $this->view->totalBugs = $totalBugs;
  2526. $this->view->closedBugs = $closedBugs;
  2527. $this->view->unresovledBugs = $unresovledBugs;
  2528. $this->view->resolvedRate = $resolvedRate;
  2529. $this->view->activateBugs = $activateBugs;
  2530. $this->view->resolveBugs = $resolveBugs;
  2531. $this->view->closeBugs = $closeBugs;
  2532. }
  2533. /**
  2534. * 打印团队成就区块。
  2535. * Print Team Achievement block.
  2536. *
  2537. * @access protected
  2538. * @return void
  2539. */
  2540. protected function printTeamAchievementBlock()
  2541. {
  2542. /* 获取昨日和今日可能的年月组合。 */
  2543. $years = array();
  2544. $months = array();
  2545. for($i = 0; $i <= 1; $i ++)
  2546. {
  2547. $years[] = date('Y', strtotime("-{$i} day"));
  2548. $months[] = date('m', strtotime("-{$i} day"));
  2549. }
  2550. $this->loadModel('metric');
  2551. $finishedTaskGroup = $this->metric->getResultByCodeWithArray('count_of_daily_finished_task', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 完成任务数。
  2552. $createdStoryGroup = $this->metric->getResultByCodeWithArray('count_of_daily_created_story', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 创建需求数。
  2553. $closedBugGroup = $this->metric->getResultByCodeWithArray('count_of_daily_closed_bug', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 关闭Bug数。
  2554. $runCaseGroup = $this->metric->getResultByCodeWithArray('count_of_daily_run_case', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 执行用例数。
  2555. $consumedGroup = $this->metric->getResultByCodeWithArray('hour_of_daily_effort', array('year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 消耗工时。
  2556. /* 获取今日完成任务数和昨日完成任务数。 */
  2557. $finishedTasks = 0;
  2558. $yesterdayTasks = 0;
  2559. if($finishedTaskGroup)
  2560. {
  2561. foreach($finishedTaskGroup as $data)
  2562. {
  2563. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  2564. if($currentDay == date('Y-m-d')) $finishedTasks = $data['value'];
  2565. if($currentDay == date('Y-m-d', strtotime("-1 day"))) $yesterdayTasks = $data['value'];
  2566. }
  2567. }
  2568. /* 获取今日创建需求数和昨日创建需求数。 */
  2569. $createdStories = 0;
  2570. $yesterdayStories = 0;
  2571. if($createdStoryGroup)
  2572. {
  2573. foreach($createdStoryGroup as $data)
  2574. {
  2575. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  2576. if($currentDay == date('Y-m-d')) $createdStories = $data['value'];
  2577. if($currentDay == date('Y-m-d', strtotime("-1 day"))) $yesterdayStories = $data['value'];
  2578. }
  2579. }
  2580. /* 获取今日关闭Bug数和昨日关闭Bug数。 */
  2581. $closedBugs = 0;
  2582. $yesterdayBugs = 0;
  2583. if($closedBugGroup)
  2584. {
  2585. foreach($closedBugGroup as $data)
  2586. {
  2587. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  2588. if($currentDay == date('Y-m-d')) $closedBugs = $data['value'];
  2589. if($currentDay == date('Y-m-d', strtotime("-1 day"))) $yesterdayBugs = $data['value'];
  2590. }
  2591. }
  2592. /* 获取今日执行用例数和昨日执行用例数。 */
  2593. $runCases = 0;
  2594. $yesterdayCases = 0;
  2595. if($runCaseGroup)
  2596. {
  2597. foreach($runCaseGroup as $data)
  2598. {
  2599. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  2600. if($currentDay == date('Y-m-d')) $runCases = $data['value'];
  2601. if($currentDay == date('Y-m-d', strtotime("-1 day"))) $yesterdayCases = $data['value'];
  2602. }
  2603. }
  2604. /* 获取今日消耗工时和昨日消耗工时。 */
  2605. $consumedHours = 0;
  2606. $yesterdayHours = 0;
  2607. if($consumedGroup)
  2608. {
  2609. foreach($consumedGroup as $data)
  2610. {
  2611. $currentDay = "{$data['year']}-{$data['month']}-{$data['day']}";
  2612. if($currentDay == date('Y-m-d')) $consumedHours = $data['value'];
  2613. if($currentDay == date('Y-m-d', strtotime("-1 day"))) $yesterdayHours = $data['value'];
  2614. }
  2615. }
  2616. $this->view->finishedTasks = $finishedTasks;
  2617. $this->view->yesterdayTasks = $yesterdayTasks;
  2618. $this->view->createdStories = $createdStories;
  2619. $this->view->yesterdayStories = $yesterdayStories;
  2620. $this->view->closedBugs = $closedBugs;
  2621. $this->view->yesterdayBugs = $yesterdayBugs;
  2622. $this->view->runCases = $runCases;
  2623. $this->view->yesterdayCases = $yesterdayCases;
  2624. $this->view->consumedHours = $consumedHours;
  2625. $this->view->yesterdayHours = $yesterdayHours;
  2626. }
  2627. /**
  2628. * 打印单个产品统计区块。
  2629. * Print product statistic block.
  2630. *
  2631. * @param object $block
  2632. * @access protected
  2633. * @return bool
  2634. */
  2635. protected function printSingleStatisticBlock($block)
  2636. {
  2637. /* 获取需要统计的产品列表。 */
  2638. /* Obtain a list of product that require statistics. */
  2639. $status = isset($block->params->type) ? $block->params->type : '';
  2640. $count = isset($block->params->count) ? $block->params->count : '';
  2641. $productID = $this->session->product;
  2642. $this->loadModel('metric');
  2643. $storyDeliveryRate = $this->metric->getResultByCodeWithArray('rate_of_delivery_story_in_product', array('product' => $productID), 'cron');
  2644. $totalStories = $this->metric->getResultByCodeWithArray('count_of_valid_story_in_product', array('product' => $productID), 'cron');
  2645. $closedStories = $this->metric->getResultByCodeWithArray('count_of_delivered_story_in_product', array('product' => $productID), 'cron');
  2646. $unclosedStories = $this->metric->getResultByCodeWithArray('count_of_unclosed_story_in_product', array('product' => $productID), 'cron');
  2647. if(!empty($storyDeliveryRate)) $storyDeliveryRate = array_column($storyDeliveryRate, null, 'product');
  2648. if(!empty($totalStories)) $totalStories = array_column($totalStories, null, 'product');
  2649. if(!empty($closedStories)) $closedStories = array_column($closedStories, null, 'product');
  2650. if(!empty($unclosedStories)) $unclosedStories = array_column($unclosedStories, null, 'product');
  2651. /* 按照产品和日期分组获取产品每月新增和完成的需求数度量项。 */
  2652. $years = array();
  2653. $months = array();
  2654. $dates = array();
  2655. for($i = 5; $i >= 0; $i --)
  2656. {
  2657. $years[] = date('Y', strtotime("first day of -{$i} month"));
  2658. $months[] = date('m', strtotime("first day of -{$i} month"));
  2659. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  2660. }
  2661. $monthFinish = $this->metric->getResultByCodeWithArray('count_of_monthly_finished_story_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron');
  2662. $monthCreated = $this->metric->getResultByCodeWithArray('count_of_monthly_created_story_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron');
  2663. /* 根据产品列表获取预计开始日期距离现在最近且预计开始日期大于当前日期的未开始状态计划。 */
  2664. /* Obtain an unstarted status plan based on the product list, with an expected start date closest to the current date and an expected start date greater than the current date. */
  2665. $newPlan = $this->dao->select('*')->from(TABLE_PRODUCTPLAN)
  2666. ->where('deleted')->eq('0')
  2667. ->andWhere('product')->eq($productID)
  2668. ->andWhere('begin')->ge(date('Y-m-d'))
  2669. ->andWhere('status')->eq('wait')
  2670. ->orderBy('begin_desc,id_desc')
  2671. ->fetch();
  2672. /* 根据产品列表获取实际开始日期距离当前最近的进行中状态的执行。 */
  2673. /* Obtain the execution of the current in progress status closest to the actual start date based on the product list. */
  2674. $newExecution = $this->dao->select('execution.*,relation.product')->from(TABLE_EXECUTION)->alias('execution')
  2675. ->leftJoin(TABLE_PROJECTPRODUCT)->alias('relation')->on('execution.id=relation.project')
  2676. ->where('execution.deleted')->eq('0')
  2677. ->andWhere('execution.type')->eq('sprint')
  2678. ->andWhere('relation.product')->eq($productID)
  2679. ->andWhere('execution.status')->eq('doing')
  2680. ->orderBy('realBegan_desc,id_desc')
  2681. ->fetch();
  2682. /* 根据产品列表获取发布日期距离现在最近且发布日期小于当前日期的发布。 */
  2683. /* Retrieve releases with the latest release date from the product list and a release date earlier than the current date. */
  2684. $newRelease = $this->dao->select('*')->from(TABLE_RELEASE)
  2685. ->where('deleted')->eq('0')
  2686. ->andWhere('product')->eq($productID)
  2687. ->andWhere('date')->le(date('Y-m-d'))
  2688. ->orderBy('date_desc,id_desc')
  2689. ->fetch();
  2690. $product = $this->loadModel('product')->getByID($productID);
  2691. $product->storyDeliveryRate = !empty($storyDeliveryRate) && !empty($storyDeliveryRate[$productID]) ? zget($storyDeliveryRate[$productID], 'value') * 100 : 0;
  2692. $product->totalStories = !empty($totalStories) && !empty($totalStories[$productID]) ? zget($totalStories[$productID], 'value') : 0;
  2693. $product->closedStories = !empty($closedStories) && !empty($closedStories[$productID]) ? zget($closedStories[$productID], 'value') : 0;
  2694. $product->unclosedStories = !empty($unclosedStories) && !empty($unclosedStories[$productID]) ? zget($unclosedStories[$productID], 'value') : 0;
  2695. $product->newPlan = $newPlan;
  2696. $product->newExecution = $newExecution;
  2697. $product->newRelease = $newRelease;
  2698. /* 将按照产品分组的统计数据放入产品列表中。 */
  2699. /* Place statistical data grouped by product into the product list. */
  2700. foreach($dates as $date)
  2701. {
  2702. $product->monthFinish[$date] = 0;
  2703. $product->monthCreated[$date] = 0;
  2704. if(!empty($monthFinish))
  2705. {
  2706. foreach($monthFinish as $story)
  2707. {
  2708. if($date == "{$story['year']}-{$story['month']}" && $productID == $story['product']) $product->monthFinish[$date] = $story['value'];
  2709. }
  2710. }
  2711. if(!empty($monthCreated))
  2712. {
  2713. foreach($monthCreated as $story)
  2714. {
  2715. if($date == "{$story['year']}-{$story['month']}" && $productID == $story['product']) $product->monthCreated[$date] = $story['value'];
  2716. }
  2717. }
  2718. }
  2719. $this->view->product = $product;
  2720. }
  2721. /**
  2722. * 打印单个产品的bug统计区块。
  2723. * Print single product bug statistic block.
  2724. *
  2725. * @param object $block
  2726. * @access protected
  2727. * @return void
  2728. */
  2729. protected function printSingleBugStatisticBlock($block)
  2730. {
  2731. /* 获取需要统计的产品列表。 */
  2732. /* Obtain a list of products that require statistics. */
  2733. $status = isset($block->params->type) ? $block->params->type : '';
  2734. $count = isset($block->params->count) ? $block->params->count : '';
  2735. $productID = $this->session->product;
  2736. $this->loadModel('metric');
  2737. $bugFixedRate = $this->metric->getResultByCodeWithArray('rate_of_fixed_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的Bug修复率。
  2738. $effectiveBugGroup = $this->metric->getResultByCodeWithArray('count_of_effective_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的有效Bug数。
  2739. $fixedBugGroup = $this->metric->getResultByCodeWithArray('count_of_fixed_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的Bug修复数。
  2740. $activatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_activated_bug_in_product', array('product' => $productID), 'cron'); // 从度量项获取各个产品的Bug激活数。
  2741. if(!empty($bugFixedRate)) $bugFixedRate = array_column($bugFixedRate, null, 'product');
  2742. if(!empty($effectiveBugGroup)) $effectiveBugGroup = array_column($effectiveBugGroup, null, 'product');
  2743. if(!empty($fixedBugGroup)) $fixedBugGroup = array_column($fixedBugGroup, null, 'product');
  2744. if(!empty($fixedBugGroup)) $activatedBugGroup = array_column($activatedBugGroup, null, 'product');
  2745. /* 按照产品和日期分组获取产品每月新增和完成的需求数度量项。 */
  2746. $years = array();
  2747. $months = array();
  2748. $dates = array();
  2749. for($i = 5; $i >= 0; $i --)
  2750. {
  2751. $years[] = date('Y', strtotime("first day of -{$i} month"));
  2752. $months[] = date('m', strtotime("first day of -{$i} month"));
  2753. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  2754. }
  2755. $monthCreatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_created_bug_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的激活Bug数。
  2756. $monthClosedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_closed_bug_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的关闭Bug数。
  2757. /* 组装页面所需的度量项数组。 */
  2758. $activateBugs = array();
  2759. $resolveBugs = array();
  2760. $closeBugs = array();
  2761. $closedBugs = isset($fixedBugGroup[$productID]['value']) ? $fixedBugGroup[$productID]['value'] : 0;
  2762. $unresovledBugs = isset($activatedBugGroup[$productID]['value']) ? $activatedBugGroup[$productID]['value'] : 0;
  2763. $totalBugs = isset($effectiveBugGroup[$productID]['value']) ? $effectiveBugGroup[$productID]['value'] : 0;
  2764. $resolvedRate = isset($bugFixedRate[$productID]['value']) ? $bugFixedRate[$productID]['value'] * 100 : 0;
  2765. foreach($dates as $date)
  2766. {
  2767. $activateBugs[$date] = 0;
  2768. $resolveBugs[$date] = 0;
  2769. $closeBugs[$date] = 0;
  2770. if(!empty($monthCreatedBugGroup))
  2771. {
  2772. foreach($monthCreatedBugGroup as $data)
  2773. {
  2774. if($date == "{$data['year']}-{$data['month']}") $activateBugs[$date] = $data['value'];
  2775. }
  2776. }
  2777. if(!empty($monthClosedBugGroup))
  2778. {
  2779. foreach($monthClosedBugGroup as $data)
  2780. {
  2781. if($date == "{$data['year']}-{$data['month']}") $closeBugs[$date] = $data['value'];
  2782. }
  2783. }
  2784. }
  2785. $this->view->productID = $productID;
  2786. $this->view->months = $months;
  2787. $this->view->totalBugs = $totalBugs;
  2788. $this->view->closedBugs = $closedBugs;
  2789. $this->view->unresovledBugs = $unresovledBugs;
  2790. $this->view->resolvedRate = $resolvedRate;
  2791. $this->view->activateBugs = $activateBugs;
  2792. $this->view->resolveBugs = $resolveBugs;
  2793. $this->view->closeBugs = $closeBugs;
  2794. }
  2795. /**
  2796. * 打印单个产品的需求列表区块。
  2797. * Print single product story block.
  2798. *
  2799. * @params object $block
  2800. * @access protected
  2801. * @return void
  2802. * @param object $block
  2803. */
  2804. protected function printSingleStoryBlock($block)
  2805. {
  2806. $this->session->set('storyList', $this->createLink('product', 'dashboard'), 'product');
  2807. if(preg_match('/[^a-zA-Z0-9_]/', $block->params->type)) return;
  2808. $this->app->loadClass('pager', true);
  2809. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  2810. $pager = pager::init(0, $count , 1);
  2811. $type = isset($block->params->type) ? $block->params->type : 'assignedTo';
  2812. $orderBy = isset($block->params->type) ? $block->params->orderBy : 'id_asc';
  2813. $productID = $this->session->product;
  2814. $this->view->stories = $this->loadModel('story')->getUserStories($this->app->user->account, $type, $orderBy, $this->viewType != 'json' ? $pager : '', 'story', true, 0, $productID);
  2815. }
  2816. /**
  2817. * 打印单个产品发布列表区块数据。
  2818. * Print releases block.
  2819. *
  2820. * @param object $block
  2821. * @access protected
  2822. * @return void
  2823. */
  2824. protected function printSingleReleaseBlock($block)
  2825. {
  2826. $uri = $this->createLink('product', 'dashboard');
  2827. $this->session->set('releaseList', $uri, 'product');
  2828. $this->session->set('buildList', $uri, 'execution');
  2829. $productID = $this->session->product;
  2830. $this->app->loadLang('release');
  2831. $this->view->releases = $this->dao->select('t1.*,t2.name as productName')->from(TABLE_RELEASE)->alias('t1')
  2832. ->leftJoin(TABLE_PRODUCT)->alias('t2')->on('t1.product=t2.id')
  2833. ->where('t1.deleted')->eq('0')
  2834. ->andWhere('t1.product')->eq($productID)
  2835. ->orderBy('t1.id desc')
  2836. ->beginIF($this->viewType != 'json')->limit((int)$block->params->count)->fi()
  2837. ->fetchAll();
  2838. $this->view->builds = $this->dao->select('id,name')->from(TABLE_BUILD)->where('deleted')->eq(0)->andWhere('product')->eq($productID)->fetchPairs();
  2839. }
  2840. /**
  2841. * 打印单个产品计划列表区块。
  2842. * Print single product plan block.
  2843. *
  2844. * @param object $block
  2845. * @access protected
  2846. * @return bool
  2847. */
  2848. protected function printSinglePlanBlock($block)
  2849. {
  2850. $uri = $this->createLink('product', 'dashboard');
  2851. $this->session->set('productList', $uri, 'product');
  2852. $this->session->set('productPlanList', $uri, 'product');
  2853. $this->app->loadClass('pager', true);
  2854. $count = isset($block->params->count) ? (int)$block->params->count : 0;
  2855. $pager = pager::init(0, $count , 1);
  2856. $productID = $this->session->product;
  2857. $product = $this->loadModel('product')->getByID($productID);
  2858. $this->view->plans = $this->loadModel('productplan')->getList($productID, 0, 'all', $pager, 'begin_desc', 'noproduct');
  2859. $this->view->products = array($productID => $product->name);
  2860. }
  2861. /**
  2862. * Print single product latest dynamic.
  2863. *
  2864. * @access protected
  2865. * @return void
  2866. */
  2867. protected function printSingleDynamicBlock()
  2868. {
  2869. $productID = $this->session->product;
  2870. $this->view->productID = $productID;
  2871. $this->view->actions = $this->loadModel('action')->getDynamic('all', 'all', 'date_desc', 30, $productID);
  2872. $this->view->users = $this->loadModel('user')->getPairs('nodeleted|noletter|all');
  2873. }
  2874. /**
  2875. * 打印产品月度推进分析区块.
  2876. * Print monthly progress for the product.
  2877. *
  2878. * @access protected
  2879. * @return void
  2880. */
  2881. protected function printSingleMonthlyProgressBlock()
  2882. {
  2883. $productID = $this->session->product;
  2884. /* 按照产品和日期分组获取产品每月新增和完成的需求数度量项。 */
  2885. $years = array();
  2886. $months = array();
  2887. $dates = array();
  2888. for($i = 5; $i >= 0; $i --)
  2889. {
  2890. $years[] = date('Y', strtotime("first day of -{$i} month"));
  2891. $months[] = date('m', strtotime("first day of -{$i} month"));
  2892. $dates[] = date('Y-m', strtotime("first day of -{$i} month"));
  2893. }
  2894. $this->loadModel('metric');
  2895. $monthStroyScaleGroup = $this->metric->getResultByCodeWithArray('scale_of_monthly_finished_story_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的完成需求数。
  2896. $monthCreatedStroyGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_created_story_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的新增需求数。
  2897. $monthFinishedStoryGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_finished_story_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的完成需求数。
  2898. $monthCreatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_created_bug_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的新增Bug数。
  2899. $monthFixedBugGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_fixed_bug_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的修复Bug数。
  2900. $monthCreatedReleaseGroup = $this->metric->getResultByCodeWithArray('count_of_monthly_created_release_in_product', array('product' => $productID, 'year' => join(',', $years), 'month' => join(',', $months)), 'cron'); // 从度量项获取每月的发布数。
  2901. $months = array();
  2902. $doneStoryEstimate = array();
  2903. $doneStoryCount = array();
  2904. $createStoryCount = array();
  2905. $fixedBugCount = array();
  2906. $createBugCount = array();
  2907. $releaseCount = array();
  2908. foreach($dates as $date)
  2909. {
  2910. $doneStoryEstimate[$date] = 0;
  2911. $doneStoryCount[$date] = 0;
  2912. $createStoryCount[$date] = 0;
  2913. $fixedBugCount[$date] = 0;
  2914. $createBugCount[$date] = 0;
  2915. $releaseCount[$date] = 0;
  2916. if(!empty($monthStroyScaleGroup))
  2917. {
  2918. foreach($monthStroyScaleGroup as $data)
  2919. {
  2920. if($date == "{$data['year']}-{$data['month']}") $doneStoryEstimate[$date] = $data['value'];
  2921. }
  2922. }
  2923. if(!empty($monthCreatedStroyGroup))
  2924. {
  2925. foreach($monthCreatedStroyGroup as $data)
  2926. {
  2927. if($date == "{$data['year']}-{$data['month']}") $createStoryCount[$date] = $data['value'];
  2928. }
  2929. }
  2930. if(!empty($monthFinishedStoryGroup))
  2931. {
  2932. foreach($monthFinishedStoryGroup as $data)
  2933. {
  2934. if($date == "{$data['year']}-{$data['month']}") $doneStoryCount[$date] = $data['value'];
  2935. }
  2936. }
  2937. if(!empty($monthCreatedBugGroup))
  2938. {
  2939. foreach($monthCreatedBugGroup as $data)
  2940. {
  2941. if($date == "{$data['year']}-{$data['month']}") $createBugCount[$date] = $data['value'];
  2942. }
  2943. }
  2944. if(!empty($monthFixedBugGroup))
  2945. {
  2946. foreach($monthFixedBugGroup as $data)
  2947. {
  2948. if($date == "{$data['year']}-{$data['month']}") $fixedBugCount[$date] = $data['value'];
  2949. }
  2950. }
  2951. if(!empty($monthCreatedReleaseGroup))
  2952. {
  2953. foreach($monthCreatedReleaseGroup as $data)
  2954. {
  2955. if($date == "{$data['year']}-{$data['month']}") $releaseCount[$date] = $data['value'];
  2956. }
  2957. }
  2958. }
  2959. $this->view->months = $months;
  2960. $this->view->doneStoryEstimate = $doneStoryEstimate;
  2961. $this->view->doneStoryCount = $doneStoryCount;
  2962. $this->view->createStoryCount = $createStoryCount;
  2963. $this->view->fixedBugCount = $fixedBugCount;
  2964. $this->view->createBugCount = $createBugCount;
  2965. $this->view->releaseCount = $releaseCount;
  2966. }
  2967. /**
  2968. * 判断是否为内部调用。
  2969. * Check request client is chandao or not.
  2970. *
  2971. * @access protected
  2972. * @return bool
  2973. */
  2974. protected function isExternalCall()
  2975. {
  2976. return isset($_GET['hash']);
  2977. }
  2978. /**
  2979. * 为control 层 printBlock 方法返回json 格式数据。
  2980. * Return json data for printBlock.
  2981. *
  2982. * @access protected
  2983. * @return string
  2984. */
  2985. protected function printBlock4Json()
  2986. {
  2987. unset($this->view->app);
  2988. unset($this->view->config);
  2989. unset($this->view->lang);
  2990. unset($this->view->header);
  2991. unset($this->view->position);
  2992. unset($this->view->moduleTree);
  2993. $output['status'] = is_object($this->view) ? 'success' : 'fail';
  2994. $output['data'] = json_encode($this->view);
  2995. $output['md5'] = md5(json_encode($this->view));
  2996. return print(json_encode($output));
  2997. }
  2998. /**
  2999. * 组织外部数据。
  3000. * Organiza external data.
  3001. *
  3002. * @param object $block
  3003. * @access protected
  3004. * @return void
  3005. */
  3006. protected function organizaExternalData($block)
  3007. {
  3008. $lang = isset($this->get->lang) ? $this->get->lang : 'zh-cn';
  3009. $lang = str_replace('_', '-', $lang);
  3010. $this->app->setClientLang($lang);
  3011. $this->app->loadLang('common');
  3012. if(!isset($block->params) && !isset($block->params->account))
  3013. {
  3014. $this->app->user = new stdclass();
  3015. $this->app->user->account = 'guest';
  3016. $this->app->user->realname= 'guest';
  3017. }
  3018. else
  3019. {
  3020. $this->app->user = $this->dao->select('*')->from(TABLE_USER)->where('ranzhi')->eq($block->params->account)->fetch();
  3021. if(empty($this->app->user))
  3022. {
  3023. $this->app->user = new stdclass();
  3024. $this->app->user->account = 'guest';
  3025. $this->app->user->realname= 'guest';
  3026. }
  3027. }
  3028. $this->app->user->admin = strpos($this->app->company->admins, ",{$this->app->user->account},") !== false;
  3029. $this->app->user->rights = $this->loadModel('user')->authorize($this->app->user->account);
  3030. $this->app->user->groups = $this->user->getGroups($this->app->user->account);
  3031. $this->app->user->view = $this->user->grantUserView($this->app->user->account, $this->app->user->rights['acls']);
  3032. $sso = isset($this->get->sso) ? base64_decode($this->get->sso) : '';
  3033. $this->view->sso = $sso;
  3034. $this->view->sign = strpos($sso, '?') === false ? '?' : '&';
  3035. }
  3036. /**
  3037. * 获取项目总览相关数据。
  3038. * Get project overview related data.
  3039. *
  3040. * @param array $projectIdList
  3041. * @access protected
  3042. * @return array
  3043. */
  3044. protected function getProjectsStatisticData($projectIdList)
  3045. {
  3046. $vision = $this->config->vision;
  3047. /* 敏捷和瀑布相关目的统计信息。 */
  3048. $riskCountGroup = $this->loadModel('metric')->getResultByCodeWithArray('count_of_opened_risk_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3049. $issueCountGroup = $this->metric->getResultByCodeWithArray('count_of_opened_issue_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3050. if($riskCountGroup) $riskCountGroup = array_column($riskCountGroup, null, 'project');
  3051. if($issueCountGroup) $issueCountGroup = array_column($issueCountGroup, null, 'project');
  3052. $modelType = $this->block->getModelType4Projects($projectIdList);
  3053. $getScrum = in_array($modelType, array('all', 'scrum'));
  3054. $getWaterfall = in_array($modelType, array('all', 'waterfall'));
  3055. $investedGroup = array();
  3056. $consumeTaskGroup = array();
  3057. $leftTaskGroup = array();
  3058. $countStoryGroup = array();
  3059. $finishedStoryGroup = array();
  3060. $unclosedStoryGroup = array();
  3061. $countTaskGroup = array();
  3062. $waitTaskGroup = array();
  3063. $doingTaskGroup = array();
  3064. $countBugGroup = array();
  3065. $closedBugGroup = array();
  3066. $activatedBugGroup = array();
  3067. $SVGroup = array();
  3068. $PVGroup = array();
  3069. $EVGroup = array();
  3070. $CVGroup = array();
  3071. $ACGroup = array();
  3072. if($getScrum)
  3073. {
  3074. /* 敏捷项目的统计信息。 */
  3075. $investedGroup = $this->metric->getResultByCodeWithArray('day_of_invested_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3076. $consumeTaskGroup = $this->metric->getResultByCodeWithArray('consume_of_task_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3077. $leftTaskGroup = $this->metric->getResultByCodeWithArray('left_of_task_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3078. $countStoryGroup = $this->metric->getResultByCodeWithArray('scale_of_story_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3079. $finishedStoryGroup = $this->metric->getResultByCodeWithArray('count_of_finished_story_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3080. $unclosedStoryGroup = $this->metric->getResultByCodeWithArray('count_of_unclosed_story_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3081. $countTaskGroup = $this->metric->getResultByCodeWithArray('count_of_task_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3082. $waitTaskGroup = $this->metric->getResultByCodeWithArray('count_of_wait_task_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3083. $doingTaskGroup = $this->metric->getResultByCodeWithArray('count_of_doing_task_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3084. $countBugGroup = $this->metric->getResultByCodeWithArray('count_of_bug_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3085. $closedBugGroup = $this->metric->getResultByCodeWithArray('count_of_closed_bug_in_project ', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3086. $activatedBugGroup = $this->metric->getResultByCodeWithArray('count_of_activated_bug_in_project', array('project' => join(',', $projectIdList)), 'cron', null, $vision);
  3087. if($investedGroup) $investedGroup = array_column($investedGroup, null, 'project');
  3088. if($consumeTaskGroup) $consumeTaskGroup = array_column($consumeTaskGroup, null, 'project');
  3089. if($leftTaskGroup) $leftTaskGroup = array_column($leftTaskGroup, null, 'project');
  3090. if($countStoryGroup) $countStoryGroup = array_column($countStoryGroup, null, 'project');
  3091. if($finishedStoryGroup) $finishedStoryGroup = array_column($finishedStoryGroup, null, 'project');
  3092. if($unclosedStoryGroup) $unclosedStoryGroup = array_column($unclosedStoryGroup, null, 'project');
  3093. if($countTaskGroup) $countTaskGroup = array_column($countTaskGroup, null, 'project');
  3094. if($waitTaskGroup) $waitTaskGroup = array_column($waitTaskGroup, null, 'project');
  3095. if($doingTaskGroup) $doingTaskGroup = array_column($doingTaskGroup, null, 'project');
  3096. if($countBugGroup) $countBugGroup = array_column($countBugGroup, null, 'project');
  3097. if($closedBugGroup) $closedBugGroup = array_column($closedBugGroup, null, 'project');
  3098. if($activatedBugGroup) $activatedBugGroup = array_column($activatedBugGroup, null, 'project');
  3099. }
  3100. if($getWaterfall)
  3101. {
  3102. /* 瀑布项目的统计信息。 */
  3103. $SVGroup = $this->metric->getResultByCodeWithArray('sv_weekly_in_waterfall', array('project' => join(',', $projectIdList), 'week' => substr(date('oW'), -2)), 'cron', null, $vision);
  3104. $PVGroup = $this->metric->getResultByCodeWithArray('pv_of_weekly_task_in_waterfall', array('project' => join(',', $projectIdList), 'week' => substr(date('oW'), -2)), 'cron', null, $vision);
  3105. $EVGroup = $this->metric->getResultByCodeWithArray('ev_of_weekly_finished_task_in_waterfall', array('project' => join(',', $projectIdList), 'week' => substr(date('oW'), -2)), 'cron', null, $vision);
  3106. $CVGroup = $this->metric->getResultByCodeWithArray('cv_weekly_in_waterfall', array('project' => join(',', $projectIdList), 'week' => substr(date('oW'), -2)), 'cron', null, $vision);
  3107. $ACGroup = $this->metric->getResultByCodeWithArray('ac_of_weekly_all_in_waterfall', array('project' => join(',', $projectIdList), 'week' => substr(date('oW'), -2)), 'cron', null, $vision);
  3108. if($SVGroup) $SVGroup = array_column($SVGroup, null, 'project');
  3109. if($PVGroup) $PVGroup = array_column($PVGroup, null, 'project');
  3110. if($EVGroup) $EVGroup = array_column($EVGroup, null, 'project');
  3111. if($CVGroup) $CVGroup = array_column($CVGroup, null, 'project');
  3112. if($ACGroup) $ACGroup = array_column($ACGroup, null, 'project');
  3113. }
  3114. return array('riskCountGroup' => $riskCountGroup, 'issueCountGroup' => $issueCountGroup, 'investedGroup' => $investedGroup, 'consumeTaskGroup' => $consumeTaskGroup, 'leftTaskGroup' => $leftTaskGroup, 'countStoryGroup' => $countStoryGroup, 'finishedStoryGroup' => $finishedStoryGroup, 'unclosedStoryGroup' => $unclosedStoryGroup, 'countTaskGroup' => $countTaskGroup, 'waitTaskGroup' => $waitTaskGroup, 'doingTaskGroup' => $doingTaskGroup, 'countBugGroup' => $countBugGroup, 'closedBugGroup' => $closedBugGroup, 'activatedBugGroup' => $activatedBugGroup) + ($getWaterfall ? array('SVGroup' => $SVGroup, 'PVGroup' => $PVGroup, 'EVGroup' => $EVGroup, 'CVGroup' => $CVGroup, 'ACGroup' => $ACGroup) : array());
  3115. }
  3116. /**
  3117. * 构建项目统计信息。
  3118. * Build project statistic.
  3119. *
  3120. * @param object $project
  3121. * @param array $data
  3122. * @param object $pager
  3123. * @access protected
  3124. * @return object
  3125. */
  3126. protected function buildProjectStatistic($project, $data, $pager = null)
  3127. {
  3128. extract($data);
  3129. $projectID = $project->id;
  3130. if(in_array($project->model, array('scrum', 'kanban', 'agileplus')))
  3131. {
  3132. $project->executions = $this->loadModel('execution')->getStatData($projectID, 'all', 0, 0, false, '', 'id_desc', $pager);
  3133. $project->costs = isset($investedGroup[$projectID]['value']) ? $investedGroup[$projectID]['value'] : 0;
  3134. $project->consumed = isset($consumeTaskGroup[$projectID]['value']) ? $consumeTaskGroup[$projectID]['value'] : 0;
  3135. $project->remainder = isset($leftTaskGroup[$projectID]['value']) ? $leftTaskGroup[$projectID]['value'] : 0;
  3136. $project->storyPoints = isset($countStoryGroup[$projectID]['value']) ? $countStoryGroup[$projectID]['value'] : 0;
  3137. $project->done = isset($finishedStoryGroup[$projectID]['value']) ? $finishedStoryGroup[$projectID]['value'] : 0;
  3138. $project->undone = isset($unclosedStoryGroup[$projectID]['value']) ? $unclosedStoryGroup[$projectID]['value'] : 0;
  3139. $project->tasks = isset($countTaskGroup[$projectID]['value']) ? $countTaskGroup[$projectID]['value'] : 0;
  3140. $project->wait = isset($waitTaskGroup[$projectID]['value']) ? $waitTaskGroup[$projectID]['value'] : 0;
  3141. $project->doing = isset($doingTaskGroup[$projectID]['value']) ? $doingTaskGroup[$projectID]['value'] : 0;
  3142. $project->bugs = isset($countBugGroup[$projectID]['value']) ? $countBugGroup[$projectID]['value'] : 0;
  3143. $project->closed = isset($closedBugGroup[$projectID]['value']) ? $closedBugGroup[$projectID]['value'] : 0;
  3144. $project->activated = isset($activatedBugGroup[$projectID]['value']) ? $activatedBugGroup[$projectID]['value'] : 0;
  3145. }
  3146. elseif(in_array($project->model, array('waterfall', 'waterfallplus', 'ipd')))
  3147. {
  3148. $project->pv = isset($PVGroup[$projectID]['value']) ? sprintf('%.2f', $PVGroup[$projectID]['value']) : 0;
  3149. $project->ev = isset($EVGroup[$projectID]['value']) ? sprintf('%.2f', $EVGroup[$projectID]['value']) : 0;
  3150. $project->ac = isset($ACGroup[$projectID]['value']) ? sprintf('%.2f', $ACGroup[$projectID]['value']) : 0;
  3151. $project->sv = isset($SVGroup[$projectID]['value']) ? sprintf('%.4f', $SVGroup[$projectID]['value']) * 100 : 0;
  3152. $project->cv = isset($CVGroup[$projectID]['value']) ? sprintf('%.4f', $CVGroup[$projectID]['value']) * 100 : 0;
  3153. }
  3154. if($project->end != LONG_TIME) $project->remainingDays = helper::diffDate($project->end, helper::today());
  3155. $project->risks = isset($riskCountGroup[$projectID]['value']) ? (int)$riskCountGroup[$projectID]['value'] : 0;
  3156. $project->issues = isset($issueCountGroup[$projectID]['value']) ? (int)$issueCountGroup[$projectID]['value'] : 0;
  3157. return $project;
  3158. }
  3159. }