Model.php
116 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\MultiFormGoals\MultiFormGoal; |
| 4 | |
| 5 | use Give\MultiFormGoals\ProgressBar\Model as ProgressBar; |
| 6 | |
| 7 | class Model { |
| 8 | |
| 9 | // Settings for shortcode context |
| 10 | protected $ids; |
| 11 | protected $tags; |
| 12 | protected $categories; |
| 13 | protected $goal; |
| 14 | protected $enddate; |
| 15 | protected $color; |
| 16 | protected $heading; |
| 17 | protected $summary; |
| 18 | protected $imageSrc; |
| 19 | |
| 20 | // Settings for block context |
| 21 | protected $innerBlocks; |
| 22 | |
| 23 | /** |
| 24 | * Constructs and sets up setting variables for a new Multi Form Goal model |
| 25 | * |
| 26 | * @param array $args Arguments for new Multi Form Goal, including 'ids' |
| 27 | * @since 2.9.0 |
| 28 | **/ |
| 29 | public function __construct( array $args ) { |
| 30 | isset( $args['ids'] ) ? $this->ids = $args['ids'] : $this->ids = []; |
| 31 | isset( $args['tags'] ) ? $this->tags = $args['tags'] : $this->tags = []; |
| 32 | isset( $args['categories'] ) ? $this->categories = $args['categories'] : $this->categories = []; |
| 33 | isset( $args['goal'] ) ? $this->goal = $args['goal'] : $this->goal = '1000'; |
| 34 | isset( $args['enddate'] ) ? $this->enddate = $args['enddate'] : $this->enddate = ''; |
| 35 | isset( $args['color'] ) ? $this->color = $args['color'] : $this->color = '#28c77b'; |
| 36 | isset( $args['heading'] ) ? $this->heading = $args['heading'] : $this->heading = 'Example Heading'; |
| 37 | isset( $args['summary'] ) ? $this->summary = $args['summary'] : $this->summary = 'This is a summary.'; |
| 38 | isset( $args['imageSrc'] ) ? $this->imageSrc = $args['imageSrc'] : $this->imageSrc = GIVE_PLUGIN_URL . 'assets/dist/images/onboarding-preview-form-image.min.jpg'; |
| 39 | isset( $args['innerBlocks'] ) ? $this->innerBlocks = $args['innerBlocks'] : $this->innerBlocks = false; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Get output markup for Multi-Form Goal |
| 44 | * |
| 45 | * @return string |
| 46 | * @since 2.9.0 |
| 47 | **/ |
| 48 | public function getOutput() { |
| 49 | ob_start(); |
| 50 | $output = ''; |
| 51 | require $this->getTemplatePath(); |
| 52 | $output = ob_get_contents(); |
| 53 | ob_end_clean(); |
| 54 | return $output; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Get image source for MultiFormGoal |
| 59 | * |
| 60 | * @return string |
| 61 | * @since 2.9.0 |
| 62 | **/ |
| 63 | public function getImageSrc() { |
| 64 | return $this->imageSrc; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Get heading for MultiFormGoal |
| 69 | * |
| 70 | * @return string |
| 71 | * @since 2.9.0 |
| 72 | **/ |
| 73 | public function getHeading() { |
| 74 | return $this->heading; |
| 75 | } |
| 76 | |
| 77 | /** |
| 78 | * Get summary for MultiFormGoal |
| 79 | * |
| 80 | * @return string |
| 81 | * @since 2.9.0 |
| 82 | **/ |
| 83 | public function getSummary() { |
| 84 | return $this->summary; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * Get Progress Bar output |
| 89 | * |
| 90 | * @return string |
| 91 | * @since 2.9.0 |
| 92 | **/ |
| 93 | protected function getProgressBarOutput() { |
| 94 | $progressBar = new ProgressBar( |
| 95 | [ |
| 96 | 'ids' => $this->ids, |
| 97 | 'tags' => $this->tags, |
| 98 | 'categories' => $this->categories, |
| 99 | 'goal' => $this->goal, |
| 100 | 'enddate' => $this->enddate, |
| 101 | 'color' => $this->color, |
| 102 | ] |
| 103 | ); |
| 104 | return $progressBar->getOutput(); |
| 105 | } |
| 106 | |
| 107 | /** |
| 108 | * Get template path for Multi-Form Goal component template |
| 109 | * @since 2.9.0 |
| 110 | **/ |
| 111 | public function getTemplatePath() { |
| 112 | return GIVE_PLUGIN_DIR . '/src/MultiFormGoals/resources/views/multiformgoal.php'; |
| 113 | } |
| 114 | |
| 115 | } |
| 116 |