<commit_before><?php
namespace Search\View\Cell;

use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Search\Model\Entity\SavedSearch;

use Cake\View\Cell;
use Cake\Datasource\ConnectionManager;

/**
 * Widget cell
 */
class WidgetCell extends Cell
{

    /**
     * List of valid options that can be passed into this
     * cell's constructor.
     *
     * @var array
     */
    protected $_validCellOptions = [];

    /**
     * Default display method.
     *
     * @return void
     */
    public function display(array $widgets)
    {

    }

    public function displayReport(array $widgets, array $options)
    {
        $renderData = [];
        $renderOptions = [];

        $widget = array_shift($widgets);
        $widgetData = $widget->widgetData;

        $columns = explode(',', $widgetData['info']['columns']);

        $dbh = ConnectionManager::get('default');
        $sth = $dbh->execute($widgetData['info']['query']);
        $resultSet = $sth->fetchAll('assoc');

        if( !empty($resultSet) ) {
            foreach($resultSet as $k => $row) {
                $renderRow = [];
                foreach($row as $column => $value) {
                    if( in_array($column, $columns) ) {
                        $renderRow[$column] = $value;
                    }
                }
                array_push($renderData, $renderRow);
            }
        }


        $this->set('widget', $widget);
        $this->set('widgetData', $widget->widgetData);

        $this->set('renderData', $renderData);
        $this->set('renderOptions', $renderOptions);
    }


    public function displaySavedSearch(array $widgets, array $options = []) {
        $widget = array_shift($widgets);

        $renderData = [];
        $renderOptions = [];

        //actual ORM\Entity of savedSearch
        $widgetData = $widget->widgetData;

       $savedSearchTable = TableRegistry::get('Search.SavedSearches');

        switch($widgetData->type) {
            case $savedSearchTable->getCriteriaType():
                $search = $savedSearchTable->search(
                    $widgetData->model,
                    $options['user'],
                    json_decode($widgetData->content, true),
                    true
                );
                $widgetData->entities = $search['entities'];
                break;
            case $savedSearchTable->getResultType():
                $widgetData->entities = json_decode($widgetData->content, true);
                break;
        }



        $widgetData->entities['display_columns'] = array_diff(
            $widgetData->entities['display_columns'],
            $savedSearchTable->getSkippedDisplayFields()
        );


        $this->set('widget', $widget);
        $this->set('widgetData', $widget->widgetData);
        $this->set('renderData', $widgetData);
        $this->set('renderOptions', $renderOptions);
    }


    /**
    * In this case we have same displayMethod for all
    * the widgets, when dealing with Drag/Drop jQuery plugin
    */
    public function displayDroppableBlock(array $widgets) {


    }
}<commit_msg>adding droppable block for views on (task #2686)<commit_after><?php
namespace Search\View\Cell;

use Cake\ORM\Table;
use Cake\ORM\TableRegistry;
use Search\Model\Entity\SavedSearch;

use Cake\View\Cell;
use Cake\Datasource\ConnectionManager;

/**
 * Widget cell
 */
class WidgetCell extends Cell
{

    /**
     * List of valid options that can be passed into this
     * cell's constructor.
     *
     * @var array
     */
    protected $_validCellOptions = [];

    /**
     * Default display method.
     *
     * @return void
     */
    public function display(array $widgets)
    {

    }

    public function displayReport(array $widgets, array $options)
    {
        $renderData = [];
        $renderOptions = [];

        $widget = array_shift($widgets);
        $widgetData = $widget->widgetData;

        $columns = explode(',', $widgetData['info']['columns']);

        $dbh = ConnectionManager::get('default');
        $sth = $dbh->execute($widgetData['info']['query']);
        $resultSet = $sth->fetchAll('assoc');

        if( !empty($resultSet) ) {
            foreach($resultSet as $k => $row) {
                $renderRow = [];
                foreach($row as $column => $value) {
                    if( in_array($column, $columns) ) {
                        $renderRow[$column] = $value;
                    }
                }
                array_push($renderData, $renderRow);
            }
        }


        $this->set('widget', $widget);
        $this->set('widgetData', $widget->widgetData);

        $this->set('renderData', $renderData);
        $this->set('renderOptions', $renderOptions);
    }


    public function displaySavedSearch(array $widgets, array $options = []) {
        $widget = array_shift($widgets);

        $renderData = [];
        $renderOptions = [];

        //actual ORM\Entity of savedSearch
        $widgetData = $widget->widgetData;

       $savedSearchTable = TableRegistry::get('Search.SavedSearches');

        switch($widgetData->type) {
            case $savedSearchTable->getCriteriaType():
                $search = $savedSearchTable->search(
                    $widgetData->model,
                    $options['user'],
                    json_decode($widgetData->content, true),
                    true
                );
                $widgetData->entities = $search['entities'];
                break;
            case $savedSearchTable->getResultType():
                $widgetData->entities = json_decode($widgetData->content, true);
                break;
        }



        $widgetData->entities['display_columns'] = array_diff(
            $widgetData->entities['display_columns'],
            $savedSearchTable->getSkippedDisplayFields()
        );


        $this->set('widget', $widget);
        $this->set('widgetData', $widget->widgetData);
        $this->set('renderData', $widgetData);
        $this->set('renderOptions', $renderOptions);
    }


    /**
    * In this case we have same displayMethod for all
    * the widgets, when dealing with Drag/Drop jQuery plugin
    */
    public function displayDroppableBlock(array $widget) {
        $this->set('widget', $widget);
    }
}
{'fraction_non_alphanumeric': 0.14035367213637087, 'fraction_numerical': 0.0006372470925601402, 'mean_word_length': 2.025542168674699, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 60, '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': '6247389', 'n_tokens_mistral': 1759, 'n_tokens_neox': 1667, 'n_words': 331}