Controller_Commit.class.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. <?php
  2. /**
  3. * Controller for displaying a commit
  4. *
  5. * @author Christopher Han <xiphux@gmail.com>
  6. * @copyright Copyright (c) 2010 Christopher Han
  7. * @package GitPHP
  8. * @subpackage Controller
  9. */
  10. class GitPHP_Controller_Commit extends GitPHP_ControllerBase
  11. {
  12. /**
  13. * Initialize controller
  14. */
  15. public function Initialize()
  16. {
  17. parent::Initialize();
  18. if (empty($this->params['hash']))
  19. $this->params['hash'] = 'HEAD';
  20. if (!empty($this->params['output']) && ($this->params['output'] == 'jstip'))
  21. $this->DisableLogging();
  22. }
  23. /**
  24. * Gets the template for this controller
  25. *
  26. * @return string template filename
  27. */
  28. protected function GetTemplate()
  29. {
  30. if (isset($this->params['output']) && ($this->params['output'] == 'jstip')) {
  31. return 'committip.tpl';
  32. }
  33. return 'commit.tpl';
  34. }
  35. /**
  36. * Gets the cache key for this controller
  37. *
  38. * @return string cache key
  39. */
  40. protected function GetCacheKey()
  41. {
  42. return $this->params['hash'];
  43. }
  44. /**
  45. * Gets the name of this controller's action
  46. *
  47. * @param boolean $local true if caller wants the localized action name
  48. * @return string action name
  49. */
  50. public function GetName($local = false)
  51. {
  52. if ($local && $this->resource) {
  53. return $this->resource->translate('commit');
  54. }
  55. return 'commit';
  56. }
  57. /**
  58. * Loads data for this template
  59. */
  60. protected function LoadData()
  61. {
  62. $commit = $this->GetProject()->GetCommit($this->params['hash']);
  63. $this->tpl->assign('commit', $commit);
  64. $this->tpl->assign('tree', $commit->GetTree());
  65. $treediff = $commit->DiffToParent($this->exe);
  66. $treediff->SetRenames(true);
  67. $this->tpl->assign('treediff', $treediff);
  68. }
  69. }