/drupal/sites/all/modules/civicrm/CRM/Core/DAO/Email.php

https://github.com/michaellenahan/civicrm · PHP · 347 lines · 174 code · 0 blank · 173 comment · 10 complexity · 832e933695c70c9ceecb86238fb23657 MD5 · raw file

  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 3.3 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2010 |
  7. +--------------------------------------------------------------------+
  8. | This file is a part of CiviCRM. |
  9. | |
  10. | CiviCRM is free software; you can copy, modify, and distribute it |
  11. | under the terms of the GNU Affero General Public License |
  12. | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
  13. | |
  14. | CiviCRM is distributed in the hope that it will be useful, but |
  15. | WITHOUT ANY WARRANTY; without even the implied warranty of |
  16. | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
  17. | See the GNU Affero General Public License for more details. |
  18. | |
  19. | You should have received a copy of the GNU Affero General Public |
  20. | License and the CiviCRM Licensing Exception along |
  21. | with this program; if not, contact CiviCRM LLC |
  22. | at info[AT]civicrm[DOT]org. If you have questions about the |
  23. | GNU Affero General Public License or the licensing of CiviCRM, |
  24. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  25. +--------------------------------------------------------------------+
  26. */
  27. /**
  28. *
  29. * @package CRM
  30. * @copyright CiviCRM LLC (c) 2004-2010
  31. * $Id$
  32. *
  33. */
  34. require_once 'CRM/Core/DAO.php';
  35. require_once 'CRM/Utils/Type.php';
  36. class CRM_Core_DAO_Email extends CRM_Core_DAO
  37. {
  38. /**
  39. * static instance to hold the table name
  40. *
  41. * @var string
  42. * @static
  43. */
  44. static $_tableName = 'civicrm_email';
  45. /**
  46. * static instance to hold the field values
  47. *
  48. * @var array
  49. * @static
  50. */
  51. static $_fields = null;
  52. /**
  53. * static instance to hold the FK relationships
  54. *
  55. * @var string
  56. * @static
  57. */
  58. static $_links = null;
  59. /**
  60. * static instance to hold the values that can
  61. * be imported / apu
  62. *
  63. * @var array
  64. * @static
  65. */
  66. static $_import = null;
  67. /**
  68. * static instance to hold the values that can
  69. * be exported / apu
  70. *
  71. * @var array
  72. * @static
  73. */
  74. static $_export = null;
  75. /**
  76. * static value to see if we should log any modifications to
  77. * this table in the civicrm_log table
  78. *
  79. * @var boolean
  80. * @static
  81. */
  82. static $_log = true;
  83. /**
  84. * Unique Email ID
  85. *
  86. * @var int unsigned
  87. */
  88. public $id;
  89. /**
  90. * FK to Contact ID
  91. *
  92. * @var int unsigned
  93. */
  94. public $contact_id;
  95. /**
  96. * Which Location does this email belong to.
  97. *
  98. * @var int unsigned
  99. */
  100. public $location_type_id;
  101. /**
  102. * Email address
  103. *
  104. * @var string
  105. */
  106. public $email;
  107. /**
  108. * Is this the primary?
  109. *
  110. * @var boolean
  111. */
  112. public $is_primary;
  113. /**
  114. * Is this the billing?
  115. *
  116. * @var boolean
  117. */
  118. public $is_billing;
  119. /**
  120. * Is this address on bounce hold?
  121. *
  122. * @var boolean
  123. */
  124. public $on_hold;
  125. /**
  126. * Is this address for bulk mail ?
  127. *
  128. * @var boolean
  129. */
  130. public $is_bulkmail;
  131. /**
  132. * When the address went on bounce hold
  133. *
  134. * @var datetime
  135. */
  136. public $hold_date;
  137. /**
  138. * When the address bounce status was last reset
  139. *
  140. * @var datetime
  141. */
  142. public $reset_date;
  143. /**
  144. * Text formatted signature for the email.
  145. *
  146. * @var text
  147. */
  148. public $signature_text;
  149. /**
  150. * HTML formatted signature for the email.
  151. *
  152. * @var text
  153. */
  154. public $signature_html;
  155. /**
  156. * class constructor
  157. *
  158. * @access public
  159. * @return civicrm_email
  160. */
  161. function __construct()
  162. {
  163. parent::__construct();
  164. }
  165. /**
  166. * return foreign links
  167. *
  168. * @access public
  169. * @return array
  170. */
  171. function &links()
  172. {
  173. if (!(self::$_links)) {
  174. self::$_links = array(
  175. 'contact_id' => 'civicrm_contact:id',
  176. );
  177. }
  178. return self::$_links;
  179. }
  180. /**
  181. * returns all the column names of this table
  182. *
  183. * @access public
  184. * @return array
  185. */
  186. function &fields()
  187. {
  188. if (!(self::$_fields)) {
  189. self::$_fields = array(
  190. 'id' => array(
  191. 'name' => 'id',
  192. 'type' => CRM_Utils_Type::T_INT,
  193. 'required' => true,
  194. ) ,
  195. 'contact_id' => array(
  196. 'name' => 'contact_id',
  197. 'type' => CRM_Utils_Type::T_INT,
  198. 'FKClassName' => 'CRM_Contact_DAO_Contact',
  199. ) ,
  200. 'location_type_id' => array(
  201. 'name' => 'location_type_id',
  202. 'type' => CRM_Utils_Type::T_INT,
  203. ) ,
  204. 'email' => array(
  205. 'name' => 'email',
  206. 'type' => CRM_Utils_Type::T_STRING,
  207. 'title' => ts('Email') ,
  208. 'maxlength' => 64,
  209. 'size' => CRM_Utils_Type::BIG,
  210. 'import' => true,
  211. 'where' => 'civicrm_email.email',
  212. 'headerPattern' => '/e.?mail/i',
  213. 'dataPattern' => '/^[a-zA-Z][\w\.-]*[a-zA-Z0-9]@[a-zA-Z0-9][\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]$/',
  214. 'export' => true,
  215. 'rule' => 'email',
  216. ) ,
  217. 'is_primary' => array(
  218. 'name' => 'is_primary',
  219. 'type' => CRM_Utils_Type::T_BOOLEAN,
  220. ) ,
  221. 'is_billing' => array(
  222. 'name' => 'is_billing',
  223. 'type' => CRM_Utils_Type::T_BOOLEAN,
  224. ) ,
  225. 'on_hold' => array(
  226. 'name' => 'on_hold',
  227. 'type' => CRM_Utils_Type::T_BOOLEAN,
  228. 'title' => ts('On Hold') ,
  229. 'required' => true,
  230. 'export' => true,
  231. 'where' => 'civicrm_email.on_hold',
  232. 'headerPattern' => '',
  233. 'dataPattern' => '',
  234. ) ,
  235. 'is_bulkmail' => array(
  236. 'name' => 'is_bulkmail',
  237. 'type' => CRM_Utils_Type::T_BOOLEAN,
  238. 'title' => ts('Use for Bulk Mail') ,
  239. 'required' => true,
  240. 'export' => true,
  241. 'where' => 'civicrm_email.is_bulkmail',
  242. 'headerPattern' => '',
  243. 'dataPattern' => '',
  244. ) ,
  245. 'hold_date' => array(
  246. 'name' => 'hold_date',
  247. 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
  248. 'title' => ts('Hold Date') ,
  249. ) ,
  250. 'reset_date' => array(
  251. 'name' => 'reset_date',
  252. 'type' => CRM_Utils_Type::T_DATE + CRM_Utils_Type::T_TIME,
  253. 'title' => ts('Reset Date') ,
  254. ) ,
  255. 'signature_text' => array(
  256. 'name' => 'signature_text',
  257. 'type' => CRM_Utils_Type::T_TEXT,
  258. 'title' => ts('Signature Text') ,
  259. 'import' => true,
  260. 'where' => 'civicrm_email.signature_text',
  261. 'headerPattern' => '',
  262. 'dataPattern' => '',
  263. 'export' => true,
  264. 'default' => 'UL',
  265. ) ,
  266. 'signature_html' => array(
  267. 'name' => 'signature_html',
  268. 'type' => CRM_Utils_Type::T_TEXT,
  269. 'title' => ts('Signature Html') ,
  270. 'import' => true,
  271. 'where' => 'civicrm_email.signature_html',
  272. 'headerPattern' => '',
  273. 'dataPattern' => '',
  274. 'export' => true,
  275. 'default' => 'UL',
  276. ) ,
  277. );
  278. }
  279. return self::$_fields;
  280. }
  281. /**
  282. * returns the names of this table
  283. *
  284. * @access public
  285. * @return string
  286. */
  287. function getTableName()
  288. {
  289. return self::$_tableName;
  290. }
  291. /**
  292. * returns if this table needs to be logged
  293. *
  294. * @access public
  295. * @return boolean
  296. */
  297. function getLog()
  298. {
  299. return self::$_log;
  300. }
  301. /**
  302. * returns the list of fields that can be imported
  303. *
  304. * @access public
  305. * return array
  306. */
  307. function &import($prefix = false)
  308. {
  309. if (!(self::$_import)) {
  310. self::$_import = array();
  311. $fields = & self::fields();
  312. foreach($fields as $name => $field) {
  313. if (CRM_Utils_Array::value('import', $field)) {
  314. if ($prefix) {
  315. self::$_import['email'] = & $fields[$name];
  316. } else {
  317. self::$_import[$name] = & $fields[$name];
  318. }
  319. }
  320. }
  321. }
  322. return self::$_import;
  323. }
  324. /**
  325. * returns the list of fields that can be exported
  326. *
  327. * @access public
  328. * return array
  329. */
  330. function &export($prefix = false)
  331. {
  332. if (!(self::$_export)) {
  333. self::$_export = array();
  334. $fields = & self::fields();
  335. foreach($fields as $name => $field) {
  336. if (CRM_Utils_Array::value('export', $field)) {
  337. if ($prefix) {
  338. self::$_export['email'] = & $fields[$name];
  339. } else {
  340. self::$_export[$name] = & $fields[$name];
  341. }
  342. }
  343. }
  344. }
  345. return self::$_export;
  346. }
  347. }