Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Contact{
- private $contact = array();
- private $row;
- public function __construct(Nette\Database\Table\ActiveRow $row){
- $this->row = $row;
- $this->contact['id'] = $row->id;
- $this->contact['firstname'] = $row->firstname;
- $this->contact['surname'] = $row->surname;
- $this->contact['nickname'] = $row->nickname;
- }
- private function getContactData(){
- $this->contact['data'] = array();
- if($cardsdata = $this->row->related("cardata")
- ->where("carddatatype.name NOT ",array("Gendre"))
- ->order('cardata.timecreated DESC')
- ){
- foreach($cardsdata as $cardata){
- $data['key'] = $cardata->carddatatype
- ->name;
- $data['value'] = $cardata->value;
- $this->contact['data'][] = $data;
- }
- }
- }
- private function getContactGendre(){
- if($genre = $this->row->related("cardata")
- ->where("carddatatype.name","Gendre")
- ->limit(1)
- ->fetch()
- ){
- $this->contact['gendre'] = $genre->value;
- }else{
- $this->contact['gendre'] = "none";
- }
- }
- public function getContactImage(){
- if($image = $this->row->related("cardata")
- ->where("carddatatype.name","Image")
- ->order("RAND()")
- ->limit(1)
- ->fetch()
- ){
- $this->contact['image'] = $image->value;
- }else{
- $this->contact['image'] = "http://images.sodahead.com/polls/002787787/1333899647_no_answer_2_xlarge.gif";
- }
- }
- public function __get($string){
- if(!isset($this->contact[$string])){
- switch($string){
- case "image":
- $this->getContactImage();
- break;
- case "gendre":
- $this->getContactGendre();
- break;
- case "data":
- $this->getContactData();
- break;
- }
- }
- if(isset($this->contact[$string])){
- return $this->contact[$string];
- }
- return false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment