Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Created by PhpStorm.
- * User: uygfd
- * Date: 04-Jul-15
- * Time: 15:22
- */
- require_once __DIR__."/define.php";
- require_once __DIR__."/CPSConnection.php";
- class User
- {
- private $name;
- private $password;
- private $type;
- private $email;
- private $birthday;
- private $phone;
- public function __construct($name=null,$password=null,$type=null,$email=null,$birthday=null,$phone=null)
- {
- $this->name=$name;
- $this->password=$password;
- $this->type=$type;
- $this->email=$email;
- $this->birthday=$birthday;
- $this->phone=$phone;
- }
- /**
- * @return mixed
- */
- public function getName()
- {
- return $this->name;
- }
- /**
- * @param mixed $name
- */
- public function setName($name)
- {
- $this->name = $name;
- }
- /**
- * @return mixed
- */
- public function getPassword()
- {
- return $this->password;
- }
- /**
- * @param mixed $password
- */
- public function setPassword($password)
- {
- $this->password = $password;
- }
- /**
- * @return mixed
- */
- public function getType()
- {
- return $this->type;
- }
- /**
- * @param mixed $type
- */
- public function setType($type)
- {
- $this->type = $type;
- }
- /**
- * @return mixed
- */
- public function getEmail()
- {
- return $this->email;
- }
- /**
- * @param mixed $email
- */
- public function setEmail($email)
- {
- $this->email = $email;
- }
- /**
- * @return mixed
- */
- public function getBirthday()
- {
- return $this->birthday;
- }
- /**
- * @param mixed $birthday
- */
- public function setBirthday($birthday)
- {
- $this->birthday = $birthday;
- }
- /**
- * @return mixed
- */
- public function getPhone()
- {
- return $this->phone;
- }
- /**
- * @param mixed $phone
- */
- public function setPhone($phone)
- {
- $this->phone = $phone;
- }
- public function insertUser()
- {
- $CPSConn = new CPSConnection(DB_NAME,USERNAME,PASSWORD,ACCOUNT_ID);
- $cps = $CPSConn->initConnection();
- $insert=array("title"=>"user",
- "body"=>array(
- "name"=>$this->getName(),
- "password"=>$this->getPassword(),
- "type"=>$this->getType(),
- "email"=>$this->getEmail(),
- "birthday"=>$this->getBirthday(),
- "phone"=>$this->getPhone())
- );
- $insertReq = new CPS_InsertRequest(uniqid(),$insert);
- $cps->sendRequest($insertReq);
- echo "User inserted!";
- }
- public function updateUser($id,$name,$password,$type,$email,$birthday,$phone)
- {
- $CPSConn = new CPSConnection(DB_NAME,USERNAME,PASSWORD,ACCOUNT_ID);
- $cps = $CPSConn->initConnection();
- $update=array("title"=>"user",
- "body"=>array(
- "name"=>$name,
- "password"=>$password,
- "type"=>$type,
- "email"=>$email,
- "birthday"=>$birthday,
- "phone"=>$phone)
- );
- $updateReq = new CPS_UpdateRequest($id,$update);
- $cps->sendRequest($updateReq);
- echo "User updated!";
- }
- public function selectUser($id)
- {
- $CPSConn = new CPSConnection(DB_NAME,USERNAME,PASSWORD,ACCOUNT_ID);
- $cps = $CPSConn->initConnection();
- $selectReq=new CPS_RetrieveRequest($id);
- $selectRes=$cps->sendRequest($selectReq);
- echo "User selected!<br>";
- foreach ($selectRes->getDocuments() as $id=>$doc)
- {
- if ($doc->title=="user") {
- echo "Found!<br>";
- $this->setName($doc->body->name);
- $this->setPassword($doc->body->password);
- $this->setType($doc->body->type);
- $this->setEmail($doc->body->email);
- $this->setBirthday($doc->body->birthday);
- $this->setPhone($doc->body->phone);
- }
- }
- }
- public function deleteUser($id)
- {
- $CPSConn = new CPSConnection(DB_NAME,USERNAME,PASSWORD,ACCOUNT_ID);
- $cps = $CPSConn->initConnection();
- $deleteReq=new CPS_DeleteRequest($id);
- $cps->sendRequest($deleteReq);
- echo "User deleted!";
- }
- public function selectUserByName($name)
- {
- $CPSConn = new CPSConnection(DB_NAME,USERNAME,PASSWORD,ACCOUNT_ID);
- $cps = $CPSConn->initConnection();
- $query=CPS_Term("user","title");
- $searchReq=new CPS_SearchRequest($query);
- $searchRes=$cps->sendRequest($searchReq);
- echo "User selected!<br>";
- if ($searchRes->getHits()>0)
- {
- foreach ($searchRes->getDocuments() as $id=>$doc)
- {
- if ($doc->body->name==$name)
- {
- echo "Found!<br>";
- $this->setName($doc->body->name);
- $this->setPassword($doc->body->password);
- $this->setType($doc->body->type);
- $this->setEmail($doc->body->email);
- $this->setBirthday($doc->body->birthday);
- $this->setPhone($doc->body->phone);
- }
- }
- }
- }
- public function selectUserByNameKeyword($keyword)
- {
- $CPSConn = new CPSConnection(DB_NAME,USERNAME,PASSWORD,ACCOUNT_ID);
- $cps = $CPSConn->initConnection();
- $searchReq=new CPS_SQLSearchRequest('SELECT id WHERE CONTAINS(body.name,"*'.$keyword.'*") AND CONTAINS(title,"user")');
- $searchRes=$cps->sendRequest($searchReq);
- echo "User selected!<br>";
- if ($searchRes->getHits()>0)
- {
- foreach ($searchRes->getDocuments() as $id=>$doc)
- {
- echo "Found!<br>";
- $this->setName($doc->body->name);
- $this->setPassword($doc->body->password);
- $this->setType($doc->body->type);
- $this->setEmail($doc->body->email);
- $this->setBirthday($doc->body->birthday);
- $this->setPhone($doc->body->phone);
- }
- }
- }
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement