#29754 Progress bar listing page
[com.zyxware.civiwci.git] / CRM / Wci / Page / ProgressBarList.php
1 <?php
2
3 require_once 'CRM/Core/Page.php';
4 require_once 'CRM/Wci/DAO/ProgressBar.php';
5
6 class CRM_Wci_Page_ProgressBarList extends CRM_Core_Page {
7 private static $_actionLinks;
8 function run() {
9 // get the requested action
10 $action = CRM_Utils_Request::retrieve('action', 'String',
11 // default to 'browse'
12 $this, FALSE, 'browse'
13 );
14 // assign vars to templates
15 $this->assign('action', $action);
16 $id = CRM_Utils_Request::retrieve('id', 'Positive',
17 $this, FALSE, 0
18 );
19
20 if ($action & CRM_Core_Action::UPDATE) {
21 $controller = new CRM_Core_Controller_Simple('CRM_Wci_Form_ProgressBar',
22 'Edit Progressbar',
23 CRM_Core_Action::UPDATE
24 );
25 $controller->set('id', $id);
26 $controller->process();
27 return $controller->run();
28 } elseif ($action & CRM_Core_Action::DELETE) {
29 try {
30 $transaction = new CRM_Core_Transaction();
31 $sql = "DELETE FROM civicrm_wci_progress_bar_formula where progress_bar_id = " . $id;
32 CRM_Core_DAO::executeQuery($sql);
33
34 $sql = "DELETE FROM civicrm_wci_progress_bar where id = " . $id;
35 CRM_Core_DAO::executeQuery($sql);
36 $transaction->commit();
37 }
38 catch (Exception $e) {
39 //TODO
40 print_r($e->getMessage());
41 $transaction->rollback();
42 }
43 }
44 // Example: Set the page-title dynamically; alternatively, declare a static title in xml/Menu/*.xml
45 CRM_Utils_System::setTitle(ts('ProgressBarList'));
46
47 // Example: Assign a variable for use in a template
48 $this->assign('currentTime', date('Y-m-d H:i:s'));
49
50 $query = "SELECT * FROM civicrm_wci_progress_bar";
51 $params = array();
52
53 $dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_WCI_DAO_ProgressBar');
54
55 while ($dao->fetch()) {
56 $con_page[$dao->id] = array();
57 CRM_Core_DAO::storeValues($dao, $con_page[$dao->id]);
58
59 $action = array_sum(array_keys($this->actionLinks()));
60 //build the normal action links.
61 $con_page[$dao->id]['action'] = CRM_Core_Action::formLink(self::actionLinks(),
62 $action,
63 array('id' => $dao->id),
64 ts('more'),
65 TRUE
66 );
67 }
68
69 if (isset($con_page)) {
70 $this->assign('rows', $con_page);
71 }
72 return parent::run();
73 }
74
75 function &actionLinks() {
76 // check if variable _actionsLinks is populated
77 if (!isset(self::$_actionLinks)) {
78 // helper variable for nicer formatting
79 $deleteExtra = ts('Are you sure you want to delete this Progressbar page?');
80
81 self::$_actionLinks = array(
82 CRM_Core_Action::UPDATE => array(
83 'name' => ts('Update'),
84 'url' => CRM_Utils_System::currentPath(),
85 'qs' => 'action=update&reset=1&id=%%id%%',
86 'title' => ts('Update'),
87 ),
88 CRM_Core_Action::DELETE => array(
89 'name' => ts('Delete'),
90 'url' => CRM_Utils_System::currentPath(),
91 'qs' => 'action=delete&reset=1&id=%%id%%',
92 'title' => ts('Delete Custom Field'),
93 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
94 ),
95 );
96 }
97 return self::$_actionLinks;
98 }
99 }