<?php

Doo::loadCore ( 'db/DooModel' );

class BuildActivation extends DooModel {
	
	public $id;
	public $mobile;
	public $sso_id;
	public $compilation_id;
	public $cname;
	public $sid;
	public $cid;
	public $status;
	public $client_id;
	public $addtime;

	public $_table = 'build_activation';
	public $_primarykey = 'id';
	public $_fields = array ('id','mobile','sso_id','compilation_id','cname','sid','cid','status','client_id','addtime');

	public function insertActivation($postData, $staff) {
		$this->mobile = $postData['mobile'];
		$this->sso_id = $postData['id'];
		$this->compilation_id = $postData['cid'];
		$this->cname = $postData['cname'];
		$this->sid = $staff['sid'];
		$this->cid = $staff['cid'];
		$this->client_id = !empty($postData['client_id']) && $postData['client_id'] != 0 ? $postData['client_id'] : 0;
		$this->addtime = time();
		return $this->insert();
	}

	public function getList($sql = ' 1') {
		return $this->find(array('where' => $sql, 'desc' => 'id', 'asArray' => true));
	}

	public function getListByssoID($ssoid) {
		return $this->find(array('where' => 'sso_id=?', 'param' => array($ssoid), 'desc' => 'id', 'asArray' => TRUE));
	}

	public function getOneByssoID($ssoid) {
		return $this->getOne(array('where' => 'sso_id=?', 'param' => array($ssoid), 'desc' => 'id', 'asArray' => TRUE));
	}

	public function setClientID($ssoid, $client_id) {
		$this->client_id = $client_id;
		return $this->update(array('where' => 'sso_id=?', 'param' => array($ssoid)));
	}

	public function getCompilationList() {
		return $this->find(array('select' => 'compilation_id,cname,cid', 'groupby' => 'cname', 'desc' => 'id', 'asArray' => TRUE));
	}
}

?>