1<?php
2
3namespace GO\Email\Model;
4
5use GO\Base\Model\Template;
6
7class DefaultTemplateForAccount extends \GO\Base\Db\ActiveRecord {
8
9	public static function model($className=__CLASS__)
10	{
11		return parent::model($className);
12	}
13
14	public function tableName() {
15		return 'email_default_email_account_templates';
16	}
17
18	public function primaryKey() {
19		return 'account_id';
20	}
21
22	public function relations(){
23		return array(
24			'emailTemplate' => array('type'=>self::BELONGS_TO, 'model'=>'GO\Base\Model\Template', 'field'=>'template_id'),
25			'emailAccount' => array('type'=>self::BELONGS_TO, 'model'=>'GO\Email\Model\Account', 'field'=>'account_id')
26		);
27	}
28
29
30	protected function defaultAttributes() {
31		$attr = parent::defaultAttributes();
32
33		$findParams = \GO\Base\Db\FindParams::newInstance()->limit(1);
34		$stmt = Template::model()->find($findParams);
35
36		if($template=$stmt->fetch())
37		{
38			$attr['template_id']=$template->id;
39		}
40
41		return $attr;
42	}
43}
44