3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.5 |
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
36 require_once 'CRM/Core/Page.php';
39 * Page for displaying list of auctions
41 class CRM_Auction_Page_Item
extends CRM_Core_Page
{
44 * the id of the auction for this item
51 protected $_pager = NULL;
53 protected $_sortByCharacter;
58 * This method is called after the page is created. It checks for the
59 * type of action and executes that action.
60 * Finally it calls the parent's run method.
66 // get the requested action
67 $action = CRM_Utils_Request
::retrieve('action', 'String',
68 // default to 'browse'
69 $this, FALSE, 'browse'
72 // assign vars to templates
73 $this->assign('action', $action);
74 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
78 $this->_aid
= CRM_Utils_Request
::retrieve('aid', 'Positive', $this);
80 // set breadcrumb to append to 2nd layer pages
81 $breadCrumb = array(array('title' => ts('Manage Items'),
82 'url' => CRM_Utils_System
::url(CRM_Utils_System
::currentPath(),
87 // what action to take ?
88 if ($action & CRM_Core_Action
::DISABLE
) {
89 require_once 'CRM/Auction/BAO/Auction.php';
90 CRM_Auction_BAO_Auction
::setIsActive($id, 0);
92 elseif ($action & CRM_Core_Action
::ENABLE
) {
93 require_once 'CRM/Auction/BAO/Auction.php';
94 CRM_Auction_BAO_Auction
::setIsActive($id, 1);
96 elseif ($action & CRM_Core_Action
::DELETE
) {
97 $session = CRM_Core_Session
::singleton();
98 $session->pushUserContext(CRM_Utils_System
::url(CRM_Utils_System
::currentPath(), 'reset=1&action=browse'));
99 $controller = new CRM_Core_Controller_Simple('CRM_Auction_Form_Auction_Delete',
103 $id = CRM_Utils_Request
::retrieve('id', 'Positive',
106 $controller->set('id', $id);
107 $controller->process();
108 return $controller->run();
111 // finally browse the auctions
119 * Browse all auctions
128 $this->assign('manageItemURL', CRM_Utils_System
::url('civicrm/auction/item/manage',
129 'reset=1&aid=' . $this->_aid
133 $this->_sortByCharacter
= CRM_Utils_Request
::retrieve('sortByCharacter',
137 if ($this->_sortByCharacter
== 1 ||
140 $this->_sortByCharacter
= '';
141 $this->set('sortByCharacter', '');
144 $this->_force
= NULL;
145 $this->_searchResult
= NULL;
149 $config = CRM_Core_Config
::singleton();
152 $this->_force
= CRM_Utils_Request
::retrieve('force', 'Boolean',
155 $this->_searchResult
= CRM_Utils_Request
::retrieve('searchResult', 'Boolean', $this);
157 $whereClause = $this->whereClause($params, FALSE, $this->_force
);
158 $this->pagerAToZ($whereClause, $params);
161 $whereClause = $this->whereClause($params, TRUE, $this->_force
);
162 $this->pager($whereClause, $params);
163 list($offset, $rowCount) = $this->_pager
->getOffsetAndRowCount();
166 $whereClause .= " AND auction_id = {$this->_aid}";
170 SELECT i.*, c.display_name as donorName, max(b.bid_value) as maxBid
171 FROM civicrm_auction_item i
172 INNER JOIN civicrm_contact c ON i.donor_id = c.id
173 LEFT JOIN civicrm_auction_bid b ON i.id = b.auction_item_id
176 LIMIT $offset, $rowCount";
178 $dao = CRM_Core_DAO
::executeQuery($query, $params, TRUE, 'CRM_Auction_DAO_Item');
180 // get all custom groups sorted by weight
182 $auctionItemTypes = CRM_Core_OptionGroup
::values('auction_item_type');
183 while ($dao->fetch()) {
184 $items[$dao->id
] = array();
185 CRM_Core_DAO
::storeValues($dao, $items[$dao->id
]);
187 $items[$dao->id
]['donorName'] = $dao->donorName
;
188 $items[$dao->id
]['auction_item_type'] = CRM_Utils_Array
::value($dao->auction_type_id
, $auctionItemTypes);
189 $items[$dao->id
]['max_bid'] = $dao->maxBid
;
191 $this->assign('rows', $items);
195 $form = new CRM_Core_Controller_Simple('CRM_Auction_Form_SearchAuction', ts('Search Auctions'), CRM_Core_Action
::ADD
);
196 $form->setEmbedded(TRUE);
197 $form->setParent($this);
202 function whereClause(&$params, $sortBy = TRUE, $force) {
205 $title = $this->get('title');
207 $clauses[] = "title LIKE %1";
208 if (strpos($title, '%') !== FALSE) {
209 $params[1] = array(trim($title), 'String', FALSE);
212 $params[1] = array(trim($title), 'String', TRUE);
217 $this->_sortByCharacter
219 $clauses[] = 'title LIKE %6';
220 $params[6] = array($this->_sortByCharacter
. '%', 'String');
223 // dont do a the below assignment when doing a
226 if (count($clauses) > 1) {
227 $this->assign('isSearch', 1);
230 $this->assign('isSearch', 0);
234 if (empty($clauses)) {
238 return implode(' AND ', $clauses);
241 function pager($whereClause, $whereParams) {
242 require_once 'CRM/Utils/Pager.php';
244 $params['status'] = ts('Item %%StatusMessage%%');
245 $params['csvString'] = NULL;
246 $params['buttonTop'] = 'PagerTopButton';
247 $params['buttonBottom'] = 'PagerBottomButton';
248 $params['rowCount'] = $this->get(CRM_Utils_Pager
::PAGE_ROWCOUNT
);
249 if (!$params['rowCount']) {
250 $params['rowCount'] = CRM_Utils_Pager
::ROWCOUNT
;
255 FROM civicrm_auction_item
258 $params['total'] = CRM_Core_DAO
::singleValueQuery($query, $whereParams);
260 $this->_pager
= new CRM_Utils_Pager($params);
261 $this->assign_by_ref('pager', $this->_pager
);
264 function pagerAtoZ($whereClause, $whereParams) {
265 require_once 'CRM/Utils/PagerAToZ.php';
268 SELECT DISTINCT UPPER(LEFT(title, 1)) as sort_name
269 FROM civicrm_auction_item
271 ORDER BY LEFT(title, 1)
273 $dao = CRM_Core_DAO
::executeQuery($query, $whereParams);
275 $aToZBar = CRM_Utils_PagerAToZ
::getAToZBar($dao, $this->_sortByCharacter
, TRUE);
276 $this->assign('aToZ', $aToZBar);