Created
March 6, 2009 09:07
-
-
Save shadowhand/74834 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Model_Page extends ORM { | |
protected $belongs_to = array('menu', 'user'); | |
protected $sorting = array('created' => 'asc'); | |
public function __get($column) | |
{ | |
if ($column === 'primary_val_value') | |
{ | |
if ($this->menu_id) | |
{ | |
return ($this->menu->parent_id ? $this->menu->parent->title.': ' : '').$this->menu->title; | |
} | |
else | |
{ | |
return 'Unlinked Page: <small>'.text::limit_chars(strip_tags($this->html), 60).'</small>'; | |
} | |
} | |
return parent::__get($column); | |
} | |
public function __set($column, $value) | |
{ | |
if ($column === 'markdown') | |
{ | |
if ($value !== $this->markdown) | |
{ | |
$this->html = marko::convert($value); | |
} | |
} | |
return parent::__set($column, $value); | |
} | |
public function validate(array & $array, $save = FALSE) | |
{ | |
$array = Validation::factory($array) | |
->pre_filter('trim') | |
->add_rules('menu_id', 'digit') | |
->add_rules('markdown', 'required'); | |
return parent::validate($array, $save); | |
} | |
public function save() | |
{ | |
if ($this->loaded) | |
{ | |
$this->edited = time(); | |
} | |
else | |
{ | |
$this->created = time(); | |
} | |
if ($status = parent::save() AND class_exists('hook_page_cache', FALSE)) | |
{ | |
// Delete the cached page | |
hook_page_cache::delete($this->menu->link); | |
} | |
return $status; | |
} | |
} // End News |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment