Skip to content
Snippets Groups Projects
Commit 9fb0a693 authored by Jared Hancock's avatar Jared Hancock
Browse files

orm: Convert Priority to ORM

parent 1b52a128
No related branches found
No related tags found
No related merge requests found
...@@ -14,55 +14,36 @@ ...@@ -14,55 +14,36 @@
vim: expandtab sw=4 ts=4 sts=4: vim: expandtab sw=4 ts=4 sts=4:
**********************************************************************/ **********************************************************************/
class Priority { class Priority extends VerySimpleModel {
var $id; static $meta = array(
var $ht; 'table' => PRIORITY_TABLE,
'pk' => array('priority_id'),
function Priority($id){ 'ordering' => array('-priority_urgency')
);
$this->id =0;
$this->load($id);
}
function load($id) {
if(!$id && !($id=$this->getId()))
return false;
$sql='SELECT * FROM '.PRIORITY_TABLE
.' WHERE priority_id='.db_input($id);
if(!($res=db_query($sql)) || !db_num_rows($res))
return false;
$this->ht= db_fetch_array($res);
$this->id= $this->ht['priority_id'];
return true;;
}
function getId() { function getId() {
return $this->id; return $this->priority_id;
} }
function getTag() { function getTag() {
return $this->ht['priority']; return $this->priority;
} }
function getDesc() { function getDesc() {
return $this->ht['priority_desc']; return $this->priority_desc;
} }
function getColor() { function getColor() {
return $this->ht['priority_color']; return $this->priority_color;
} }
function getUrgency() { function getUrgency() {
return $this->ht['priority_urgency']; return $this->priority_urgency;
} }
function isPublic() { function isPublic() {
return ($this->ht['ispublic']); return $this->ispublic;
} }
function __toString() { function __toString() {
...@@ -70,20 +51,16 @@ class Priority { ...@@ -70,20 +51,16 @@ class Priority {
} }
/* ------------- Static ---------------*/ /* ------------- Static ---------------*/
function lookup($id) { static function getPriorities( $publicOnly=false) {
return ($id && is_numeric($id) && ($p=new Priority($id)) && $p->getId()==$id)?$p:null;
}
function getPriorities( $publicOnly=false) {
$priorities=array(); $priorities=array();
$sql ='SELECT priority_id, priority_desc FROM '.PRIORITY_TABLE;
if($publicOnly)
$sql.=' WHERE ispublic=1';
if(($res=db_query($sql)) && db_num_rows($res)) { $objects = static::objects()->values_flat('priority_id', 'priority_desc');
while(list($id, $name)=db_fetch_row($res)) if ($publicOnly)
$priorities[$id] = $name; $objects->filter(array('ispublic'=>1));
foreach ($objects as $row) {
list($id, $name) = $row;
$priorities[$id] = $name;
} }
return $priorities; return $priorities;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment