zen.php 4.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. class projectreleaseZen extends projectrelease
  3. {
  4. /**
  5. * 获取当前项目的所有产品,当前产品,分支,项目
  6. * Get products of the project and current product, branch, project.
  7. *
  8. * @param int $projectID
  9. * @param int $productID
  10. * @param string $branch
  11. * @access public
  12. * @return void
  13. */
  14. protected function commonAction($projectID = 0, $productID = 0, $branch = '')
  15. {
  16. /* 获取当前项目的所有产品。*/
  17. /* Get product list by project. */
  18. $this->products = $this->product->getProductPairsByProject($projectID);
  19. if(empty($this->products)) $this->locate($this->createLink('product', 'showErrorNone', 'moduleName=project&activeMenu=projectrelease&projectID=' . $projectID));
  20. /* 获取当前的产品。*/
  21. /* Get current product. */
  22. if(!$productID) $productID = key($this->products);
  23. $this->loadModel('product')->checkAccess($productID, $this->products);
  24. $product = $this->product->getByID($productID);
  25. $this->view->products = $this->products;
  26. $this->view->product = $product;
  27. $this->view->branches = (isset($product->type) and $product->type == 'normal') ? array() : $this->loadModel('branch')->getPairs($productID, 'active', $projectID);
  28. $this->view->branch = $branch;
  29. $this->view->project = $this->project->getByID($projectID);
  30. $this->view->appList = $this->loadModel('system')->getList($productID);
  31. }
  32. /**
  33. * 构造项目发布数据。
  34. * Construct project release data.
  35. *
  36. * @param int $projectID
  37. * @access protected
  38. * @return void
  39. */
  40. protected function buildReleaseForCreate($projectID)
  41. {
  42. $this->lang->projectrelease->system = $this->lang->release->system;
  43. if(!$this->post->newSystem && !$this->post->system) $this->config->release->form->create['system']['required'] = true;
  44. if($this->post->newSystem && !$this->post->systemName)
  45. {
  46. $this->config->release->form->create['systemName'] = array('type' => 'string', 'required' => true, 'filter' => 'trim');
  47. $this->lang->projectrelease->systemName = $this->lang->release->system;
  48. }
  49. $release = form::data($this->config->release->form->create)
  50. ->add('product', $this->post->product ? $this->post->product : 0)
  51. ->add('branch', $this->post->branch ? $this->post->branch : 0)
  52. ->setIF($projectID, 'project', $projectID)
  53. ->setIF($this->post->build === false, 'build', 0)
  54. ->setIF($this->post->status != 'normal', 'releasedDate', null)
  55. ->get();
  56. /* Check build if build is required. */
  57. if(strpos($this->config->release->create->requiredFields, 'build') !== false && empty($release->build)) dao::$errors['build'] = sprintf($this->lang->error->notempty, $this->lang->release->build);
  58. if(!$this->post->newSystem && $this->post->system)
  59. {
  60. $system = $this->loadModel('system')->fetchByID((int)$this->post->system);
  61. if(!$system) dao::$errors['system'][] = sprintf($this->lang->error->notempty, $this->lang->release->system);
  62. if($system->integrated == '1')
  63. {
  64. $releases = (array)$this->post->releases;
  65. $release->build = '';
  66. $release->releases = trim(implode(',', array_filter($releases)), ',');
  67. if(!$release->releases) dao::$errors['releases[' . key($releases) . ']'][] = sprintf($this->lang->error->notempty, $this->lang->release->name);
  68. }
  69. }
  70. if(dao::isError()) return false;
  71. if($this->post->newSystem && $this->post->systemName && $this->post->product)
  72. {
  73. $system = new stdclass();
  74. $system->name = trim($this->post->systemName);
  75. $system->product = $this->post->product;
  76. $system->createdBy = $this->app->user->account;
  77. $system->createdDate = helper::now();
  78. $release->system = $this->loadModel('system')->create($system);
  79. }
  80. return $release;
  81. }
  82. }