/drupal/sites/all/modules/civicrm/CRM/Mailing/DAO/Component.php

https://github.com/michaelmcandrew/citylink · PHP · 318 lines · 155 code · 0 blank · 163 comment · 11 complexity · a5181c0b5b2492fc14dca495cc05b734 MD5 · raw file

  1. <?php
  2. /*
  3. +--------------------------------------------------------------------+
  4. | CiviCRM version 2.2 |
  5. +--------------------------------------------------------------------+
  6. | Copyright CiviCRM LLC (c) 2004-2009 |
  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. |
  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 along with this program; if not, contact CiviCRM LLC |
  21. | at info[AT]civicrm[DOT]org. If you have questions about the |
  22. | GNU Affero General Public License or the licensing of CiviCRM, |
  23. | see the CiviCRM license FAQ at http://civicrm.org/licensing |
  24. +--------------------------------------------------------------------+
  25. */
  26. /**
  27. *
  28. * @package CRM
  29. * @copyright CiviCRM LLC (c) 2004-2009
  30. * $Id$
  31. *
  32. */
  33. require_once 'CRM/Core/DAO.php';
  34. require_once 'CRM/Utils/Type.php';
  35. class CRM_Mailing_DAO_Component extends CRM_Core_DAO
  36. {
  37. /**
  38. * static instance to hold the table name
  39. *
  40. * @var string
  41. * @static
  42. */
  43. static $_tableName = 'civicrm_mailing_component';
  44. /**
  45. * static instance to hold the field values
  46. *
  47. * @var array
  48. * @static
  49. */
  50. static $_fields = null;
  51. /**
  52. * static instance to hold the FK relationships
  53. *
  54. * @var string
  55. * @static
  56. */
  57. static $_links = null;
  58. /**
  59. * static instance to hold the values that can
  60. * be imported / apu
  61. *
  62. * @var array
  63. * @static
  64. */
  65. static $_import = null;
  66. /**
  67. * static instance to hold the values that can
  68. * be exported / apu
  69. *
  70. * @var array
  71. * @static
  72. */
  73. static $_export = null;
  74. /**
  75. * static value to see if we should log any modifications to
  76. * this table in the civicrm_log table
  77. *
  78. * @var boolean
  79. * @static
  80. */
  81. static $_log = false;
  82. /**
  83. *
  84. * @var int unsigned
  85. */
  86. public $id;
  87. /**
  88. * The name of this component
  89. *
  90. * @var string
  91. */
  92. public $name;
  93. /**
  94. * Type of Component.
  95. *
  96. * @var enum('Header', 'Footer', 'Subscribe', 'Welcome', 'Unsubscribe', 'OptOut', 'Reply', 'Resubscribe')
  97. */
  98. public $component_type;
  99. /**
  100. *
  101. * @var string
  102. */
  103. public $subject;
  104. /**
  105. * Body of the component in html format.
  106. *
  107. * @var text
  108. */
  109. public $body_html;
  110. /**
  111. * Body of the component in text format.
  112. *
  113. * @var text
  114. */
  115. public $body_text;
  116. /**
  117. * Is this the default component for this component_type?
  118. *
  119. * @var boolean
  120. */
  121. public $is_default;
  122. /**
  123. * Is this property active?
  124. *
  125. * @var boolean
  126. */
  127. public $is_active;
  128. /**
  129. * class constructor
  130. *
  131. * @access public
  132. * @return civicrm_mailing_component
  133. */
  134. function __construct()
  135. {
  136. parent::__construct();
  137. }
  138. /**
  139. * returns all the column names of this table
  140. *
  141. * @access public
  142. * @return array
  143. */
  144. function &fields()
  145. {
  146. if (!(self::$_fields)) {
  147. self::$_fields = array(
  148. 'id' => array(
  149. 'name' => 'id',
  150. 'type' => CRM_Utils_Type::T_INT,
  151. 'required' => true,
  152. ) ,
  153. 'name' => array(
  154. 'name' => 'name',
  155. 'type' => CRM_Utils_Type::T_STRING,
  156. 'title' => ts('Component Name') ,
  157. 'maxlength' => 64,
  158. 'size' => CRM_Utils_Type::BIG,
  159. ) ,
  160. 'component_type' => array(
  161. 'name' => 'component_type',
  162. 'type' => CRM_Utils_Type::T_ENUM,
  163. 'title' => ts('Component Type') ,
  164. ) ,
  165. 'subject' => array(
  166. 'name' => 'subject',
  167. 'type' => CRM_Utils_Type::T_STRING,
  168. 'title' => ts('Subject') ,
  169. 'maxlength' => 255,
  170. 'size' => CRM_Utils_Type::HUGE,
  171. ) ,
  172. 'body_html' => array(
  173. 'name' => 'body_html',
  174. 'type' => CRM_Utils_Type::T_TEXT,
  175. 'title' => ts('Body Html') ,
  176. 'rows' => 8,
  177. 'cols' => 80,
  178. ) ,
  179. 'body_text' => array(
  180. 'name' => 'body_text',
  181. 'type' => CRM_Utils_Type::T_TEXT,
  182. 'title' => ts('Body Text') ,
  183. 'rows' => 8,
  184. 'cols' => 80,
  185. ) ,
  186. 'is_default' => array(
  187. 'name' => 'is_default',
  188. 'type' => CRM_Utils_Type::T_BOOLEAN,
  189. ) ,
  190. 'is_active' => array(
  191. 'name' => 'is_active',
  192. 'type' => CRM_Utils_Type::T_BOOLEAN,
  193. ) ,
  194. );
  195. }
  196. return self::$_fields;
  197. }
  198. /**
  199. * returns the names of this table
  200. *
  201. * @access public
  202. * @return string
  203. */
  204. function getTableName()
  205. {
  206. return self::$_tableName;
  207. }
  208. /**
  209. * returns if this table needs to be logged
  210. *
  211. * @access public
  212. * @return boolean
  213. */
  214. function getLog()
  215. {
  216. return self::$_log;
  217. }
  218. /**
  219. * returns the list of fields that can be imported
  220. *
  221. * @access public
  222. * return array
  223. */
  224. function &import($prefix = false)
  225. {
  226. if (!(self::$_import)) {
  227. self::$_import = array();
  228. $fields = &self::fields();
  229. foreach($fields as $name => $field) {
  230. if (CRM_Utils_Array::value('import', $field)) {
  231. if ($prefix) {
  232. self::$_import['mailing_component'] = &$fields[$name];
  233. } else {
  234. self::$_import[$name] = &$fields[$name];
  235. }
  236. }
  237. }
  238. }
  239. return self::$_import;
  240. }
  241. /**
  242. * returns the list of fields that can be exported
  243. *
  244. * @access public
  245. * return array
  246. */
  247. function &export($prefix = false)
  248. {
  249. if (!(self::$_export)) {
  250. self::$_export = array();
  251. $fields = &self::fields();
  252. foreach($fields as $name => $field) {
  253. if (CRM_Utils_Array::value('export', $field)) {
  254. if ($prefix) {
  255. self::$_export['mailing_component'] = &$fields[$name];
  256. } else {
  257. self::$_export[$name] = &$fields[$name];
  258. }
  259. }
  260. }
  261. }
  262. return self::$_export;
  263. }
  264. /**
  265. * returns an array containing the enum fields of the civicrm_mailing_component table
  266. *
  267. * @return array (reference) the array of enum fields
  268. */
  269. static function &getEnums()
  270. {
  271. static $enums = array(
  272. 'component_type',
  273. );
  274. return $enums;
  275. }
  276. /**
  277. * returns a ts()-translated enum value for display purposes
  278. *
  279. * @param string $field the enum field in question
  280. * @param string $value the enum value up for translation
  281. *
  282. * @return string the display value of the enum
  283. */
  284. static function tsEnum($field, $value)
  285. {
  286. static $translations = null;
  287. if (!$translations) {
  288. $translations = array(
  289. 'component_type' => array(
  290. 'Header' => ts('Header') ,
  291. 'Footer' => ts('Footer') ,
  292. 'Subscribe' => ts('Subscribe') ,
  293. 'Welcome' => ts('Welcome') ,
  294. 'Unsubscribe' => ts('Unsubscribe') ,
  295. 'OptOut' => ts('OptOut') ,
  296. 'Reply' => ts('Reply') ,
  297. 'Resubscribe' => ts('Resubscribe') ,
  298. ) ,
  299. );
  300. }
  301. return $translations[$field][$value];
  302. }
  303. /**
  304. * adds $value['foo_display'] for each $value['foo'] enum from civicrm_mailing_component
  305. *
  306. * @param array $values (reference) the array up for enhancing
  307. * @return void
  308. */
  309. static function addDisplayEnums(&$values)
  310. {
  311. $enumFields = &CRM_Mailing_DAO_Component::getEnums();
  312. foreach($enumFields as $enum) {
  313. if (isset($values[$enum])) {
  314. $values[$enum . '_display'] = CRM_Mailing_DAO_Component::tsEnum($enum, $values[$enum]);
  315. }
  316. }
  317. }
  318. }