label) { throw new UserException("Object hasn't label."); } return $this->label; } /** * pola wystepujace tylko w obiekatch (nie sa zapisywane do BD) * * @var array */ static $classFields = array(); protected $id; /** zdjecia **/ /** * Export danych do tablicy asocjacyjnej z pol klasy. * * @return array() */ public function ToArrayAssoc() { $fields = $this->GetFields(); $done = array(); foreach($fields as $index => $value) { $temp = 'Get'.$fields[$index]; $done[$index] = $this->$temp(); } return $done; } /** * Import danych z tablicy asocjacyjnej do p�l klasy. * * @param string $array tablica asocjacyjna zawieraj�ca rekordy pobrane z bazy * @param int $cut 1 - klucze musz� mie� posta� _, 0 - */ public function FromArray($array, $cut = false, $alias = null) { $fields = $this->GetFields(); // sprawdzenie czy istnieje metoda dla pol niebedacych w BD if(method_exists($this, 'GetClassFields')) { $fields = array_merge($fields, $this -> GetClassFields()); } $prfx = ((!empty($alias) && is_string($alias)) ? $alias .'_' : '' ); if (is_array($array)) foreach ($array as $index => $var) { if($cut == true) $index = str_replace($prfx . $this->GetClassName() . "_", "", $index); if (array_key_exists($index, $fields)) { $temp = 'Set'.$fields[$index]; $this->$temp($var); } } } /** * Import danych z tablicy asocjacyjnej do p�l klasy. * Jedyn� r�nic� w por�wnaniu do @see FromArray jest zmiana postaci * klucza, kt�re teraz maja posta�: $prefix__ * * @param string $array tablica asocjacyjna zawieraj�ca rekordy pobrane z bazy */ public function FromArrayPrefix($array, $prefix) { $fields = $this->GetFields(); if (is_array($array)) { foreach ($array as $index => $var) { $index = str_replace($prefix . "_" . $this->GetClassName() . "_", "", $index); if (array_key_exists($index, $fields)) { $temp = 'Set'.$fields[$index]; $this->$temp($var); } } } } // public function GetType() { // //MAKL:!! // return array_search($this->GetClassName(),'Stars'); // } public abstract function GetId(); public abstract function GetTableName(); public abstract function GetFields(); public abstract function GetClassName(); public abstract function GetClassTablePK(); public static function GetStaticVariable($variableName) { if(isset(self::$$variableName)) { return self::$$variableName; } else { throw new Exception('Klasa '.__CLASS__.' nie posiada staÅ‚ej: '.$variableName.' !'); } } /** * Metoda zwraca tablice id'k�w tablicy obiekt�w. * Wykorzystywana na potrzeby DefaultDAL::ToJavaScriptArray($array, $jsName) * * @param array $objArray */ public static function GetObjIDs($objArray) { $array = array(); if(is_array($objArray)) { foreach($objArray as $obj) { $array[] = $obj->GetId(); } } else { return $array; } return $array; } /** * Metoda zwraca tablice nazw * Wykorzystywana tylko w slownikach! * * @param unknown_type $objArray */ public static function ToArray($objArray) { $done = array(); foreach($objArray as $value) { $done[$value->GetId()] = $value->GetName(); } return $done; } public static function ToArrayUrl($objArray) { $done = array(); foreach($objArray as $value) { $done[$value->GetName()] = $value->GetUrlName(); } return $done; } public function GetTitleAlt() { return strip_tags(Utils::cleanUrlSpaces($this->GetTitle())); } public function GetTitleUrl() { return Utils::TextToUrl(strip_tags(Utils::cleanUrl($this->GetTitle()))); } /** * Funkcja generuje url * * TODO: Dopisaæ dzia³anie matrixa. * * @param String $label Opcjonalnie, niestandardowy label */ public function GenerateUrl($label = null, $matrix = array()) { if (!$label) { $label = $this->GetLabel(); } $route = Router::$route[$label]; $dataArray = array(); foreach ($route['variables'] as $v) { $fun = 'Get' . ucfirst($v); $dataArray[$v] = Utils::TextToUrl($this->$fun()); } return Router::GenerateUrl($label, $dataArray); } // abstract public function GetUrl(); } ?>