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