<commit_before><?php
/**
 * Minds activity entity.
 */

namespace Minds\Entities;

use Minds\Helpers;
use Minds\Core\Queue;
use Minds\Core\Analytics;

class Activity extends Entity
{
    public $indexes = null;

    /**
     * Initialise attributes
     * @return void
     */
    public function initializeAttributes()
    {
        parent::initializeAttributes();
        $this->attributes = array_merge($this->attributes, array(
            'type' => 'activity',
            'owner_guid' => elgg_get_logged_in_user_guid(),
            'access_id' => 2, //private,

        //	'node' => elgg_get_site_url()
        ));
    }

    public function __construct($guid = null)
    {
        parent::__construct($guid);
    }

    public function save($index = true)
    {

        //cache owner_guid for brief
        if (!$this->ownerObj && $owner = $this->getOwnerEntity(false)) {
            $this->ownerObj = $owner->export();
        }

        $guid = parent::save($index);

        return $guid;
    }

    public function delete()
    {
        if ($this->p2p_boosted) {
            return false;
        }

        $indexes = $this->getIndexKeys(true);
        $db = new \Minds\Core\Data\Call('entities');
        $res = $db->removeRow($this->guid);

        $db = new \Minds\Core\Data\Call('entities_by_time');
        foreach ($indexes as $index) {
            $db->removeAttributes($index, array($this->guid));
        }

        Queue\Client::build()->setExchange("mindsqueue")
                            ->setQueue("FeedCleanup")
                            ->send(array(
                                "guid" => $this->guid,
                                "owner_guid" => $this->owner_guid,
                                                                "type" => "activity"
                                ));

        return true;
    }
    /**
     * Returns an array of indexes into which this entity is stored
     *
     * @param bool $ia - ignore access
     * @return array
     */
    protected function getIndexKeys($ia = false)
    {
        if ($this->indexes) {
            return $this->indexes;
        }

        $indexes = array(
            $this->type
        );

        $owner = $this->getOwnerEntity();

        array_push($indexes, "$this->type:user:$owner->guid");
        array_push($indexes, "$this->type:network:$owner->guid");


        if ($this->to_guid == $owner->guid) {
            array_push($indexes, "$this->type:user:own:$owner->guid");
        }

        /**
         * @todo make it only post to a group if we are in a group
         */
        array_push($indexes, "$this->type:container:$this->container_guid");

        /**
         * Make a link from entity to this activity post
         */
        if ($this->entity_guid) {
            array_push($indexes, "$this->type:entitylink:$this->entity_guid");
        }

        return $indexes;
    }

    public function getExportableValues()
    {
        return array_merge(parent::getExportableValues(),
            array(
                'title',
                'blurb',
                'perma_url',
                'message',
                'ownerObj',
                'containerObj',
                'thumbnail_src',
                'remind_object',
                'entity_guid',
                'custom_type',
                'custom_data',
                'thumbs:up:count',
                'thumbs:up:user_guids',
                'thumbs:down:count',
                'thumbs:down:user_guids',
                'p2p_boosted'
            ));
    }

    public function export()
    {
        $export = parent::export();
        if ($this->entity_guid) {
            $export['entity_guid'] = (string) $this->entity_guid;
        }

        $export['impressions'] = $this->getImpressions();
        $export['reminds'] = $this->getRemindCount();

        if ($this->entity_guid && !$this->remind_object) {
            $export['thumbs:up:count'] = Helpers\Counters::get($this->entity_guid, 'thumbs:up');
            $export['thumbs:down:count'] = Helpers\Counters::get($this->entity_guid, 'thumbs:down');
        } elseif ($this->remind_object) {
            if ($this->remind_object['entity_guid']) {
                $export['thumbs:up:count'] = Helpers\Counters::get($this->remind_object['entity_guid'], 'thumbs:up');
                $export['thumbs:down:count'] = Helpers\Counters::get($this->remind_object['entity_guid'], 'thumbs:down');
            } else {
                $export['thumbs:up:count'] = Helpers\Counters::get($this->remind_object['guid'], 'thumbs:up');
                $export['thumbs:down:count'] = Helpers\Counters::get($this->remind_object['guid'], 'thumbs:down');
            }
        } else {
            $export['thumbs:up:count'] = Helpers\Counters::get($this, 'thumbs:up');
            $export['thumbs:down:count'] = Helpers\Counters::get($this, 'thumbs:down');
        }

        $export = array_merge($export, \Minds\Core\Events\Dispatcher::trigger('export:extender', 'activity', array('entity'=>$this), array()));

        return $export;
    }

    /**
     * Return a friendly url
     */
    public function getURL()
    {
        return elgg_get_site_url() . 'newsfeed/'.$this->guid;
    }

    /**
     * Returns the owner entity
     */<commit_msg>(fix): force thumbs GUIDS to be array<commit_after><?php
/**
 * Minds activity entity.
 */

namespace Minds\Entities;

use Minds\Helpers;
use Minds\Core\Queue;
use Minds\Core\Analytics;

class Activity extends Entity
{
    public $indexes = null;

