Source of file MultipleTestimonialsWidget.php

Size: 1,072 Bytes - Last Modified: 2021-12-23T10:11:29+00:00

/var/www/docs.ssmods.com/process/src/MultipleTestimonialsWidget.php

123456789101112131415161718192021222324252627282930313233343536373839
<?php

class MultipleTestimonialsWidget extends Widget
{
    private static $title = "Testimonials";
    private static $cmsTitle = "Testimonials";
    private static $description = "Displays multiple random testimonials from the database.";

    private static $has_one = array(
        'Page' => 'TestimonialsHolderPage'
    );

    protected $testimonials;

    public function getTestimonials()
    {
        $limit = Config::inst()->get('TestimonialsHolderPage', 'no_of_testimonials_in_widget');
        if (empty($limit)) {
            $limit = 2;
        }
        
        if (!$this->testimonials) {
            $this->testimonials = Testimonial::get()->sort("RAND()")->limit($limit);
        }
        return $this->testimonials;
    }

    public function getCMSFields()
    {
        $fields = parent::getCMSFields();
        $fields->push(
            DropdownField::create("PageID", "Testimonials Holder Page",
                TestimonialsHolderPage::get()->map()->toArray()
            )->setHasEmptyDefault(true)
        );
        return $fields;
    }
}