<commit_before><?php
namespace Concrete\Core\Page\Collection\Version;

use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Attribute\ObjectTrait;
use Concrete\Core\Entity\Attribute\Value\PageValue;
use Concrete\Core\Foundation\Object;
use Block;
use Page;
use PageType;
use Permissions;
use User;
use Concrete\Core\Feature\Assignment\CollectionVersionAssignment as CollectionVersionFeatureAssignment;
use Concrete\Core\Support\Facade\Facade;

class Version extends Object implements \Concrete\Core\Permission\ObjectInterface
{
    use ObjectTrait;

    // Properties from database record
    public $cvID;
    public $cvIsApproved;
    public $cvIsNew;
    public $cvHandle;
    public $cvName;
    public $cvDescription;
    public $cvDateCreated;
    public $cvDatePublic;
    public $pTemplateID;
    public $cvAuthorUID;
    public $cvApproverUID;
    public $cvComments;
    public $pThemeID;
    public $cvPublishDate;

    // Other properties
    public $cID;
    protected $attributes = array();
    public $layoutStyles = array();
    protected $isMostRecent;
    protected $customAreaStyles;

    public function getPermissionObjectIdentifier()
    {
        return $this->getCollectionID() . ':' . $this->getVersionID();
    }

    public function getPermissionResponseClassName()
    {
        return '\\Concrete\\Core\\Permission\\Response\\CollectionVersionResponse';
    }

    public function getPermissionAssignmentClassName()
    {
        return '\\Concrete\\Core\\Permission\\Assignment\\PageAssignment';
    }

    public function getPermissionObjectKeyCategoryHandle()
    {
        return 'page';
    }

    public function refreshCache()
    {
        $app = Facade::getFacadeApplication();
        $cache = $app->make('cache/request');
        if ($cache->isEnabled()) {
            $cache->delete('page/'.$this->getCollectionID());
        }
    }

    public static function get($c, $cvID)
    {
        $app = Facade::getFacadeApplication();
        $db = $app->make('database')->connection();

        if (($c instanceof Page) && $c->getCollectionPointerID()) {
            $v = array(
                $c->getCollectionPointerID(),
            );
        } else {
            $v = array(
                $c->getCollectionID(),
            );
        }

        $q = "select cvID, cvIsApproved, cvIsNew, cvHandle, cvName, cvDescription, cvDateCreated, cvDatePublic, " .
             "pTemplateID, cvAuthorUID, cvApproverUID, cvComments, pThemeID, cvPublishDate from CollectionVersions " .
             "where cID = ?";

        if ($cvID == 'ACTIVE') {
            $q .= ' and cvIsApproved = 1 and cvPublishDate is NULL';
        } elseif ($cvID == 'SCHEDULED') {
                $q .= ' and cvIsApproved = 1 and cvPublishDate is not NULL';
        } elseif ($cvID == 'RECENT') {
            $q .= ' order by cvID desc';
        } else {
            $v[] = $cvID;
            $q .= ' and cvID = ?';
        }

        $row = $db->fetchAssoc($q, $v);
        $cv = new static();

        if ($row !== false) {
            $cv->setPropertiesFromArray($row);
        }

        // load the attributes for a particular version object
        $cv->cID = $c->getCollectionID();

        return $cv;
    }

    public function getObjectAttributeCategory()
    {
        $app = Facade::getFacadeApplication();
        return $app->make('\Concrete\Core\Attribute\Category\PageCategory');
    }
<commit_msg>Add phpDoc and simplify Version::get<commit_after><?php
namespace Concrete\Core\Page\Collection\Version;

use Concrete\Core\Attribute\Key\CollectionKey;
use Concrete\Core\Attribute\ObjectTrait;
use Concrete\Core\Entity\Attribute\Value\PageValue;
use Concrete\Core\Foundation\Object;
use Block;
use Page;
use PageType;
use Permissions;
use User;
use Concrete\Core\Feature\Assignment\CollectionVersionAssignment as CollectionVersionFeatureAssignment;
use Concrete\Core\Support\Facade\Facade;

class Version extends Object implements \Concrete\Core\Permission\ObjectInterface
{
    use ObjectTrait;

    // Properties from database record
    public $cvID;
    public $cvIsApproved;
    public $cvIsNew;
    public $cvHandle;
    public $cvName;
    public $cvDescription;
    public $cvDateCreated;
    public $cvDatePublic;
    public $pTemplateID;
    public $cvAuthorUID;
    public $cvApproverUID;
    public $cvComments;
    public $pThemeID;
    public $cvPublishDate;

    // Other properties
    public $cID;
    protected $attributes = array();
    public $layoutStyles = array();
    protected $isMostRecent;
    protected $customAreaStyles;

    public function getPermissionObjectIdentifier()
    {
        return $this->getCollectionID() . ':' . $this->getVersionID();
    }

    public function getPermissionResponseClassName()
    {
        return '\\Concrete\\Core\\Permission\\Response\\CollectionVersionResponse';
    }

    public function getPermissionAssignmentClassName()
    {
        return '\\Concrete\\Core\\Permission\\Assignment\\PageAssignment';
    }

    public function getPermissionObjectKeyCategoryHandle()
    {
        return 'page';
    }

    public function refreshCache()
    {
        $app = Facade::getFacadeApplication();
        $cache = $app->make('cache/request');
        if ($cache->isEnabled()) {
            $cache->delete('page/'.$this->getCollectionID());
        }
    }

    /**
     * Get a Version instance given the Collection and a version identifier.
     *
     * @param \Concrete\Core\Page\Collection $c The collection for which you want the version.
     * @param int|string $cvID The specific version ID (or 'ACTIVE', 'SCHEDULED', 'RECENT').
     *
     * @return static
     */
    public static function get($c, $cvID)
    {
        $app = Facade::getFacadeApplication();
        $db = $app->make('database')->connection();

        $cID = false;
        if ($c instanceof \Concrete\Core\Page\Page) {
            $cID = $c->getCollectionPointerID();
        }
        if (!$cID) {
            $cID = $c->getCollectionID();
        }
        $v = array($cID);

        $q = "select cvID, cvIsApproved, cvIsNew, cvHandle, cvName, cvDescription, cvDateCreated, cvDatePublic, " .
             "pTemplateID, cvAuthorUID, cvApproverUID, cvComments, pThemeID, cvPublishDate from CollectionVersions " .
             "where cID = ?";

        switch ($cvID) {
            case 'ACTIVE':
                $q .= ' and cvIsApproved = 1 and cvPublishDate is NULL';
                break;
            case 'SCHEDULED':
                $q .= ' and cvIsApproved = 1 and cvPublishDate is not NULL';
                break;
            case 'RECENT':
                $q .= ' order by cvID desc';
                break;
            default:
                $v[] = $cvID;
                $q .= ' and cvID = ?';
                break;
        }

        $row = $db->fetchAssoc($q, $v);
        $cv = new static();

        if ($row !== false) {
            $cv->setPropertiesFromArray($row);
        }

        $cv->cID = $c->getCollectionID();

        return $cv;
    }

    public function getObjectAttributeCategory()
    {
        $app = Facade::getFacadeApplication();
        return $app->make('\Concrete\Core\Attribute\Category\PageCategory');
    }

{'fraction_non_alphanumeric': 0.12216694306246545, 'fraction_numerical': 0.000552791597567717, 'mean_word_length': 2.396058188643829, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 34, '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': '6738652', 'n_tokens_mistral': 2081, 'n_tokens_neox': 2050, 'n_words': 474}