<commit_before><?php

namespace Symbiote\Interactives\Model;

use ArrayObject;
use SilverStripe\Forms\TreeDropdownField;

use Symbiote\Interactives\Model\InteractiveCampaign;
use SilverStripe\Assets\Image;
use Symbiote\Interactives\Extension\InteractiveLocationExtension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Security\Permission;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Core\Convert;
use SilverStripe\View\Requirements;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\ORM\Connect\PDOQuery;

/**
 *
 * @author <NAME> <<EMAIL>>
 * @license BSD http://silverstripe.org/BSD-license
 */
class Interactive extends DataObject
{

    private static $use_js_tracking = false;

    private static $table_name = 'Interactive';

    private static $db = [
        'Title'                => 'Varchar',
        'TargetURL'            => 'Varchar(255)',
        'NewWindow'         => 'Boolean',
        'HTMLContent'       => 'HTMLText',
        'Label'             => 'Varchar(64)',
        'PostInteractionContent' => 'HTMLText',
        'SubsequentContent' => 'HTMLText',

        'Preset'            => 'Varchar(64)',             // 'friendly' way to map element class / position options
        // to configured sets

        'Element'           => 'Varchar(64)',           // within which containing element will it display?
        'Location'          => 'Varchar(64)',           // where in its container element?
        'Frequency'         => 'Int',                   // how often? 1 in X number of users see this
        'Delay'             => 'Int',                   // how long until it displays?
        'Transition'        => 'Varchar(64)',           // how does it appear?
        'HideAfterInteraction'  => 'Boolean',           // should the item not appear if someone has interacted with it?
        'TrackViews'        => 'Varchar(16)',

        'CompletionElement'   => 'Varchar(64)',         // what element needs clicking to be considered a 'complete' event
    ];

    private static $has_one = [
        'InternalPage'        => 'Page',
        'Campaign'            => InteractiveCampaign::class,
        'Image'                => Image::class,
    ];

    private static $owns = [
        'Image',
    ];

    private static $extensions = [
        InteractiveLocationExtension::class,
        Versioned::class
    ];

    private static $defaults = [
        'Frequency' => 1,
        'Delay' => 0,
    ];

    private static $interactive_presets = [];

    private static $tracker_type = 'Local';

    private static $summary_fields = ['Title', 'Clicks', 'Impressions', 'Completes'];

    public function getTypeLabel()
    {
        return "Viewed item";
    }

    public function canView($member = null)
    {
        $p = $this->Campaign();
        if ($p && $p->ID) {
            return $p->canView($member);
        }
        return parent::canView($member);
    }

    public function canCreate($member = null, $context = array())
    {
        if ($context && isset($context['Parent']) && $context['Parent']->ID) {
            return $context['Parent']->canEdit($member);
        }
        return parent::canCreate($member);
    }

    public function canDelete($member = null)
    {
        $p = $this->Campaign();
        if ($p && $p->ID) {
            return $p->canEdit($member);
        }
        return parent::canDelete($member);
    }

    public function canEdit($member = null)
    {
        $p = $this->Campaign();
        if ($p && $p->ID) {
            return $p->canEdit($member);
        }
        return parent::canEdit($member);
    }

