From 530851a10fcb43f460b1d6130cae3aad31b02995 Mon Sep 17 00:00:00 2001 From: Fredric N Date: Sat, 26 Feb 2011 14:04:06 +0100 Subject: [PATCH] A rework of the model structure --- application/Bootstrap.php | 31 +--- application/models/About.php | 6 - application/models/BlogPost.php | 175 ------------------ application/models/Mapper/About.php | 22 --- application/models/Mapper/BlogPost.php | 139 -------------- application/models/ModelBlogPost.php | 110 +++++++++++ application/models/ModelPostTag.php | 21 +++ application/models/ModelTag.php | 35 ++++ .../models/{Mapper/User.php => ModelUser.php} | 59 ++---- application/models/Table/About.php | 8 - application/models/Table/BlogPost.php | 9 - application/models/Table/PosthasTag.php | 20 -- application/models/Table/Tag.php | 8 - application/models/Table/User.php | 9 - application/models/{Mapper => }/Tag.php | 0 application/models/User.php | 173 ----------------- application/models/rows/Post.php | 36 ++++ application/models/rows/User.php | 9 + .../Controller/Action/Helper/DataService.php | 17 -- library/Fiktiv/Controller/Plugin/Language.php | 9 + library/Fiktiv/Data/Service.php | 68 ------- library/Fiktiv/Model/Abstract.php | 71 +------ .../Fiktiv/Model/Mapper/DbTableAbstract.php | 34 ---- library/Fiktiv/Model/Row/Abstract.php | 6 + 24 files changed, 253 insertions(+), 822 deletions(-) delete mode 100644 application/models/About.php delete mode 100644 application/models/BlogPost.php delete mode 100644 application/models/Mapper/About.php delete mode 100644 application/models/Mapper/BlogPost.php create mode 100644 application/models/ModelBlogPost.php create mode 100644 application/models/ModelPostTag.php create mode 100644 application/models/ModelTag.php rename application/models/{Mapper/User.php => ModelUser.php} (60%) delete mode 100644 application/models/Table/About.php delete mode 100644 application/models/Table/BlogPost.php delete mode 100644 application/models/Table/PosthasTag.php delete mode 100644 application/models/Table/Tag.php delete mode 100644 application/models/Table/User.php rename application/models/{Mapper => }/Tag.php (100%) delete mode 100644 application/models/User.php create mode 100644 application/models/rows/Post.php create mode 100644 application/models/rows/User.php delete mode 100644 library/Fiktiv/Controller/Action/Helper/DataService.php delete mode 100644 library/Fiktiv/Data/Service.php delete mode 100644 library/Fiktiv/Model/Mapper/DbTableAbstract.php create mode 100644 library/Fiktiv/Model/Row/Abstract.php diff --git a/application/Bootstrap.php b/application/Bootstrap.php index a9df6a8..44bdae6 100644 --- a/application/Bootstrap.php +++ b/application/Bootstrap.php @@ -1,5 +1,4 @@ getResource('view'); $view->navigation()->setTranslator($this->getResource('translate')); $view->navigation($navigation); @@ -163,7 +162,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap // Route for admin? - $router->addRoute('admin', new Zend_Controller_Router_Route(':lang/admin/:controller/:action',array( + $router->addRoute('admin', new Zend_Controller_Router_Route(':lang/admin/:controller/:action/*',array( 'module' => 'admin', 'controller' => 'index', 'action' => 'index' @@ -192,6 +191,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap // Include global model directory set_include_path(implode(PATH_SEPARATOR, array( APPLICATION_PATH . '/models', + APPLICATION_PATH . '/models/rows', get_include_path() ))); @@ -229,7 +229,7 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap 'locale' => 'sv', 'content' => APPLICATION_PATH . '/languages/se.ini' )); - + $translate->addTranslation(APPLICATION_PATH . '/languages/en.ini', 'en'); Zend_Form::setDefaultTranslator($translate); @@ -239,20 +239,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap return $translate; } - /** - * Setup datastorage - */ - protected function _initDatastorage() - { - $this->bootstrap('autoloader'); - - // Include datapoints directory - set_include_path(implode(PATH_SEPARATOR, array( - APPLICATION_PATH . '/datastorage', - get_include_path() - ))); - } - /** * Setup a sweet and simple database * connection. @@ -270,15 +256,6 @@ class Bootstrap extends Zend_Application_Bootstrap_Bootstrap // Use the adapter by default Zend_Db_Table::setDefaultAdapter($database); - /* - * Fire up the data service - * This is not needed as the data service will be - * started when it is first accessed. Also, the - * data service will automaticly load datapoints - * on demand. - */ - $dbLayer = Fiktiv_Data_Service::getInstance(); - return $database; } diff --git a/application/models/About.php b/application/models/About.php deleted file mode 100644 index 88e2986..0000000 --- a/application/models/About.php +++ /dev/null @@ -1,6 +0,0 @@ - 0, - 'title' => null, - 'content' => null, - 'pubDate' => null, - 'author' => null, - 'permalink' => null, - 'isPublished' => false, - 'tags' => array(), - ); - - public function setAttribs(array $data) { - - foreach ($data as $key => $value) { - - switch(strtolower($key)) { - case 'title': - $this->setTitle($value); - break; - case 'content': - $this->setContent($value); - break; - case 'author': - $this->setAuthor($value); - break; - case 'pubdate': - $this->setPubDate(new Zend_Date($value)); - break; - case 'tags': - $this->setTags($value); - break; - case 'permalink': - $this->setPermalink($value); - break; - } - } - } - - public function setId($id) - { - if (is_numeric($id)) - $this->_data['id'] = $id; - } - - public function setTitle($title) - { - if (is_string($title) && !isset($title[30])) { - - $this->_data['title'] = $title; - $this->generatePermalink(); - return true; - } - - return false; - } - - public function setContent($content) - { - if (is_string($content)) { - - $this->_data['content'] = $content; - return true; - } - - return false; - } - - public function setAuthor($author) - { - if ($author instanceof User) { - - $this->_data['author'] = $author; - return true; - } - - return false; - } - - public function addTag($tag) - { - if (is_string($tag)) { - $this->_data['tags'][] = $tag; - return true; - } - - return false; - } - - public function setTags(array $tags) - { - // make sure the all elements are strings - foreach ($tags as $key => $tag) { - - if (!is_string($tag)) { - return false; - } - } - - $this->_data['tags'] = $tags; - return true; - } - - public function setPubDate($date) - { - - if (Fiktiv_Date::isDate($date)) { - - $this->_data['pubDate'] = new Fiktiv_Date($date); - - } else if ($date instanceof Zend_Date) { - - $this->_data['pubDate'] = $date; - - } else { - - return false; - } - - return true; - } - - public function isPublished($flag = null) - { - if (null === $flag) { - return $this->_data['isPublished']; - } - - $this->_data['isPublished'] = (boolean)$flag; - } - - public function setPermalink($permalink) - { - if (is_string($permalink)) { - $this->_data['permalink'] = $permalink; - return true; - } - - return false; - } - - protected function generatePermalink() - { - $permalink = $this->_data['title']; - - // All to lowercase - $permalink = strtolower($permalink); - - // Remove special characters - $permalink = filter_var($permalink, FILTER_SANITIZE_SPECIAL_CHARS); - - // Replace stuff - $replace = array( - ' ' => '-', - 'å' => 'a', - 'ä' => 'a', - 'ö' => 'o', - '_' => '-', - '!' => '', - '?' => '', - '.' => '', - ',' => '', - ); - foreach($replace as $char => $value) { - $permalink = str_replace($char,$value,$permalink); - } - - $this->_data['permalink'] = $permalink; - } -} \ No newline at end of file diff --git a/application/models/Mapper/About.php b/application/models/Mapper/About.php deleted file mode 100644 index b7f99ea..0000000 --- a/application/models/Mapper/About.php +++ /dev/null @@ -1,22 +0,0 @@ -fet - $adapter = $this->_dbTable->getAdapter(); - - $select = $adapter - ->select() - ->from('About', array('Title', 'Content')) - ->where('Locale = ?', $locale); - - return $adapter->fetchPairs($select); - } -} \ No newline at end of file diff --git a/application/models/Mapper/BlogPost.php b/application/models/Mapper/BlogPost.php deleted file mode 100644 index 87c6ac1..0000000 --- a/application/models/Mapper/BlogPost.php +++ /dev/null @@ -1,139 +0,0 @@ -_mapperUser = new Mapper_User(new Table_User()); - } - - protected function _createBlogPosts($obj) - { - $posts = array(); - foreach($obj as $post) - $posts[] = $this->_createBlogPost($post); - - return $posts; - } - - protected function _createBlogPost($obj) - { - - if ($obj instanceof Zend_Db_Table_Row) - $obj = $obj->toArray(); - - - if ($obj instanceof stdClass) - $obj = (array) $obj; - - - if (is_array($obj)) { - - // Get Author - if (isset($obj['userId'])) { - $obj['author'] = Fiktiv_Data_Service::getInstance()->User->findById($obj['userId']); - unset($obj['userId']); - } - - // Get tags - $obj['tags'] = $this->getTags($obj['id']); - - $blogPost = new BlogPost($obj); - - } else { - $blogPost = null; - } - - return $blogPost; - } - - public function getTags($blogPostId) - { - return Fiktiv_Data_Service::getInstance()->Tag->findByBlogPost($blogPostId); - } - - public function findById($id) - { - if (is_numeric($id)) { - return $this->_createBlogPost($this->_dbTable->find($id)->current()); - } - - return null; - } - - public function findByPermalink($permalink) - { - if (is_string($permalink)) { - return $this->_createBlogPost($this->_dbTable->fetchRow($this->quoteInto('permalink LIKE ?', $permalink))); - } - - return null; - } - - public function findAllPostByAuthor($user) - { - if ($user instanceof User) { - return $this->_createBlogPost($this->_dbTable->findByUser($user->getId())); - } - } - - public function findByTag($tag) - { - $rows = $this->_dbTable->getAdapter() - ->select()->from('Post') - ->join('Post_has_Tag', 'Post_has_Tag.postId = Post.id') - ->join('Tag', 'Tag.id = Post_has_Tag.tagId') - ->where('Tag.name = ?', $tag) - ->query()->fetchAll(); - - return $this->_createBlogPosts($rows); - } - - public function findByMonth($month = null) - { - return $this->_dbTable->select() - ->from($this->_dbTable->_name,array('Month' => 'DATE_FORMAT(pubDate,"%Y %M")', 'Date' => 'DATE_FORMAT(pubDate,"%Y-%M")')) - ->group('Month') - ->query() - ->fetchAll(); - } - - public function findByDate($date) - { - $date = new Fiktiv_Date($date); - - $where = $this->quoteInto('pubDate LIKE ?', $date->getIso()); - - return $this->_createBlogPosts($this->_dbTable->fetchAll($where)); - } - - public function findAll($limit = null) - { - - if (!is_numeric($limit)) - throw new Fiktiv_Exception('limit must be numeric'); - - return $this->_createBlogPosts($this->_dbTable->fetchAll(null, 'pubDate DESC', $limit)); - } - - public function save(BlogPost $post) - { - $data = $post->toArray(); - - unset($data['id']); - - $tags = $data['tags']; - unset($data['tags']); - - - - return $this->_dbTable->update( - $data, - $this->quoteInto('id = ?',$post->getId()) - ); - } -} \ No newline at end of file diff --git a/application/models/ModelBlogPost.php b/application/models/ModelBlogPost.php new file mode 100644 index 0000000..1e4b585 --- /dev/null +++ b/application/models/ModelBlogPost.php @@ -0,0 +1,110 @@ +select()->from($this->_name, array('Month' => 'DATE_FORMAT(pubDate,"%Y %M")', 'Date' => 'DATE_FORMAT(pubDate,"%Y-%M")')) + ->group('Month') + ->query() + ->fetchAll(); + + return $posts; + } + + public function findByAuthor($user) + { + if ($user instanceof User) { + + } else if (is_integer($user)) { + + } + } + + public function findByTag($tag) + { + // Is this right? + + $tags = new ModelTag(); + $row = $tags->fetchRow("name = 'Linux'"); + $posts = $row->findManyToManyRowset('ModelBlogPost', 'ModelPostTag'); + + return $posts; + } + + public function findByDate($date, $format) + { + // This is a joke, FIXIT! + + $date = new Fiktiv_Date($date,$format); + + $where = $this->quoteInto('DATE_FORMAT(pubDate,"%Y %M") LIKE ?', $date->toString('Y MMMM')); + + return $this->fetchAll($where); + } + + public function findByPermlink($permlink) + { + return $this->fetchRow($this->quoteInto('permlink', $permlink)); + } + + public function createPost($data, $id = null) + { + $myTags = explode(',', $data['tags']); + unset($data['tags']); + $data['userId'] = Zend_Auth::getInstance()->getIdentity()->id; + + $data['pubDate'] = Zend_Date::now()->getIso(); + $data['isPublished'] = 1; + + if ($id) { + $row = $this->find($id)->current(); + $row->setFromArray($data); + $row->save(); + } else { + $row = $this->find($this->insert($data))->current(); + } + + if ($myTags) { + $tags = new ModelTag(); + $tags->tagsToPost($myTags, $row->id); + } + + } + + protected function generatePermalink() + { + $permalink = $this->_data['title']; + + // All to lowercase + $permalink = strtolower($permalink); + + // Remove special characters + $permalink = filter_var($permalink, FILTER_SANITIZE_SPECIAL_CHARS); + + // Replace stuff + $replace = array( + ' ' => '-', + 'å' => 'a', + 'ä' => 'a', + 'ö' => 'o', + '_' => '-', + '!' => '', + '?' => '', + '.' => '', + ',' => '', + ); + foreach($replace as $char => $value) { + $permalink = str_replace($char,$value,$permalink); + } + + $this->_data['permalink'] = $permalink; + } +} \ No newline at end of file diff --git a/application/models/ModelPostTag.php b/application/models/ModelPostTag.php new file mode 100644 index 0000000..78ee06f --- /dev/null +++ b/application/models/ModelPostTag.php @@ -0,0 +1,21 @@ + array( + 'columns' => 'postId', + 'refTableClass' => 'ModelBlogPost', + 'refColumns' => 'id' + ), + 'ModelTag' => array( + 'columns' => 'tagId', + 'refTableClass' => 'ModelTag', + 'refColumns' => 'id' + ) + ); + +} \ No newline at end of file diff --git a/application/models/ModelTag.php b/application/models/ModelTag.php new file mode 100644 index 0000000..0a1a709 --- /dev/null +++ b/application/models/ModelTag.php @@ -0,0 +1,35 @@ +delete($this->quoteInto('postId = ?', $postId)); + + foreach ($tags as $key => $tag) { + $tags[$key] = trim($tag); + + $tag = $this->fetchRow($this->quoteInto('name = ?', $tags[$key])); + + if (!$tag) { + $tagId = $this->insert(array('name' => $tags[$key])); + } else { + $tagId = $tag->id; + } + + + $postsTags->insert(array( + 'postId' => $postId, + 'tagId' => $tagId + )); + + } + } +} diff --git a/application/models/Mapper/User.php b/application/models/ModelUser.php similarity index 60% rename from application/models/Mapper/User.php rename to application/models/ModelUser.php index c5d1402..319b055 100644 --- a/application/models/Mapper/User.php +++ b/application/models/ModelUser.php @@ -1,33 +1,27 @@ toArray(); - - - $user = null; - - if (is_array($object)) - $user = new User($object); - - return $user; - } - + protected $_referenceMap = array( + 'ModelBlogPost' => array( + 'columns' => array('id'), + 'refTableClass' => 'ModelBlogPost', + 'refColumns' => array('userId') + ) + ); public function findById($id) { if (is_numeric($id)) { return $this->_createUser($this->_dbTable->find($id)->current()); } + + return null; } /** @@ -55,7 +49,7 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract */ public function findRandom() { - return $this->_createUser($this->_dbTable->fetchAll(null, 'RAND()', 1)->current()); + return $this->fetchAll(null, 'RAND()', 1)->current(); } @@ -70,7 +64,7 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract $auth = Zend_Auth::getInstance(); // Setup auth adapter - $authAdapter = new Zend_Auth_Adapter_DbTable($this->_dbTable->getAdapter(), $this->_dbTable->_name, 'email', 'password'); + $authAdapter = new Zend_Auth_Adapter_DbTable($this->getAdapter(), $this->_name, 'email', 'password'); // Set credentials $authAdapter->setIdentity($email); @@ -84,7 +78,8 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract // Keep all but password and salt in session. $storage = $auth->getStorage(); - $storage->write($this->_createUser($authAdapter->getResultRowObject(null, array('password', 'salt')))); + $user = $authAdapter->getResultRowObject(null, array('password', 'salt')); + $storage->write($user); return true; } @@ -105,25 +100,11 @@ class Mapper_User extends Fiktiv_Model_Mapper_DbTableAbstract if (!is_numeric($userId)) return false; - return $this->_dbTable->update( + return $this->update( array( 'password' => hash('sha256',$password) ), - $this->_dbTable->getAdapter()->quoteInto('id = ?',$userId) - ); - } - - - /** - * Save User object - */ - public function save(User $user) - { - $data = $user->toArray(); - unset($data['id']); - - return $this->_dbTable->update($data, - $this->_dbTable->getAdapter()->quoteInto('id = ?',$user->getId()) + $this->getAdapter()->quoteInto('id = ?',$userId) ); } diff --git a/application/models/Table/About.php b/application/models/Table/About.php deleted file mode 100644 index 201c831..0000000 --- a/application/models/Table/About.php +++ /dev/null @@ -1,8 +0,0 @@ - array( - 'columns' => 'postId', - 'refTableClass' => 'Post', - 'refColumns' => 'id' - ), - 'Tag' => array( - 'columns' => 'tagId', - 'refTableClass' => 'Tag', - 'refColumns' => 'id' - ) - ); - -} \ No newline at end of file diff --git a/application/models/Table/Tag.php b/application/models/Table/Tag.php deleted file mode 100644 index 00fd7e5..0000000 --- a/application/models/Table/Tag.php +++ /dev/null @@ -1,8 +0,0 @@ - 0, - 'email' => null, - 'firstName' => null, - 'lastName' => null, - 'regDate' => null, - 'isDeleted' => false, - 'avatar' => self::AVATAR_NONE, - 'avatarImage' => null, - 'userRole' => Acl::ROLE_VISITOR - ); - - public function setId($id) - { - if (is_numeric($id)) - $this->_data['id'] = $id; - } - - /** - * Set user email - * - * @return boolean - */ - public function setEmail($email) - { - $validator = new Zend_Validate_EmailAddress(); - - if ($validator->isValid($email)) { - $this->_data['email'] = $email; - - return true; - } - - return false; - } - - /** - * Set user lastname - * - * @param string $name - * @return boolean - */ - public function setLastName($name) - { - if (is_string($name) && preg_match('/^[A-ö\ \.\-]{0,20}$/', $name)) { - $this->_data['lastName'] = $name; - return true; - } - - return false; - } - - /** - * Set user firstname - * - * @param string $name - * @return boolean - */ - public function setFirstName($name) - { - $name = trim($name); - - if (is_string($name) && preg_match('/^[A-ö]{2,8}\-?[A-ö]{2,8}$/', $name)) { - $this->_data['firstName'] = $name; - return true; - } - - return false; - } - - /** - * Set the user registration date - * - * @param Zend_Date | string $date - * @return boolean - */ - public function setRegDate($date) - { - if (is_string($date) && preg_match('/^(?:(?:19[0-9]{2})|(?:20[0-9]{2}))\-' . - '(?:(?:0[1-9])|(?:1[012]))\-(?:(?:0[1-9])|(?:[12][0-9])|(?:3[01]))$/', $date)) { - - $this->_data['regDate'] = $date; - } else if ($date instanceof Zend_Date) { - - $this->_data['regDate'] = $date->toString('yyyy-MM-dd'); - } else { - - return false; - } - - return true; - } - - public function setAvatar($type) - { - - if (self::AVATAR_NONE === $type) { - - $this->_data['avatar'] = self::AVATAR_NONE; - $this->_data['avatarImage'] = null; - - } else if (self::AVATAR_GRVTAR === $type) { - - $this->_data['avatar'] = self::AVATAR_GRVTAR; - $this->_data['avatarImage'] = null; - - } else if (is_string($type)) { - - $this->_data['avatar'] = self::AVATAR_FIKTIV; - $this->_data['avatarImage'] = $type; - } - - } - - public function setPassword($password) - { - if (!is_string($password)) - throw new Fiktiv_Exception('password must be string'); - - Fiktiv_Data_Service::getInstance()->User->setPassword($this, $password); - } - - /** - * Returns the user registration date - * - * @return string $_regDate - */ - public function userSince() - { - return !empty($_regDate) ? $_regDate : false; - } - - /** - * Returns the current status of the account. - * - * @return boolean - */ - public function isActive() - { - return !$this->_data['isDeleted']; - } - - /** - * String representation of the object - * @return string - */ - public function __toString() - { - return '(' . __CLASS__ . '){' . $this->_data['email'] . ', ' . $this->_data['firstName'] . ' ' . $this->_data['lastName'] . '}'; - } - - /** - * Convert object to array - */ - public function toArray() - { - return $this->_data; - } - -} \ No newline at end of file diff --git a/application/models/rows/Post.php b/application/models/rows/Post.php new file mode 100644 index 0000000..dfff4a9 --- /dev/null +++ b/application/models/rows/Post.php @@ -0,0 +1,36 @@ +pubDate); + } + + public function hasTags() + { + if (null === $this->_tags) { + $this->_tags = $this->getTags(); + } + + return (0 !== $this->_tags->count()); + } + + public function getTags() + { + // Quickie! + if (null !== $this->_tags) { + return $this->_tags; + } + + return $this->findManyToManyRowset('ModelTag', 'ModelPostTag'); + } + + public function getAuthor() + { + return $this->findDependentRowset('ModelUser')->current(); + } +} diff --git a/application/models/rows/User.php b/application/models/rows/User.php new file mode 100644 index 0000000..b89e601 --- /dev/null +++ b/application/models/rows/User.php @@ -0,0 +1,9 @@ +dataService(); - } -} \ No newline at end of file diff --git a/library/Fiktiv/Controller/Plugin/Language.php b/library/Fiktiv/Controller/Plugin/Language.php index e97451f..60f0cd2 100644 --- a/library/Fiktiv/Controller/Plugin/Language.php +++ b/library/Fiktiv/Controller/Plugin/Language.php @@ -32,6 +32,15 @@ class Fiktiv_Controller_Plugin_Language extends Zend_Controller_Plugin_Abstract if ($translate->isAvailable($lang)) { $translate->setLocale($lang); } + + // Set database locale + $lookup = array( + 'sv' => 'sv_SE', + 'en' => 'en_US' + ); + + $database = $bootstrap->getResource('database'); + $database->query("SET lc_time_names = ?;", $lookup[$lang]); } protected function test() diff --git a/library/Fiktiv/Data/Service.php b/library/Fiktiv/Data/Service.php deleted file mode 100644 index a8d9547..0000000 --- a/library/Fiktiv/Data/Service.php +++ /dev/null @@ -1,68 +0,0 @@ -_dataStorage)) { - - // If we for some very odd reason have lost the object, re-create it! - if (!is_object($this->_dataStorage[$name])) { - $this->_dataStorage[$name] = new $name($table); - } - - - } else if (class_exists($name)) { - - $this->_dataStorage[$name] = new $name($table); - } - - return $this->_dataStorage[$name]; - } - -} \ No newline at end of file diff --git a/library/Fiktiv/Model/Abstract.php b/library/Fiktiv/Model/Abstract.php index 3e03347..8d5d175 100644 --- a/library/Fiktiv/Model/Abstract.php +++ b/library/Fiktiv/Model/Abstract.php @@ -1,74 +1,9 @@ _default, array_intersect_key($data, $this->_default)); - - $this->setAttribs($data); - } - - public function __call($name, $args) - { - - // getX methods - if ('get' == substr($name,0,3)) { - $property = substr($name, 3); - - // Wrong! use mb_ - $property[0] = strtolower($property[0]); - - if (isset($this->_data[$property])) - return $this->_data[$property]; - - - } else if ('set' == substr($name,0,3)) { - $property = substr($name, 3); - - // Wrong! use mb_ - $property[0] = strtolower($property[0]); - - if (in_array($property,$this->_default)) - $this->_data[$property] = $args[0]; - } - } - - public function __set($name, $value) - { - $methodName = 'set' . ucfirst($name); - if (method_exists($this, $methodName)) { - return $this->$methodName($value); - } - - if (array_key_exists($name, $this->_default)) - return $this->_data[$name] = $value; - } - - // Direct access to read data fields - public function __get($name) - { - if (isset($this->_data[$name])) { - return $this->_data[$name]; - } - - } - - public function setAttribs(array $data) - { - foreach ($data as $key => $value) { - - $this->$key = $value; - } - } - - public function save() - { - $class = get_class($this); - return Fiktiv_Data_Service::getInstance()->$class->save($this); + return $this->getAdapter()->quoteInto($text, $value, $type, $count); } } \ No newline at end of file diff --git a/library/Fiktiv/Model/Mapper/DbTableAbstract.php b/library/Fiktiv/Model/Mapper/DbTableAbstract.php deleted file mode 100644 index 755f8db..0000000 --- a/library/Fiktiv/Model/Mapper/DbTableAbstract.php +++ /dev/null @@ -1,34 +0,0 @@ -setDbTable($dbtable); - } - - - public function setDbTable($dbtable) - { - if ($dbtable instanceof Zend_Db_Table_Abstract) { - $this->_dbTable = $dbtable; - } else if (is_string($dbtable) && class_exists($dbtable)) { - $this->_dbTable = new $dbtable(); - } else { - throw new Fiktiv_Exception('Invalid database table supplied to ' . __CLASS__); - } - } - - public function update($data, $where) - { - return $this->_dbTable->update($data, $where); - } - - public function quoteInto($text, $value) - { - return $this->_dbTable->getAdapter()->quoteInto($text,$value); - } -} \ No newline at end of file diff --git a/library/Fiktiv/Model/Row/Abstract.php b/library/Fiktiv/Model/Row/Abstract.php new file mode 100644 index 0000000..f0c072f --- /dev/null +++ b/library/Fiktiv/Model/Row/Abstract.php @@ -0,0 +1,6 @@ +