Airship\Cabin\Bridge\Blueprint\Author::savePhotoChoice PHP Method

savePhotoChoice() public method

Save the photo to display in a given context.
public savePhotoChoice ( integer $authorId, string $context, string $cabin, string $filename ) : boolean
$authorId integer
$context string
$cabin string
$filename string
return boolean
    public function savePhotoChoice(int $authorId, string $context, string $cabin, string $filename) : bool
    {
        $this->db->beginTransaction();
        $contextId = $this->getPhotoContextId($context);
        if (empty($filename)) {
            $this->db->delete('hull_blog_author_photos', ['context' => $contextId, 'author' => $authorId]);
            return $this->db->commit();
        }
        $options = $this->getAvailablePhotos($authorId, $cabin, true);
        $exists = $this->db->exists('SELECT count(*) FROM hull_blog_author_photos WHERE author = ? AND context = ?', $authorId, $contextId);
        foreach ($options as $opt) {
            if ($opt['filename'] === $filename) {
                if ($exists) {
                    $this->db->update('hull_blog_author_photos', ['file' => $opt['fileid']], ['author' => $authorId, 'context' => $contextId]);
                } else {
                    $this->db->insert('hull_blog_author_photos', ['context' => $contextId, 'author' => $authorId, 'file' => $opt['fileid']]);
                }
                return $this->db->commit();
            }
        }
        $this->db->rollBack();
        return false;
    }