Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- class Contact extends Nette\Object
- {
- const DEFAULT_IMAGE = "http://images.sodahead.com/polls/002787787/1333899647_no_answer_2_xlarge.gif";
- private $contact = array();
- private $data = array();
- private $image;
- private $genre;
- private $contact;
- public function __construct(Nette\Database\Table\ActiveRow $row)
- {
- $this->contact = $row;
- }
- public function getImage()
- {
- if ($this->image) {
- return $this->image;
- }
- $image = $this->row->related("cardata")
- ->where("carddatatype.name","Image")
- ->order("RAND()")->limit(1)->fetch();
- return $this->image = ($image ? $image->value : self::DEFAULT_IMAGE);
- }
- public function getGendre()
- {
- if ($this->genre) {
- return $this->genre;
- }
- $genre = $this->row->related("cardata")->where("carddatatype.name","Gendre")->limit(1)->fetch();
- return $this->genre = ($genre ? $genre->value : "none");
- }
- public function getData()
- {
- if ($this->data) {
- return $this->data;
- }
- $cards = $this->contact->related("cardata")
- ->where("carddatatype.name NOT ",array("Gendre"))
- ->order('cardata.timecreated DESC');
- foreach ($cards as $cardata) {
- $this->data[] = array(
- 'key' => $cardata->carddatatype->name,
- 'value' => $cardata->value
- );
- }
- return $this->data;
- }
- public function &__get($name)
- {
- if (isset($this->contact->$name)) {
- return $this->contact->$name;
- }
- return parent::__get($name);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment