<commit_before><?
/**
 * These are EAV rows.  Entities are dual-named in Stuki as both Doctrine Entities (this class)
 * and EAV entities.
 */
namespace Entities;

use Stuki\Entity\Entity,
    Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @ORM\Table(name="entities")
 */
class Entities extends Entity
{

    public $valueEntities = array(
        'Entities\ValuesArray',
        'Entities\ValuesDatetime',
        'Entities\ValuesDecimal',
        'Entities\ValuesInteger',
        'Entities\ValuesText',
        'Entities\ValuesVarchar'
    );


    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue
     */
    protected $entity_key;

    public function getKey() {
        return $this->entity_key;
    }

    /**
     * @ORM\ManyToOne(targetEntity="Users", inversedBy="entities")
     * @ORM\JoinColumn(name="ref_user", referencedColumnName="user_key")
     */
    protected $user;

    public function getUser() {
        return $this->user;
    }

    public function setUser($value) {
        $this->user = $value;
    }

    /**
     * @ORM\ManyToOne(targetEntity="AttributeSets", inversedBy="entities")
     * @ORM\JoinColumn(name="ref_attribute_set", referencedColumnName="attribute_set_key")
     */
    protected $attributeSet;

    public function getAttributeSet() {
        return $this->attributeSet;
    }

    public function setAttributeSet($value) {
        $this->attributeSet = $value;
    }

    /**
     * @ORM\ManyToOne(targetEntity="Entities", inversedBy="children")
     * @ORM\JoinColumn(name="ref_entity", referencedColumnName="entity_key")
     */
    protected $parent;

    public function getParent() {
        return $this->parent;
    }

    public function setParent($value) {
        $this->parent = $value;
    }

    /**
     * @ORM\OneToMany(targetEntity="Entities", mappedBy="parent")
     * @ORM\OrderBy({"title" = "ASC"})
     */
    protected $children;

    public function getChildren() {
        return $this->children;
    }

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    protected $title;

    public function getTitle() {
        return $this->title;
    }

    public function setTitle($value) {
        $this->title = $value;
    }

    /**
     * @ORM\Column(name="is_locked", type="boolean", nullable=true)
     */
    protected $isLocked;

    public function getIsLocked() {
        return $this->isLocked;
    }

    public function setIsLocked($value) {
        $this->isLocked = $value;
    }

    /**
     * Because values are stored in 6 tables this aggregates entity's values.
     */
    public function getValues() {
        $search = array(
            'entity' => $this,
        );

        $res = array();
        foreach ($this->valueEntities as $ve) {
            $res = array_merge($res, $this->getEm()->getRepository($ve)->findBy($search));
        }

        uasort($res, array($this, 'sortValues'));

        // Remove values no longer associated with this entity (decoupled from attribute set)
        foreach ($res as $key => $val) {
            if ($val->getAttribute()->getAttributeSet() != $this->getAttributeSet())
                unset($res[$key]);
        }

        return $res;
    }

    /**
     * Return a value based on the params
     */
    public function findOneValueBy($params) {
        $params['entity'] = $this;

        foreach ($this->valueEntities as $repository) {
            switch ($repository) {
                case 'Entities\ValuesDatetime':
                    // Only search datetimes if a datetime is specified for the value
                    if (isset($params['value']) AND $params['value'] instanceof \Datetime)
                        if ($entity = $this->getEm()->getRepository($repository)->findOneBy($params))
                            return $entity;
                    break;
                default:
                    if ($entity = $this->getEm()->getRepository($repository)->findOneBy($params))
                        return $entity;
                    break;
            }
        }
    }

