/lib/max/Dal/DataObjects/Audit.php

https://bitbucket.org/blackriver/openx · PHP · 138 lines · 74 code · 12 blank · 52 comment · 24 complexity · c5760997c8c0ae4293a5b5c6f9e9341b MD5 · raw file

  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v2.8 |
  5. | ========== |
  6. | |
  7. | Copyright (c) 2003-2009 OpenX Limited |
  8. | For contact details, see: http://www.openx.org/ |
  9. | |
  10. | This program is free software; you can redistribute it and/or modify |
  11. | it under the terms of the GNU General Public License as published by |
  12. | the Free Software Foundation; either version 2 of the License, or |
  13. | (at your option) any later version. |
  14. | |
  15. | This program is distributed in the hope that it will be useful, |
  16. | but WITHOUT ANY WARRANTY; without even the implied warranty of |
  17. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
  18. | GNU General Public License for more details. |
  19. | |
  20. | You should have received a copy of the GNU General Public License |
  21. | along with this program; if not, write to the Free Software |
  22. | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
  23. +---------------------------------------------------------------------------+
  24. $Id: Audit.php 81772 2012-09-11 00:07:29Z chris.nutting $
  25. */
  26. /**
  27. * Table Definition for audit
  28. */
  29. define('OA_AUDIT_ACTION_INSERT',1);
  30. define('OA_AUDIT_ACTION_UPDATE',2);
  31. define('OA_AUDIT_ACTION_DELETE',3);
  32. require_once 'DB_DataObjectCommon.php';
  33. class DataObjects_Audit extends DB_DataObjectCommon
  34. {
  35. ###START_AUTOCODE
  36. /* the code below is auto generated do not remove the above tag */
  37. public $__table = 'audit'; // table name
  38. public $auditid; // MEDIUMINT(9) => openads_mediumint => 129
  39. public $actionid; // MEDIUMINT(9) => openads_mediumint => 129
  40. public $context; // VARCHAR(255) => openads_varchar => 130
  41. public $contextid; // MEDIUMINT(9) => openads_mediumint => 1
  42. public $parentid; // MEDIUMINT(9) => openads_mediumint => 1
  43. public $details; // TEXT() => openads_text => 162
  44. public $userid; // MEDIUMINT(9) => openads_mediumint => 129
  45. public $username; // VARCHAR(64) => openads_varchar => 2
  46. public $usertype; // TINYINT(4) => openads_tinyint => 129
  47. public $updated; // DATETIME() => openads_datetime => 14
  48. public $account_id; // MEDIUMINT(9) => openads_mediumint => 129
  49. public $advertiser_account_id; // MEDIUMINT(9) => openads_mediumint => 1
  50. public $website_account_id; // MEDIUMINT(9) => openads_mediumint => 1
  51. /* Static get */
  52. function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Audit',$k,$v); }
  53. var $defaultValues = array(
  54. 'context' => '',
  55. 'details' => '',
  56. 'userid' => 0,
  57. 'usertype' => 0,
  58. 'advertiser_account_id' => OX_DATAOBJECT_NULL,
  59. 'website_account_id' => OX_DATAOBJECT_NULL,
  60. );
  61. /* the code above is auto generated do not remove the tag below */
  62. ###END_AUTOCODE
  63. /**
  64. * The belongsToAccount() method behaves in a different way when looking
  65. * at entries in the "audit" table. To check if an account has access
  66. * to view specific audit data, we only need to check if the account's
  67. * ID is set in the appropriate column in the record.
  68. *
  69. * @param string $accountId The account ID to test if this DB_DataObject is
  70. * owned by.
  71. * @return boolean|null Returns true if the entity belongs to the specified
  72. * account, false if doesn't, or null if it was not
  73. * possible to find the required object references.
  74. */
  75. function belongsToAccount($accountId = null)
  76. {
  77. // Set the account ID, if not passed in
  78. if (empty($accountId)) {
  79. $accountId = OA_Permission::getAccountId();
  80. }
  81. // Prepare $this with the required info of the "entity" to be tested
  82. if (!$this->N) {
  83. $key = $this->getFirstPrimaryKey();
  84. if (empty($this->$key)) {
  85. MAX::raiseError('Key on object is not set, table: '.$this->getTableWithoutPrefix());
  86. return null;
  87. }
  88. if (!$this->find($autoFetch = true)) {
  89. return null;
  90. }
  91. }
  92. // Test the account ID type, and then test for access
  93. $accountType = OA_Permission::getAccountTypeByAccountId($accountId);
  94. // Test the access to the audit trail entry
  95. if ($accountType == OA_ACCOUNT_ADMIN) {
  96. // Admin always has access
  97. return true;
  98. } else if ($accountType == OA_ACCOUNT_MANAGER) {
  99. // Test if the account ID is equal to the account_id field
  100. if (is_null($this->account_id)) {
  101. return null;
  102. }
  103. if ($this->account_id == $accountId) {
  104. return true;
  105. }
  106. } else if ($accountType == OA_ACCOUNT_ADVERTISER) {
  107. // Test if the account ID is equal to the advertiser_account_id field
  108. if (is_null($this->advertiser_account_id)) {
  109. return null;
  110. }
  111. if ($this->advertiser_account_id == $accountId) {
  112. return true;
  113. }
  114. } else if ($accountType == OA_ACCOUNT_TRAFFICKER) {
  115. // Test if the account ID is equal to the website_account_id field
  116. if (is_null($this->website_account_id)) {
  117. return null;
  118. }
  119. if ($this->website_account_id == $accountId) {
  120. return true;
  121. }
  122. }
  123. return false;
  124. }
  125. }
  126. ?>