Generates a wallpaper with the latest data and updates desktop background

@param array $data Array with the latest build history per project
166815
private function updateBackground($data)
    {
        $this->updatedAt = microtime(true);

        $this->image = imagecreatetruecolor($this->get('image_width'), $this->get('image_height'));
        imageantialias($this->image, true);

        $this->initializeColors();
        imagefill($this->image, 0, 0, $this->get('background_color'));

        $numProject = 0;
        foreach ($data['projects'] as $project => $builds) {
            // the most recent build is always shown on top
            rsort($builds);

            $x1 = $this->get('horizontal_padding') + (($this->get('bar_width') + $this->get('horizontal_gutter')) * $numProject);
            $x2 = $x1 + $this->get('bar_width');

            // plot each project slug
            $this->addTextToImage(
                substr($project, 0, $this->get('max_number_letters')),
                $x1,
                $this->get('vertical_padding') - 0.2 * $this->get('font_size')
            );

            foreach ($builds as $i => $build) {
                $y1 = $this->get('vertical_padding') + $this->get('font_size') + (($this->get('bar_height') + $this->get('vertical_gutter')) * $i);
                $y2 = $y1 + $this->get('bar_height');
                $color = 'ok' == $build ? $this->get('success_color') : $this->get('failure_color');

                // plot a bar for each project build
                imageFilledRectangle($this->image, $x1, $y1, $x2, $y2, $color);
            }
            $numProject++;
        }

        $this->addTextToImage(
            'Last update: '.$data['last_update'],
            $this->get('horizontal_padding'),
            $this->get('image_height') - $this->get('font_size')
        );

        // Hack: two different images are needed to update the wallpaper
        // One holds the current wallpaper and the other is the new one
        // If you use just one image and modify it, the OS doesn't reload it
        if (file_exists($this->evenBackgroundImagePath)) {
            $this->imagePath = $this->oddBackgroundImagePath;
            unlink($this->evenBackgroundImagePath);
        } elseif (file_exists($this->oddBackgroundImagePath)) {
            $this->imagePath = $this->evenBackgroundImagePath;
            unlink($this->oddBackgroundImagePath);
        } else {
            $this->imagePath = $this->oddBackgroundImagePath;
        }

        imagepng($this->image, $this->imagePath);
        imagedestroy($this->image);

        // Wallpaper is reloaded via AppleScript
        $scriptPath = $this->dir.'/update-background.scpt';

        file_put_contents($scriptPath, <<<END
tell application "System Events"
    tell current desktop
        set picture to POSIX file "file://localhost/$this->imagePath"
    end tell
end tell
END
);
        system("osascript $scriptPath");
    }
414629
public function update(array $data)
    {
        $todo = Basecamp::todos($this->bucket->id)->update($this->id, $data);

        $this->setAttributes($todo);

        return $todo;
    }
582773
public function run(array $data) {
        $this->getLogger()->info('Executing on data ' . md5(print_r($data, true)));

        $this->setData($data);

        $path = array();
        $this->runFilters($data, $path);

        return true;
    }
378536
private function setData(array $data)
    {
        $_documentClass = $this->_documentClass;
        $_edgeClass = $this->_edgeClass;

        if (isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT]) {
            $this->_result = $data;
        } else {
            $this->_result = [];

            if ($this->_options[self::ENTRY_TYPE] === Collection::TYPE_EDGE) {
                foreach ($data as $row) {
                    $this->_result[] = $_edgeClass::createFromArray($row, $this->_options);
                }
            } else {
                foreach ($data as $row) {
                    $this->_result[] = $_documentClass::createFromArray($row, $this->_options);
                }
            }
        }
    }
1297697
protected function buildRows(array $data)
    {
        $this->rows = collect($data)->map(function ($model, $number) {
            return new Row($number, $model);
        });

        if ($this->rowsCallback) {
            $this->rows->map($this->rowsCallback);
        }
    }
505590
public function update($data)
    {
        if (isset($data['stackName'])) {
            $txt = Core::make('helper/text');
            $data['cName'] = $data['stackName'];
            $data['cHandle'] = str_replace('-', Config::get('concrete.seo.page_path_separator'), $txt->urlify($data['stackName']));
        }
        $worked = parent::update($data);

        if (isset($data['stackName'])) {
            // Make sure the stack path is always up-to-date after a name change
            $this->rescanCollectionPath();

            $db = Database::connection();
            $stackName = $data['stackName'];
            $db->Execute('update Stacks set stName = ? WHERE cID = ?', [$stackName, $this->getCollectionID()]);
        }

        return $worked;
    }
1078337
private function importData($data)
    {
        $this->line(sprintf('Importing %s records...', count($data)));
        $this->line('');

        $this->progress_bar = $this->output->createProgressBar(count($data));

        foreach ($data as $row) {
            $this->processImportRow($row);
        }

        $this->line('     ');
        $this->line('     ');
    }
669576
public function setRawData(array $data) {

        $this->rawData = $data;

        if (isset($data['message'])) {
            $this->setMessage($data['message']);
        }

        return $this;

    }
