<commit_before><?php

namespace bedezign\yii2\audit\models;

use bedezign\yii2\audit\components\db\ActiveRecord;
use bedezign\yii2\audit\components\Helper;
use Yii;
use yii\db\ActiveQuery;

/**
 * Class AuditEntry
 * @package bedezign\yii2\audit\models
 *
 * @property int               $id
 * @property string            $created
 * @property float             $duration
 * @property int               $user_id        0 means anonymous
 * @property string            $ip
 * @property string            $route
 * @property int               $memory_max
 * @property string            $request_method
 * @property string            $ajax
 *
 * @property AuditError[]      $linkedErrors
 * @property AuditJavascript[] $javascripts
 * @property AuditTrail[]      $trails
 * @property AuditData[]       $associatedPanels
 */
class AuditEntry extends ActiveRecord
{
    /**
     * @var
     */
    protected $start_time;

    /**
     * @var bool
     */
    protected $autoSerialize = false;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%audit_entry}}';
    }

    /**
     * @param bool $initialise
     * @return static
     */
    public static function create($initialise = true)
    {
        $entry = new static;
        if ($initialise)
            $entry->record();

        return $entry;
    }

    /**
     * @return array
     */
    public function getAssociatedPanels()
    {
        if (!$this->isRelationPopulated('associatedPanels')) {
            $panels = AuditData::findEntryTypes($this->id);
            if (count($this->linkedErrors))
                $panels[] = 'audit/error';

            if (count($this->javascripts))
                $panels[] = 'audit/javascript';

            if (count($this->trails))
                $panels[] = 'audit/trail';

            $this->populateRelation('associatedPanels', $panels);
        }
        $related  = $this->getRelatedRecords();
        return $related['associatedPanels'];
    }

    /**
     * @param $type
     * @return mixed|null
     */
    public function typeData($type)
    {
        $record = AuditData::findForEntry($this->id, $type);
        return $record ? $record->data : null;
    }

    /**
     * Returns all linked AuditError instances
     * (Called `linkedErrors()` to avoid confusion with the `getErrors()` method)
     * @return ActiveQuery
     */
    public function getLinkedErrors()
    {
        return static::hasMany(AuditError::className(), ['entry_id' => 'id']);
    }

    /**
     * Returns all linked AuditTrail instances
     * @return ActiveQuery
     */
    public function getTrails()
    {
        return static::hasMany(AuditTrail::className(), ['entry_id' => 'id']);
    }

    /**
     * Returns all linked AuditJavascript instances
     * @return ActiveQuery
     */
    public function getJavascripts()
    {
        return static::hasMany(AuditJavascript::className(), ['entry_id' => 'id']);
    }

    /**
     * @param      $type
     * @param      $data
     * @param bool $compact
     */
    public function addData($type, $data, $compact = true)
    {
        $this->addBatchData([$type => $data], $compact);
    }

    /**
     * @param      $batchData
     * @param bool $compact
     * @throws \yii\db\Exception<commit_msg>remove addData() no longer needed<commit_after><?php

namespace bedezign\yii2\audit\models;

use bedezign\yii2\audit\components\db\ActiveRecord;
use bedezign\yii2\audit\components\Helper;
use Yii;
use yii\db\ActiveQuery;

/**
 * Class AuditEntry
 * @package bedezign\yii2\audit\models
 *
 * @property int               $id
 * @property string            $created
 * @property float             $duration
 * @property int               $user_id        0 means anonymous
 * @property string            $ip
 * @property string            $route
 * @property int               $memory_max
 * @property string            $request_method
 * @property string            $ajax
 *
 * @property AuditError[]      $linkedErrors
 * @property AuditJavascript[] $javascripts
 * @property AuditTrail[]      $trails
 * @property AuditData[]       $associatedPanels
 */
class AuditEntry extends ActiveRecord
{
    /**
     * @var
     */
    protected $start_time;

    /**
     * @var bool
     */
    protected $autoSerialize = false;

    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return '{{%audit_entry}}';
    }

    /**
     * @param bool $initialise
     * @return static
     */
    public static function create($initialise = true)
    {
        $entry = new static;
        if ($initialise)
            $entry->record();

        return $entry;
    }

    /**
     * @return array
     */
    public function getAssociatedPanels()
    {
        if (!$this->isRelationPopulated('associatedPanels')) {
            $panels = AuditData::findEntryTypes($this->id);
            if (count($this->linkedErrors))
                $panels[] = 'audit/error';

            if (count($this->javascripts))
                $panels[] = 'audit/javascript';

            if (count($this->trails))
                $panels[] = 'audit/trail';

            $this->populateRelation('associatedPanels', $panels);
        }
        $related  = $this->getRelatedRecords();
        return $related['associatedPanels'];
    }

    /**
     * @param $type
     * @return mixed|null
     */
    public function typeData($type)
    {
        $record = AuditData::findForEntry($this->id, $type);
        return $record ? $record->data : null;
    }

    /**
     * Returns all linked AuditError instances
     * (Called `linkedErrors()` to avoid confusion with the `getErrors()` method)
     * @return ActiveQuery
     */
    public function getLinkedErrors()
    {
        return static::hasMany(AuditError::className(), ['entry_id' => 'id']);
    }

    /**
     * Returns all linked AuditTrail instances
     * @return ActiveQuery
     */
    public function getTrails()
    {
        return static::hasMany(AuditTrail::className(), ['entry_id' => 'id']);
    }

    /**
     * Returns all linked AuditJavascript instances
     * @return ActiveQuery
     */
    public function getJavascripts()
    {
        return static::hasMany(AuditJavascript::className(), ['entry_id' => 'id']);
    }

    /**
     * @param      $batchData
     * @param bool $compact
     * @throws \yii\db\Exception
{'fraction_non_alphanumeric': 0.13295792272798374, 'fraction_numerical': 0.001564210855623338, 'mean_word_length': 2.0740384615384615, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 31, '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': '4089438', 'n_tokens_mistral': 1902, 'n_tokens_neox': 1847, 'n_words': 405}