    /**
     * A function to sort values by their attribute's sort
     */
    private function sortValues($a, $b) {
        $aSort = $a->getAttribute()->getSort();
        $bSort = $b->getAttribute()->getSort();
<commit_msg>Fixed? problem with date renderers not populating.  Left comment in code to address this one.<commit_after><?
/**
 * These are EAV rows.  Entities are dual-named in Stuki as both Doctrine Entities (this class)
 * and EAV entities.
 */
namespace Entities;

use Stuki\Entity\Entity,
    Doctrine\ORM\Mapping AS ORM;

/**
 * @ORM\Entity
 * @ORM\HasLifecycleCallbacks
 * @ORM\Table(name="entities")
 */
class Entities extends Entity
{

    public $valueEntities = array(
        'Entities\ValuesArray',
        'Entities\ValuesDatetime',
        'Entities\ValuesDecimal',
        'Entities\ValuesInteger',
        'Entities\ValuesText',
        'Entities\ValuesVarchar'
    );


    /**
     * @ORM\Column(type="integer")
     * @ORM\Id
     * @ORM\GeneratedValue
     */
    protected $entity_key;

    public function getKey() {
        return $this->entity_key;
    }

    /**
     * @ORM\ManyToOne(targetEntity="Users", inversedBy="entities")
     * @ORM\JoinColumn(name="ref_user", referencedColumnName="user_key")
     */
    protected $user;

    public function getUser() {
        return $this->user;
    }

    public function setUser($value) {
        $this->user = $value;
    }

    /**
     * @ORM\ManyToOne(targetEntity="AttributeSets", inversedBy="entities")
     * @ORM\JoinColumn(name="ref_attribute_set", referencedColumnName="attribute_set_key")
     */
    protected $attributeSet;

    public function getAttributeSet() {
        return $this->attributeSet;
    }

    public function setAttributeSet($value) {
        $this->attributeSet = $value;
    }

    /**
     * @ORM\ManyToOne(targetEntity="Entities", inversedBy="children")
     * @ORM\JoinColumn(name="ref_entity", referencedColumnName="entity_key")
     */
    protected $parent;

    public function getParent() {
        return $this->parent;
    }

    public function setParent($value) {
        $this->parent = $value;
    }

    /**
     * @ORM\OneToMany(targetEntity="Entities", mappedBy="parent")
     * @ORM\OrderBy({"title" = "ASC"})
     */
    protected $children;

    public function getChildren() {
        return $this->children;
    }

    /**
     * @ORM\Column(type="text", nullable=true)
     */
    protected $title;

    public function getTitle() {
        return $this->title;
    }

    public function setTitle($value) {
        $this->title = $value;
    }

    /**
     * @ORM\Column(name="is_locked", type="boolean", nullable=true)
     */
    protected $isLocked;

    public function getIsLocked() {
        return $this->isLocked;
    }

    public function setIsLocked($value) {
        $this->isLocked = $value;
    }

    /**
     * Because values are stored in 6 tables this aggregates entity's values.
     */
    public function getValues() {
        $search = array(
            'entity' => $this,
        );

        $res = array();
        foreach ($this->valueEntities as $ve) {
            $res = array_merge($res, $this->getEm()->getRepository($ve)->findBy($search));
        }

        uasort($res, array($this, 'sortValues'));

        // Remove values no longer associated with this entity (decoupled from attribute set)
        foreach ($res as $key => $val) {
            if ($val->getAttribute()->getAttributeSet() != $this->getAttributeSet())
                unset($res[$key]);
        }

        return $res;
    }

    /**
     * Return a value based on the params
     */
    public function findOneValueBy($params) {
        $params['entity'] = $this;

        foreach ($this->valueEntities as $repository) {
            switch ($repository) {
                case 'Entities\ValuesDatetime-remove':
                    // Only search datetimes if a datetime is specified for the value
                    if (isset($params['value']) AND $params['value'] instanceof \Datetime)
                        if ($entity = $this->getEm()->getRepository($repository)->findOneBy($params))
                            return $entity;
                    break;
                default:
                    if ($entity = $this->getEm()->getRepository($repository)->findOneBy($params))
                        return $entity;
                    break;
            }
        }
    }

    /**
     * A function to sort values by their attribute's sort
     */
    private function sortValues($a, $b) {
        $aSort = $a->getAttribute()->getSort();
        $bSort = $b->getAttribute()->getSort();

{'fraction_non_alphanumeric': 0.13990170305177735, 'fraction_numerical': 0.00022859755400617213, 'mean_word_length': 2.176043557168784, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 67, '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': '2765065', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2464, 'n_words': 534}