499597
protected function updateObjectToPopulate(array $data, array &$context)
    {
        try {
            $context['object_to_populate'] = $this->iriConverter->getItemFromIri(
                (string) $data['id'],
                $context + ['fetch_data' => false]
            );
        } catch (InvalidArgumentException $e) {
            $identifier = null;
            $properties = $this->propertyNameCollectionFactory->create($context['resource_class'], $context);
            foreach ($properties as $propertyName) {
                if ($this->propertyMetadataFactory->create($context['resource_class'], $propertyName)->isIdentifier()) {
                    $identifier = $propertyName;
                    break;
                }
            }

            if (null === $identifier) {
                throw $e;
            }

            $context['object_to_populate'] = $this->iriConverter->getItemFromIri(
                sprintf(
                    '%s/%s',
                    $this->iriConverter->getIriFromResourceClass($context['resource_class']),
                    $data[$identifier]
                ),
                $context + ['fetch_data' => false]
            );
        }
    }
782378
private function setCoreData(array $data)
    {
        if (isset($data['input_type'])) {
            $this->setInputType($data['input_type']);
        }

        if (isset($data['display_type'])) {
            $this->setDisplayType($data['display_type']);
        }

        if (isset($data['property_type'])) {
            $this->setPropertyType($data['property_type']);
        }

        if (isset($data['output_type'])) {
            $this->setOutputType($data['output_type']);
        }

        if (isset($data['type'])) {
            $this->setType($data['type']);
        }

        return $data;
    }
348932
private static function pretty(array $data) {

        $color = new Color();
        $output = $color->getColoredString(self::VERBOSE_TITLE, 'blue', 'light-gray').PHP_EOL;

        foreach($data as $key => $value) {
            if(is_array($value) === false) {
                $output .= $color->getColoredString(sprintf(self::VERBOSE_ROW, $key, $value), 'dark_gray').PHP_EOL;
            }
            else {
                $output .= $color->getColoredString(sprintf(self::VERBOSE_ROW, $key, ''), 'dark_gray').PHP_EOL;
                foreach($value as $line => $string) {
                    $output .= $color->getColoredString(sprintf("\t".self::VERBOSE_ROW, '', $string), 'dark_gray').PHP_EOL;
                }
            }
        }
        $output .= $color->getColoredString('-----------------', 'blue', 'light-gray').PHP_EOL;

        return $output;
    }
540251
public static function buildDeEmojiData(array $data)
    {
        foreach ($data as $key => $value) {
            if (is_array($value)) {
                $data[$key] = self::buildDeEmojiData($value);
            } elseif (is_string($value)) {
                $data[$key] = self::emojiDecode($value);
            } else {
                $data[$key] = $value;
            }
        }
        return $data;
    }
610657
private function add(array $data)
    {
        foreach ($this->sanitize($data) as $row) {
            if (!is_array($row) || (isset($this->_options[self::ENTRY_FLAT]) && $this->_options[self::ENTRY_FLAT])) {
                $this->addFlatFromArray($row);
            } else {
                if (!isset($this->_options['objectType'])) {
                    $this->addDocumentsFromArray($row);
                } else {
                    switch ($this->_options['objectType']) {
                        case 'edge' :
                            $this->addEdgesFromArray($row);
                            break;
                        case 'vertex' :
                            $this->addVerticesFromArray($row);
                            break;
                        case 'path' :
                            $this->addPathsFromArray($row);
                            break;
                        case 'shortestPath' :
                            $this->addShortestPathFromArray($row);
                            break;
                        case 'distanceTo' :
                            $this->addDistanceToFromArray($row);
                            break;
                        case 'commonNeighbors' :
                            $this->addCommonNeighborsFromArray($row);
                            break;
                        case 'commonProperties' :
                            $this->addCommonPropertiesFromArray($row);
                            break;
                        case 'figure' :
                            $this->addFigureFromArray($row);
                            break;
                        default :
                            $this->addDocumentsFromArray($row);
                            break;
                    }
                }
            }
        }
    }
95938
protected function write(array $data)
    {
        $changes = $this->getChanges($data);

        $this->syncUpdated($changes['updated']);
        $this->syncInserted($changes['inserted']);
        $this->syncDeleted($changes['deleted']);
    }
98670
private function transformSnapshotTimestamps(array $data)
    {
        foreach (['createTime', 'updateTime', 'readTime'] as $timestampField) {
            if (!isset($data[$timestampField])) {
                continue;
            }

            list ($dt, $nanos) = $this->parseTimeString($data[$timestampField]);

            $data[$timestampField] = new Timestamp($dt, $nanos);
        }

        return $data;
    }
1001319
public function update(array $data)
    {
        $project = Basecamp::projects()->update($this->id, $data);

        $this->setAttributes($project);

        return $project;
    }
490571
private function createRootObjects($data)
    {
        if ($this->isCollection($data)) {
            $this->setRootObjects($data['data']);
        } else {
            $this->setRootObjects([$data['data']]);
        }
    }