send most action links thru hook_civicrm_links
[civicrm-core.git] / CRM / Member / Page / MembershipType.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.4 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2013 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
10 | CiviCRM is free software; you can copy, modify, and distribute it |
11 | under the terms of the GNU Affero General Public License |
12 | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. |
13 | |
14 | CiviCRM is distributed in the hope that it will be useful, but |
15 | WITHOUT ANY WARRANTY; without even the implied warranty of |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
17 | See the GNU Affero General Public License for more details. |
18 | |
19 | You should have received a copy of the GNU Affero General Public |
20 | License and the CiviCRM Licensing Exception along |
21 | with this program; if not, contact CiviCRM LLC |
22 | at info[AT]civicrm[DOT]org. If you have questions about the |
23 | GNU Affero General Public License or the licensing of CiviCRM, |
24 | see the CiviCRM license FAQ at http://civicrm.org/licensing |
25 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2013
32 * $Id$
33 *
34 */
35
36 /**
37 * Page for displaying list of membership types
38 */
39 class CRM_Member_Page_MembershipType extends CRM_Core_Page {
40
41 /**
42 * The action links that we need to display for the browse screen
43 *
44 * @var array
45 * @static
46 */
47 static $_links = NULL;
48
49 /**
50 * Get action Links
51 *
52 * @return array (reference) of action links
53 */
54 function &links() {
55 if (!(self::$_links)) {
56 self::$_links = array(
57 CRM_Core_Action::UPDATE => array(
58 'name' => ts('Edit'),
59 'url' => 'civicrm/admin/member/membershipType/add',
60 'qs' => 'action=update&id=%%id%%&reset=1',
61 'title' => ts('Edit Membership Type'),
62 ),
63 CRM_Core_Action::DISABLE => array(
64 'name' => ts('Disable'),
65 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Member_BAO_MembershipType' . '\',\'' . 'enable-disable' . '\' );"',
66 'ref' => 'disable-action',
67 'title' => ts('Disable Membership Type'),
68 ),
69 CRM_Core_Action::ENABLE => array(
70 'name' => ts('Enable'),
71 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Member_BAO_MembershipType' . '\',\'' . 'disable-enable' . '\' );"',
72 'ref' => 'enable-action',
73 'title' => ts('Enable Membership Type'),
74 ),
75 CRM_Core_Action::DELETE => array(
76 'name' => ts('Delete'),
77 'url' => 'civicrm/admin/member/membershipType/add',
78 'qs' => 'action=delete&id=%%id%%',
79 'title' => ts('Delete Membership Type'),
80 ),
81 );
82 }
83 return self::$_links;
84 }
85
86 /**
87 * Run the page.
88 *
89 * This method is called after the page is created. It checks for the
90 * type of action and executes that action.
91 * Finally it calls the parent's run method.
92 *
93 * @return void
94 * @access public
95 *
96 */
97 function run() {
98 $this->browse();
99
100 // parent run
101 return parent::run();
102 }
103
104 /**
105 * Browse all membership types.
106 *
107 *
108 * @return void
109 * @access public
110 * @static
111 */
112 function browse() {
113 // get all membership types sorted by weight
114 $membershipType = array();
115 $dao = new CRM_Member_DAO_MembershipType();
116
117 $dao->orderBy('weight');
118 $dao->find();
119
120
121 while ($dao->fetch()) {
122 $membershipType[$dao->id] = array();
123 CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]);
124
125 //adding column for relationship type label. CRM-4178.
126 if ($dao->relationship_type_id) {
127 //If membership associated with 2 or more relationship then display all relationship with comma separated
128 $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id);
129 $relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction);
130 $membershipType[$dao->id]['relationshipTypeName'] = NULL;
131 foreach ($relTypeIds as $key => $value) {
132 $relationshipName = 'label_' . $relTypeNames[$key];
133 if ($membershipType[$dao->id]['relationshipTypeName']) {
134 $membershipType[$dao->id]['relationshipTypeName'] .= ", ";
135 }
136 $membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType',
137 $value, $relationshipName
138 );
139 }
140 $membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$dao->id]);
141 }
142 // form all action links
143 $action = array_sum(array_keys($this->links()));
144
145 // update enable/disable links depending on if it is is_reserved or is_active
146 if (!isset($dao->is_reserved)) {
147 if ($dao->is_active) {
148 $action -= CRM_Core_Action::ENABLE;
149 }
150 else {
151 $action -= CRM_Core_Action::DISABLE;
152 }
153 $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight'];
154 $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action,
155 array('id' => $dao->id),
156 ts('more'),
157 FALSE,
158 'membershipType.manage.action',
159 'MembershipType',
160 $dao->id
161 );
162 }
163 }
164
165 $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse");
166 CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType',
167 'id', $returnURL
168 );
169
170 CRM_Member_BAO_MembershipType::convertDayFormat($membershipType);
171 $this->assign('rows', $membershipType);
172 }
173 }
174