TripalLoader.inc 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. <?php
  2. class TripalLoader {
  3. // --------------------------------------------------------------------------
  4. // EDITABLE STATIC CONSTANTS
  5. //
  6. // The following constants SHOULD be set for each descendent class. They are
  7. // used by the static functions to provide information to Drupal about
  8. // the field and it's default widget and formatter.
  9. // --------------------------------------------------------------------------
  10. /**
  11. * The name of this loader. This name will be presented to the site
  12. * user.
  13. */
  14. public static $name = 'Tripal Loader';
  15. /**
  16. * A brief description for this loader. This description will be
  17. * presented to the site user.
  18. */
  19. public static $description = 'A base loader for all Tripal loaders';
  20. // --------------------------------------------------------------------------
  21. // PROTECTED CLASS MEMBERS -- DO NOT OVERRIDE
  22. // --------------------------------------------------------------------------
  23. /**
  24. * The loader can be executed as a Tripal job, in that case we want
  25. * to keep track of the job record.
  26. */
  27. protected $job;
  28. // --------------------------------------------------------------------------
  29. // CONSTRUCTORS
  30. // --------------------------------------------------------------------------
  31. /**
  32. * Instantiates a new TripalLoader object.
  33. *
  34. * @param $job_id
  35. */
  36. public function __construct($job_id = NULL) {
  37. $this->job = NULL;
  38. if ($job_id) {
  39. $this->job = tripal_get_job($job_id);
  40. }
  41. }
  42. // --------------------------------------------------------------------------
  43. // PROTECTED FUNCTIONS
  44. // --------------------------------------------------------------------------
  45. protected function setJobProgress($percentage) {
  46. if (!is_numeric($percent_complete)) {
  47. throw new Exception('TripalLoader: Percent complete must be numeric.');
  48. }
  49. if (!$this->job) {
  50. throw new Exception('TripalLoader: This loader is not associated with a job. Cannot set the job progress.');
  51. }
  52. tripal_set_job_progress($this->job->job_id, $percentage);
  53. }
  54. // --------------------------------------------------------------------------
  55. // OVERRIDEABLE FUNCTIONS
  56. // --------------------------------------------------------------------------
  57. public function form($form, &$form_state) {
  58. return $form;
  59. }
  60. public function formSubmit($form, &$form_state) {
  61. }
  62. public function formValidate($form, &$form_state) {
  63. }
  64. public function preRun() {
  65. }
  66. public function run() {
  67. if (!$this->job) {
  68. throw new Exception('TripalLoader: This loader is not associated with a job. Cannot run the loader.');
  69. }
  70. }
  71. public function postRun() {
  72. }
  73. }