<?php
namespace App\Model\Table;

use Cake\ORM\Query;
use Cake\ORM\RulesChecker;
use Cake\ORM\Table;
use Cake\Validation\Validator;

/**
 * Albums Model
 *
 */
class AlbumsTable extends Table
{
    /**
     * Initialize method
     *
     * @param array $config The configuration for the Table.
     * @return void
     */
    public function initialize(array $config): void
    {
        parent::initialize($config);

        $this->setTable('albums');
        $this->setDisplayField('name');
        $this->setPrimaryKey('id');

        $this->hasMany('Galleries', [
            'foreignKey' => 'album_id'
        ]);
    }

    public function getGalleryAlbums()
    {
        $query = $this->find('all', [
            'contain' => [
                'Galleries'
            ],
            'conditions' => [
                'Albums.status' => 1
            ]
        ])->toArray();

        return $query;
    }

    public function getGaleryContent($album_id)
    {
        $query = $this->find('all', [
            'conditions' => [
                'Albums.status' => 1,
                'Albums.id' => $album_id
            ]
        ])->first();

        return $query;
    }

}