    public function getCMSFields()<commit_msg>fix(Interactive) Further permission check enhancements<commit_after><?php

namespace Symbiote\Interactives\Model;

use ArrayObject;
use SilverStripe\Forms\TreeDropdownField;

use Symbiote\Interactives\Model\InteractiveCampaign;
use SilverStripe\Assets\Image;
use Symbiote\Interactives\Extension\InteractiveLocationExtension;
use SilverStripe\Forms\FieldList;
use SilverStripe\Forms\TextField;
use SilverStripe\Forms\CheckboxField;
use SilverStripe\Forms\DropdownField;
use SilverStripe\Forms\NumericField;
use SilverStripe\Forms\Tab;
use SilverStripe\Forms\TabSet;
use SilverStripe\Security\Permission;
use SilverStripe\Forms\ReadonlyField;
use SilverStripe\Forms\LiteralField;
use SilverStripe\AssetAdmin\Forms\UploadField;
use SilverStripe\Forms\TextareaField;
use SilverStripe\Versioned\Versioned;
use SilverStripe\Core\Convert;
use SilverStripe\View\Requirements;
use SilverStripe\Control\Director;
use SilverStripe\Control\Controller;
use SilverStripe\ORM\DataObject;
use SilverStripe\Core\ClassInfo;
use SilverStripe\Core\Config\Config;
use SilverStripe\Forms\ToggleCompositeField;
use SilverStripe\ORM\Connect\PDOQuery;
use Symbiote\Interactives\Control\InteractiveAdmin;

/**
 *
 * @author <NAME> <<EMAIL>>
 * @license BSD http://silverstripe.org/BSD-license
 */
class Interactive extends DataObject
{

    private static $use_js_tracking = false;

    private static $table_name = 'Interactive';

    private static $db = [
        'Title'                => 'Varchar',
        'TargetURL'            => 'Varchar(255)',
        'NewWindow'         => 'Boolean',
        'HTMLContent'       => 'HTMLText',
        'Label'             => 'Varchar(64)',
        'PostInteractionContent' => 'HTMLText',
        'SubsequentContent' => 'HTMLText',

        'Preset'            => 'Varchar(64)',             // 'friendly' way to map element class / position options
        // to configured sets

        'Element'           => 'Varchar(64)',           // within which containing element will it display?
        'Location'          => 'Varchar(64)',           // where in its container element?
        'Frequency'         => 'Int',                   // how often? 1 in X number of users see this
        'Delay'             => 'Int',                   // how long until it displays?
        'Transition'        => 'Varchar(64)',           // how does it appear?
        'HideAfterInteraction'  => 'Boolean',           // should the item not appear if someone has interacted with it?
        'TrackViews'        => 'Varchar(16)',

        'CompletionElement'   => 'Varchar(64)',         // what element needs clicking to be considered a 'complete' event
    ];

    private static $has_one = [
        'InternalPage'        => 'Page',
        'Campaign'            => InteractiveCampaign::class,
        'Image'                => Image::class,
    ];

    private static $owns = [
        'Image',
    ];

    private static $extensions = [
        InteractiveLocationExtension::class,
        Versioned::class
    ];

    private static $defaults = [
        'Frequency' => 1,
        'Delay' => 0,
    ];

    private static $interactive_presets = [];

    private static $tracker_type = 'Local';

    private static $summary_fields = ['Title', 'Clicks', 'Impressions', 'Completes'];

    public function getTypeLabel()
    {
        return "Viewed item";
    }

    public function canView($member = null)
    {
        $p = $this->Campaign();
        if ($p && $p->ID) {
            return $p->canView($member);
        }
        return $this->ID === 0 ? true : parent::canView($member);
    }

    public function canCreate($member = null, $context = array())
    {
        if ($context && isset($context['Parent']) && $context['Parent']->ID) {
            return $context['Parent']->canEdit($member);
        }

        $createNew = $this->ID == 0 && Permission::check('CMS_ACCESS_' . InteractiveAdmin::class);
        return $createNew || parent::canCreate($member);
    }

    public function canDelete($member = null)
    {
        $p = $this->Campaign();
        if ($p && $p->ID) {
            return $p->canEdit($member);
        }
        return parent::canDelete($member);
    }

    public function canEdit($member = null)
    {
        $p = $this->Campaign();
        if ($p && $p->ID) {
            return $p->canEdit($member);
        }
        return $this->ID == 0 && Permission::check('CMS_ACCESS_' . InteractiveAdmin::class) ? true : parent::canEdit($member);
    }

    public function getCMSFields()
{'fraction_non_alphanumeric': 0.13009619789280807, 'fraction_numerical': 0.004924415941365094, 'mean_word_length': 2.469606674612634, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 76, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1174632', 'n_tokens_mistral': 2608, 'n_tokens_neox': 2517, 'n_words': 567}