Guest User

Untitled

a guest
Aug 7th, 2012
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.85 KB | None | 0 0
  1. <?php
  2.  
  3. class Contact{
  4.  
  5.     private $contact = array();
  6.     private $row;
  7.  
  8.     public function __construct(Nette\Database\Table\ActiveRow $row){
  9.        
  10.         $this->row = $row;
  11.        
  12.         $this->contact['id'] = $row->id;
  13.         $this->contact['firstname'] = $row->firstname;
  14.         $this->contact['surname'] = $row->surname;
  15.         $this->contact['nickname'] = $row->nickname;
  16.  
  17.     }
  18.  
  19.     private function getContactData(){
  20.    
  21.         $this->contact['data'] = array();
  22.  
  23.         if($cardsdata = $this->row->related("cardata")
  24.                     ->where("carddatatype.name NOT ",array("Gendre"))
  25.                     ->order('cardata.timecreated DESC')
  26.             ){
  27.        
  28.             foreach($cardsdata as $cardata){
  29.  
  30.                 $data['key'] = $cardata->carddatatype
  31.                             ->name;
  32.                 $data['value'] = $cardata->value;
  33.            
  34.                 $this->contact['data'][] = $data;
  35.  
  36.             }
  37.  
  38.         }
  39.     }
  40.  
  41.     private function getContactGendre(){
  42.  
  43.         if($genre = $this->row->related("cardata")
  44.                     ->where("carddatatype.name","Gendre")
  45.                     ->limit(1)
  46.                     ->fetch()
  47.             ){
  48.  
  49.             $this->contact['gendre'] = $genre->value;
  50.  
  51.         }else{
  52.  
  53.             $this->contact['gendre'] = "none";
  54.  
  55.         }
  56.  
  57.     }
  58.    
  59.     public function getContactImage(){
  60.  
  61.         if($image = $this->row->related("cardata")
  62.                     ->where("carddatatype.name","Image")
  63.                     ->order("RAND()")
  64.                     ->limit(1)
  65.                     ->fetch()
  66.             ){
  67.  
  68.             $this->contact['image'] = $image->value;
  69.  
  70.         }else{
  71.  
  72.             $this->contact['image'] = "http://images.sodahead.com/polls/002787787/1333899647_no_answer_2_xlarge.gif";
  73.            
  74.         }  
  75.  
  76.     }
  77.  
  78.     public function __get($string){
  79.  
  80.         if(!isset($this->contact[$string])){
  81.  
  82.             switch($string){
  83.                 case "image":
  84.                     $this->getContactImage();
  85.                     break;
  86.                 case "gendre":
  87.                     $this->getContactGendre();
  88.                     break;
  89.                 case "data":
  90.                     $this->getContactData();
  91.                     break;     
  92.             }
  93.  
  94.         }
  95.  
  96.         if(isset($this->contact[$string])){
  97.  
  98.             return $this->contact[$string];
  99.    
  100.         }
  101.  
  102.         return false;
  103.  
  104.     }
  105.  
  106. }
Advertisement
Add Comment
Please, Sign In to add comment