View file upload/src/addons/BS/Contests/Entity/Participant.php

File size: 1.23Kb
<?php

namespace BS\Contests\Entity;

use XF\Mvc\Entity\Entity;
use XF\Mvc\Entity\Structure;

class Participant extends Entity
{
	public static function getStructure(Structure $structure)
	{
		$structure->table = 'xf_bs_contest_participant';
		$structure->shortName = 'BS\Contests:Participant';
		$structure->primaryKey = 'participant_id';
		$structure->columns = [
			'participant_id' => ['type' => self::UINT, 'autoIncrement' => true],
			'contest_id' => ['type' => self::UINT, 'required' => true],
			'user_id' => ['type' => self::UINT, 'required' => true],
			'username' => ['type' => self::STR, 'maxLength' => 50,
				'required' => 'please_enter_valid_name'
			],
			'is_winner' => ['type' => self::BOOL, 'default' => false],
			'win_date' => ['type' => self::UINT, 'default' => 0],
			'place' => ['type' => self::UINT, 'default' => 0]
		];
		$structure->relations = [
			'Contest' => [
				'entity' => 'BS\Contests:Contest',
				'type' => self::TO_ONE,
				'conditions' => 'thread_id',
				'primary' => true
			],
			'User' => [
				'entity' => 'XF:User',
				'type' => self::TO_ONE,
				'conditions' => 'user_id',
				'primary' => true
			]
		];
		$structure->defaultWith = ['User'];

		return $structure;
	}
}