PageRenderTime 26ms CodeModel.GetById 18ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/max/Dal/DataObjects/Banners.php

https://github.com/orchestra-io/sample-openx
PHP | 322 lines | 187 code | 31 blank | 104 comment | 19 complexity | 380298fbc84e60e6cfbf9d86bd112794 MD5 | raw file
  1. <?php
  2. /*
  3. +---------------------------------------------------------------------------+
  4. | OpenX v${RELEASE_MAJOR_MINOR} |
  5. | =======${RELEASE_MAJOR_MINOR_DOUBLE_UNDERLINE} |
  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: Banners.php 44998 2009-10-20 16:15:30Z matthieu.aubry $
  25. */
  26. /**
  27. * Table Definition for banners
  28. */
  29. require_once 'DB_DataObjectCommon.php';
  30. include_once MAX_PATH . '/www/admin/lib-banner.inc.php';
  31. include_once MAX_PATH . '/www/admin/lib-storage.inc.php';
  32. class DataObjects_Banners extends DB_DataObjectCommon
  33. {
  34. var $onDeleteCascade = true;
  35. var $refreshUpdatedFieldIfExists = true;
  36. /*
  37. * Define Market banner ext_bannertype field value
  38. */
  39. const BANNER_TYPE_MARKET = 'market-optin-banner';
  40. ###START_AUTOCODE
  41. /* the code below is auto generated do not remove the above tag */
  42. public $__table = 'banners'; // table name
  43. public $bannerid; // MEDIUMINT(9) => openads_mediumint => 129
  44. public $campaignid; // MEDIUMINT(9) => openads_mediumint => 129
  45. public $contenttype; // ENUM('gif','jpeg','png','html','swf','dcr','rpm','mov','txt') => openads_enum => 130
  46. public $pluginversion; // MEDIUMINT(9) => openads_mediumint => 129
  47. public $storagetype; // ENUM('sql','web','url','html','network','txt') => openads_enum => 130
  48. public $filename; // VARCHAR(255) => openads_varchar => 130
  49. public $imageurl; // VARCHAR(255) => openads_varchar => 130
  50. public $htmltemplate; // TEXT() => openads_text => 162
  51. public $htmlcache; // TEXT() => openads_text => 162
  52. public $width; // SMALLINT(6) => openads_smallint => 129
  53. public $height; // SMALLINT(6) => openads_smallint => 129
  54. public $weight; // TINYINT(4) => openads_tinyint => 129
  55. public $seq; // TINYINT(4) => openads_tinyint => 129
  56. public $target; // VARCHAR(16) => openads_varchar => 130
  57. public $url; // TEXT() => openads_text => 162
  58. public $alt; // VARCHAR(255) => openads_varchar => 130
  59. public $statustext; // VARCHAR(255) => openads_varchar => 130
  60. public $bannertext; // TEXT() => openads_text => 162
  61. public $description; // VARCHAR(255) => openads_varchar => 130
  62. public $adserver; // VARCHAR(255) => openads_varchar => 130
  63. public $block; // INT(11) => openads_int => 129
  64. public $capping; // INT(11) => openads_int => 129
  65. public $session_capping; // INT(11) => openads_int => 129
  66. public $compiledlimitation; // TEXT() => openads_text => 162
  67. public $acl_plugins; // TEXT() => openads_text => 34
  68. public $append; // TEXT() => openads_text => 162
  69. public $bannertype; // TINYINT(4) => openads_tinyint => 129
  70. public $alt_filename; // VARCHAR(255) => openads_varchar => 130
  71. public $alt_imageurl; // VARCHAR(255) => openads_varchar => 130
  72. public $alt_contenttype; // ENUM('gif','jpeg','png') => openads_enum => 130
  73. public $comments; // TEXT() => openads_text => 34
  74. public $updated; // DATETIME() => openads_datetime => 142
  75. public $acls_updated; // DATETIME() => openads_datetime => 142
  76. public $keyword; // VARCHAR(255) => openads_varchar => 130
  77. public $transparent; // TINYINT(1) => openads_tinyint => 145
  78. public $parameters; // TEXT() => openads_text => 34
  79. public $an_banner_id; // INT(11) => openads_int => 1
  80. public $as_banner_id; // INT(11) => openads_int => 1
  81. public $status; // INT(11) => openads_int => 129
  82. public $ad_direct_status; // TINYINT(4) => openads_tinyint => 129
  83. public $ad_direct_rejection_reason_id; // TINYINT(4) => openads_tinyint => 129
  84. public $ext_bannertype; // VARCHAR(255) => openads_varchar => 2
  85. public $prepend; // TEXT() => openads_text => 162
  86. /* Static get */
  87. function staticGet($k,$v=NULL) { return DB_DataObject::staticGet('DataObjects_Banners',$k,$v); }
  88. var $defaultValues = array(
  89. 'campaignid' => 0,
  90. 'contenttype' => 'gif',
  91. 'pluginversion' => 0,
  92. 'storagetype' => 'sql',
  93. 'filename' => '',
  94. 'imageurl' => '',
  95. 'htmltemplate' => '',
  96. 'htmlcache' => '',
  97. 'width' => 0,
  98. 'height' => 0,
  99. 'weight' => 1,
  100. 'seq' => 0,
  101. 'target' => '',
  102. 'url' => '',
  103. 'alt' => '',
  104. 'statustext' => '',
  105. 'bannertext' => '',
  106. 'description' => '',
  107. 'adserver' => '',
  108. 'block' => 0,
  109. 'capping' => 0,
  110. 'session_capping' => 0,
  111. 'compiledlimitation' => '',
  112. 'append' => '',
  113. 'bannertype' => 0,
  114. 'alt_filename' => '',
  115. 'alt_imageurl' => '',
  116. 'alt_contenttype' => 'gif',
  117. 'updated' => '%DATE_TIME%',
  118. 'acls_updated' => '%NO_DATE_TIME%',
  119. 'keyword' => '',
  120. 'transparent' => 0,
  121. 'status' => 0,
  122. 'ad_direct_status' => 0,
  123. 'ad_direct_rejection_reason_id' => 0,
  124. 'prepend' => '',
  125. );
  126. /* the code above is auto generated do not remove the tag below */
  127. ###END_AUTOCODE
  128. function delete($useWhere = false, $cascade = true, $parentid = null)
  129. {
  130. $doBanner = clone($this);
  131. $doBanner->find();
  132. while ($doBanner->fetch()) {
  133. $this->deleteBannerFile($doBanner->storagetype, $doBanner->filename);
  134. }
  135. return parent::delete($useWhere, $cascade, $parentid);
  136. }
  137. /**
  138. * A method to delete the banner file.
  139. *
  140. * @param string $storageType The storage type of the banner to delete
  141. * @param string $fileName The name of the banner file to be deleted
  142. */
  143. function deleteBannerFile($storageType, $fileName) {
  144. if ($storageType == 'web') {
  145. $doBanner = OA_Dal::factoryDO('banners');
  146. $doBanner->filename = $fileName;
  147. $doBanner->find();
  148. // If there is only a banner using the same file delete the file
  149. if ($doBanner->getRowCount() == 1) {
  150. phpAds_ImageDelete ($storageType, $fileName);
  151. }
  152. } else {
  153. phpAds_ImageDelete ($storageType, $fileName);
  154. }
  155. }
  156. /**
  157. * Duplicates the banner.
  158. * @param string $new_campaignId only when the banner is
  159. * duplicated as consequence of a campaign duplication
  160. * @return int the new bannerid
  161. *
  162. */
  163. function duplicate($new_campaignId = null)
  164. {
  165. // unset the bannerId
  166. $old_adId = $this->bannerid;
  167. unset($this->bannerid);
  168. $this->description = $GLOBALS['strCopyOf'] . ' ' . $this->description;
  169. if ($new_campaignId != null) {
  170. $this->campaignid = $new_campaignId;
  171. }
  172. // Set the filename
  173. // We want to rename column 'storagetype' to 'type' so...
  174. if ($this->storagetype == 'web' || $this->storagetype == 'sql') {
  175. $this->filename = $this->_imageDuplicate($this->storagetype, $this->filename);
  176. } elseif ($this->type == 'web' || $this->type == 'sql') {
  177. $this->filename = $this->_imageDuplicate($this->type, $this->filename);
  178. }
  179. // Insert the new banner and get the ID
  180. $new_adId = $this->insert(false);
  181. // Copy ACLs and capping
  182. MAX_AclCopy(basename($_SERVER['SCRIPT_NAME']), $old_adId, $new_adId);
  183. // Duplicate and ad-zone associations
  184. MAX_duplicateAdZones($old_adId, $new_adId);
  185. // Return the new bannerId
  186. return $new_adId;
  187. }
  188. function insert($autoLinkMatchingZones = true)
  189. {
  190. $this->_rebuildCache();
  191. $id = parent::insert();
  192. if ($id) {
  193. // add default zone
  194. $aVariables = array('ad_id' => $id, 'zone_id' => 0);
  195. Admin_DA::addAdZone($aVariables);
  196. if ($autoLinkMatchingZones) {
  197. MAX_addDefaultPlacementZones($id, $this->campaignid);
  198. }
  199. }
  200. return $id;
  201. }
  202. function _rebuildCache()
  203. {
  204. if (!is_null($this->htmltemplate)) {
  205. $this->htmlcache = phpAds_getBannerCache($this->toArray());
  206. }
  207. }
  208. /**
  209. * Automatically refreshes HTML cache in addition to normal
  210. * update() call.
  211. *
  212. * @see DB_DataObject::update()
  213. * @param object $dataObject
  214. * @return boolean
  215. * @access public
  216. */
  217. function update($dataObject = false)
  218. {
  219. $this->_rebuildCache();
  220. return parent::update($dataObject);
  221. }
  222. /**
  223. * Wrapper for phpAds_ImageDuplicate
  224. *
  225. * @access private
  226. */
  227. function _imageDuplicate($storagetype, $filename)
  228. {
  229. return phpAds_ImageDuplicate($storagetype, $filename);
  230. }
  231. function _auditEnabled()
  232. {
  233. return true;
  234. }
  235. function _getContextId()
  236. {
  237. return $this->bannerid;
  238. }
  239. function _getContext()
  240. {
  241. return 'Banner';
  242. }
  243. /**
  244. * A method to return an array of account IDs of the account(s) that
  245. * should "own" any audit trail entries for this entity type; these
  246. * are NOT related to the account ID of the currently active account
  247. * (which is performing some kind of action on the entity), but is
  248. * instead related to the type of entity, and where in the account
  249. * heirrachy the entity is located.
  250. *
  251. * @return array An array containing up to three indexes:
  252. * - "OA_ACCOUNT_ADMIN" or "OA_ACCOUNT_MANAGER":
  253. * Contains the account ID of the manager account
  254. * that needs to be able to see the audit trail
  255. * entry, or, the admin account, if the entity
  256. * is a special case where only the admin account
  257. * should see the entry.
  258. * - "OA_ACCOUNT_ADVERTISER":
  259. * Contains the account ID of the advertiser account
  260. * that needs to be able to see the audit trail
  261. * entry, if such an account exists.
  262. * - "OA_ACCOUNT_TRAFFICKER":
  263. * Contains the account ID of the trafficker account
  264. * that needs to be able to see the audit trail
  265. * entry, if such an account exists.
  266. */
  267. function getOwningAccountIds()
  268. {
  269. // Banners don't have an account_id, get it from the parent
  270. // campaign (stored in the "campaigns" table) using the
  271. // "campaignid" key
  272. return parent::getOwningAccountIds('campaigns', 'campaignid');
  273. }
  274. /**
  275. * build a campaign specific audit array
  276. *
  277. * @param integer $actionid
  278. * @param array $aAuditFields
  279. */
  280. function _buildAuditArray($actionid, &$aAuditFields)
  281. {
  282. $aAuditFields['key_desc'] = $this->description;
  283. switch ($actionid)
  284. {
  285. case OA_AUDIT_ACTION_UPDATE:
  286. $aAuditFields['campaignid'] = $this->campaignid;
  287. break;
  288. }
  289. }
  290. }
  291. ?>