<?php
namespace App\Model\Table;

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

/**
 * Galleries Model
 *
 */
class GalleriesTable 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('galleries');
        $this->setDisplayField('name');
        $this->setPrimaryKey('id');

        $this->belongsTo('Albums', [
            'foreignKey' => 'album_id'
        ]);
    }

    public function getGallery($album_id)
    {
        $query = $this->find('all', [
            'conditions' => [
                'status' => 1,
                'album_id' => $album_id
            ]
        ])->toArray();

        return $query;
    }

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

        return $query;
    }

}
