fork download
  1. <?php
  2.  
  3. namespace common\modules\registration\models;
  4.  
  5. use backend\modules\event\models\Event;
  6. use backend\modules\profile\models\Profile;
  7. use backend\modules\registration\models\query\RegEventQuery;
  8. use common\models\User;
  9. use common\modules\registration\Registration;
  10. use Yii;
  11. use yii\behaviors\TimestampBehavior;
  12. use yii\helpers\ArrayHelper;
  13.  
  14. /**
  15.  * This is the model class for table "reg_event".
  16.  *
  17.  * @property int $id
  18.  * @property int $number Номер участника
  19.  * @property int $user_id
  20.  * @property int $event_id
  21.  * @property int $rang_id
  22.  * @property int $discipline_id
  23.  * @property int $nomination_id
  24.  * @property int $category_id
  25.  * @property int $status Не оплачено, Оплачено, Отменено
  26.  * @property int $visit Посетил, не посетил
  27.  * @property int $created_at
  28.  * @property int $updated_at
  29.  *
  30.  * @property RegEventCategory $category
  31.  * @property RegEventDiscipline $discipline
  32.  * @property Event $event
  33.  * @property RegEventNomination $nomination
  34.  * @property RegEventRang $rang
  35.  * @property Profile $profile
  36.  * @property User $user
  37.  * @property RegEventPrice $price
  38.  * @property RegEventMusic $music
  39.  */
  40. class RegEvent extends \yii\db\ActiveRecord
  41. {
  42.  
  43. const STATUS_NOT_PAID = 0;
  44. const STATUS_PAID = 1;
  45. const STATUS_CANCEL = 3;
  46.  
  47. const VISIT_TRUE = 1;
  48. const VISIT_FALSE = 0;
  49.  
  50. private $messageUniqueValidator = 'Такая регистрация уже существует!';
  51.  
  52. public $musicFile;
  53.  
  54. /**
  55.   * {@inheritdoc}
  56.   */
  57. public static function tableName()
  58. {
  59. return 'reg_event';
  60. }
  61.  
  62. /**
  63.   * @inheritdoc
  64.   */
  65. public function behaviors()
  66. {
  67. return [
  68. 'timestamp' => [
  69. 'class' => TimestampBehavior::className(),
  70. ],
  71. ];
  72. }
  73.  
  74. /**
  75.   * {@inheritdoc}
  76.   */
  77. public function rules()
  78. {
  79. return [
  80. [['user_id', 'visit'], 'required'],
  81. [['number', 'user_id', 'event_id', 'rang_id', 'discipline_id', 'nomination_id', 'category_id', 'receipt_id', 'status'], 'integer'],
  82. [['created_at', 'updated_at'], 'safe'],
  83.  
  84. [['created_at'], 'default', 'value' => time()],
  85. [['visit'], 'default', 'value' => self::VISIT_FALSE],
  86. [['status'], 'default', 'value' => self::STATUS_NOT_PAID],
  87.  
  88. [['number'], 'default', 'value' => self::setNumber()],
  89. [['event_id'], 'default', 'value' => self::getEventId()],
  90.  
  91. [['category_id'], 'required', 'skipOnError' => false, 'when' => function (){
  92. return $this->rang_id || $this->discipline_id || $this->nomination_id;
  93. }],
  94.  
  95. [['nomination_id'], 'required', 'skipOnError' => false, 'when' => function (){
  96. return $this->rang_id || $this->discipline_id;
  97. }],
  98.  
  99. [['discipline_id'], 'required', 'skipOnError' => false, 'when' => function (){
  100. return $this->rang_id;
  101. }],
  102.  
  103. [['category_id'], 'required', 'skipOnError' => false, 'when' => function (){
  104. return !$this->rang_id || !$this->discipline_id || !$this->nomination_id;
  105. }],
  106.  
  107. [['user_id'], 'unique', 'skipOnEmpty' => false, 'targetAttribute' => ['event_id', 'user_id','rang_id', 'discipline_id', 'nomination_id', 'category_id'], 'message' => $this->messageUniqueValidator],
  108. /*[['user_id'], 'unique', 'targetAttribute' => ['event_id', 'discipline_id', 'nomination_id', 'category_id'], 'message' => $this->messageUniqueValidator, 'when' => function (){
  109.   return !$this->rang_id;
  110.   }],*/
  111. /*[['user_id'], 'unique', 'targetAttribute' => ['event_id', 'user_id', 'nomination_id', 'category_id'], 'message' => $this->messageUniqueValidator, 'when' => function (){
  112.   return !$this->rang_id && !$this->discipline_id;
  113.   }],
  114.   [['user_id'], 'unique', 'targetAttribute' => ['event_id', 'user_id', 'category_id'], 'message' => $this->messageUniqueValidator, 'when' => function (){
  115.   return !$this->rang_id && !$this->discipline_id && !$this->nomination_id;
  116.   }],*/
  117.  
  118. [['receipt_id'], 'exist', 'skipOnError' => true, 'targetClass' => RegEventReceipt::className(), 'targetAttribute' => ['receipt_id' => 'id']],
  119. [['category_id'], 'exist', 'skipOnError' => true, 'targetClass' => RegEventCategory::className(), 'targetAttribute' => ['category_id' => 'id']],
  120. [['discipline_id'], 'exist', 'skipOnError' => true, 'targetClass' => RegEventDiscipline::className(), 'targetAttribute' => ['discipline_id' => 'id']],
  121. [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => Event::className(), 'targetAttribute' => ['event_id' => 'id']],
  122. [['nomination_id'], 'exist', 'skipOnError' => true, 'targetClass' => RegEventNomination::className(), 'targetAttribute' => ['nomination_id' => 'id']],
  123. [['event_id'], 'exist', 'skipOnError' => true, 'targetClass' => RegEventRang::className(), 'targetAttribute' => ['event_id' => 'id']],
  124. [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => Profile::className(), 'targetAttribute' => ['user_id' => 'user_id']],
  125. [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
  126. ];
  127. }
  128.  
  129. /**
  130.   * {@inheritdoc}
  131.   */
  132. public function attributeLabels()
  133. {
  134. return [
  135. 'id' => Registration::t('reg-event', 'ID'),
  136. 'number' => Registration::t('reg-event', 'Number'),
  137. 'user_id' => Registration::t('reg-event', 'User ID'),
  138. 'profile.fullName' => Registration::t('reg-event', 'User ID'),
  139. 'event_id' => Registration::t('reg-event', 'Event ID'),
  140. 'event.name' => Registration::t('reg-event', 'Event ID'),
  141. 'rang_id' => Registration::t('reg-event', 'Rang ID'),
  142. 'rang.shortName' => Registration::t('reg-event', 'Rang ID'),
  143. 'discipline_id' => Registration::t('reg-event', 'Discipline ID'),
  144. 'discipline.shortName' => Registration::t('reg-event', 'Discipline ID'),
  145. 'nomination_id' => Registration::t('reg-event', 'Nomination ID'),
  146. 'nomination.shortName' => Registration::t('reg-event', 'Nomination ID'),
  147. 'category_id' => Registration::t('reg-event', 'Category ID'),
  148. 'category.shortName' => Registration::t('reg-event', 'Category ID'),
  149. 'receipt_id' => Registration::t('reg-event', 'Receipt ID'),
  150. 'status' => Registration::t('reg-event', 'Status'),
  151. 'visit' => Registration::t('reg-event', 'Visit'),
  152. 'music' => Registration::t('reg-event', 'Music'),
  153. 'price' => Registration::t('reg-event', 'Price'),
  154. 'price.cost' => Registration::t('reg-event', 'Price'),
  155. 'statusName' => Registration::t('reg-event', 'Status'),
  156. 'created_at' => Registration::t('reg-event', 'Created At'),
  157. 'updated_at' => Registration::t('reg-event', 'Updated At'),
  158. ];
  159. }
  160.  
  161. /**
  162.   * @return \yii\db\ActiveQuery
  163.   */
  164. public function getReceipt()
  165. {
  166. return $this->hasOne(RegEventReceipt::className(), ['id' => 'receipt_id']);
  167. }
  168.  
  169. /**
  170.   * @return \yii\db\ActiveQuery
  171.   */
  172. public function getCategory()
  173. {
  174. return $this->hasOne(RegEventCategory::className(), ['id' => 'category_id']);
  175. }
  176.  
  177. /**
  178.   * @return \yii\db\ActiveQuery
  179.   */
  180. public function getDiscipline()
  181. {
  182. return $this->hasOne(RegEventDiscipline::className(), ['id' => 'discipline_id']);
  183. }
  184.  
  185. /**
  186.   * @return \yii\db\ActiveQuery
  187.   */
  188. public function getEvent()
  189. {
  190. return $this->hasOne(Event::className(), ['id' => 'event_id']);
  191. }
  192.  
  193. /**
  194.   * @return \yii\db\ActiveQuery
  195.   */
  196. public function getNomination()
  197. {
  198. return $this->hasOne(RegEventNomination::className(), ['id' => 'nomination_id']);
  199. }
  200.  
  201. /**
  202.   * @return \yii\db\ActiveQuery
  203.   */
  204. public function getRang()
  205. {
  206. return $this->hasOne(RegEventRang::className(), ['id' => 'rang_id']);
  207. }
  208.  
  209. /**
  210.   * @return \yii\db\ActiveQuery
  211.   */
  212. public function getProfile()
  213. {
  214. return $this->hasOne(Profile::className(), ['user_id' => 'user_id']);
  215. }
  216.  
  217. /**
  218.   * @return \yii\db\ActiveQuery
  219.   */
  220. public function getMusic()
  221. {
  222. return $this->hasOne(RegEventMusic::className(), ['number' => 'number']);
  223. }
  224.  
  225. /**
  226.   * @return \yii\db\ActiveQuery
  227.   */
  228. public function getUser()
  229. {
  230. return $this->hasOne(User::className(), ['id' => 'user_id']);
  231. }
  232.  
  233. /**
  234.   * @return \yii\db\ActiveQuery
  235.   */
  236. public function getPrice()
  237. {
  238. return $this->hasOne(RegEventPrice::className(), ['event_id' => 'event_id'])
  239. ->andWhere(['rang_id' => $this->rang_id, 'discipline_id' => $this->discipline_id, 'nomination_id' => $this->nomination_id, ])
  240. ->orWhere(['discipline_id' => $this->discipline_id, 'nomination_id' => $this->nomination_id, ]);
  241. }
  242.  
  243. /**
  244.   * {@inheritdoc}
  245.   * @return RegEventQuery the active query used by this AR class.
  246.   */
  247. public static function find()
  248. {
  249. return new RegEventQuery(get_called_class());
  250. }
  251.  
  252. /**
  253.   * Статусы для регистрации
  254.   * @return array
  255.   */
  256. public static function getStatusList()
  257. {
  258. return [
  259. self::STATUS_NOT_PAID => 'Не оплачено',
  260. self::STATUS_PAID => 'Оплачено',
  261. self::STATUS_CANCEL => 'Отменена'
  262. ];
  263. }
  264.  
  265. /**
  266.   * Cтатус регистрации
  267.   * @return mixed
  268.   */
  269. public function getStatusName()
  270. {
  271. return ArrayHelper::getValue(self::getStatusList(),$this->status);
  272. }
  273.  
  274. /**
  275.   * Визит для регистрации
  276.   * @return array
  277.   */
  278. public static function getVisitList()
  279. {
  280. return [
  281. self::VISIT_TRUE => 'Пришел',
  282. self::VISIT_FALSE => 'Не пришел',
  283. ];
  284. }
  285.  
  286. /**
  287.   * Визит регистрации
  288.   * @return mixed
  289.   */
  290. public function getVisitName()
  291. {
  292. return ArrayHelper::getValue(self::getVisitList(), $this->visit);
  293. }
  294.  
  295. /**
  296.   * Список цветов для статусов
  297.   * @return array
  298.   */
  299. public static function getStatusOptionsList()
  300. {
  301. return [
  302. self::STATUS_NOT_PAID => [
  303. 'style' => 'background: #f3d0c9',
  304. 'class' => 'danger'
  305. ],
  306. self::STATUS_PAID => [
  307. 'style' => 'background: #dff0d8',
  308. 'class' => 'success'
  309. ],
  310. self::STATUS_CANCEL => [
  311. 'style' => 'background: #eee; color: #b6b6b6; text-decoration: line-through;',
  312. 'class' => 'default'
  313. ],
  314. ];
  315. }
  316.  
  317. /**
  318.   * @return mixed
  319.   */
  320. public function getStatusOptions()
  321. {
  322. return ArrayHelper::getValue(self::getStatusOptionsList(), $this->status);
  323. }
  324.  
  325. /**
  326.   * Добавить номер
  327.   * @return mixed
  328.   */
  329. public static function setNumber()
  330. {
  331. return self::find()->where(['event_id' => self::getEventId()])->max('number') + 1;
  332. }
  333.  
  334. /**
  335.   * Получение текущего мероприятия
  336.   * @return mixed
  337.   */
  338. public static function getEventId($id = null)
  339. {
  340. return Yii::$app->getModule('registration')->EventSelect->getEventId($id);
  341. }
  342.  
  343. public function getMusicExists()
  344. {
  345. return $this->music ? true : false ;
  346. }
  347.  
  348. }
  349.  
Runtime error #stdin #stdout #stderr 0.01s 23272KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
PHP Fatal error:  Class 'yii\db\ActiveRecord' not found in /home/Ts5M2w/prog.php on line 40