3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2014 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2014
37 * Page for displaying list of auctions
39 class CRM_Auction_Page_ManageItem
extends CRM_Core_Page
{
42 * the id of the auction for this item
49 * The action links that we need to display for the browse screen
53 static $_actionLinks = NULL;
55 static $_links = NULL;
57 protected $_pager = NULL;
59 protected $_sortByCharacter;
64 * @return array (reference) of action links
67 if (!(self
::$_actionLinks)) {
68 // helper variable for nicer formatting
69 $disableExtra = ts('Are you sure you want to disable this Item?');
70 $deleteExtra = ts('Are you sure you want to delete this Item?');
71 $copyExtra = ts('Are you sure you want to make a copy of this Item?');
73 self
::$_actionLinks = array(
74 CRM_Core_Action
::UPDATE
=> array(
76 'url' => 'civicrm/auction/item/add',
77 'qs' => 'action=update&id=%%id%%&aid=%%aid%%&reset=1',
78 'title' => ts('Edit Item'),
80 CRM_Core_Action
::DISABLE
=> array(
81 'name' => ts('Reject'),
82 'url' => CRM_Utils_System
::currentPath(),
83 'qs' => 'action=disable&id=%%id%%&aid=%%aid%%',
84 'extra' => 'onclick = "return confirm(\'' . $disableExtra . '\');"',
85 'title' => ts('Disable Item'),
87 CRM_Core_Action
::ENABLE
=> array(
88 'name' => ts('Approve'),
89 'url' => CRM_Utils_System
::currentPath(),
90 'qs' => 'action=enable&id=%%id%%&aid=%%aid%%',
91 'title' => ts('Enable Item'),
93 CRM_Core_Action
::DELETE
=> array(
94 'name' => ts('Delete'),
95 'url' => 'civicrm/auction/item/add',
96 'qs' => 'action=delete&id=%%id%%&aid=%%aid%%&reset=1',
97 'extra' => 'onclick = "return confirm(\'' . $deleteExtra . '\');"',
98 'title' => ts('Delete Item'),
102 return self
::$_actionLinks;
108 * This method is called after the page is created. It checks for the
109 * type of action and executes that action.
110 * Finally it calls the parent's run method.
115 // get the requested action
116 $action = CRM_Utils_Request
::retrieve('action', 'String',
117 // default to 'browse'
118 $this, FALSE, 'browse'
121 // assign vars to templates
122 $this->assign('action', $action);
123 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
127 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this, TRUE);
129 // set breadcrumb to append to 2nd layer pages
130 $breadCrumb = array(array('title' => ts('Manage Items'),
131 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
136 // what action to take ?
137 if ($action & CRM_Core_Action
::DISABLE
) {
138 require_once 'CRM/Auction/BAO/Item.php';
139 CRM_Auction_BAO_Item
::setIsActive($id, 0);
141 elseif ($action & CRM_Core_Action
::ENABLE
) {
142 require_once 'CRM/Auction/BAO/Item.php';
143 CRM_Auction_BAO_Item
::setIsActive($id, 1);
145 elseif ($action & CRM_Core_Action
::DELETE
) {
146 $session = CRM_Core_Session
::singleton();
147 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
148 $controller = new CRM_Core_Controller_Simple('CRM_Auction_Form_Auction_Delete',
152 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
155 $controller->set('id', $id);
156 $controller->process();
157 return $controller->run();
159 elseif ($action & CRM_Core_Action
::COPY
) {
163 // finally browse the auctions
171 * Browse all auctions
176 $this->assign('newItemURL', CRM_Utils_System
::url('civicrm/auction/item/add',
177 'reset=1&action=add&aid=' . $this->_aid
179 $this->assign('previewItemURL', CRM_Utils_System
::url('civicrm/auction/item',
180 'reset=1&aid=' . $this->_aid
183 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
187 if ($this->_sortByCharacter
== 1 ||
190 $this->_sortByCharacter
= '';
191 $this->set('sortByCharacter', '');
194 $this->_force
= NULL;
195 $this->_searchResult
= NULL;
199 $config = CRM_Core_Config
::singleton();
202 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean',
205 $this->_searchResult
= CRM_Utils_Request
::retrieve('searchResult', 'Boolean', $this);
207 $whereClause = $this->whereClause($params, FALSE, $this->_force
);
208 $this->pagerAToZ($whereClause, $params);
211 $whereClause = $this->whereClause($params, TRUE, $this->_force
);
212 $this->pager($whereClause, $params);
213 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
215 //check for delete CRM-4418
216 require_once 'CRM/Core/Permission.php';
217 $allowToDelete = CRM_Core_Permission
::check('delete in CiviAuction');
220 SELECT i.*, c.display_name as donorName
221 FROM civicrm_auction_item i,
224 AND auction_id = {$this->_aid}
225 AND i.donor_id = c.id
226 LIMIT $offset, $rowCount";
228 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Auction_DAO_Item');
230 // get all custom groups sorted by weight
232 $auctionItemTypes = CRM_Core_OptionGroup
::values('auction_item_type');
233 while ($dao->fetch()) {
234 $items[$dao->id
] = array();
235 CRM_Core_DAO
::storeValues($dao, $items[$dao->id
]);
237 $items[$dao->id
]['donorName'] = $dao->donorName
;
238 $items[$dao->id
]['auction_item_type'] = CRM_Utils_Array
::value($dao->auction_type_id
, $auctionItemTypes);
240 // form all action links
241 $action = array_sum(array_keys($this->links()));
243 if ($dao->is_active
) {
244 $action -= CRM_Core_Action
::ENABLE
;
247 $action -= CRM_Core_Action
::DISABLE
;
250 if (!$allowToDelete) {
251 $action -= CRM_Core_Action
::DELETE
;
254 $items[$dao->id
]['action'] = CRM_Core_Action
::formLink(self
::links(),
256 array('id' => $dao->id
,
257 'aid' => $this->_aid
,
261 $this->assign('rows', $items);
265 * This function is to make a copy of a Auction, including
266 * all the fields in the event wizard
271 $id = CRM_Utils_Request
::retrieve('id', 'Positive', $this, TRUE, 0, 'GET');
273 require_once 'CRM/Auction/BAO/Auction.php';
274 CRM_Auction_BAO_Auction
::copy($id);
276 return CRM_Utils_System
::redirect(CRM_Utils_System
::url('civicrm/event/manage', 'reset=1'));
280 $form = new CRM_Core_Controller_Simple('CRM_Auction_Form_SearchAuction', ts('Search Auctions'), CRM_Core_Action
::ADD
);
281 $form->setEmbedded(TRUE);
282 $form->setParent($this);
288 * @param array $params
289 * @param bool $sortBy
294 function whereClause(&$params, $sortBy = TRUE, $force) {
297 $title = $this->get('title');
299 $clauses[] = "title LIKE %1";
300 if (strpos($title, '%') !== FALSE) {
301 $params[1] = array(trim($title), 'String', FALSE);
304 $params[1] = array(trim($title), 'String', TRUE);
309 $this->_sortByCharacter
311 $clauses[] = 'title LIKE %6';
312 $params[6] = array($this->_sortByCharacter
. '%', 'String');
315 // dont do a the below assignment when doing a
318 if (count($clauses) > 1) {
319 $this->assign('isSearch', 1);
322 $this->assign('isSearch', 0);
326 if (empty($clauses)) {
330 return implode(' AND ', $clauses);
334 * @param $whereClause
335 * @param $whereParams
337 function pager($whereClause, $whereParams) {
338 require_once 'CRM/Utils/Pager.php';
340 $params['status'] = ts('Item %%StatusMessage%%');
341 $params['csvString'] = NULL;
342 $params['buttonTop'] = 'PagerTopButton';
343 $params['buttonBottom'] = 'PagerBottomButton';
344 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
345 if (!$params['rowCount']) {
346 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
351 FROM civicrm_auction_item
354 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
356 $this->_pager
= new CRM_Utils_Pager($params);
357 $this->assign_by_ref('pager', $this->_pager
);
361 * @param $whereClause
362 * @param $whereParams
364 function pagerAtoZ($whereClause, $whereParams) {
365 require_once 'CRM/Utils/PagerAToZ.php';
368 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
369 FROM civicrm_auction_item
371 ORDER BY LEFT(title, 1)
373 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
375 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
376 $this->assign('aToZ', $aToZBar);