1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
<?php
namespace hji\AgentRoster\controllers;
use \hji\AgentRoster\models\TestimonialsModel;
class Testimonials
{
private $redirect_page_id = false;
private $model;
function __construct()
{
require_once AGRO_MODELS . 'testimonials.php';
$this->model = new TestimonialsModel;
$this->init();
add_shortcode('testimonials-submission-form', array($this, 'submission_form'));
}
private function init()
{
if (isset($_POST['submit-testimonial']))
{
$new_post_id = $this->model->processPostData();
if ($new_post_id) $this->confirmation();
}
}
static function get_testimonials(array $args = array())
{
return TestimonialsModel::get_testimonials($args);
}
static function get_agent_testimonials($agent_id)
{
return TestimonialsModel::get_agent_testimonials($agent_id);
}
function confirmation()
{
if ($this->redirect_page_id)
{
if ($permalink = get_permalink($this->redirect_page_id))
{
wp_redirect($permalink);
exit;
}
}
else
{
add_filter('testimonial_submission_confirmation', array($this, 'submission_confirmation'));
}
}
public function submission_confirmation()
{
echo '<p class="testimonial-submission-confirmation">Thank you very much for taking the time to send us your feedback!
</p>';
}
public function submission_form($atts)
{
extract( shortcode_atts( array(
'send_to' => false,
'agent_id' => false,
), $atts ) );
$errors = $this->model->getErrors();
ob_start();
do_action('testimonial_submission_confirmation');
include AGRO_VIEWS . 'testimonials-form.phtml';
return ob_get_clean();
}
}
new Testimonials();