PageRenderTime 41ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/application/helpers/application.php

https://github.com/fb83/Project-Pier
PHP | 729 lines | 432 code | 72 blank | 225 comment | 109 complexity | b03891682a9a21695eced18216288bc6 MD5 | raw file
Possible License(s): AGPL-1.0, GPL-2.0, AGPL-3.0, LGPL-2.1, GPL-3.0
  1. <?php
  2. /**
  3. * Application helpers. This helpers are injected into the controllers
  4. * through ApplicationController construction so they are available in
  5. * whole application
  6. *
  7. * @http://www.projectpier.org/
  8. */
  9. /**
  10. * Render user box
  11. *
  12. * @param User $user
  13. * @return null
  14. */
  15. function render_user_box(User $user) {
  16. tpl_assign('_userbox_user', $user);
  17. tpl_assign('_userbox_contact', $user->getContact());
  18. tpl_assign('_userbox_projects', $user->getActiveMainProjects());
  19. return tpl_fetch(get_template_path('user_box', 'application'));
  20. } // render_user_box
  21. /**
  22. * This function will render system notices for this user
  23. *
  24. * @param User $user
  25. * @return string
  26. */
  27. function render_system_notices(User $user) {
  28. if (!$user->isAdministrator()) {
  29. return;
  30. }
  31. $system_notices = array();
  32. if (config_option('upgrade_check_enabled', false) && config_option('upgrade_last_check_new_version', false)) {
  33. $system_notices[] = lang('new version available', get_url('administration', 'upgrade'));
  34. }
  35. if (count($system_notices)) {
  36. tpl_assign('_system_notices', $system_notices);
  37. return tpl_fetch(get_template_path('system_notices', 'application'));
  38. } // if
  39. } // render_system_notices
  40. /**
  41. * Render select company box
  42. *
  43. * @param integer $selected ID of selected company
  44. * @param array $attributes Additional attributes
  45. * @return string
  46. */
  47. function select_company($name, $selected = null, $attributes = null) {
  48. $companies = Companies::getAll();
  49. $options = array(option_tag(lang('none'), 0));
  50. if (is_array($companies)) {
  51. foreach ($companies as $company) {
  52. $option_attributes = $company->getId() == $selected ? array('selected' => 'selected') : null;
  53. $company_name = $company->getName();
  54. if ($company->isOwner()) {
  55. $company_name .= ' (' . lang('owner company') . ')';
  56. }
  57. $options[] = option_tag($company_name, $company->getId(), $option_attributes);
  58. } // foreach
  59. } // if
  60. return select_box($name, $options, $attributes);
  61. } // select_company
  62. /**
  63. * Render select user box
  64. *
  65. * @param integer $selected ID of selected user
  66. * @param array $attributes Additional attributes
  67. * @return string
  68. */
  69. function select_user($name, $selected = null, $attributes = null) {
  70. $users = Users::getAll();
  71. $options = array(option_tag(lang('none'), 0));
  72. if (is_array($users)) {
  73. foreach ($users as $user) {
  74. $option_attributes = $user->getId() == $selected ? array('selected' => 'selected') : null;
  75. $user_name = $user->getUsername();
  76. if ($user->isAdministrator()) {
  77. $user_name .= ' (' . lang('administrator') . ')';
  78. }
  79. $options[] = option_tag($user_name, $user->getId(), $option_attributes);
  80. } // foreach
  81. } // if
  82. return select_box($name, $options, $attributes);
  83. } // select_company
  84. /**
  85. * Render select contact box
  86. *
  87. * @param integer $selected ID of selected contact
  88. * @param array $exclude_contacts Array of IDs of contacts that need to be excluded (already attached to project etc)
  89. * @param array $attributes Additional attributes
  90. * @return string
  91. */
  92. function select_contact($name, $selected = null, $exclude_contacts = null, $attributes = null) {
  93. $grouped_contacts = Contacts::getGroupedByCompany();
  94. $all_options = array(option_tag(lang('none'), 0));
  95. if (is_array($grouped_contacts)) {
  96. foreach ($grouped_contacts as $company_name => $contacts) {
  97. if (is_array($contacts) && is_array($contacts['contacts']) && count($contacts['contacts'])) {
  98. $options = array();
  99. foreach ($contacts['contacts'] as $contact) {
  100. if (is_array($exclude_contacts) && in_array($contact->getId(), $exclude_contacts)) {
  101. continue;
  102. }
  103. $contact_name = $contact->getDisplayName();
  104. if ($contact->isAdministrator()) {
  105. $contact_name .= ' (' . lang('administrator') . ')';
  106. }
  107. $option_attributes = $contact->getId() == $selected ? array('selected' => 'selected') : null;
  108. $options[] = option_tag($contact_name, $contact->getId(), $option_attributes);
  109. } // foreach
  110. if (count($options)) {
  111. $all_options[] = option_tag('', 0); // separator
  112. $all_options[] = option_group_tag($company_name, $options);
  113. } // if
  114. } // if
  115. } // foreach
  116. } // if
  117. return select_box($name, $all_options, $attributes);
  118. } // select_contact
  119. /**
  120. * Render select project user box
  121. *
  122. * @param string $name Name of the widget
  123. * @param Project $project
  124. * @param integer $selected ID of selected user
  125. * @param array $exclude_users Array of IDs of users that need to be excluded (e.g. already subscribers)
  126. * @param array $attributes Additional attributes
  127. * @return string
  128. */
  129. function select_project_user($name, $project = null, $selected = null, $exclude_users = null, $attributes = null) {
  130. if (is_null($project)) {
  131. $project = active_project();
  132. } // if
  133. if (!($project instanceof Project)) {
  134. throw new InvalidInstanceError('$project', $project, 'Project');
  135. } // if
  136. if (is_array($attributes)) {
  137. if (!isset($attributes['class'])) {
  138. $attributes['class'] = 'select_project_user';
  139. } // if
  140. } else {
  141. $attributes = array('class' => 'select_project_user');
  142. } // if
  143. $grouped_project_users = $project->getUsers(true);
  144. $all_options = array(option_tag(lang('none'), 0));
  145. if (is_array($grouped_project_users)) {
  146. foreach ($grouped_project_users as $company_id => $users) {
  147. $company = Companies::findById($company_id);
  148. if (!($company instanceof Company)) {
  149. continue;
  150. } // if
  151. $options = array();
  152. if (is_array($users)) {
  153. foreach ($users as $user) {
  154. if (is_array($exclude_users) && in_array($user->getId(), $exclude_users)) {
  155. continue;
  156. } // if
  157. $option_attributes = ($user->getId() == $selected ? array('selected' => 'selected') : null);
  158. $display_name = $user->getDisplayName().($user->getId() == logged_user()->getId() ? ' ('.lang('you').')' : '');
  159. $options[] = option_tag($display_name, $user->getId(), $option_attributes);
  160. } // foreach
  161. if (count($options)) {
  162. $all_options[] = option_group_tag($company->getName(), $options);
  163. } // if
  164. }
  165. } // foreach
  166. } // if
  167. return select_box($name, $all_options, $attributes);
  168. } // select_project_user
  169. /**
  170. * Renders select project box
  171. *
  172. * @param string $name
  173. * @param Project $project
  174. * @param integer $selected ID of selected milestone
  175. * @param array $attributes Array of additional attributes
  176. * @return string
  177. * @throws InvalidInstanceError
  178. */
  179. function select_project($name, $projectname = null, $selected = null, $attributes = null) {
  180. if (is_array($attributes)) {
  181. if (!isset($attributes['class'])) {
  182. $attributes['class'] = 'select_project';
  183. }
  184. } else {
  185. $attributes = array('class' => 'select_project');
  186. } // if
  187. $options = array(option_tag(lang('none'), 0));
  188. if (logged_user()->isAdministrator()) {
  189. $projects = Projects::getAll();
  190. } else {
  191. $projects = logged_user()->getActiveProjects();
  192. }
  193. if (is_array($projects)) {
  194. foreach ($projects as $project) {
  195. $option_attributes = $project->getId() == $selected ? array('selected' => 'selected') : null;
  196. $options[] = option_tag($project->getName(), $project->getId(), $option_attributes);
  197. } // foreach
  198. } // if
  199. return select_box($name, $options, $attributes);
  200. } // select_milestone
  201. /**
  202. * Render select assignee box
  203. *
  204. * @param string $name Name of the widget
  205. * @param array $assignees
  206. * @param integer $selected ID of selected assignee
  207. * @param array $attributes Additional attributes
  208. * @return string
  209. */
  210. function select_assignee($name, $assignees = null, $selected = null, $attributes = null) {
  211. if (!is_array($assignees)) {
  212. return '';
  213. } // if
  214. if (is_array($attributes)) {
  215. if (!isset($attributes['class'])) {
  216. $attributes['class'] = 'select_assignee';
  217. } // if
  218. } else {
  219. $attributes = array('class' => 'select_assignee');
  220. } // if
  221. $options = array();
  222. $option_attributes = ('all' == $selected ? array('selected' => 'selected') : null);
  223. $options[] = option_tag(lang('all'), 'all', $option_attributes);
  224. $option_attributes = ('0:0' == $selected ? array('selected' => 'selected') : null);
  225. $options[] = option_tag(lang('unassigned'), '0:0', $option_attributes);
  226. if (is_array($assignees)) {
  227. foreach ($assignees as $assignee) {
  228. $option_attributes = ($assignee->getId() == $selected ? array('selected' => 'selected') : null);
  229. $display_name = $assignee->getObjectName().($assignee->getId() == logged_user()->getId() ? ' ('.lang('you').')' : '');
  230. $options[] = option_tag($display_name, $assignee->getId(), $option_attributes);
  231. } // foreach
  232. }
  233. return select_box($name, $options, $attributes);
  234. } // select_assignee
  235. /**
  236. * Render assign to SELECT
  237. *
  238. * @param string $list_name Name of the select control
  239. * @param Project $project Selected project, if NULL active project will be used
  240. * @param integer $selected ID of selected user
  241. * @param array $attributes Array of select box attributes, if needed
  242. * @return null
  243. */
  244. function assign_to_select_box($list_name, $project = null, $selected = null, $attributes = null) {
  245. if (is_null($project)) {
  246. $project = active_project();
  247. } // if
  248. if (!($project instanceof Project)) {
  249. throw new InvalidInstanceError('$project', $project, 'Project');
  250. } // if
  251. $logged_user = logged_user();
  252. $can_assign_to_owners = $logged_user->isMemberOfOwnerCompany() || $logged_user->getProjectPermission($project, PermissionManager::CAN_ASSIGN_TO_OWNERS);
  253. $can_assign_to_other = $logged_user->isMemberOfOwnerCompany() || $logged_user->getProjectPermission($project, PermissionManager::CAN_ASSIGN_TO_OTHER);
  254. $grouped_users = $project->getUsers(true);
  255. $options = array(option_tag(lang('anyone'), '0:0'));
  256. if (is_array($grouped_users) && count($grouped_users)) {
  257. foreach ($grouped_users as $company_id => $users) {
  258. $company = Companies::findById($company_id);
  259. if (!($company instanceof Company)) {
  260. continue;
  261. } // if
  262. // Check if $logged_user can assign task to members of this company
  263. if ($company_id <> $logged_user->getCompanyId()) {
  264. if ($company->isOwner()) {
  265. if (!$can_assign_to_owners) {
  266. continue;
  267. } // if
  268. } else {
  269. if (!$can_assign_to_other) {
  270. continue;
  271. } // if
  272. } // if
  273. } // if
  274. $options[] = option_tag('--', '0:0'); // separator
  275. $option_attributes = $company->getId() . ':0' == $selected ? array('selected' => 'selected') : null;
  276. $options[] = option_tag($company->getName(), $company_id . ':0', $option_attributes);
  277. if (is_array($users)) {
  278. foreach ($users as $user) {
  279. $option_attributes = $company_id . ':' . $user->getId() == $selected ? array('selected' => 'selected') : null;
  280. $options[] = option_tag($company->getName() . ': ' . $user->getDisplayName(), $company_id . ':' . $user->getId(), $option_attributes);
  281. } // foreach
  282. } // if
  283. } // foreach
  284. } // if
  285. return select_box($list_name, $options, $attributes);
  286. } // assign_to_select_box
  287. /**
  288. * Renders select milestone box
  289. *
  290. * @param string $name
  291. * @param Project $project
  292. * @param integer $selected ID of selected milestone
  293. * @param array $attributes Array of additional attributes
  294. * @return string
  295. * @throws InvalidInstanceError
  296. */
  297. function select_milestone($name, $project = null, $selected = null, $attributes = null) {
  298. if (is_null($project)) {
  299. $project = active_project();
  300. }
  301. if (!($project instanceof Project)) {
  302. throw new InvalidInstanceError('$project', $project, 'Project');
  303. }
  304. if (is_array($attributes)) {
  305. if (!isset($attributes['class'])) {
  306. $attributes['class'] = 'select_milestone';
  307. }
  308. } else {
  309. $attributes = array('class' => 'select_milestone');
  310. } // if
  311. $options = array(option_tag(lang('none'), 0));
  312. $milestones = $project->getOpenMilestones();
  313. if (is_array($milestones)) {
  314. foreach ($milestones as $milestone) {
  315. $option_attributes = $milestone->getId() == $selected ? array('selected' => 'selected') : null;
  316. //$options[] = option_tag($milestone->getName(), $milestone->getId(), $option_attributes);
  317. $options[] = option_tag($milestone->getName()." (".format_date($milestone->getDueDate()).")", $milestone->getId(), $option_attributes);
  318. } // foreach
  319. } // if
  320. return select_box($name, $options, $attributes);
  321. } // select_milestone
  322. /**
  323. * Render select task list box
  324. *
  325. * @param string $name Form control name
  326. * @param Project $project
  327. * @param integer $selected ID of selected object
  328. * @param boolean $open_only List only active task lists (skip completed)
  329. * @param array $attach_data Additional attributes
  330. * @return string
  331. */
  332. function select_task_list($name, $project = null, $selected = null, $open_only = false, $attributes = null) {
  333. if (is_null($project)) {
  334. $project = active_project();
  335. }
  336. if (!($project instanceof Project)) {
  337. throw new InvalidInstanceError('$project', $project, 'Project');
  338. }
  339. if (is_array($attributes)) {
  340. if (!isset($attributes['class'])) {
  341. $attributes['class'] = 'select_task_list';
  342. }
  343. } else {
  344. $attributes = array('class' => 'select_task_list');
  345. } // if
  346. $options = array(option_tag(lang('none'), 0));
  347. $task_lists = $open_only ? $project->getOpenTaskLists() : $project->getTaskLists();
  348. if (is_array($task_lists)) {
  349. foreach ($task_lists as $task_list) {
  350. $option_attributes = $task_list->getId() == $selected ? array('selected' => 'selected') : null;
  351. $options[] = option_tag($task_list->getName(), $task_list->getId(), $option_attributes);
  352. } // foreach
  353. } // if
  354. return select_box($name, $options, $attributes);
  355. } // select_task_list
  356. /**
  357. * Return select message control
  358. *
  359. * @param string $name Control name
  360. * @param Project $project
  361. * @param integer $selected ID of selected message
  362. * @param array $attributes Additional attributes
  363. * @return string
  364. */
  365. function select_message($name, $project = null, $selected = null, $attributes = null) {
  366. if (is_null($project)) {
  367. $project = active_project();
  368. }
  369. if (!($project instanceof Project)) {
  370. throw new InvalidInstanceError('$project', $project, 'Project');
  371. }
  372. if (is_array($attributes)) {
  373. if (!isset($attributes['class'])) {
  374. $attributes['class'] = 'select_message';
  375. }
  376. } else {
  377. $attributes = array('class' => 'select_message');
  378. } // if
  379. $options = array(option_tag(lang('none'), 0));
  380. $messages = $project->getMessages();
  381. if (is_array($messages)) {
  382. foreach ($messages as $message) {
  383. $option_attributes = $message->getId() == $selected ? array('selected' => 'selected') : null;
  384. $options[] = option_tag($message->getTitle(), $message->getId(), $option_attributes);
  385. } // foreach
  386. } // if
  387. return select_box($name, $options, $attributes);
  388. } // select_message
  389. /**
  390. * Return select ticket control
  391. *
  392. * @param string $name Control name
  393. * @param Project $project
  394. * @param integer $selected ID of selected ticket
  395. * @param array $attributes Additional attributes
  396. * @return string
  397. */
  398. function select_ticket($name, $project = null, $selected = null, $attributes = null) {
  399. if (is_null($project)) {
  400. $project = active_project();
  401. }
  402. if (!($project instanceof Project)) {
  403. throw new InvalidInstanceError('$project', $project, 'Project');
  404. }
  405. if (is_array($attributes)) {
  406. if (!isset($attributes['class'])) {
  407. $attributes['class'] = 'select_ticket';
  408. }
  409. } else {
  410. $attributes = array('class' => 'select_ticket');
  411. } // if
  412. $options = array(option_tag(lang('none'), 0));
  413. $tickets = $project->getTickets();
  414. if (is_array($tickets)) {
  415. foreach ($tickets as $ticket) {
  416. $option_attributes = $ticket->getId() == $selected ? array('selected' => 'selected') : null;
  417. $options[] = option_tag($ticket->getTitle(), $ticket->getId(), $option_attributes);
  418. } // foreach
  419. } // if
  420. return select_box($name, $options, $attributes);
  421. } // select_ticket
  422. /**
  423. * Return project object tags widget
  424. *
  425. * @param string $name
  426. * @param Project $project
  427. * @param string $value
  428. * @Param array $attributes Array of control attributes
  429. * @return string
  430. */
  431. function project_object_tags_widget($name, Project $project, $value, $attributes) {
  432. return text_field($name, $value, $attributes) . '<br /><span class="desc">' . lang('tags widget description') . '</span>';
  433. } // project_object_tag_widget
  434. /**
  435. * Render comma separated tags of specific object that link on project tag page
  436. *
  437. * @param ProjectDataObject $object
  438. * @param Project $project
  439. * @return string
  440. */
  441. function project_object_tags(ProjectDataObject $object, Project $project) {
  442. $tag_names = $object->getTagNames();
  443. if (!is_array($tag_names) || !count($tag_names)) {
  444. return '--';
  445. }
  446. $links = array();
  447. foreach ($tag_names as $tag_name) {
  448. $links[] = '<a href="' . $project->getTagUrl($tag_name) . '">' . clean($tag_name) . '</a>';
  449. } // foreach
  450. return implode(', ', $links);
  451. } // project_object_tags
  452. /**
  453. * Show object comments block
  454. *
  455. * @param ProjectDataObject $object Show comments of this object
  456. * @return null
  457. */
  458. function render_object_comments(ProjectDataObject $object) {
  459. if (!$object->isCommentable()) {
  460. return '';
  461. }
  462. tpl_assign('__comments_object', $object);
  463. return tpl_fetch(get_template_path('object_comments', 'comment'));
  464. } // render_object_comments
  465. /**
  466. * Render post comment form for specific project object
  467. *
  468. * @param ProjectDataObject $object
  469. * @param string $redirect_to
  470. * @return string
  471. */
  472. function render_comment_form(ProjectDataObject $object) {
  473. $comment = new Comment();
  474. tpl_assign('comment_form_comment', $comment);
  475. tpl_assign('comment_form_object', $object);
  476. return tpl_fetch(get_template_path('post_comment_form', 'comment'));
  477. } // render_post_comment_form
  478. /**
  479. * Show object comments block in short form
  480. * Status updates are just comments displayed in a short form
  481. *
  482. * @param ProjectDataObject $object Show comments of this object
  483. * @return null
  484. */
  485. function render_object_status_updates(ProjectDataObject $object) {
  486. if (!$object->isCommentable()) {
  487. return '';
  488. }
  489. tpl_assign('__comments_object', $object);
  490. return tpl_fetch(get_template_path('object_statuses', 'comment'));
  491. } // render_object_status_updates
  492. /**
  493. * Render post comment form for specific project object in short form
  494. * Status updates are just comments displayed in a short form
  495. *
  496. * @param ProjectDataObject $object
  497. * @return string
  498. */
  499. function render_status_update_form(ProjectDataObject $object) {
  500. $comment = new Comment();
  501. tpl_assign('comment_form_comment', $comment);
  502. tpl_assign('comment_form_object', $object);
  503. return tpl_fetch(get_template_path('post_status_update_form', 'comment'));
  504. } // render_status_update_form
  505. /**
  506. * This function will render the code for file attachment section of the form. Note that
  507. * this need to be part of the existing form
  508. *
  509. * @param string $prefix File input name prefix
  510. * @param integer $max_controls Max number of controls
  511. * @return string
  512. */
  513. function render_attach_files($prefix = 'attach_files', $max_controls = 5) {
  514. if (!plugin_active('files')) {
  515. return '';
  516. }
  517. static $ids = array();
  518. static $js_included = false;
  519. $attach_files_id = 0;
  520. do {
  521. $attach_files_id++;
  522. } while (in_array($attach_files_id, $ids));
  523. $old_js_included = $js_included;
  524. $js_included = true;
  525. tpl_assign('attach_files_js_included', $old_js_included);
  526. tpl_assign('attach_files_id', $attach_files_id);
  527. tpl_assign('attach_files_prefix', $prefix);
  528. tpl_assign('attach_files_max_controls', (integer) $max_controls);
  529. return tpl_fetch(get_template_path('attach_files', 'files'));
  530. } // render_attach_files
  531. /**
  532. * List all fields attached to specific object
  533. *
  534. * @param ProjectDataObject $object
  535. * @param boolean $can_remove Logged user can remove attached files
  536. * @return string
  537. */
  538. function render_object_files(ProjectDataObject $object, $can_remove = false) {
  539. if (plugin_active('files')) {
  540. tpl_assign('attached_files_object', $object);
  541. tpl_assign('attached_files', $object->getAttachedFiles());
  542. return tpl_fetch(get_template_path('list_attached_files', 'files'));
  543. }
  544. return '';
  545. } // render_object_files
  546. /**
  547. * List briefly all files attached to specific object
  548. *
  549. * @param ProjectDataObject $object
  550. * @param boolean $can_remove Logged user can remove attached files
  551. * @return string
  552. */
  553. function render_object_files_brief(ProjectDataObject $object, $can_remove = false) {
  554. if (plugin_active('files')) {
  555. tpl_assign('attached_files_object', $object);
  556. tpl_assign('attached_files', $object->getAttachedFiles());
  557. return tpl_fetch(get_template_path('brief_list_attached_files', 'files'));
  558. }
  559. return '';
  560. } // render_object_files
  561. /**
  562. * Render the tags of a specific object
  563. *
  564. * @param ProjectDataObject $object
  565. * @return string
  566. */
  567. function render_object_tags(ProjectDataObject $object) {
  568. if (plugin_active('tags')) {
  569. tpl_assign('object', $object);
  570. //tpl_assign('tags', $object->getTags());
  571. return tpl_fetch(get_template_path('object_tags', 'tags'));
  572. }
  573. return '';
  574. } // render_tags
  575. /**
  576. * Render the options available for the given object
  577. *
  578. * @param ProjectDataObject $object
  579. * @return string
  580. */
  581. function render_object_options(ProjectDataObject $object, $additional_options = null) {
  582. $options = array();
  583. if ($object->canEdit(logged_user())) {
  584. $options[] = '<a href="' . $object->getEditUrl() . '">' . lang('edit') . '</a>';
  585. } // if
  586. if ($object->canView(logged_user())) {
  587. $options[] = '<a href="' . $object->getViewUrl() . '">' . lang('view') . '</a>';
  588. } // if
  589. if ($object->canDelete(logged_user())) {
  590. $options[] = '<a href="' . $object->getDeleteUrl() . '">' . lang('delete') . '</a>';
  591. } // if
  592. if (is_array($additional_options)) {
  593. $options = array_merge( $options, $additional_options );
  594. }
  595. if (count($options)) {
  596. tpl_assign('options', $options);
  597. return tpl_fetch(get_template_path('object_options', 'application'));
  598. }
  599. return '';
  600. } // render_options
  601. /**
  602. * Render application logs
  603. *
  604. * This helper will render array of log entries. Options array of is array of template options and it can have this
  605. * fields:
  606. *
  607. * - show_project_column - When we are on project dashboard we don't actually need to display project column because
  608. * all entries are related with current project. That is not the situation on dashboard so we want to have the
  609. * control over this. This option is true by default
  610. *
  611. * @param array $log_entries
  612. * @return null
  613. */
  614. function render_application_logs($log_entries, $options = null) {
  615. if (config_option('display_application_logs', true)) {
  616. tpl_assign('application_logs_entries', $log_entries);
  617. tpl_assign('application_logs_show_project_column', array_var($options, 'show_project_column', true));
  618. return tpl_fetch(get_template_path('render_application_logs', 'application'));
  619. }
  620. return '';
  621. } // render_application_logs
  622. /**
  623. * Render one project's application logs
  624. *
  625. * This helper will render array of log entries.
  626. *
  627. * @param array $project The project.
  628. * @param array $log_entries An array of entries for this project.
  629. * @return null
  630. */
  631. function render_project_application_logs($project, $log_entries) {
  632. if (config_option('display_application_logs', true)) {
  633. tpl_assign('application_logs_project', $project);
  634. tpl_assign('application_logs_entries', $log_entries);
  635. return tpl_fetch(get_template_path('render_project_application_logs', 'application'));
  636. }
  637. return '';
  638. } // render_application_logs
  639. /**
  640. * Render text that says when action was taken and by who
  641. *
  642. * @param ApplicationLog $application_log_entry
  643. * @return string
  644. */
  645. function render_action_taken_on_by(ApplicationLog $application_log_entry) {
  646. if ($application_log_entry->isToday()) {
  647. $result = lang('today') . ' ' . clean(format_time($application_log_entry->getCreatedOn()));
  648. } elseif ($application_log_entry->isYesterday()) {
  649. $result = lang('yesterday') . ' ' . clean(format_time($application_log_entry->getCreatedOn()));
  650. } else {
  651. $result = clean(format_date($application_log_entry->getCreatedOn()));
  652. } // if
  653. $result = "<span class=\"logTakenOn\">$result</span></td><td><span class=\"logBy\">";
  654. $taken_by = $application_log_entry->getTakenBy();
  655. return $taken_by instanceof User ? $result . '<a href="' . $taken_by->getCardUrl() . '">' . clean($taken_by->getDisplayName()) . '</a></span>' : $result . '</span>';
  656. } // render_action_taken_on
  657. ?>