CerPreset.inc 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @file
  4. * Contains the entity class for CER presets.
  5. */
  6. class CerPreset extends Entity {
  7. /**
  8. * @var integer
  9. * The preset's numeric ID in the database.
  10. */
  11. public $pid = 0;
  12. /**
  13. * @var string
  14. * The export identifier, in the format $this->cer_left*$this->cer_right.
  15. */
  16. public $identifier;
  17. /**
  18. * @var EntityMetadataWrapper
  19. * A metadata wrapper around this preset, for convenience.
  20. */
  21. public $wrapper;
  22. /**
  23. * @var integer
  24. * The exportable status of this preset.
  25. */
  26. public $status = 0x01; // ENTITY_CUSTOM
  27. /**
  28. * @var string
  29. * The module exporting this preset.
  30. */
  31. public $module = 'cer';
  32. /**
  33. * Overrides Entity::__construct().
  34. */
  35. public function __construct(array $values = array()) {
  36. parent::__construct($values, 'cer');
  37. $this->wrapper = new EntityDrupalWrapper('cer', $this);
  38. }
  39. /**
  40. * Overrides Entity::label().
  41. */
  42. public function label() {
  43. return isset($this->label_variables) ? t('@left !operator @right', $this->label_variables) : $this->defaultLabel();
  44. }
  45. /**
  46. * Overrides Entity::save().
  47. */
  48. public function save() {
  49. // Generate the export identifier automagically before saving.
  50. $this->identifier = $this->wrapper->cer_left->value() . '*' . $this->wrapper->cer_right->value();
  51. parent::save();
  52. }
  53. public function invert() {
  54. $init = get_object_vars($this);
  55. unset($init['pid'], $init['wrapper'], $init['identifier'], $init['status']);
  56. $buf = $init['cer_left'];
  57. $init['cer_left'] = $init['cer_right'];
  58. $init['cer_right'] = $buf;
  59. return entity_create('cer', $init);
  60. }
  61. }