/** * @param string $scenario * @param int $id Model primary key */ function __construct($scenario = self::SC_INSERT, $id = null) { $this->initAttributes(); $this->_scenario = $scenario; $this->_db = App::db(); /** If set id search by primary key else create default attributes */ if (isset($id)) { $this->findByPk($id); } }
/** Save files count */ public function saveFilesCount() { $this->saveAttr(array('files_count' => App::db()->runSql('select count(*) from tbl_file where userid = :userid and statusid = ' . FileModel::SC_STATUS_ACTIVE, array(':userid' => $this->userid))->fetchColumn())); }