albumTable.php

<?php

namespace Album\Model;

use Zend\Db\TableGateway\AbstractTableGateway;
use Zend\Db\Adapter\Adapter;
use Zend\Db\ResultSet\ResultSet;

class AlbumTable extends AbstractTableGateway
{
    protected $table = 'aii_user';

    public function __construct(Adapter $adapter)
    {
        $this->adapter = $adapter;
        $this->resultSetPrototype = new ResultSet();
        $this->resultSetPrototype->setArrayObjectPrototype(new Album());

        $this->initialize();
    }

    public function fetchAll()
    {
        $resultSet = $this->select();
        return $resultSet;
    }

    public function getAlbum($id)
    {
        $id  = (int) $id;
        $rowset = $this->select(array('id' => $id));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("Could not find row $id");
        }
        return $row;
    }
    
     public function checkReg($aii_username)
    {
        $aii_username  = $aii_username;
        $rowset = $this->select(array('aii_username' => $aii_username));
        $row = $rowset->current();
        if ($row) {
            throw new \Exception("this username already reg");
        }
        return true;
    } //检查该用户名是否被注册
    
     public function checkLogin($aii_username,$aii_password)
    {
        $aii_username  = $aii_username;
        $aii_password=$aii_password;
        $rowset = $this->select(array('aii_username' => $aii_username,'aii_password'=>$aii_password));
        $row = $rowset->current();
        if (!$row) {
            throw new \Exception("the username or password is wrong");
        }
        return true;
    } //验证登录

    public function saveAlbum(Album $album)
    {
        $data = array(
            'aii_username' => $album->aii_username,
            'aii_password'  => $album->aii_password,
        );
        $this->checkReg($data['aii_username']);
        $id = (int)$album->id;
        if ($id == 0) {
            $this->insert($data);
        } else {
            if ($this->getAlbum($id)) {
                $this->update($data, array('id' => $id));
            } else {
                throw new \Exception('Form id does not exist');
            }
        }
    }

    public function deleteAlbum($id)
    {
        $this->delete(array('id' => $id));
    }

}

 

posted @ 2013-04-23 14:25  徐耀湘  阅读(156)  评论(0编辑  收藏  举报