send most action links thru hook_civicrm_links
[civicrm-core.git] / CRM / Campaign / Page / Campaign.php
CommitLineData
6a488035
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
232624b1 4 | CiviCRM version 4.4 |
6a488035
TO
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 Campaigns
38 */
39class CRM_Campaign_Page_Campaign extends CRM_Core_Page {
40
41 /**
42 * The action links that we need to display for the browse screen
43 *
44 * @var array
45 */
46 private static $_actionLinks;
47
48 /**
49 * Get the action links for this page.
50 *
51 * @return array $_actionLinks
52 *
53 */
54 function &actionLinks() {
55 // check if variable _actionsLinks is populated
56 if (!isset(self::$_actionLinks)) {
57 $deleteExtra = ts('Are you sure you want to delete this Campaign?');
58 self::$_actionLinks = array(
59 CRM_Core_Action::UPDATE => array(
60 'name' => ts('Edit'),
61 'url' => 'civicrm/campaign/add',
62 'qs' => 'reset=1&action=update&id=%%id%%',
63 'title' => ts('Update Campaign'),
64 ),
65 CRM_Core_Action::DISABLE => array(
66 'name' => ts('Disable'),
67 'title' => ts('Disable Campaign'),
68 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Campaign' . '\',\'' . 'enable-disable' . '\' );"',
69 'ref' => 'disable-action',
70 ),
71 CRM_Core_Action::ENABLE => array(
72 'name' => ts('Enable'),
73 'title' => ts('Enable Campaign'),
74 'extra' => 'onclick = "enableDisable( %%id%%,\'' . 'CRM_Campaign_BAO_Campaign' . '\',\'' . 'disable-enable' . '\' );"',
75 'ref' => 'enable-action',
76 ),
77 CRM_Core_Action::DELETE => array(
78 'name' => ts('Delete'),
79 'url' => 'civicrm/campaign/add',
80 'qs' => 'action=delete&reset=1&id=%%id%%',
81 'title' => ts('Delete Campaign'),
82 ),
83 );
84 }
85 return self::$_actionLinks;
86 }
87
88 function browse() {
89
90 $campaigns = CRM_Campaign_BAO_Campaign::getCampaignSummary();
91
92 if (!empty($campaigns)) {
93 $campaignType = CRM_Core_PseudoConstant::campaignType();
94 $campaignStatus = CRM_Core_PseudoConstant::campaignStatus();
95
96 foreach ($campaigns as $cmpid => $campaign) {
97
98 $campaigns[$cmpid]['campaign_id'] = $campaign['id'];
99 $campaigns[$cmpid]['title'] = $campaign['title'];
100 $campaigns[$cmpid]['name'] = $campaign['name'];
101 $campaigns[$cmpid]['description'] = $campaign['description'];
102 $campaigns[$cmpid]['campaign_type_id'] = $campaignType[$campaign['campaign_type_id']];
103 $campaigns[$cmpid]['status_id'] = $campaignStatus[$campaign['status_id']];
104
105 $action = array_sum(array_keys($this->actionLinks()));
106 if ($campaign['is_active']) {
107 $action -= CRM_Core_Action::ENABLE;
108 }
109 else {
110 $action -= CRM_Core_Action::DISABLE;
111 }
112 $campaigns[$cmpid]['action'] = CRM_Core_Action::formLink(self::actionLinks(), $action,
87dab4a4
AH
113 array('id' => $campaign['id']),
114 ts('more'),
115 FALSE,
116 'campaign.selector.row',
117 'Campaign',
118 $campaign['id']
6a488035
TO
119 );
120 }
121 }
122
123 $this->assign('campaigns', $campaigns);
124 $this->assign('addCampaignUrl', CRM_Utils_System::url('civicrm/campaign/add', 'reset=1&action=add'));
125 }
126
127 function run() {
128 if (!CRM_Core_Permission::check('administer CiviCampaign')) {
129 CRM_Utils_System::permissionDenied();
130 }
131
132 $action = CRM_Utils_Request::retrieve('action', 'String',
133 $this, FALSE, 0
134 );
135 $this->assign('action', $action);
136 $this->browse();
137
138 return parent::run();
139 }
140}
141