Skip to content
Snippets Groups Projects
Commit 550bf161 authored by Peter Rotich's avatar Peter Rotich
Browse files

orm: Convert Topic to ORM

parent 3370a02f
No related branches found
No related tags found
No related merge requests found
...@@ -59,8 +59,7 @@ class Priority extends VerySimpleModel { ...@@ -59,8 +59,7 @@ class Priority extends VerySimpleModel {
$objects->filter(array('ispublic'=>1)); $objects->filter(array('ispublic'=>1));
foreach ($objects as $row) { foreach ($objects as $row) {
list($id, $name) = $row; $priorities[$row[0]] = $row[1];
$priorities[$id] = $name;
} }
return $priorities; return $priorities;
......
...@@ -40,6 +40,12 @@ class Topic extends VerySimpleModel { ...@@ -40,6 +40,12 @@ class Topic extends VerySimpleModel {
'page_id' => 'Page.id', 'page_id' => 'Page.id',
), ),
), ),
'priority' => array(
'null' => true,
'constraint' => array(
'priority_id' => 'Priority.priority_id',
),
),
), ),
); );
...@@ -114,9 +120,6 @@ class Topic extends VerySimpleModel { ...@@ -114,9 +120,6 @@ class Topic extends VerySimpleModel {
} }
function getPage() { function getPage() {
if(!$this->page && $this->getPageId())
$this->page = Page::lookup($this->getPageId());
return $this->page; return $this->page;
} }
......
...@@ -118,11 +118,11 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"'; ...@@ -118,11 +118,11 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"';
<select name="dept_id"> <select name="dept_id">
<option value="0">&mdash; <?php echo __('System Default'); ?> &mdash;</option> <option value="0">&mdash; <?php echo __('System Default'); ?> &mdash;</option>
<?php <?php
$sql='SELECT dept_id,dept_name FROM '.DEPT_TABLE.' dept ORDER by dept_name'; if (($depts=Dept::getDepartments())) {
if(($res=db_query($sql)) && db_num_rows($res)){ foreach ($depts as $id => $name) {
while(list($id,$name)=db_fetch_row($res)){
$selected=($info['dept_id'] && $id==$info['dept_id'])?'selected="selected"':''; $selected=($info['dept_id'] && $id==$info['dept_id'])?'selected="selected"':'';
echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); echo sprintf('<option value="%d" %s>%s</option>',
$id, $selected, $name);
} }
} }
?> ?>
...@@ -169,11 +169,10 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"'; ...@@ -169,11 +169,10 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"';
<select name="priority_id"> <select name="priority_id">
<option value="">&mdash; <?php echo __('System Default'); ?> &mdash;</option> <option value="">&mdash; <?php echo __('System Default'); ?> &mdash;</option>
<?php <?php
$sql='SELECT priority_id,priority_desc FROM '.PRIORITY_TABLE.' pri ORDER by priority_urgency DESC'; if (($priorities=Priority::getPriorities())) {
if(($res=db_query($sql)) && db_num_rows($res)){ foreach ($priorities as $id => $name) {
while(list($id,$name)=db_fetch_row($res)){
$selected=($info['priority_id'] && $id==$info['priority_id'])?'selected="selected"':''; $selected=($info['priority_id'] && $id==$info['priority_id'])?'selected="selected"':'';
echo sprintf('<option value="%d" %s>%s</option>',$id,$selected,$name); echo sprintf('<option value="%d" %s>%s</option>', $id, $selected, $name);
} }
} }
?> ?>
...@@ -231,9 +230,9 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"'; ...@@ -231,9 +230,9 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"';
<option value="0">&mdash; <?php echo __('Unassigned'); ?> &mdash;</option> <option value="0">&mdash; <?php echo __('Unassigned'); ?> &mdash;</option>
<?php <?php
if (($users=Staff::getStaffMembers())) { if (($users=Staff::getStaffMembers())) {
echo sprintf('<OPTGROUP label="%s">', sprintf(__('Agents (%d)'), count($user))); echo sprintf('<OPTGROUP label="%s">',
sprintf(__('Agents (%d)'), count($users)));
foreach ($users as $id => $name) { foreach ($users as $id => $name) {
$name = new PersonsName($name);
$k="s$id"; $k="s$id";
$selected = ($info['assign']==$k || $info['staff_id']==$id)?'selected="selected"':''; $selected = ($info['assign']==$k || $info['staff_id']==$id)?'selected="selected"':'';
?> ?>
...@@ -243,15 +242,12 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"'; ...@@ -243,15 +242,12 @@ if ($info['form_id'] == Topic::FORM_USE_PARENT) echo 'selected="selected"';
} }
echo '</OPTGROUP>'; echo '</OPTGROUP>';
} }
$sql='SELECT team_id, name, isenabled FROM '.TEAM_TABLE.' ORDER BY name'; if (($teams=Team::getTeams())) {
if(($res=db_query($sql)) && ($cteams = db_num_rows($res))) { echo sprintf('<OPTGROUP label="%s">',
echo sprintf('<OPTGROUP label="%s">', sprintf(__('Teams (%d)'), $cteams)); sprintf(__('Teams (%d)'), count($teams)));
while (list($id, $name, $isenabled) = db_fetch_row($res)){ foreach ($teams as $id => $name) {
$k="t$id"; $k="t$id";
$selected = ($info['assign']==$k || $info['team_id']==$id)?'selected="selected"':''; $selected = ($info['assign']==$k || $info['team_id']==$id) ? 'selected="selected"' : '';
if (!$isenabled)
$name .= ' '.__('(disabled)');
?> ?>
<option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option> <option value="<?php echo $k; ?>"<?php echo $selected; ?>><?php echo $name; ?></option>
<?php <?php
......
<?php <?php
if(!defined('OSTADMININC') || !$thisstaff->isAdmin()) die('Access Denied'); if (!defined('OSTADMININC') || !$thisstaff->isAdmin()) die('Access Denied');
$sql='SELECT topic.* '
.', dept.dept_name as department '
.', priority_desc as priority '
.' FROM '.TOPIC_TABLE.' topic '
.' LEFT JOIN '.DEPT_TABLE.' dept ON (dept.dept_id=topic.dept_id) '
.' LEFT JOIN '.TICKET_PRIORITY_TABLE.' pri ON (pri.priority_id=topic.priority_id) ';
$sql.=' WHERE 1';
$order_by = '`sort`';
$page=($_GET['p'] && is_numeric($_GET['p']))?$_GET['p']:1; $page = ($_GET['p'] && is_numeric($_GET['p'])) ? $_GET['p'] : 1;
//Ok..lets roll...create the actual query $count = Topic::objects()->count();
$query="$sql ORDER BY $order_by"; $pageNav = new Pagenate($count, $page, PAGE_LIMIT);
$res=db_query($query); $pageNav->setURL('helptopics.php', $_qstr);
if($res && ($num=db_num_rows($res))) $showing = $pageNav->showing().' '._N('help topic', 'help topics', $count);
$showing=sprintf(_N('Showing %d help topic', 'Showing %d help topics', $num), $num);
else
$showing=__('No help topics found!');
// Get the full names and filter for this page $order_by = ($cfg->getTopicSortMode() == 'm') ? 'sort' : 'topic';
$topics = array();
while ($row = db_fetch_array($res))
$topics[] = $row;
foreach ($topics as &$t)
$t['name'] = Topic::getTopicName($t['topic_id']);
?> ?>
<div class="pull-left" style="width:700px;padding-top:5px;"> <div class="pull-left" style="width:700px;padding-top:5px;">
...@@ -67,52 +50,67 @@ foreach ($topics as &$t) ...@@ -67,52 +50,67 @@ foreach ($topics as &$t)
<tbody class="<?php if ($cfg->getTopicSortMode() == 'm') echo 'sortable-rows'; ?>" <tbody class="<?php if ($cfg->getTopicSortMode() == 'm') echo 'sortable-rows'; ?>"
data-sort="sort-"> data-sort="sort-">
<?php <?php
$total=0; $ids= ($errors && is_array($_POST['ids'])) ? $_POST['ids'] : null;
$ids=($errors && is_array($_POST['ids']))?$_POST['ids']:null; if ($count) {
if (count($topics)): $topics = Topic::objects()
->order_by(sprintf('%s%s',
strcasecmp($order, 'DESC') ? '' : '-',
$order_by))
->limit($pageNav->getLimit())
->offset($pageNav->getStart());
$defaultDept = $cfg->getDefaultDept(); $defaultDept = $cfg->getDefaultDept();
$defaultPriority = $cfg->getDefaultPriority(); $defaultPriority = $cfg->getDefaultPriority();
$sort = 0; $sort = 0;
foreach($topics as $row) { foreach($topics as $topic) {
$id = $topic->getId();
$sort++; // Track initial order for transition $sort++; // Track initial order for transition
$sel=false; $sel=false;
if($ids && in_array($row['topic_id'],$ids)) if ($ids && in_array($id, $ids))
$sel=true; $sel=true;
if (!$row['dept_id'] && $defaultDept) { if ($topic->dept_id) {
$row['dept_id'] = $defaultDept->getId(); $deptId = $topic->dept_id;
$row['department'] = (string) $defaultDept; $dept = (string) $topic->dept;
} elseif ($defaultDept) {
$deptId = $defaultDept->getId();
$dept = (string) $defaultDept;
} else {
$deptId = 0;
$dept = '';
} }
$priority = $team->priority ?: $defaultPriority;
if (!$row['priority'] && $defaultPriority)
$row['priority'] = (string) $defaultPriority;
?> ?>
<tr id="<?php echo $row['topic_id']; ?>"> <tr id="<?php echo $id; ?>">
<td width=7px> <td width=7px>
<input type="hidden" name="sort-<?php echo $row['topic_id']; ?>" value="<?php <input type="hidden" name="sort-<?php echo $id; ?>" value="<?php
echo $row['sort'] ?: $sort; ?>"/> echo $topic->sort ?: $sort; ?>"/>
<input type="checkbox" class="ckb" name="ids[]" value="<?php echo $row['topic_id']; ?>" <input type="checkbox" class="ckb" name="ids[]"
<?php echo $sel?'checked="checked"':''; ?>> value="<?php echo $id; ?>" <?php
echo $sel ? 'checked="checked"' : ''; ?>>
</td> </td>
<td> <td>
<?php if ($cfg->getTopicSortMode() == 'm') { ?> <?php
<i class="icon-sort"></i> if ($cfg->getTopicSortMode() == 'm') { ?>
<?php } ?> <i class="icon-sort"></i>
<a href="helptopics.php?id=<?php echo $row['topic_id']; ?>"><?php echo $row['name']; ?></a>&nbsp;</td> <?php } ?>
<td><?php echo $row['isactive']?__('Active'):'<b>'.__('Disabled').'</b>'; ?></td> <a href="helptopics.php?id=<?php echo $id; ?>"><?php
<td><?php echo $row['ispublic']?__('Public'):'<b>'.__('Private').'</b>'; ?></td> echo Topic::getTopicName($id); ?></a>&nbsp;
<td><?php echo $row['priority']; ?></td> </td>
<td><a href="departments.php?id=<?php echo $row['dept_id']; ?>"><?php echo $row['department']; ?></a></td> <td><?php echo $topic->isactive ? __('Active') : '<b>'.__('Disabled').'</b>'; ?></td>
<td>&nbsp;<?php echo Format::datetime($row['updated']); ?></td> <td><?php echo $topic->ispublic ? __('Public') : '<b>'.__('Private').'</b>'; ?></td>
<td><?php echo $priority; ?></td>
<td><a href="departments.php?id=<?php echo $deptId;
?>"><?php echo $dept; ?></a></td>
<td>&nbsp;<?php echo Format::datetime($team->updated); ?></td>
</tr> </tr>
<?php <?php
} //end of while. } //end of foreach.
endif; ?> }?>
<tfoot> <tfoot>
<tr> <tr>
<td colspan="7"> <td colspan="7">
<?php if($res && $num){ ?> <?php if ($count) { ?>
<?php echo __('Select');?>:&nbsp; <?php echo __('Select');?>:&nbsp;
<a id="selectAll" href="#ckb"><?php echo __('All');?></a>&nbsp;&nbsp; <a id="selectAll" href="#ckb"><?php echo __('All');?></a>&nbsp;&nbsp;
<a id="selectNone" href="#ckb"><?php echo __('None');?></a>&nbsp;&nbsp; <a id="selectNone" href="#ckb"><?php echo __('None');?></a>&nbsp;&nbsp;
...@@ -125,7 +123,8 @@ foreach ($topics as &$t) ...@@ -125,7 +123,8 @@ foreach ($topics as &$t)
</tfoot> </tfoot>
</table> </table>
<?php <?php
if($res && $num): //Show options.. if ($count): //Show options..
echo '<div>&nbsp;'.__('Page').':'.$pageNav->getPageLinks().'&nbsp;</div>';
?> ?>
<p class="centered" id="actions"> <p class="centered" id="actions">
<?php if ($cfg->getTopicSortMode() != 'a') { ?> <?php if ($cfg->getTopicSortMode() != 'a') { ?>
......
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