HosipLan

Untitled

Aug 7th, 2012
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. class Contact extends Nette\Object
  4. {
  5.     const DEFAULT_IMAGE = "http://images.sodahead.com/polls/002787787/1333899647_no_answer_2_xlarge.gif";
  6.  
  7.     private $contact = array();
  8.     private $data = array();
  9.     private $image;
  10.     private $genre;
  11.     private $contact;
  12.  
  13.     public function __construct(Nette\Database\Table\ActiveRow $row)
  14.     {
  15.         $this->contact = $row;
  16.     }
  17.  
  18.     public function getImage()
  19.     {
  20.         if ($this->image) {
  21.             return $this->image;
  22.         }
  23.  
  24.         $image = $this->row->related("cardata")
  25.             ->where("carddatatype.name","Image")
  26.             ->order("RAND()")->limit(1)->fetch();
  27.  
  28.         return $this->image = ($image ? $image->value : self::DEFAULT_IMAGE);
  29.     }
  30.  
  31.     public function getGendre()
  32.     {
  33.         if ($this->genre) {
  34.             return $this->genre;
  35.         }
  36.  
  37.         $genre = $this->row->related("cardata")->where("carddatatype.name","Gendre")->limit(1)->fetch();
  38.         return $this->genre = ($genre ? $genre->value : "none");
  39.     }
  40.  
  41.     public function getData()
  42.     {
  43.         if ($this->data) {
  44.             return $this->data;
  45.         }
  46.  
  47.         $cards = $this->contact->related("cardata")
  48.             ->where("carddatatype.name NOT ",array("Gendre"))
  49.             ->order('cardata.timecreated DESC');
  50.  
  51.         foreach ($cards as $cardata) {
  52.             $this->data[] = array(
  53.                 'key' => $cardata->carddatatype->name,
  54.                 'value' => $cardata->value
  55.             );
  56.         }
  57.  
  58.         return $this->data;
  59.     }
  60.  
  61.     public function &__get($name)
  62.     {
  63.         if (isset($this->contact->$name)) {
  64.             return $this->contact->$name;
  65.         }
  66.         return parent::__get($name);
  67.     }
  68.  
  69. }
Advertisement
Add Comment
Please, Sign In to add comment