Create.php
00001 <?php
00012 class Dsao_Model_Hero_Create extends Dsao_Model_Abstract
00013 {
00014 protected function _init()
00015 {
00016 $this->_setDefaultTable('hero_dsa3');
00017 }
00018
00027 public function isUniqueHeroname($heroname)
00028 {
00029
00030 return !(bool) $this->_getTable()->select()
00031 ->where('name = ?', $heroname)->fetchRow();
00032 }
00033
00040 public function isUniqueHeroOfUser($userId)
00041 {
00042
00043 return !(bool) $this->_getTable()->select()
00044 ->where('idUser = ?', $userId)->fetchRow();
00045 }
00046
00047
00054 public function insertHero(Dsao_Hero $hero)
00055 {
00056
00057 $sqlHeroData = array
00058 (
00059 'idUser' => $hero->idUser,
00060 'idGroup' => 0,
00061 'name' => $hero->name,
00062 );
00063
00064
00065 $this->_getTable()->getAdapter()->beginTransaction();
00066
00067 try
00068 {
00069
00070
00071 $this->_getTable()->insert($sqlHeroData);
00072
00073
00074 $this->_getTable()->getAdapter()->commit();
00075 }
00076
00077
00078 catch (Zend_Db_Exception $e)
00079 {
00080 $this->_getTable()->getAdapter()->rollback();
00081
00082 $this->getLog()->err('global_error_mysql_write', __METHOD__);
00083
00084 return false;
00085 }
00086
00087 }
00088 }