ipd.php 3.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. <?php
  2. /**
  3. * Get libs by object.
  4. *
  5. * @param string $type
  6. * @param int $objectID
  7. * @param int $appendLib
  8. * @access public
  9. * @return array
  10. * @param int $limit
  11. */
  12. public function getLibsByObject($type, $objectID = 0, $appendLib = 0, $limit = 0)
  13. {
  14. if($type == 'custom' or $type == 'mine')
  15. {
  16. $objectLibs = $this->dao->select('*')->from(TABLE_DOCLIB)
  17. ->where('deleted')->eq(0)
  18. ->andWhere('vision')->eq($this->config->vision)
  19. ->andWhere('type')->eq($type)
  20. ->andWhere('parent')->eq($objectID)
  21. ->beginIF(!empty($appendLib))->orWhere('id')->eq($appendLib)->fi()
  22. ->beginIF($type == 'mine')->andWhere('addedBy')->eq($this->app->user->account)->fi()
  23. ->orderBy('`order` asc, id_asc')
  24. ->limit($limit)
  25. ->fetchAll('id');
  26. }
  27. elseif($type != 'product' and $type != 'project' and $type != 'execution')
  28. {
  29. return array();
  30. }
  31. else
  32. {
  33. $executionIDList = array();
  34. if($type == 'project') $executionIDList = $this->loadModel('execution')->getPairs($objectID, 'all', 'multiple,leaf');
  35. $objectLibs = $this->dao->select('*')->from(TABLE_DOCLIB)
  36. ->where('deleted')->eq(0)
  37. ->beginIF($type != 'product' or $this->config->vision != 'or')->andWhere('vision')->eq($this->config->vision)->fi()
  38. ->andWhere($type)->eq($objectID)
  39. ->beginIF($type == 'project')->andWhere('type')->in('api,project')->fi()
  40. ->beginIF(!empty($appendLib))->orWhere('id')->eq($appendLib)->fi()
  41. ->orderBy('`order` asc, id_asc')
  42. ->limit($limit)
  43. ->fetchAll('id');
  44. if($executionIDList)
  45. {
  46. $objectLibs += $this->dao->select('*')->from(TABLE_DOCLIB)
  47. ->where('deleted')->eq(0)
  48. ->andWhere('vision')->eq($this->config->vision)
  49. ->andWhere('execution')->in(array_keys($executionIDList))
  50. ->andWhere('type')->eq('execution')
  51. ->beginIF(!empty($appendLib))->orWhere('id')->eq($appendLib)->fi()
  52. ->orderBy('`order` asc, id_asc')
  53. ->limit($limit)
  54. ->fetchAll('id');
  55. }
  56. }
  57. /*
  58. if($type == 'product')
  59. {
  60. $hasProject = $this->dao->select('DISTINCT t1.product, count(t1.project) as projectCount')->from(TABLE_PROJECTPRODUCT)->alias('t1')
  61. ->leftJoin(TABLE_EXECUTION)->alias('t2')->on('t1.project=t2.id')
  62. ->where('t1.product')->eq($objectID)
  63. ->beginIF(strpos($this->config->doc->custom->showLibs, 'unclosed') !== false)->andWhere('t2.status')->notin('done,closed')->fi()
  64. ->andWhere('t2.deleted')->eq(0)
  65. ->groupBy('product')
  66. ->fetchPairs('product', 'projectCount');
  67. }
  68. */
  69. $libs = array();
  70. foreach($objectLibs as $lib)
  71. {
  72. if($this->checkPrivLib($lib)) $libs[$lib->id] = $lib;
  73. }
  74. $itemCounts = $this->statLibCounts(array_keys($libs));
  75. foreach($libs as $libID => $lib) $libs[$libID]->allCount = $itemCounts[$libID];
  76. return $libs;
  77. }