zentaomax.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815
  1. <?php
  2. /**
  3. * Assign a doc.
  4. *
  5. * @param int $docID
  6. * @access public
  7. * @return array|bool
  8. */
  9. public function assign($docID)
  10. {
  11. $oldDoc = $this->getByID($docID);
  12. $now = helper::now();
  13. $doc = fixer::input('post')
  14. ->add('editedBy', $this->app->user->account)
  15. ->add('editedDate', $now)
  16. ->add('assignedDate', $now)
  17. ->stripTags($this->config->doc->editor->assignto['id'], $this->config->allowedTags)
  18. ->remove('uid,comment,files,label')
  19. ->get();
  20. $this->dao->update(TABLE_DOC)->data($doc)->autoCheck()->where('id')->eq((int)$docID)->exec();
  21. if(!dao::isError()) return common::createChanges($oldDoc, $doc);
  22. return false;
  23. }
  24. /**
  25. * Get doc list.
  26. *
  27. * @param int|array|string $docList
  28. * @access public
  29. * @return array
  30. */
  31. public function getByList($docList = 0)
  32. {
  33. return $this->dao->select('*')->from(TABLE_DOC)
  34. ->where('deleted')->eq(0)
  35. ->beginIF($docList)->andWhere('id')->in($docList)->fi()
  36. ->fetchAll('id');
  37. }
  38. /**
  39. * Get node list.
  40. *
  41. * @param int $bookID
  42. * @access public
  43. * @return array
  44. */
  45. public function getNodeList($bookID)
  46. {
  47. $stmt = $this->dbh->query($this->dao->select('id, lib, type, chapterType, template, path, `order`, parent, grade, title')->from(TABLE_DOC)->where('template')->eq($bookID)->andWhere('deleted')->eq(0)->orderBy('grade_desc,`order`, id')->get());
  48. $parent = array();
  49. while($node = $stmt->fetch())
  50. {
  51. if(!isset($parent)) $parent = array();
  52. if(isset($parent[$node->id]))
  53. {
  54. $node->children = $parent[$node->id]->children;
  55. unset($parent[$node->id]);
  56. }
  57. if(!isset($parent[$node->parent])) $parent[$node->parent] = new stdclass();
  58. $parent[$node->parent]->children[] = $node;
  59. }
  60. $nodeList = array();
  61. foreach($parent as $node)
  62. {
  63. foreach($node->children as $children)
  64. {
  65. if($children->parent != 0 && !empty($nodeList))
  66. {
  67. foreach($nodeList as $firstChildren)
  68. {
  69. if($firstChildren->id == $children->parent) $firstChildren->children[] = $children;
  70. }
  71. }
  72. $nodeList[] = $children;
  73. }
  74. }
  75. return $nodeList;
  76. }
  77. /**
  78. * Sync book.
  79. *
  80. * @param int $templateID
  81. * @param int $docID
  82. * @param string $templateType
  83. * @access public
  84. * @return void
  85. */
  86. public function syncBook($templateID, $docID, $templateType)
  87. {
  88. $doc = $this->getByID($docID);
  89. $catalogs = $this->dao->select('*')->from(TABLE_DOC)->where('template')->eq($templateID)->andWhere('deleted')->eq(0)->fetchAll();
  90. $pairs = array();
  91. $pairs[$templateID] = $docID;
  92. foreach($catalogs as $catalog)
  93. {
  94. $oldID = $catalog->id;
  95. $catalog->template = $docID;
  96. unset($catalog->id);
  97. $this->dao->insert(TABLE_DOC)->data($catalog)->exec();
  98. $newID = $this->dao->lastInsertID();
  99. $this->dao->update(TABLE_DOC)->set('path')->eq(",$newID,")->where('id')->eq($newID)->exec();
  100. $pairs[$oldID] = $newID;
  101. $content = $this->dao->select('*')->from(TABLE_DOCCONTENT)->where('doc')->eq($oldID)->fetch();
  102. unset($content->id);
  103. $content->doc = $newID;
  104. $this->dao->insert(TABLE_DOCCONTENT)->data($content)->exec();
  105. }
  106. foreach($pairs as $oldID => $newID) $this->dao->update(TABLE_DOC)->set('parent')->eq($newID)->where('parent')->eq($oldID)->andWhere('template')->eq($docID)->exec();
  107. /* Compute path and parent. */
  108. $newCatalog = $this->dao->select('*')->from(TABLE_DOC)
  109. ->where('template')->eq($docID)
  110. ->andWhere('grade')->ge(1)
  111. ->fetchAll();
  112. foreach($newCatalog as $catalog) $this->computePath($catalog->id, $catalog->parent, $catalog->path, TABLE_DOC, $catalog->grade);
  113. }
  114. /**
  115. * Sync doc module.
  116. *
  117. * @param int $docLibID
  118. * @access public
  119. * @return void
  120. */
  121. public function syncDocModule($docLibID)
  122. {
  123. $catalog = $this->dao->select('*')->from(TABLE_MODULE)
  124. ->where('root')->eq(0)
  125. ->andWhere('type')->eq('doc')
  126. ->orderBy('grade_asc')
  127. ->fetchAll();
  128. /* Cpoy module and mark new id. */
  129. $pairs = array();
  130. foreach($catalog as $module)
  131. {
  132. $oldID = $module->id;
  133. $module->root = $docLibID;
  134. unset($module->id);
  135. unset($module->path);
  136. $this->dao->insert(TABLE_MODULE)->data($module)->exec();
  137. $newID = $this->dao->lastInsertID();
  138. $this->dao->update(TABLE_MODULE)->set('path')->eq(",$newID,")->where('id')->eq($newID)->exec();
  139. $pairs[$oldID] = $newID;
  140. }
  141. foreach($pairs as $oldID => $newID) $this->dao->update(TABLE_MODULE)->set('parent')->eq($newID)->where('parent')->eq($oldID)->andWhere('id')->in(array_values($pairs))->exec();
  142. /* Compute path and parent. */
  143. $newCatalog = $this->dao->select('*')->from(TABLE_MODULE)
  144. ->where('root')->eq($docLibID)
  145. ->andWhere('type')->eq('doc')
  146. ->andWhere('parent')->ne(0)
  147. ->fetchAll();
  148. foreach($newCatalog as $module) $this->computePath($module->id, $module->parent, $module->path, TABLE_MODULE, $module->grade);
  149. }
  150. /**
  151. * Compute path.
  152. *
  153. * @param int $moduleID
  154. * @param int $parentID
  155. * @param string $path
  156. * @param string $table
  157. * @param int $grade
  158. * @access public
  159. * @return void
  160. */
  161. public function computePath($moduleID, $parentID, $path = '', $table = TABLE_MODULE, $grade = 1)
  162. {
  163. if($grade == 1)
  164. {
  165. $this->dao->update($table)->set('path')->eq($path)->where('id')->eq($moduleID)->exec();
  166. return true;
  167. }
  168. $parent = $this->dao->select('*')->from($table)->where('id')->eq($parentID)->fetch();
  169. $path = ',' . $parent->id . $path;
  170. $this->computePath($moduleID, $parent->parent, $path, $table, $parent->grade);
  171. }
  172. /**
  173. * Get doc structure.
  174. *
  175. * @param int $bookID
  176. * @param string $serial
  177. * @param object $object
  178. * @access public
  179. * @return string
  180. */
  181. public function getCmStructure($bookID, $serial, $object)
  182. {
  183. $structure = '';
  184. $data = json_decode($object->data);
  185. $objectCategory = $this->dao->select('category')->from(TABLE_DELIVERABLE)->where('id')->eq($object->category)->fetch('category');
  186. $objectCategory = $objectCategory ?: $object->category;
  187. if(in_array($objectCategory, array('SRS', 'URS', 'ERS')))
  188. {
  189. $stories = isset($data->story) ? (array)$data->story : array();
  190. if(empty($stories)) return '';
  191. foreach($stories as $id => $story) $story->id = $id;
  192. $moduleIdList = helper::arrayColumn($stories, 'module');
  193. $modules = $this->dao->select('*')->from(TABLE_MODULE)
  194. ->where('root')->eq($object->product)
  195. ->andWhere('id')->in($moduleIdList)
  196. ->andWhere('type')->eq('story')
  197. ->andWhere('deleted')->eq(0)
  198. ->orderBy('`order` asc')
  199. ->fetchAll();
  200. /* Get all path in modules. */
  201. $pathModules = array();
  202. foreach($modules as $module)
  203. {
  204. if($module->grade == 1)
  205. {
  206. $pathModules[$module->id] = $module->id;
  207. }
  208. else
  209. {
  210. $moduleBases = explode(',', trim($module->path, ','));
  211. $pathModules += array_combine($moduleBases, $moduleBases);
  212. }
  213. }
  214. $modules = $this->dao->select('*')->from(TABLE_MODULE)
  215. ->where('root')->eq($object->product)
  216. ->andWhere('id')->in($pathModules)
  217. ->andWhere('type')->eq('story')
  218. ->andWhere('grade')->eq('1')
  219. ->andWhere('deleted')->eq(0)
  220. ->orderBy('`order` asc')
  221. ->fetchAll();
  222. $serials = $this->computeModuleSN($object->product, $serial, array_keys($stories));
  223. $structure .= '<ul>';
  224. foreach($stories as $id => $story)
  225. {
  226. if($story->module == 0)
  227. {
  228. $structure .= "<li class='story'><span class='item' title='{$story->title}'>" . zget($serials, "s$story->id", '') . ' ' . html::a(helper::createLink('story', 'storyView', "objectID=$story->id&version=$story->version&param=$object->project") . "#app={$this->app->tab}", $story->title) . "</li>";
  229. unset($stories[$id]);
  230. }
  231. }
  232. $structure .= '</ul>';
  233. $structure .= $this->getStoryStructure((array)$stories, $modules, $object, $serials, $pathModules);
  234. }
  235. elseif(in_array($objectCategory, array('HLDS', 'DDS', 'DBDS', 'ADS')))
  236. {
  237. $designs = (array)$data->design;
  238. if(empty($designs)) return;
  239. $structure .= '<ul>';
  240. foreach($designs as $id => $design)
  241. {
  242. if(empty($id)) continue;
  243. $structure .= "<li class='design' data-id={$id}><span class='item' title='{$design->name}'>" . html::a(helper::createLink('design', 'view', "id=$id"), "#$id" . ':' . $design->name, '', "data-toggle='modal' data-size='lg'") . "</span></li>";
  244. }
  245. $structure .= '</ul>';
  246. }
  247. elseif(in_array($objectCategory, array('ITTC', 'STTC', 'intergrate', 'system')))
  248. {
  249. $cases = (array)$data->case;
  250. if(empty($cases)) return;
  251. $moduleIdList = helper::arrayColumn($cases, 'module');
  252. $modules = $this->dao->select('*')->from(TABLE_MODULE)
  253. ->where('root')->eq($object->product)
  254. ->andWhere('type')->in('story,case')
  255. ->andWhere('id')->in($moduleIdList)
  256. ->andWhere('deleted')->eq(0)
  257. ->orderBy('`order` asc')
  258. ->fetchAll();
  259. /* Get all path in modules. */
  260. $pathModules = array();
  261. foreach($modules as $module)
  262. {
  263. if($module->grade == 1)
  264. {
  265. $pathModules[$module->id] = $module->id;
  266. }
  267. else
  268. {
  269. $moduleBases = explode(',', trim($module->path, ','));
  270. $pathModules += array_combine($moduleBases, $moduleBases);
  271. }
  272. }
  273. $modules = $this->dao->select('*')->from(TABLE_MODULE)
  274. ->where('root')->eq($object->product)
  275. ->andWhere('id')->in($pathModules)
  276. ->andWhere('type')->in('story,case')
  277. ->andWhere('grade')->eq('1')
  278. ->andWhere('deleted')->eq(0)
  279. ->orderBy('`order` asc')
  280. ->fetchAll();
  281. $structure .= '<ul>';
  282. foreach($cases as $id => $case)
  283. {
  284. if($case->module == 0)
  285. {
  286. $structure .= "<li class='case' data-id={$id}><span class='item' title='{$case->title}'>" . html::a(helper::createLink('testcase', 'view', "caseID=$id"), "#$id" . ':' . $case->title, '', "data-toggle='modal' data-size='lg'") . "</span></li>";
  287. unset($cases->$id);
  288. }
  289. }
  290. $structure .= '</ul>';
  291. $structure .= $this->getCaseStructure($modules, $cases, $pathModules);
  292. }
  293. return $structure;
  294. }
  295. /**
  296. * Get story structure.
  297. *
  298. * @param array $stories
  299. * @param object $modules
  300. * @param object $book
  301. * @param string $serials
  302. * @param array $moduleIDList
  303. * @access public
  304. * @return string
  305. */
  306. public function getStoryStructure($stories, $modules, $book, $serials, $moduleIDList)
  307. {
  308. $html = '';
  309. $html .= '<ul class="object">';
  310. foreach($modules as $module)
  311. {
  312. if(!in_array($module->id, $moduleIDList)) continue;
  313. $html .= "<li class='module'>" . "<span class='item'>" . $serials[$module->id] . '</span> ' . $module->name;
  314. $html .= '<ul>';
  315. foreach($stories as $id => $story)
  316. {
  317. if($story->module == $module->id)
  318. {
  319. $html .= "<li class='story' data-id={$story->id}>" . "<span class='item'>" . zget($serials, "s$story->id", '') . ' ' . html::a(helper::createLink('story', 'storyView', "objectID=$story->id&version=$story->version&param={$this->session->project}") . "#app={$this->app->tab}", $story->title) . '</span>' . "</li>";
  320. unset($stories[$id]);
  321. }
  322. }
  323. $html .= '</ul>';
  324. $childModules = $this->getChildModules($module->id);
  325. if($childModules) $html .= $this->getStoryStructure($stories, $childModules, $book, $serials, $moduleIDList);
  326. $html .= '</li>';
  327. }
  328. $html .= '</ul>';
  329. return $html;
  330. }
  331. /**
  332. * Get design structure.
  333. *
  334. * @param object $book
  335. * @param string $serial
  336. * @access public
  337. * @return string
  338. */
  339. public function getDesignStructure($book, $serial)
  340. {
  341. $designs = $this->dao->select('*')->from(TABLE_DESIGN)
  342. ->where('deleted')->eq(0)
  343. ->andWhere('product')->eq($book->product)
  344. ->andWhere('type')->eq($book->templateType)
  345. ->fetchAll('id');
  346. $i = 1;
  347. $structure = '';
  348. $structure .= '<ul class="object">';
  349. foreach($designs as $id => $design)
  350. {
  351. $structure .= "<li class='design' data-id={$design->id}>" . "<span class='item'>" . $serial . '.' . $i . ' ' . html::a(helper::createLink('design', 'view', "objectID=$design->id"), $design->name, '', "data-toggle='modal' data-size='lg'") . "</span></li>";
  352. $i ++;
  353. }
  354. $structure .= '</ul>';
  355. return $structure;
  356. }
  357. /**
  358. * Get case structure.
  359. *
  360. * @param object $modules
  361. * @param object $cases
  362. * @param array $moduleIDList
  363. * @access public
  364. * @return string
  365. */
  366. public function getCaseStructure($modules, $cases, $moduleIDList)
  367. {
  368. $tree = '';
  369. $tree .= '<ul>';
  370. foreach($modules as $module)
  371. {
  372. if(!in_array($module->id, $moduleIDList)) continue;
  373. $tree .= "<li class='module'>" . $module->name;
  374. $tree .= '<ul>';
  375. foreach($cases as $id => $case)
  376. {
  377. if($case->module == $module->id)
  378. {
  379. $tree .= "<li class='case' data-id={$case->id}><span class='item' title='{$case->title}'>" . html::a(helper::createLink('testcase', 'view', "caseID=$id"), "#$id" . ':' . $case->title, '', "data-toggle='modal' data-size='lg'") . "</span></li>";
  380. unset($cases->$id);
  381. }
  382. }
  383. $tree .= '</ul>';
  384. $childModules = $this->getChildModules($module->id);
  385. if($childModules) $tree .= $this->getCaseStructure($childModules, $cases, $moduleIDList);
  386. $tree .= '</li>';
  387. }
  388. $tree .= '</ul>';
  389. return $tree;
  390. }
  391. /**
  392. * Compute module SN.
  393. *
  394. * @param int $productID
  395. * @param string $parentSerial
  396. * @param array $storyIdList
  397. * @access public
  398. * @return array
  399. */
  400. public function computeModuleSN($productID, $parentSerial, $storyIdList = array())
  401. {
  402. /* Get all children of the startNode. */
  403. $modules = $this->dao->select('id, parent, `order`, path')->from(TABLE_MODULE)
  404. ->where('root')->eq($productID)
  405. ->andWhere('deleted')->eq(0)
  406. ->andWhere('type')->eq('story')
  407. ->orderBy('grade, `order`, id')
  408. ->fetchAll('id');
  409. $stories = $this->dao->select('id, module')->from(TABLE_STORY)
  410. ->where('product')->eq($productID)
  411. ->andWhere('type')->eq('story')
  412. ->beginIF(!empty($storyIdList))->andWhere('id')->in($storyIdList)->fi()
  413. ->orderBy('id_desc')
  414. ->fetchAll('id');
  415. /* Push story to module array. */
  416. foreach($modules as $moduleID => $module)
  417. {
  418. foreach($stories as $storyID => $story)
  419. {
  420. $array = array();
  421. $data = new stdclass();
  422. $key = 's' . $storyID;
  423. $data->id = $key;
  424. if($story->module == 0)
  425. {
  426. $data->parent = 0;
  427. $data->path = ',' . $key . ',';
  428. $array[$key] = $data;
  429. $modules = $array + $modules;
  430. continue;
  431. }
  432. if($story->module == $moduleID)
  433. {
  434. $data->parent = $moduleID;
  435. $data->path = $module->path . $key . ',';
  436. $array[$key] = $data;
  437. $modules = $array + $modules;
  438. }
  439. }
  440. }
  441. /* Group them by their parent. */
  442. $groupedModules = array();
  443. foreach($modules as $module) $groupedModules[$module->parent][$module->id] = $module;
  444. $serials = array();
  445. foreach($modules as $module)
  446. {
  447. $path = explode(',', $module->path);
  448. $serial = '';
  449. foreach($path as $moduleID)
  450. {
  451. if(!$moduleID) continue;
  452. /* Compute the serial. */
  453. if(isset($modules[$moduleID]))
  454. {
  455. $parentID = $modules[$moduleID]->parent;
  456. $brothers = $groupedModules[$parentID];
  457. $serial .= array_search($moduleID, array_keys($brothers)) + 1 . '.';
  458. }
  459. }
  460. $serials[$module->id] = $parentSerial . '.' . rtrim($serial, '.');
  461. }
  462. return $serials;
  463. }
  464. /**
  465. * Import doc to asset lib.
  466. *
  467. * @param array $docIdList
  468. * @param string $assetType
  469. * @access public
  470. * @return bool
  471. */
  472. public function importToLib($docIdList = array(), $assetType = 'practice')
  473. {
  474. $data = fixer::input('post')->get();
  475. if(empty($data->lib))
  476. {
  477. $libName = $assetType == 'practice' ? $this->lang->doc->practiceLib : $this->lang->doc->componentLib;
  478. dao::$errors['lib'] = sprintf($this->lang->error->notempty, $libName);
  479. return false;
  480. }
  481. $docs = $this->getByIdList($docIdList);
  482. $importedDocs = $this->dao->select('`from`,`fromVersion`')->from(TABLE_DOC)
  483. ->where('assetlib')->eq($data->lib)
  484. ->andWhere('`from`')->in($docIdList)
  485. ->fetchGroup('from');
  486. if(is_numeric($docIdList) and isset($importedDocs[$docIdList]))
  487. {
  488. dao::$errors['message'] = $assetType == 'practice' ? $this->lang->doc->isExistPracticeLib : $this->lang->doc->isExistComponentLib;
  489. return false;
  490. }
  491. /* Remove duplicate doc and save file id list. */
  492. $fileIDList = array();
  493. foreach($docs as $doc)
  494. {
  495. $fileIDList = array_merge($fileIDList, explode(',', $doc->files));
  496. if(isset($importedDocs[$doc->docID]))
  497. {
  498. foreach($importedDocs[$doc->docID] as $improtedDoc)
  499. {
  500. if($improtedDoc->fromVersion == $doc->version) unset($docs[$doc->docID]);
  501. }
  502. }
  503. }
  504. $fileIDList = array_unique($fileIDList);
  505. $files = $this->dao->select('*')->from(TABLE_FILE)->where('id')->in($fileIDList)->andWhere('deleted')->eq(0)->fetchAll('id');
  506. $now = helper::now();
  507. $hasApprovePiv = false;
  508. if($assetType == 'practice' and (common::hasPriv('assetlib', 'approvePractice') or common::hasPriv('assetlib', 'batchApprovePractice'))) $hasApprovePiv = true;
  509. if($assetType == 'component' and (common::hasPriv('assetlib', 'approveComponent') or common::hasPriv('assetlib', 'batchApproveComponent'))) $hasApprovePiv = true;
  510. $this->loadModel('action');
  511. /* Create doc to asset lib. */
  512. $now = helper::now();
  513. $this->loadModel('action');
  514. foreach($docs as $doc)
  515. {
  516. $assetDoc = new stdclass();
  517. $assetDoc->title = $doc->title;
  518. $assetDoc->keywords = $doc->keywords;
  519. $assetDoc->type = $doc->docType;
  520. $assetDoc->lib = 0;
  521. $assetDoc->version = 1;
  522. $assetDoc->acl = 'open';
  523. $assetDoc->status = $hasApprovePiv ? 'active' : 'draft';
  524. $assetDoc->assetLib = $data->lib;
  525. $assetDoc->assetLibType = $assetType;
  526. $assetDoc->from = $doc->docID;
  527. $assetDoc->fromVersion = $doc->version;
  528. $assetDoc->addedBy = $this->app->user->account;
  529. $assetDoc->addedDate = $now;
  530. if(!empty($data->assignedTo)) $assetDoc->assignedTo = $data->assignedTo;
  531. if($hasApprovePiv)
  532. {
  533. $assetDoc->assignedTo = $this->app->user->account;
  534. $assetDoc->approvedDate = $now;
  535. }
  536. $this->dao->insert(TABLE_DOC)->data($assetDoc)->exec();
  537. $assetDocID = $this->dao->lastInsertID();
  538. if(!dao::isError())
  539. {
  540. /* Copy file info. */
  541. $docFiles = explode(',', $doc->files);
  542. $newFiles = '';
  543. foreach($docFiles as $fileID)
  544. {
  545. if(isset($files[$fileID]))
  546. {
  547. $file = $files[$fileID];
  548. unset($file->id);
  549. $file->objectID = $assetDocID;
  550. $file->addedBy = $this->app->user->account;
  551. $file->addedDate = $now;
  552. $file->downloads = 0;
  553. $this->dao->insert(TABLE_FILE)->data($file)->exec();
  554. $copyFileID = $this->dao->lastInsertID();
  555. $newFiles = empty($newFiles) ? $copyFileID : "$newFiles,$copyFileID";
  556. }
  557. }
  558. $content = new stdclass();
  559. $content->doc = $assetDocID;
  560. $content->title = $doc->title;
  561. $content->digest = $doc->digest;
  562. $content->content = $doc->content;
  563. $content->files = $newFiles;
  564. $content->type = $doc->contentType;
  565. $content->version = 1;
  566. $this->dao->insert(TABLE_DOCCONTENT)->data($content)->exec();
  567. $action = $assetType == 'practice' ? 'import2PracticeLib' : 'import2ComponentLib';
  568. $this->action->create('doc', $assetDocID, $action);
  569. }
  570. }
  571. return true;
  572. }
  573. /**
  574. * Get template content by doc id.
  575. *
  576. * @param int $id
  577. * @access public
  578. * @return int
  579. */
  580. public function getTemplateContentByID($id)
  581. {
  582. return $this->dao->select('*')->from(TABLE_DOCCONTENT)->where('doc')->eq($id)->orderBy('version_desc')->fetch();
  583. }
  584. /**
  585. * @param int $templateID
  586. * @param int $docID
  587. */
  588. public function getTemplateContent($templateID, $docID = 0)
  589. {
  590. return $this->loadExtension('zentaomax')->getTemplateContent($templateID, $docID);
  591. }
  592. public function getProductStoryTableCols()
  593. {
  594. return $this->loadExtension('zentaomax')->getProductStoryTableCols();
  595. }
  596. /**
  597. * @param mixed[] $product
  598. * @param string $searchTab
  599. */
  600. public function getProductStoryTableData($product, $searchTab)
  601. {
  602. return $this->loadExtension('zentaomax')->getProductStoryTableData($product, $searchTab);
  603. }
  604. public function getProjectStoryTableCols()
  605. {
  606. return $this->loadExtension('zentaomax')->getProductStoryTableCols();
  607. }
  608. /**
  609. * @param mixed[] $project
  610. * @param mixed[] $product
  611. * @param string $searchTab
  612. */
  613. public function getProjectStoryTableData($project, $product, $searchTab)
  614. {
  615. return $this->loadExtension('zentaomax')->getProjectStoryTableData($project, $product, $searchTab);
  616. }
  617. public function getExecutionStoryTableCols()
  618. {
  619. return $this->loadExtension('zentaomax')->getExecutionStoryTableCols();
  620. }
  621. /**
  622. * @param mixed[] $execution
  623. * @param string $searchTab
  624. */
  625. public function getExecutionStoryTableData($execution, $searchTab)
  626. {
  627. return $this->loadExtension('zentaomax')->getExecutionStoryTableData($execution, $searchTab);
  628. }
  629. public function getTaskTableCols()
  630. {
  631. return $this->loadExtension('zentaomax')->getTaskTableCols();
  632. }
  633. /**
  634. * @param mixed[] $execution
  635. * @param string $searchTab
  636. */
  637. public function getTaskTableData($execution, $searchTab)
  638. {
  639. return $this->loadExtension('zentaomax')->getTaskTableData($execution, $searchTab);
  640. }
  641. public function getBugTableCols()
  642. {
  643. return $this->loadExtension('zentaomax')->getBugTableCols();
  644. }
  645. /**
  646. * @param mixed[] $product
  647. * @param string $searchTab
  648. * @param int $projectID
  649. * @param mixed[] $execution
  650. */
  651. public function getBugTableData($product, $searchTab, $projectID = 0, $execution = array())
  652. {
  653. return $this->loadExtension('zentaomax')->getBugTableData($product, $searchTab, $projectID, $execution);
  654. }
  655. public function getProductCaseTableCols()
  656. {
  657. return $this->loadExtension('zentaomax')->getProductCaseTableCols();
  658. }
  659. public function getProjectCaseTableCols()
  660. {
  661. return $this->loadExtension('zentaomax')->getProductCaseTableCols();
  662. }
  663. /**
  664. * @param mixed[] $product
  665. * @param string $searchTab
  666. * @param string $caseStage
  667. */
  668. public function getProductCaseTableData($product, $searchTab, $caseStage = '')
  669. {
  670. if(empty(array_filter($product))) return array('result' => 'fail', 'message' => array('product' => sprintf($this->lang->error->notempty, $this->lang->doc->selectProduct)));
  671. return $this->loadExtension('zentaomax')->getProductCaseTableData($product, $searchTab, $caseStage);
  672. }
  673. /**
  674. * @param mixed[] $project
  675. * @param mixed[] $product
  676. * @param string $searchTab
  677. * @param string $caseStage
  678. */
  679. public function getProjectCaseTableData($project, $product, $searchTab, $caseStage = '')
  680. {
  681. if(empty(array_filter($project))) return array('result' => 'fail', 'message' => array('project' => sprintf($this->lang->error->notempty, $this->lang->doc->selectProject)));
  682. return $this->loadExtension('zentaomax')->getProductCaseTableData($product, $searchTab, $caseStage, $project);
  683. }
  684. public function getDesignTableCols()
  685. {
  686. return $this->loadExtension('zentaomax')->getDesignTableCols();
  687. }
  688. /**
  689. * @param mixed[] $project
  690. * @param mixed[] $product
  691. * @param string $type
  692. */
  693. public function getDesignTableData($project, $product, $type)
  694. {
  695. return $this->loadExtension('zentaomax')->getDesignTableData($project, $product, $type);
  696. }
  697. /**
  698. * @param int $project
  699. */
  700. public function getGanttData($project)
  701. {
  702. return $this->loadExtension('zentaomax')->getGanttData($project);
  703. }
  704. public function getGanttFields()
  705. {
  706. return $this->loadExtension('zentaomax')->getGanttFields();
  707. }
  708. /**
  709. * @param string $objectType
  710. * @param int $objectID
  711. */
  712. public function getMainLibByObject($objectType, $objectID)
  713. {
  714. return $this->loadExtension('zentaomax')->getMainLibByObject($objectType, $objectID);
  715. }