    /**
     * Initialise attributes
     * @return void
     */
    public function initializeAttributes()
    {
        parent::initializeAttributes();
        $this->attributes = array_merge($this->attributes, array(
            'type' => 'activity',
            'owner_guid' => elgg_get_logged_in_user_guid(),
            'access_id' => 2, //private,

        //	'node' => elgg_get_site_url()
        ));
    }

    public function __construct($guid = null)
    {
        parent::__construct($guid);
    }

    public function save($index = true)
    {

        //cache owner_guid for brief
        if (!$this->ownerObj && $owner = $this->getOwnerEntity(false)) {
            $this->ownerObj = $owner->export();
        }

        $guid = parent::save($index);

        return $guid;
    }

    public function delete()
    {
        if ($this->p2p_boosted) {
            return false;
        }

        $indexes = $this->getIndexKeys(true);
        $db = new \Minds\Core\Data\Call('entities');
        $res = $db->removeRow($this->guid);

        $db = new \Minds\Core\Data\Call('entities_by_time');
        foreach ($indexes as $index) {
            $db->removeAttributes($index, array($this->guid));
        }

        Queue\Client::build()->setExchange("mindsqueue")
                            ->setQueue("FeedCleanup")
                            ->send(array(
                                "guid" => $this->guid,
                                "owner_guid" => $this->owner_guid,
                                                                "type" => "activity"
                                ));

        return true;
    }
    /**
     * Returns an array of indexes into which this entity is stored
     *
     * @param bool $ia - ignore access
     * @return array
     */
    protected function getIndexKeys($ia = false)
    {
        if ($this->indexes) {
            return $this->indexes;
        }

        $indexes = array(
            $this->type
        );

        $owner = $this->getOwnerEntity();

        array_push($indexes, "$this->type:user:$owner->guid");
        array_push($indexes, "$this->type:network:$owner->guid");


        if ($this->to_guid == $owner->guid) {
            array_push($indexes, "$this->type:user:own:$owner->guid");
        }

        /**
         * @todo make it only post to a group if we are in a group
         */
        array_push($indexes, "$this->type:container:$this->container_guid");

        /**
         * Make a link from entity to this activity post
         */
        if ($this->entity_guid) {
            array_push($indexes, "$this->type:entitylink:$this->entity_guid");
        }

        return $indexes;
    }

    public function getExportableValues()
    {
        return array_merge(parent::getExportableValues(),
            array(
                'title',
                'blurb',
                'perma_url',
                'message',
                'ownerObj',
                'containerObj',
                'thumbnail_src',
                'remind_object',
                'entity_guid',
                'custom_type',
                'custom_data',
                'thumbs:up:count',
                'thumbs:up:user_guids',
                'thumbs:down:count',
                'thumbs:down:user_guids',
                'p2p_boosted'
            ));
    }

    public function export()
    {
        $export = parent::export();
        if ($this->entity_guid) {
            $export['entity_guid'] = (string) $this->entity_guid;
        }

        $export['impressions'] = $this->getImpressions();
        $export['reminds'] = $this->getRemindCount();

        if ($this->entity_guid && !$this->remind_object) {
            $export['thumbs:up:count'] = Helpers\Counters::get($this->entity_guid, 'thumbs:up');
            $export['thumbs:down:count'] = Helpers\Counters::get($this->entity_guid, 'thumbs:down');
        } elseif ($this->remind_object) {
            if ($this->remind_object['entity_guid']) {
                $export['thumbs:up:count'] = Helpers\Counters::get($this->remind_object['entity_guid'], 'thumbs:up');
                $export['thumbs:down:count'] = Helpers\Counters::get($this->remind_object['entity_guid'], 'thumbs:down');
            } else {
                $export['thumbs:up:count'] = Helpers\Counters::get($this->remind_object['guid'], 'thumbs:up');
                $export['thumbs:down:count'] = Helpers\Counters::get($this->remind_object['guid'], 'thumbs:down');
            }
        } else {
            $export['thumbs:up:count'] = Helpers\Counters::get($this, 'thumbs:up');
            $export['thumbs:down:count'] = Helpers\Counters::get($this, 'thumbs:down');
        }
        $export['thumbs:up:user_guids'] = (array) array_values($export['thumbs:up:user_guids']);

        $export = array_merge($export, \Minds\Core\Events\Dispatcher::trigger('export:extender', 'activity', array('entity'=>$this), array()));

        return $export;
    }

    /**
     * Return a friendly url
     */
    public function getURL()
    {
        return elgg_get_site_url() . 'newsfeed/'.$this->guid;
    }

    /**
     * Returns the owner entity
     */
{'fraction_non_alphanumeric': 0.15461416441168238, 'fraction_numerical': 0.0005598581692637865, 'mean_word_length': 1.8467463479415671, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 117, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3584964', 'n_tokens_mistral': 3190, 'n_tokens_neox': 3075, 'n_words': 525}