Commit | Line | Data |
---|---|---|
6a488035 TO |
1 | <?php |
2 | ||
3 | /* | |
4 | +--------------------------------------------------------------------+ | |
5 | | CiviCRM version 4.3 | | |
6 | +--------------------------------------------------------------------+ | |
7 | | Copyright CiviCRM LLC (c) 2004-2013 | | |
8 | +--------------------------------------------------------------------+ | |
9 | | This file is a part of CiviCRM. | | |
10 | | | | |
11 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
12 | | under the terms of the GNU Affero General Public License | | |
13 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
14 | | | | |
15 | | CiviCRM is distributed in the hope that it will be useful, but | | |
16 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
17 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
18 | | See the GNU Affero General Public License for more details. | | |
19 | | | | |
20 | | You should have received a copy of the GNU Affero General Public | | |
21 | | License and the CiviCRM Licensing Exception along | | |
22 | | with this program; if not, contact CiviCRM LLC | | |
23 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
24 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
25 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
26 | +--------------------------------------------------------------------+ | |
27 | */ | |
28 | ||
29 | /** | |
30 | * | |
31 | * @package CRM | |
32 | * @copyright CiviCRM LLC (c) 2004-2013 | |
33 | * $Id$ | |
34 | * | |
35 | */ | |
36 | ||
37 | require_once 'CRM/Core/Page.php'; | |
38 | require_once 'CRM/Grant/BAO/GrantProgram.php'; | |
39 | ||
40 | ||
41 | /** | |
42 | * Page for displaying list of contribution types | |
43 | */ | |
44 | class CRM_Grant_Page_GrantProgram extends CRM_Core_Page | |
45 | { | |
46 | ||
47 | protected $_id; | |
48 | /** | |
49 | * The action links that we need to display for the browse screen | |
50 | * | |
51 | * @var array | |
52 | */ | |
53 | private static $_links; | |
54 | /** | |
55 | * Get action Links | |
56 | * | |
57 | * @return array (reference) of action links | |
58 | */ | |
59 | function &links() | |
60 | { | |
61 | if (!(self::$_links)) { | |
62 | self::$_links = array( | |
63 | CRM_Core_Action::VIEW => array( | |
64 | 'name' => ts('View'), | |
65 | 'url' => 'civicrm/grant_program', | |
66 | 'qs' => 'action=view&id=%%id%%&reset=1', | |
67 | 'title' => ts('View Grant Program') | |
68 | ), | |
69 | CRM_Core_Action::UPDATE => array( | |
70 | 'name' => ts('Edit'), | |
71 | 'url' => 'civicrm/grant_program', | |
72 | 'qs' => 'action=update&id=%%id%%&reset=1', | |
73 | 'title' => ts('Edit Grant Program') | |
74 | ), | |
75 | CRM_Core_Action::DELETE => array( | |
76 | 'name' => ts('Delete'), | |
77 | 'url' => 'civicrm/grant_program', | |
78 | 'qs' => 'action=delete&id=%%id%%', | |
79 | 'title' => ts('Delete Grant Program') | |
80 | ) | |
81 | ); | |
82 | } | |
83 | return self::$_links; | |
84 | } | |
85 | ||
86 | function browse( ) { | |
87 | ||
88 | $grantProgram = array(); | |
89 | require_once 'CRM/Grant/DAO/GrantProgram.php'; | |
90 | $dao = new CRM_Grant_DAO_GrantProgram(); | |
91 | ||
92 | $dao->orderBy('label'); | |
93 | $dao->find(); | |
94 | ||
95 | while ($dao->fetch()) { | |
96 | $grantProgram[$dao->id] = array(); | |
97 | CRM_Core_DAO::storeValues( $dao, $grantProgram[$dao->id]); | |
98 | $action = array_sum(array_keys($this->links())); | |
99 | ||
100 | $grantProgram[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, | |
101 | array('id' => $dao->id)); | |
102 | } | |
103 | require_once 'CRM/Grant/PseudoConstant.php'; | |
104 | $grantType = CRM_Grant_PseudoConstant::grantType( ); | |
105 | $grantStatus = CRM_Grant_PseudoConstant::grantProgramStatus( ); | |
106 | foreach ( $grantProgram as $key => $value ) { | |
107 | $grantProgram[$key]['grant_type_id'] = $grantType[CRM_Grant_BAO_GrantProgram::getOptionValue($grantProgram[$key]['grant_type_id'])]; | |
108 | $grantProgram[$key]['status_id'] = $grantStatus[CRM_Grant_BAO_GrantProgram::getOptionValue($grantProgram[$key]['status_id'])]; | |
109 | } | |
110 | $this->assign('rows',$grantProgram ); | |
111 | } | |
112 | ||
113 | function run( ) | |
114 | { | |
115 | $action = CRM_Utils_Request::retrieve('action', 'String', | |
116 | $this, false, 0 ); | |
117 | if ( $action & CRM_Core_Action::VIEW ) { | |
118 | $this->view( $action); | |
119 | } else if ( $action & ( CRM_Core_Action::UPDATE | CRM_Core_Action::ADD | CRM_Core_Action::DELETE ) ) { | |
120 | $this->edit( $action); | |
121 | } else { | |
122 | $this->browse( ); | |
123 | } | |
124 | $this->assign('action', $action); | |
125 | return parent::run( ); | |
126 | } | |
127 | ||
128 | function edit($action) | |
129 | { | |
130 | $controller = new CRM_Core_Controller_Simple('CRM_Grant_Form_GrantProgram', ts(''), $action); | |
131 | $controller->setEmbedded(true); | |
132 | $result = $controller->process(); | |
133 | $result = $controller->run(); | |
134 | } | |
135 | ||
136 | function view( $action ) | |
137 | { | |
138 | $controller = new CRM_Core_Controller_Simple( 'CRM_Grant_Form_GrantProgramView', ts(''), $action ); | |
139 | $controller->setEmbedded( true ); | |
140 | $result = $controller->process(); | |
141 | $result = $controller->run(); | |
142 | } | |
143 | } |