PageRenderTime 50ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 1ms

/application/models/projects/Project.class.php

https://github.com/fb83/Project-Pier
PHP | 2123 lines | 853 code | 213 blank | 1057 comment | 140 complexity | 673ee87f09284eb270612b436d6fdb04 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, AGPL-3.0, LGPL-2.1, GPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. <?php
  2. /**
  3. * Project class
  4. *
  5. * @http://www.projectpier.org/
  6. */
  7. class Project extends BaseProject {
  8. // ---------------------------------------------------
  9. // Page Attachments
  10. // ---------------------------------------------------
  11. /** Cache of all page attachments
  12. *
  13. * @var array
  14. */
  15. private $all_page_attachments;
  16. /**
  17. * This object is taggable
  18. *
  19. * @var boolean
  20. */
  21. protected $is_taggable = true;
  22. // ---------------------------------------------------
  23. // Projects
  24. // ---------------------------------------------------
  25. /**
  26. * Cache of all subprojects
  27. *
  28. * @var array
  29. */
  30. private $all_subprojects;
  31. /**
  32. * Cached array of subprojects that user can access. If user is member of owner company
  33. * $all_subprojects will be used (members of owner company can browse all subprojects)
  34. *
  35. * @var array
  36. */
  37. private $subprojects;
  38. // ---------------------------------------------------
  39. // Messages
  40. // ---------------------------------------------------
  41. /**
  42. * Cache of all messages
  43. *
  44. * @var array
  45. */
  46. private $all_messages;
  47. /**
  48. * Cached array of messages that user can access. If user is member of owner company
  49. * $all_messages will be used (members of owner company can browse all messages)
  50. *
  51. * @var array
  52. */
  53. private $messages;
  54. /**
  55. * Array of all important messages (including private ones)
  56. *
  57. * @var array
  58. */
  59. private $all_important_messages;
  60. /**
  61. * Array of important messages. If user is not member of owner company private
  62. * messages will be skipped
  63. *
  64. * @var array
  65. */
  66. private $important_messages;
  67. // ---------------------------------------------------
  68. // Milestones
  69. // ---------------------------------------------------
  70. /**
  71. * Cached array of milestones. This is array of all project milestones. They are not
  72. * filtered by is_private stamp
  73. *
  74. * @var array
  75. */
  76. private $all_milestones;
  77. /**
  78. * Cached array of project milestones
  79. *
  80. * @var array
  81. */
  82. private $milestones;
  83. /**
  84. * Array of all open milestones in this projects
  85. *
  86. * @var array
  87. */
  88. private $all_open_milestones;
  89. /**
  90. * Array of open milestones in this projects that user can access. If user is not member of owner
  91. * company private milestones will be hidden
  92. *
  93. * @var array
  94. */
  95. private $open_milestones;
  96. /**
  97. * Cached array of late milestones. This variable is populated by splitOpenMilestones() private
  98. * function on request
  99. *
  100. * @var array
  101. */
  102. private $late_milestones = false;
  103. /**
  104. * Cached array of today milestones. This variable is populated by splitOpenMilestones() private
  105. * function on request
  106. *
  107. * @var array
  108. */
  109. private $today_milestones = false;
  110. /**
  111. * Cached array of upcoming milestones. This variable is populated by splitOpenMilestones() private
  112. * function on request
  113. *
  114. * @var array
  115. */
  116. private $upcoming_milestones = false;
  117. /**
  118. * Cached all completed milestones
  119. *
  120. * @var array
  121. */
  122. private $all_completed_milestones;
  123. /**
  124. * Cached array of completed milestones - is_private check is made before retrieving meaning that if
  125. * user is no member of owner company all private data will be hidden
  126. *
  127. * @var array
  128. */
  129. private $completed_milestones;
  130. // ---------------------------------------------------
  131. // Task lists
  132. // ---------------------------------------------------
  133. /**
  134. * All task lists in this project
  135. *
  136. * @var array
  137. */
  138. private $all_task_lists;
  139. /**
  140. * Array of all task lists. If user is not member of owner company private task
  141. * lists will be excluded from the list
  142. *
  143. * @var array
  144. */
  145. private $task_lists;
  146. /**
  147. * All open task lists in this project
  148. *
  149. * @var array
  150. */
  151. private $all_open_task_lists;
  152. /**
  153. * Array of open task lists. If user is not member of owner company private task
  154. * lists will be excluded from the list
  155. *
  156. * @var array
  157. */
  158. private $open_task_lists;
  159. /**
  160. * Array of all completed task lists in this project
  161. *
  162. * @var array
  163. */
  164. private $all_completed_task_lists;
  165. /**
  166. * Array of completed task lists. If user is not member of owner company private task
  167. * lists will be excluded from the list
  168. *
  169. * @var array
  170. */
  171. private $completed_task_lists;
  172. // ---------------------------------------------------
  173. // Tickets
  174. // ---------------------------------------------------
  175. /**
  176. * All categories in this project
  177. *
  178. * @var array
  179. */
  180. private $categories;
  181. /**
  182. * All tickets in this project
  183. *
  184. * @var array
  185. */
  186. private $all_tickets;
  187. /**
  188. * Array of all tickets. If user is not member of owner company private tickets
  189. * will be excluded from the list
  190. *
  191. * @var array
  192. */
  193. private $tickets;
  194. /**
  195. * All open tickets in this project
  196. *
  197. * @var array
  198. */
  199. private $all_open_tickets;
  200. /**
  201. * Array of open tickets. If user is not member of owner company private tickets
  202. * will be excluded from the list
  203. *
  204. * @var array
  205. */
  206. private $open_tickets;
  207. /**
  208. * All closed tickets in this project
  209. *
  210. * @var array
  211. */
  212. private $all_closed_tickets;
  213. /**
  214. * Array of closed tickets. If user is not member of owner company private tickets
  215. * will be excluded from the list
  216. *
  217. * @var array
  218. */
  219. private $closed_tickets;
  220. // ---------------------------------------------------
  221. // Tags
  222. // ---------------------------------------------------
  223. /**
  224. * Cached object tag names
  225. *
  226. * @var array
  227. */
  228. private $tag_names;
  229. // ---------------------------------------------------
  230. // Log
  231. // ---------------------------------------------------
  232. /**
  233. * Cache of all project logs
  234. *
  235. * @var array
  236. */
  237. private $all_project_logs;
  238. /**
  239. * Cache of all project logs that current user can access
  240. *
  241. * @var array
  242. */
  243. private $project_logs;
  244. // ---------------------------------------------------
  245. // Forms
  246. // ---------------------------------------------------
  247. /**
  248. * Cache of all project forms
  249. *
  250. * @var array
  251. */
  252. private $all_forms;
  253. // ---------------------------------------------------
  254. // Files
  255. // ---------------------------------------------------
  256. /**
  257. * Cached array of project folders
  258. *
  259. * @var array
  260. */
  261. private $folders;
  262. /**
  263. * Cached array of all important files
  264. *
  265. * @var array
  266. */
  267. private $all_important_files;
  268. /**
  269. * Important files filtered by the users access permissions
  270. *
  271. * @var array
  272. */
  273. private $important_files;
  274. /**
  275. * All orphaned files, user permissions are not checked
  276. *
  277. * @var array
  278. */
  279. private $all_orphaned_files;
  280. /**
  281. * Orphaned file
  282. *
  283. * @var array
  284. */
  285. private $orphaned_files;
  286. /**
  287. * All times
  288. *
  289. * @var array
  290. */
  291. private $all_times;
  292. // ---------------------------------------------------
  293. // Milestones
  294. // ---------------------------------------------------
  295. /**
  296. * Return parent project
  297. *
  298. * @access public
  299. * @param void
  300. * @return Project or NULL
  301. */
  302. function getParent() {
  303. return Projects::findById($this->getParentId());
  304. } // getTaskList
  305. /**
  306. * Return all milestones, don't filter them by is_private stamp based on users permissions
  307. *
  308. * @param void
  309. * @return array
  310. */
  311. function getAllSubprojects() {
  312. if (is_null($this->all_subprojects)) {
  313. $this->all_subprojects = Projects::findAll(array(
  314. 'conditions' => array('`parent_id` = ?', $this->getId()),
  315. 'order' => 'name'
  316. )); // findAll
  317. } // if
  318. return $this->all_subprojects;
  319. } // getAllSubprojects
  320. /**
  321. * Return subprojects
  322. *
  323. * @access public
  324. * @param void
  325. * @return array
  326. */
  327. function getSubprojects() {
  328. if (logged_user()->isMemberOfOwnerCompany()) {
  329. return $this->getAllSubprojects();
  330. }
  331. if (is_null($this->subprojects)) {
  332. $this->subprojects = Projects::findAll(array(
  333. // 'conditions' => array('`parent_id` = ? AND `is_private` = ?', $this->getId(), 0),
  334. 'conditions' => array('`parent_id` = ?', $this->getId()),
  335. 'order' => 'name'
  336. )); // findAll
  337. } // if
  338. return $this->subprojects;
  339. } // getSubprojects
  340. // ---------------------------------------------------
  341. // Page Attachments
  342. // ---------------------------------------------------
  343. /**
  344. * This function will return all page attachments in project
  345. *
  346. * @param void
  347. * @return array
  348. */
  349. function getAllPageAttachments() {
  350. if (is_null($this->all_page_attachments)) {
  351. $this->all_page_attachments = PageAttachments::getAllByProject($this);
  352. }
  353. return $this->all_page_attachments;
  354. } // getAllPageAttachments
  355. // ---------------------------------------------------
  356. // Messages
  357. // ---------------------------------------------------
  358. /**
  359. * This function will return all messages in project and it will not exclude private
  360. * messages if logged user is not member of owner company
  361. *
  362. * @param void
  363. * @return array
  364. */
  365. function getAllMessages() {
  366. if (is_null($this->all_messages)) {
  367. $this->all_messages = ProjectMessages::getProjectMessages($this, true);
  368. } // if
  369. return $this->all_messages;
  370. } // getAllMessages
  371. /**
  372. * Return only the messages that current user can see (if not member of owner company private
  373. * messages will be excluded)
  374. *
  375. * @param null
  376. * @return null
  377. */
  378. function getMessages() {
  379. if (logged_user()->isMemberOfOwnerCompany()) {
  380. return $this->getAllMessages(); // members of owner company can view all messages
  381. } // if
  382. if (is_null($this->messages)) {
  383. $this->messages = ProjectMessages::getProjectMessages($this, false);
  384. } // if
  385. return $this->messages;
  386. } // getMessages
  387. /**
  388. * Return all important messages
  389. *
  390. * @param void
  391. * @return array
  392. */
  393. function getAllImportantMessages() {
  394. if (is_null($this->all_important_messages)) {
  395. $this->all_important_messages = ProjectMessages::getImportantProjectMessages($this, true);
  396. } // if
  397. return $this->all_important_messages;
  398. } // getAllImportantMessages
  399. /**
  400. * Return array of important messages
  401. *
  402. * @param void
  403. * @return array
  404. */
  405. function getImportantMessages() {
  406. if (logged_user()->isMemberOfOwnerCompany()) {
  407. return $this->getAllImportantMessages();
  408. } // if
  409. if (is_null($this->important_messages)) {
  410. $this->important_messages = ProjectMessages::getImportantProjectMessages($this, false);
  411. } // if
  412. return $this->important_messages;
  413. } // getImportantMessages
  414. // ---------------------------------------------------
  415. // Milestones
  416. // ---------------------------------------------------
  417. /**
  418. * Return all milestones, don't filter them by is_private stamp based on users permissions
  419. *
  420. * @param void
  421. * @return array
  422. */
  423. function getAllMilestones() {
  424. if (is_null($this->all_milestones)) {
  425. $this->all_milestones = ProjectMilestones::findAll(array(
  426. 'conditions' => array('`project_id` = ?', $this->getId()),
  427. 'order' => 'due_date'
  428. )); // findAll
  429. } // if
  430. return $this->all_milestones;
  431. } // getAllMilestones
  432. /**
  433. * Return all project milestones
  434. *
  435. * @access public
  436. * @param void
  437. * @return array
  438. */
  439. function getMilestones() {
  440. if (logged_user()->isMemberOfOwnerCompany()) {
  441. return $this->getAllMilestones(); // member of owner company
  442. }
  443. if (is_null($this->milestones)) {
  444. $this->milestones = ProjectMilestones::findAll(array(
  445. 'conditions' => array('`project_id` = ? AND `is_private` = ?', $this->getId(), 0),
  446. 'order' => 'due_date'
  447. )); // findAll
  448. } // if
  449. return $this->milestones;
  450. } // getMilestones
  451. /**
  452. * Return all open milestones without is_private check
  453. *
  454. * @param void
  455. * @return array
  456. */
  457. function getAllOpenMilestones() {
  458. if (is_null($this->all_open_milestones)) {
  459. $this->all_open_milestones = ProjectMilestones::findAll(array(
  460. 'conditions' => array('`project_id` = ? AND `completed_on` = ?', $this->getId(), EMPTY_DATETIME),
  461. 'order' => 'due_date'
  462. )); // findAll
  463. } // if
  464. return $this->all_open_milestones;
  465. } // getAllOpenMilestones
  466. /**
  467. * Return open milestones
  468. *
  469. * @access public
  470. * @param void
  471. * @return array
  472. */
  473. function getOpenMilestones() {
  474. if (logged_user()->isMemberOfOwnerCompany()) {
  475. return $this->getAllOpenMilestones();
  476. }
  477. if (is_null($this->open_milestones)) {
  478. $this->open_milestones = ProjectMilestones::findAll(array(
  479. 'conditions' => array('`project_id` = ? AND `completed_on` = ? AND `is_private` = ?', $this->getId(), EMPTY_DATETIME, 0),
  480. 'order' => 'due_date'
  481. )); // findAll
  482. } // if
  483. return $this->open_milestones;
  484. } // getOpenMilestones
  485. /**
  486. * This function will return all completed milestones
  487. *
  488. * @param void
  489. * @return array
  490. */
  491. function getAllCompletedMilestones() {
  492. if (is_null($this->all_completed_milestones)) {
  493. $this->all_completed_milestones = ProjectMilestones::findAll(array(
  494. 'conditions' => array('`project_id` = ? AND `completed_on` > ?', $this->getId(), EMPTY_DATETIME),
  495. 'order' => 'due_date'
  496. )); // findAll
  497. } // if
  498. return $this->all_completed_milestones;
  499. } // getAllCompletedMilestones
  500. /**
  501. * Return completed milestones
  502. *
  503. * @access public
  504. * @param void
  505. * @return array
  506. */
  507. function getCompletedMilestones() {
  508. if (logged_user()->isMemberOfOwnerCompany()) {
  509. return $this->getAllCompletedMilestones();
  510. }
  511. if (is_null($this->completed_milestones)) {
  512. $this->completed_milestones = ProjectMilestones::findAll(array(
  513. 'conditions' => array('`project_id` = ? AND `completed_on` > ? AND `is_private` = ?', $this->getId(), EMPTY_DATETIME, 0),
  514. 'order' => 'due_date'
  515. )); // findAll
  516. } // if
  517. return $this->completed_milestones;
  518. } // getCompletedMilestones
  519. /**
  520. * Return array of late open milestones
  521. *
  522. * @param void
  523. * @return array
  524. */
  525. function getLateMilestones() {
  526. if ($this->late_milestones === false) {
  527. $this->splitOpenMilestones();
  528. }
  529. return $this->late_milestones;
  530. } // getLateMilestones
  531. /**
  532. * Return array of today open milestones
  533. *
  534. * @param void
  535. * @return array
  536. */
  537. function getTodayMilestones() {
  538. if ($this->today_milestones === false) {
  539. $this->splitOpenMilestones();
  540. }
  541. return $this->today_milestones;
  542. } // getTodayMilestones
  543. /**
  544. * Return array of upcoming open milestones
  545. *
  546. * @param void
  547. * @return array
  548. */
  549. function getUpcomingMilestones() {
  550. if ($this->upcoming_milestones === false) {
  551. $this->splitOpenMilestones();
  552. }
  553. return $this->upcoming_milestones;
  554. } // getUpcomingMilestones
  555. /**
  556. * This function will walk through open milestones array and splid them into late, today and upcomming
  557. *
  558. * @param void
  559. * @return array
  560. */
  561. private function splitOpenMilestones() {
  562. $open_milestones = $this->getOpenMilestones();
  563. // Reset from false
  564. $this->late_milestones = null;
  565. $this->today_milestones = null;
  566. $this->upcoming_milestones = null;
  567. if (is_array($open_milestones)) {
  568. foreach ($open_milestones as $open_milestone) {
  569. if ($open_milestone->isLate()) {
  570. if (!is_array($this->late_milestones)) {
  571. $this->late_milestones = array();
  572. }
  573. $this->late_milestones[] = $open_milestone;
  574. } elseif ($open_milestone->isToday()) {
  575. if (!is_array($this->today_milestones)) {
  576. $this->today_milestones = array();
  577. }
  578. $this->today_milestones[] = $open_milestone;
  579. } else {
  580. if (!is_array($this->upcoming_milestones)) {
  581. $this->upcoming_milestones = array();
  582. }
  583. $this->upcoming_milestones[] = $open_milestone;
  584. } // if
  585. } // foreach
  586. } // if
  587. } // splitOpenMilestones
  588. /**
  589. * Return array of milestones for the month specified that the user has
  590. * access to.
  591. *
  592. * @access public
  593. * @param int $year
  594. * @param int $month
  595. * @return array
  596. */
  597. function getMilestonesByMonth($year, $month) {
  598. $from_date = DateTimeValueLib::make(0, 0, 0, $month, 1, $year);
  599. $to_date = new DateTimeValue(strtotime('+1 month -1 day', $from_date->getTimestamp()));
  600. if (logged_user()->isMemberOfOwnerCompany()) {
  601. $conditions = array('`project_id` = ? AND (`due_date` >= ? AND `due_date` < ?)', $this->getId(), $from_date, $to_date);
  602. } else {
  603. $conditions = array('`project_id` = ? AND (`due_date` >= ? AND `due_date` < ?) AND `is_private` = ?', $this->getId(), $from_date, $to_date, 0);
  604. }
  605. return ProjectMilestones::findAll(array(
  606. 'conditions' => $conditions,
  607. 'order' => 'due_date'
  608. )); // findAll
  609. } // getMilestonesByMonth
  610. // ---------------------------------------------------
  611. // Time
  612. // ---------------------------------------------------
  613. /**
  614. * Return all times, don't filter them by is_private stamp based on users permissions
  615. *
  616. * @param void
  617. * @return array
  618. */
  619. function getAllTimes() {
  620. if (!plugin_active('times')) return null;
  621. if(is_null($this->all_times)) {
  622. $this->all_times = ProjectTimes::findAll(array(
  623. 'conditions' => array('`project_id` = ?', $this->getId()),
  624. 'order' => 'done_date desc'
  625. )); // findAll
  626. } // if
  627. return $this->all_times;
  628. } // getAllTimes
  629. /**
  630. * Return all project time
  631. *
  632. * @access public
  633. * @param void
  634. * @return array
  635. */
  636. function getTimes() {
  637. if (!plugin_active('times')) return null;
  638. if(logged_user()->isMemberOfOwnerCompany()) return $this->getAllTimes(); // member of owner company
  639. if(is_null($this->times)) {
  640. $this->times = ProjectTimes::findAll(array(
  641. 'conditions' => array('`project_id` = ? AND `is_private` = ?', $this->getId(), 0),
  642. 'order' => 'done_date desc'
  643. )); // findAll
  644. } // if
  645. return $this->times;
  646. } // getTimes
  647. // ---------------------------------------------------
  648. // Task lists
  649. // ---------------------------------------------------
  650. /**
  651. * Return all task lists
  652. *
  653. * @param void
  654. * @return array
  655. */
  656. function getAllTaskLists() {
  657. if (is_null($this->all_task_lists)) {
  658. $this->all_task_lists = ProjectTaskLists::findAll(array(
  659. 'conditions' => array('`project_id` = ?', $this->getId()),
  660. 'order' => '`order`'
  661. )); // findAll
  662. } // if
  663. return $this->all_task_lists;
  664. } // getAllTaskLists
  665. /**
  666. * Return all task lists
  667. *
  668. * @access public
  669. * @param void
  670. * @return array
  671. */
  672. function getTaskLists() {
  673. if (logged_user()->isMemberOfOwnerCompany()) {
  674. return $this->getAllTaskLists();
  675. }
  676. if (is_null($this->task_lists)) {
  677. $this->task_lists = ProjectTaskLists::findAll(array(
  678. 'conditions' => array('`project_id` = ? AND `is_private` = ?', $this->getId(), 0),
  679. 'order' => '`order`'
  680. )); // findAll
  681. } // if
  682. return $this->task_lists;
  683. } // getTaskLists
  684. /**
  685. * Return all open task lists from this project
  686. *
  687. * @param void
  688. * @return array
  689. */
  690. function getAllOpenTaskLists() {
  691. if (is_null($this->all_open_task_lists)) {
  692. $this->all_open_task_lists = ProjectTaskLists::findAll(array(
  693. 'conditions' => array('`project_id` = ? AND `completed_on` = ?', $this->getId(), EMPTY_DATETIME),
  694. 'order' => '`order`'
  695. )); // findAll
  696. } // if
  697. return $this->all_open_task_lists;
  698. } // getAllOpenTaskLists
  699. /**
  700. * Return open task lists
  701. *
  702. * @access public
  703. * @param void
  704. * @return array
  705. */
  706. function getOpenTaskLists() {
  707. if (logged_user()->isMemberOfOwnerCompany()) {
  708. return $this->getAllOpenTaskLists();
  709. }
  710. if (is_null($this->open_task_lists)) {
  711. $this->open_task_lists = ProjectTaskLists::findAll(array(
  712. 'conditions' => array('`project_id` = ? AND `completed_on` = ? AND `is_private` = ?', $this->getId(), EMPTY_DATETIME, 0),
  713. 'order' => '`order`'
  714. )); // findAll
  715. } // if
  716. return $this->open_task_lists;
  717. } // getOpenTaskLists
  718. /**
  719. * Return all completed task lists
  720. *
  721. * @param void
  722. * @return array
  723. */
  724. function getAllCompletedTaskLists() {
  725. if (is_null($this->all_completed_task_lists)) {
  726. $this->all_completed_task_lists = ProjectTaskLists::findAll(array(
  727. 'conditions' => array('`project_id` = ? AND `completed_on` > ?', $this->getId(), EMPTY_DATETIME),
  728. 'order' => '`order`'
  729. )); // findAll
  730. } // if
  731. return $this->all_completed_task_lists;
  732. } // getAllCompletedTaskLists
  733. /**
  734. * Return completed task lists
  735. *
  736. * @access public
  737. * @param void
  738. * @return array
  739. */
  740. function getCompletedTaskLists() {
  741. if (logged_user()->isMemberOfOwnerCompany()) {
  742. return $this->getAllCompletedTaskLists();
  743. }
  744. if (is_null($this->completed_task_lists)) {
  745. $this->completed_task_lists = ProjectTaskLists::findAll(array(
  746. 'conditions' => array('`project_id` = ? AND `completed_on` > ? AND `is_private` = ?', $this->getId(), EMPTY_DATETIME, 0),
  747. 'order' => '`order`'
  748. )); // findAll
  749. } // if
  750. return $this->completed_task_lists;
  751. } // getCompletedTaskLists
  752. /**
  753. * Return array of milestones for the month specified that the user has
  754. * access to.
  755. *
  756. * @access public
  757. * @param int $year
  758. * @param int $month
  759. * @return array
  760. */
  761. function getTaskListsByMonth($year, $month) {
  762. $from_date = DateTimeValueLib::make(0, 0, 0, $month, 1, $year);
  763. $to_date = new DateTimeValue(strtotime('+1 month -1 day', $from_date->getTimestamp()));
  764. if (logged_user()->isMemberOfOwnerCompany()) {
  765. $conditions = array('`project_id` = ? AND (`due_date` >= ? AND `due_date` < ?)', $this->getId(), $from_date, $to_date);
  766. } else {
  767. $conditions = array('`project_id` = ? AND (`due_date` >= ? AND `due_date` < ?) AND `is_private` = ?', $this->getId(), $from_date, $to_date, 0);
  768. }
  769. return ProjectTaskLists::findAll(array(
  770. 'conditions' => $conditions,
  771. 'order' => 'due_date'
  772. )); // findAll
  773. } // getMilestonesByMonth
  774. // ---------------------------------------------------
  775. // Tickets
  776. // ---------------------------------------------------
  777. /**
  778. * Return all categories
  779. *
  780. * @param void
  781. * @return array
  782. */
  783. function getCategories() {
  784. if(is_null($this->categories)) {
  785. $this->categories = ProjectCategories::getProjectCategories($this);
  786. } // if
  787. return $this->categories;
  788. } // getCategories
  789. /**
  790. * This function will return all tickets in project and it will not exclude private
  791. * tickets if logged user is not member of owner company
  792. *
  793. * @param void
  794. * @return array
  795. */
  796. function getAllTickets() {
  797. if (!plugin_active('tickets')) return null;
  798. if(is_null($this->all_tickets)) {
  799. $this->all_tickets = ProjectTickets::getProjectTickets($this, true);
  800. } // if
  801. return $this->all_tickets;
  802. } // getAllTickets
  803. /**
  804. * Return only the tickets that current user can see (if not member of owner company private
  805. * tickets will be excluded)
  806. *
  807. * @param void
  808. * @return array
  809. */
  810. function getTickets() {
  811. if (!plugin_active('tickets')) return null;
  812. if(logged_user()->isMemberOfOwnerCompany()) {
  813. return $this->getAllTickets(); // members of owner company can view all tickets
  814. } // if
  815. if(is_null($this->tickets)) {
  816. $this->tickets = ProjectTickets::getProjectTickets($this, false);
  817. } // if
  818. return $this->tickets;
  819. } // getTickets
  820. /**
  821. * This function will return all open tickets in project and it will not exclude private
  822. * tickets if logged user is not member of owner company
  823. *
  824. * @param void
  825. * @return array
  826. */
  827. function getAllOpenTickets() {
  828. if (!plugin_active('tickets')) return null;
  829. if(is_null($this->all_open_tickets)) {
  830. $this->all_open_tickets = ProjectTickets::getOpenProjectTickets($this, true);
  831. } // if
  832. return $this->all_open_tickets;
  833. } // getAllOpenTickets
  834. /**
  835. * Return only the open tickets that current user can see (if not member of owner company private
  836. * tickets will be excluded)
  837. *
  838. * @param void
  839. * @return array
  840. */
  841. function getOpenTickets() {
  842. if (!plugin_active('tickets')) return null;
  843. if(logged_user()->isMemberOfOwnerCompany()) {
  844. return $this->getAllOpenTickets(); // members of owner company can view all tickets
  845. } // if
  846. if(is_null($this->open_tickets)) {
  847. $this->open_tickets = ProjectTickets::getOpenProjectTickets($this, false);
  848. } // if
  849. return $this->open_tickets;
  850. } // getOpenTickets
  851. /**
  852. * This function will return all closed tickets in project and it will not exclude private
  853. * tickets if logged user is not member of owner company
  854. *
  855. * @param void
  856. * @return array
  857. */
  858. function getAllClosedTickets() {
  859. if (!plugin_active('tickets')) return null;
  860. if(is_null($this->all_closed_tickets)) {
  861. $this->all_closed_tickets = ProjectTickets::getClosedProjectTickets($this, true);
  862. } // if
  863. return $this->all_closed_tickets;
  864. } // getAllClosedTickets
  865. /**
  866. * Return only the closed tickets that current user can see (if not member of owner company private
  867. * tickets will be excluded)
  868. *
  869. * @param void
  870. * @return array
  871. */
  872. function getClosedTickets() {
  873. if (!plugin_active('tickets')) return null;
  874. if(logged_user()->isMemberOfOwnerCompany()) {
  875. return $this->getAllClosedTickets(); // members of owner company can view all tickets
  876. } // if
  877. if(is_null($this->closed_tickets)) {
  878. $this->closed_tickets = ProjectTickets::getClosedProjectTickets($this, false);
  879. } // if
  880. return $this->closed_tickets;
  881. } // getClosedTickets
  882. // ---------------------------------------------------
  883. // Tags
  884. // ---------------------------------------------------
  885. /**
  886. * This function will return unique tags used on objects of this project. Result is cached!
  887. *
  888. * @access public
  889. * @param void
  890. * @return array
  891. */
  892. function getTagNames() {
  893. $exclude_private = !logged_user()->isMemberOfOwnerCompany();
  894. if (is_null($this->tag_names)) {
  895. $this->tag_names = Tags::getProjectTagNames($this, $exclude_private);
  896. } // if
  897. return $this->tag_names;
  898. } // getTagNames
  899. /**
  900. * This function return associative array of project objects tagged with specific tag. Array has following elements:
  901. *
  902. * - messages
  903. * - milestones
  904. * - task lists
  905. * - files
  906. *
  907. * @access public
  908. * @param string $tag
  909. * @return array
  910. */
  911. function getObjectsByTag($tag) {
  912. $exclude_private = !logged_user()->isMemberOfOwnerCompany();
  913. return array(
  914. 'messages' => Tags::getProjectObjects($this, $tag, 'ProjectMessages', $exclude_private),
  915. 'milestones' => Tags::getProjectObjects($this, $tag, 'ProjectMilestones', $exclude_private),
  916. 'task_lists' => Tags::getProjectObjects($this, $tag, 'ProjectTaskLists', $exclude_private),
  917. 'tickets' => Tags::getProjectObjects($this, $tag, 'ProjectTickets', $exclude_private),
  918. 'files' => Tags::getProjectObjects($this, $tag, 'ProjectFiles', $exclude_private),
  919. 'wiki' => Tags::getProjectObjects($this, $tag, 'Wiki', $exclude_private),
  920. 'links' => Tags::getProjectObjects($this, $tag, 'ProjectLinks', $exclude_private),
  921. ); // array
  922. } // getObjectsByTag
  923. /**
  924. * Return number of project objects tagged with $tag
  925. *
  926. * @param string $tag
  927. * @return integer
  928. */
  929. function countObjectsByTag($tag) {
  930. $exclude_private = !logged_user()->isMemberOfOwnerCompany();
  931. return Tags::countProjectObjectsByTag($tag, $this, $exclude_private);
  932. } // countObjectsByTag
  933. // ---------------------------------------------------
  934. // Project log
  935. // ---------------------------------------------------
  936. /**
  937. * Return full project log
  938. *
  939. * @param integer $limit
  940. * @param integer $offset
  941. * @return array
  942. */
  943. function getFullProjectLog($limit = null, $offset = null) {
  944. return ApplicationLogs::getProjectLogs($this, true, true, $limit, $offset);
  945. } // getFullProjectLog
  946. /**
  947. * Return all project log entries that this user can see
  948. *
  949. * @param integer $limit Number of logs that will be returned
  950. * @param integer $offset Return from this record
  951. * @return array
  952. */
  953. function getProjectLog($limit = null, $offset = null) {
  954. $include_private = logged_user()->isMemberOfOwnerCompany();
  955. $include_silent = logged_user()->isAdministrator();
  956. return ApplicationLogs::getProjectLogs($this, $include_private, $include_silent, $limit, $offset);
  957. } // getProjectLog
  958. /**
  959. * Return number of logs for this project
  960. *
  961. * @access public
  962. * @param void
  963. * @return null
  964. */
  965. function countProjectLogs() {
  966. return ApplicationLogs::count(array('`project_id` = ?', $this->getId()));
  967. } // countProjectLogs
  968. // ---------------------------------------------------
  969. // Project forms
  970. // ---------------------------------------------------
  971. /**
  972. * Return all project forms
  973. *
  974. * @param void
  975. * @return array
  976. */
  977. function getAllForms() {
  978. if(!plugin_active('form')) { return null; }
  979. if (is_null($this->all_forms)) {
  980. $this->all_forms = ProjectForms::findAll(array(
  981. 'conditions' => array('`project_id` = ?', $this->getId()),
  982. 'order' => '`order`'
  983. )); // findAll
  984. } // if
  985. return $this->all_forms;
  986. } // getAllForms
  987. /**
  988. * Return only visible project forms
  989. *
  990. * @param void
  991. * @return null
  992. */
  993. function getVisibleForms($only_enabled = false) {
  994. if(!plugin_active('form')) { return null; }
  995. $conditions = '`project_id` = ' . DB::escape($this->getId());
  996. if ($only_enabled) {
  997. $conditions .= ' AND `is_enabled` = ' . DB::escape(true);
  998. } // if
  999. return ProjectForms::findAll(array(
  1000. 'conditions' => $conditions,
  1001. 'order' => '`order`'
  1002. )); // findAll
  1003. } // getVisibleForms
  1004. /**
  1005. * Return owner company object
  1006. *
  1007. * @access public
  1008. * @param void
  1009. * @return Company
  1010. */
  1011. function getCompany() {
  1012. return owner_company();
  1013. } // getCompany
  1014. /**
  1015. * Get all companies involved in this project
  1016. *
  1017. * @access public
  1018. * @param boolean $include_owner_company Include owner in result
  1019. * @return array
  1020. */
  1021. function getCompanies($include_owner_company = true) {
  1022. $result = array();
  1023. if ($include_owner_company) {
  1024. $result[] = $this->getCompany();
  1025. }
  1026. $companies = ProjectCompanies::getCompaniesByProject($this);
  1027. if (is_array($companies)) {
  1028. $result = array_merge($result, $companies);
  1029. } // if
  1030. return $result;
  1031. } // getCompanies
  1032. /**
  1033. * Get all companies involved in this project visible to the given user
  1034. *
  1035. * @access public
  1036. * @param User $user The user to filter with
  1037. * @param boolean $include_owner_company Include owner in result
  1038. * @return array
  1039. */
  1040. function getVisibleCompanies($user, $include_owner_company = false) {
  1041. $visible = array();
  1042. $companies = $this->getCompanies($include_owner_company);
  1043. foreach($companies as $company) {
  1044. if (logged_user()->canSeeCompany($company)) {
  1045. $visible[] = $company;
  1046. }
  1047. }
  1048. return $visible;
  1049. } // getVisibleCompanies
  1050. /**
  1051. * Remove all companies from project
  1052. *
  1053. * @access public
  1054. * @param void
  1055. * @return boolean
  1056. */
  1057. function clearCompanies() {
  1058. return ProjectCompanies::clearByProject($this);
  1059. } // clearCompanies
  1060. /**
  1061. * Return all users involved in this project
  1062. *
  1063. * @access public
  1064. * @param void
  1065. * @return array
  1066. */
  1067. function getUsers($group_by_company = true) {
  1068. $users = ProjectUsers::getUsersByProject($this);
  1069. if (!is_array($users) || !count($users)) {
  1070. return null;
  1071. } // if
  1072. if ($group_by_company) {
  1073. $grouped = array();
  1074. foreach ($users as $user) {
  1075. if (!isset($grouped[$user->getCompanyId()]) || !is_array($grouped[$user->getCompanyId()])) {
  1076. $grouped[$user->getCompanyId()] = array();
  1077. } // if
  1078. $grouped[$user->getCompanyId()][] = $user;
  1079. } // foreach
  1080. return $grouped;
  1081. } else {
  1082. return $users;
  1083. } // if
  1084. } // getUsers
  1085. /**
  1086. * Get all users involved in this project visible to the given user
  1087. *
  1088. * @access public
  1089. * @param User $user The user to filter with
  1090. * @param boolean $include_owner_company Include owner in result
  1091. * @return array
  1092. */
  1093. function getVisibleUsers($user) {
  1094. $visible = array();
  1095. $users = $this->getUsers(false);
  1096. foreach($users as $user) {
  1097. if (logged_user()->canSeeUser($user)) {
  1098. $visible[] = $user;
  1099. }
  1100. }
  1101. return $visible;
  1102. } // getVisibleUsers
  1103. /**
  1104. * Remove all users from project
  1105. *
  1106. * @access public
  1107. * @param void
  1108. * @return boolean
  1109. */
  1110. function clearUsers() {
  1111. return ProjectUsers::clearByProject($this);
  1112. } // clearUsers
  1113. /**
  1114. * Return user who created this milestone
  1115. *
  1116. * @access public
  1117. * @param void
  1118. * @return User
  1119. */
  1120. function getCreatedBy() {
  1121. return Users::findById($this->getCreatedById());
  1122. } // getCreatedBy
  1123. /**
  1124. * Return user who completed this project
  1125. *
  1126. * @access public
  1127. * @param void
  1128. * @return User
  1129. */
  1130. function getCompletedBy() {
  1131. return Users::findById($this->getCompletedById());
  1132. } // getCompletedBy
  1133. /**
  1134. * Return display name of user who completed this project
  1135. *
  1136. * @access public
  1137. * @param void
  1138. * @return string
  1139. */
  1140. function getCompletedByDisplayName() {
  1141. $completed_by = $this->getCompletedBy();
  1142. return $completed_by instanceof User ? $completed_by->getDisplayName() : lang('n/a');
  1143. } // getCompletedByDisplayName
  1144. // ---------------------------------------------------
  1145. // User tasks
  1146. // ---------------------------------------------------
  1147. /**
  1148. * Return array of milestones that are assigned to specific user or his company
  1149. *
  1150. * @param User $user
  1151. * @return array
  1152. */
  1153. function getUsersMilestones(User $user) {
  1154. $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME));
  1155. if (!$user->isMemberOfOwnerCompany()) {
  1156. $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
  1157. } // if
  1158. return ProjectMilestones::findAll(array(
  1159. 'conditions' => $conditions,
  1160. 'order' => '`due_date`'
  1161. ));
  1162. } // getUsersMilestones
  1163. /**
  1164. * Return array of task that are assigned to specific user or his company
  1165. *
  1166. * @param User $user
  1167. * @return array
  1168. */
  1169. function getUsersTasks(User $user) {
  1170. $task_lists = $this->getTaskLists();
  1171. if (!is_array($task_lists)) {
  1172. return false;
  1173. } // if
  1174. $task_list_ids = array();
  1175. foreach ($task_lists as $task_list) {
  1176. if (!$user->isMemberOfOwnerCompany() && $task_list->isPrivate()) {
  1177. continue;
  1178. } // if
  1179. $task_list_ids[] = $task_list->getId();
  1180. } // if
  1181. return ProjectTasks::findAll(array(
  1182. 'conditions' => array('`task_list_id` IN (?) AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', $task_list_ids, $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME),
  1183. //'conditions' => array('((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?)) AND `completed_on` = ?', $task_list_ids, $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, EMPTY_DATETIME),
  1184. 'order' => '`task_list_id`, `due_date`'
  1185. )); // findAll
  1186. } // getUsersTasks
  1187. // ---------------------------------------------------
  1188. // User tickets
  1189. // ---------------------------------------------------
  1190. /**
  1191. * Return array of task that are assigned to specific user or his company
  1192. *
  1193. * @param User $user
  1194. * @param array $options
  1195. * @param boolean $include_company
  1196. * @return array
  1197. */
  1198. function getUsersTickets(User $user, $options = null, $include_company = false) {
  1199. if (!plugin_active('tickets')) return null;
  1200. if ($include_company) {
  1201. $conditions = DB::prepareString('`project_id` = ? AND ((`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR (`assigned_to_user_id` = ? AND `assigned_to_company_id` = ?) OR `created_by_id`= ?) AND `closed_on` = ?', array($this->getId(), $user->getId(), $user->getCompanyId(), 0, $user->getCompanyId(), 0, 0, $user->getId(), EMPTY_DATETIME));
  1202. } else {
  1203. $conditions = DB::prepareString('`project_id` = ? AND `assigned_to_user_id` = ? AND `closed_on` = ?', array($this->getId(), $user->getId(), EMPTY_DATETIME));
  1204. } // if
  1205. if(!$user->isMemberOfOwnerCompany()) {
  1206. $conditions .= DB::prepareString(' AND `is_private` = ?', array(0));
  1207. } // if
  1208. $options['conditions'] = $conditions;
  1209. if (!isset($options['order'])) {
  1210. $options['order'] = '`created_on`';
  1211. }
  1212. return ProjectTickets::findAll($options); // findAll
  1213. } // getUsersTickets
  1214. // ---------------------------------------------------
  1215. // Files
  1216. // ---------------------------------------------------
  1217. function getFolders() {
  1218. if(!plugin_active('files')) { return null; }
  1219. if (is_null($this->folders)) {
  1220. $this->folders = ProjectFolders::getProjectFolders($this);
  1221. } // if
  1222. return $this->folders;
  1223. } // getFolders
  1224. /**
  1225. * Return all important files
  1226. *
  1227. * @param void
  1228. * @return array
  1229. */
  1230. function getAllImportantFiles() {
  1231. trace(__FILE__,'getAllImportantFiles()');
  1232. if(!plugin_active('files')) { return null; }
  1233. if (is_null($this->all_important_files)) {
  1234. $this->all_important_files = ProjectFiles::getImportantProjectFiles($this, true);
  1235. } // if
  1236. return $this->all_important_files;
  1237. } // getAllImportantFiles
  1238. /**
  1239. * Return important files
  1240. *
  1241. * @param void
  1242. * @return array
  1243. */
  1244. function getImportantFiles() {
  1245. trace(__FILE__,'getImportantFiles()');
  1246. if(!plugin_active('files')) { return null; }
  1247. if (logged_user()->isMemberOfOwnerCompany()) {
  1248. return $this->getAllImportantFiles();
  1249. } // if
  1250. if (is_null($this->important_files)) {
  1251. $this->important_files = ProjectFiles::getImportantProjectFiles($this, false);
  1252. } // if
  1253. return $this->important_files;
  1254. } // getImportantFiles
  1255. /**
  1256. * Return all orphaned files
  1257. *
  1258. * @param void
  1259. * @return array
  1260. */
  1261. function getAllOrphanedFiles() {
  1262. if(!plugin_active('files')) { return null; }
  1263. if (is_null($this->all_orphaned_files)) {
  1264. $this->all_orphaned_files = ProjectFiles::getOrphanedFilesByProject($this, true);
  1265. } //
  1266. return $this->all_orphaned_files;
  1267. } // getAllOrphanedFiles
  1268. /**
  1269. * Return orphaned files
  1270. *
  1271. * @param void
  1272. * @return array
  1273. */
  1274. function getOrphanedFiles() {
  1275. if(!plugin_active('files')) { return null; }
  1276. if (is_null($this->orphaned_files)) {
  1277. $this->orphaned_files = ProjectFiles::getOrphanedFilesByProject($this, logged_user()->isMemberOfOwnerCompany());
  1278. } // if
  1279. return $this->orphaned_files;
  1280. } // getOrphanedFiles
  1281. // ---------------------------------------------------
  1282. // Status
  1283. // ---------------------------------------------------
  1284. /**
  1285. * Check if this project is active
  1286. *
  1287. * @access public
  1288. * @param void
  1289. * @return boolean
  1290. */
  1291. function isActive() {
  1292. return !$this->isCompleted();
  1293. } // isActive
  1294. /**
  1295. * Check if this project is completed
  1296. *
  1297. * @access public
  1298. * @param void
  1299. * @return boolean
  1300. */
  1301. function isCompleted() {
  1302. return (boolean) $this->getCompletedOn();
  1303. } // isCompleted
  1304. // ---------------------------------------------------
  1305. // Permissions
  1306. // ---------------------------------------------------
  1307. /**
  1308. * Check if user can add project
  1309. *
  1310. * @access public
  1311. * @param void
  1312. * @return null
  1313. */
  1314. function canAdd(User $user) {
  1315. return $user->isAccountOwner() || $user->isAdministrator(owner_company()) || $user->canManageProjects();
  1316. } // canAdd
  1317. /**
  1318. * Returns true if user can update specific project
  1319. *
  1320. * @access public
  1321. * @param User $user
  1322. * @return boolean
  1323. */
  1324. function canEdit(User $user) {
  1325. return ($this->getCreatedById() == $user->getId()) || $user->isAccountOwner() || $user->isAdministrator(owner_company());
  1326. } // canEdit
  1327. /**
  1328. * Returns true if user can delete specific project
  1329. *
  1330. * @access public
  1331. * @param User $user
  1332. * @return boolean
  1333. */
  1334. function canDelete(User $user) {
  1335. return ($this->getCreatedById() == $user->getId()) || $user->isAccountOwner() || $user->isAdministrator(owner_company());
  1336. } // canDelete
  1337. /**
  1338. * Returns true if user can change status of this project
  1339. *
  1340. * @access public
  1341. * @param User $user
  1342. * @return boolean
  1343. */
  1344. function canChangeStatus(User $user) {
  1345. return $this->canEdit($user);
  1346. } // canChangeStatus
  1347. /**
  1348. * Returns true if user can access permissions page and can update permissions
  1349. *
  1350. * @access public
  1351. * @param User $user
  1352. * @return boolean
  1353. */
  1354. function canChangePermissions(User $user) {
  1355. return ($this->getCreatedById() == $user->getId()) || $user->isAccountOwner() || $user->isAdministrator(owner_company());
  1356. } // canChangePermissions
  1357. /**
  1358. * Check if specific user can remove company from project
  1359. *
  1360. * @access public
  1361. * @param User $user
  1362. * @param Company $remove_company Remove this company
  1363. * @return boolean
  1364. */
  1365. function canRemoveCompanyFromProject(User $user, Company $remove_company) {
  1366. if ($remove_company->isOwner()) {
  1367. return false;
  1368. }
  1369. return ($this->getCreatedById() == $user->getId()) || $user->isAccountOwner() || $user->isAdministrator();
  1370. } // canRemoveCompanyFromProject
  1371. /**
  1372. * Check if this user can remove other user from project
  1373. *
  1374. * @access public
  1375. * @param User $user
  1376. * @param User $remove_user User that need to be removed
  1377. * @return boolean
  1378. */
  1379. function canRemoveUserFromProject(User $user, User $remove_user) {
  1380. if ($remove_user->isAccountOwner()) {
  1381. return false;
  1382. }
  1383. return ($this->getCreatedById() == $user->getId()) || $user->isAccountOwner() || $user->isAdministrator();
  1384. } // canRemoveUserFromProject
  1385. // ---------------------------------------------------
  1386. // URLS
  1387. // ---------------------------------------------------
  1388. /**
  1389. * Link to project overview page
  1390. *
  1391. * @access public
  1392. * @param void
  1393. * @return stirng
  1394. */
  1395. function getOverviewUrl() {
  1396. return get_url('project', 'overview', array('active_project' => $this->getId()));
  1397. } // getOverviewUrl
  1398. /**
  1399. * Return project messages index page URL
  1400. *
  1401. * @param void
  1402. * @return string
  1403. */
  1404. function getMessagesUrl() {
  1405. return get_url('message', 'index', array('active_project' => $this->getId()));
  1406. } // getMessagesUrl
  1407. /**
  1408. * Return project tasks index page URL
  1409. *
  1410. * @param void
  1411. * @return string
  1412. */
  1413. function getTasksUrl() {
  1414. return get_url('task', 'index', array('active_project' => $this->getId()));
  1415. } // getTasksUrl
  1416. /**
  1417. * Return project milestones index page URL
  1418. *
  1419. * @param void
  1420. * @return string
  1421. */
  1422. function getMilestonesUrl() {
  1423. return get_url('milestone', 'index', array('active_project' => $this->getId()));
  1424. } // getMilestonesUrl
  1425. /**
  1426. * Return project tickets index page URL
  1427. *
  1428. * @param void
  1429. * @return string
  1430. */
  1431. function getTicketsUrl() {
  1432. return get_url('tickets', 'index', array('active_project' => $this->getId()));
  1433. } // getTicketsUrl
  1434. /**
  1435. * Return project forms index page URL
  1436. *
  1437. * @param void
  1438. * @return string
  1439. */
  1440. function getFormsUrl() {
  1441. return get_url('form', 'index', array('active_project' => $this->getId()));
  1442. } // getFormsUrl
  1443. /**
  1444. * Return project people index page URL
  1445. *
  1446. * @param void
  1447. * @return string
  1448. */
  1449. function getPeopleUrl() {
  1450. return get_url('project', 'people', array('active_project' => $this->getId()));
  1451. } // getPeopleUrl
  1452. /**
  1453. * Return project settings page URL
  1454. *
  1455. * @param void
  1456. * @return string
  1457. */
  1458. function getSettingsUrl() {
  1459. return get_url('project_settings', 'index', array('active_project' => $this->getId()));
  1460. } // getSettingsUrl
  1461. /**
  1462. * Return project permissions page URL
  1463. *
  1464. * @param void
  1465. * @return string
  1466. */
  1467. function getPermissionsUrl() {
  1468. return get_url('project', 'permissions', array('active_project' => $this->getId()));
  1469. } // getPermissionsUrl
  1470. /**
  1471. * Return search URL
  1472. *
  1473. * @param string $search_for
  1474. * @param string placeholder for search page
  1475. * @return string
  1476. */
  1477. function getSearchUrl($search_for = null, $page = '#PAGE#') {
  1478. if (trim($search_for) <> '') {
  1479. $params = array(
  1480. 'active_project' => $this->getId(),
  1481. 'search_for' => $search_for,
  1482. 'page' => $page,
  1483. ); // array
  1484. return get_url('project', 'search', $params);
  1485. } else {
  1486. return ROOT_URL . 'index.php';
  1487. } // if
  1488. } // getSearchUrl
  1489. /**
  1490. * Return edit project URL
  1491. *
  1492. * @access public
  1493. * @param string $redirect_to URL where we need to redirect user when edit is done
  1494. * @return string
  1495. */
  1496. function getEditUrl($redirect_to = null) {
  1497. $attributes = array('id' => $this->getId(),
  1498. 'active_project' => $this->getId());
  1499. if (trim($redirect_to) <> '') {
  1500. $attributes['redirect_to'] = urlencode(trim($redirect_to));
  1501. } // if
  1502. return get_url('project', 'edit', $attributes);
  1503. } // getEditUrl
  1504. /**
  1505. * Return delete project URL
  1506. *
  1507. * @access public
  1508. * @param void
  1509. * @return string
  1510. */
  1511. function getDeleteUrl() {
  1512. return get_url('project', 'delete', array(
  1513. 'id' => $this->getId(),
  1514. 'active_project' => $this->getId(),
  1515. ));
  1516. } // getDeleteUrl
  1517. /**
  1518. * Return complete project url
  1519. *
  1520. * @access public
  1521. * @param void
  1522. * @return string
  1523. */
  1524. function getCompleteUrl() {
  1525. return get_url('project', 'complete', $this->getId());
  1526. } // getCompleteUrl
  1527. /**
  1528. * Return open project URL
  1529. *
  1530. * @access public
  1531. * @param void
  1532. * @return string
  1533. */
  1534. function getOpenUrl() {
  1535. return get_url('project', 'open', $this->getId());
  1536. } // getOpenUrl
  1537. /**
  1538. * Return add contact to project URL
  1539. *
  1540. * @access public
  1541. * @param void
  1542. * @return striā€¦

Large files files are truncated, but you can click here to view the full file