SHOW:
|
|
- or go back to the newest paste.
| 1 | <?php | |
| 2 | ||
| 3 | - | class Contact{
|
| 3 | + | class Contact extends Nette\Object |
| 4 | {
| |
| 5 | const DEFAULT_IMAGE = "http://images.sodahead.com/polls/002787787/1333899647_no_answer_2_xlarge.gif"; | |
| 6 | - | private $row; |
| 6 | + | |
| 7 | private $contact = array(); | |
| 8 | - | public function __construct(Nette\Database\Table\ActiveRow $row){
|
| 8 | + | private $data = array(); |
| 9 | - | |
| 9 | + | private $image; |
| 10 | - | $this->row = $row; |
| 10 | + | private $genre; |
| 11 | - | |
| 11 | + | private $contact; |
| 12 | - | $this->contact['id'] = $row->id; |
| 12 | + | |
| 13 | - | $this->contact['firstname'] = $row->firstname; |
| 13 | + | public function __construct(Nette\Database\Table\ActiveRow $row) |
| 14 | - | $this->contact['surname'] = $row->surname; |
| 14 | + | {
|
| 15 | - | $this->contact['nickname'] = $row->nickname; |
| 15 | + | $this->contact = $row; |
| 16 | } | |
| 17 | ||
| 18 | public function getImage() | |
| 19 | - | private function getContactData(){
|
| 19 | + | {
|
| 20 | - | |
| 20 | + | if ($this->image) {
|
| 21 | - | $this->contact['data'] = array(); |
| 21 | + | return $this->image; |
| 22 | } | |
| 23 | - | if($cardsdata = $this->row->related("cardata")
|
| 23 | + | |
| 24 | - | ->where("carddatatype.name NOT ",array("Gendre"))
|
| 24 | + | $image = $this->row->related("cardata")
|
| 25 | - | ->order('cardata.timecreated DESC')
|
| 25 | + | ->where("carddatatype.name","Image")
|
| 26 | - | ){
|
| 26 | + | ->order("RAND()")->limit(1)->fetch();
|
| 27 | - | |
| 27 | + | |
| 28 | - | foreach($cardsdata as $cardata){
|
| 28 | + | return $this->image = ($image ? $image->value : self::DEFAULT_IMAGE); |
| 29 | } | |
| 30 | - | $data['key'] = $cardata->carddatatype |
| 30 | + | |
| 31 | - | ->name; |
| 31 | + | public function getGendre() |
| 32 | - | $data['value'] = $cardata->value; |
| 32 | + | {
|
| 33 | - | |
| 33 | + | if ($this->genre) {
|
| 34 | - | $this->contact['data'][] = $data; |
| 34 | + | return $this->genre; |
| 35 | } | |
| 36 | - | } |
| 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 | - | private function getContactGendre(){
|
| 41 | + | public function getData() |
| 42 | {
| |
| 43 | - | if($genre = $this->row->related("cardata")
|
| 43 | + | if ($this->data) {
|
| 44 | - | ->where("carddatatype.name","Gendre")
|
| 44 | + | return $this->data; |
| 45 | - | ->limit(1) |
| 45 | + | |
| 46 | - | ->fetch() |
| 46 | + | |
| 47 | - | ){
|
| 47 | + | $cards = $this->contact->related("cardata")
|
| 48 | ->where("carddatatype.name NOT ",array("Gendre"))
| |
| 49 | - | $this->contact['gendre'] = $genre->value; |
| 49 | + | ->order('cardata.timecreated DESC');
|
| 50 | ||
| 51 | - | }else{
|
| 51 | + | foreach ($cards as $cardata) {
|
| 52 | $this->data[] = array( | |
| 53 | - | $this->contact['gendre'] = "none"; |
| 53 | + | 'key' => $cardata->carddatatype->name, |
| 54 | 'value' => $cardata->value | |
| 55 | ); | |
| 56 | } | |
| 57 | ||
| 58 | - | |
| 58 | + | return $this->data; |
| 59 | - | public function getContactImage(){
|
| 59 | + | |
| 60 | ||
| 61 | - | if($image = $this->row->related("cardata")
|
| 61 | + | public function &__get($name) |
| 62 | - | ->where("carddatatype.name","Image")
|
| 62 | + | {
|
| 63 | - | ->order("RAND()")
|
| 63 | + | if (isset($this->contact->$name)) {
|
| 64 | - | ->limit(1) |
| 64 | + | return $this->contact->$name; |
| 65 | - | ->fetch() |
| 65 | + | |
| 66 | - | ){
|
| 66 | + | return parent::__get($name); |
| 67 | } | |
| 68 | - | $this->contact['image'] = $image->value; |
| 68 | + | |
| 69 | } |