copyValues($params); if ($auction->find(TRUE)) { CRM_Core_DAO::storeValues($auction, $defaults); return $auction; } return NULL; } /** * update the is_active flag in the db * * @param int $id id of the database record * @param boolean $is_active value we want to set the is_active field * * @return Object DAO object on sucess, null otherwise * @static */ static function setIsActive($id, $is_active) { return CRM_Core_DAO::setFieldValue('CRM_Auction_DAO_Auction', $id, 'is_active', $is_active); } /** * function to add the auction * * @param array $params reference array contains the values submitted by the form * * @access public * @static * * @return object */ static function add(&$params) { require_once 'CRM/Utils/Hook.php'; if (!empty($params['id'])) { CRM_Utils_Hook::pre('edit', 'Auction', $params['id'], $params); } else { CRM_Utils_Hook::pre('create', 'Auction', NULL, $params); } $auction = new CRM_Auction_DAO_Auction(); $auction->copyValues($params); $result = $auction->save(); if (!empty($params['id'])) { CRM_Utils_Hook::post('edit', 'Auction', $auction->id, $auction); } else { CRM_Utils_Hook::post('create', 'Auction', $auction->id, $auction); } return $result; } /** * function to create the auction * * @param array $params reference array contains the values submitted by the form * * @access public * @static * */ public static function create(&$params) { require_once 'CRM/Core/Transaction.php'; $transaction = new CRM_Core_Transaction(); $auction = self::add($params); if (is_a($auction, 'CRM_Core_Error')) { CRM_Core_DAO::transaction('ROLLBACK'); return $auction; } $transaction->commit(); return $auction; } /** * Function to delete the auction * * @param int $id auction id * * @access public * @static * */ static function del($id) { require_once 'CRM/Auction/DAO/Auction.php'; $auction = new CRM_Auction_DAO_Auction(); $auction->id = $id; $result = $auction->delete(); return $result; } /** * Function to get current/future Auctions * * @param $all boolean true if auctions all are required else returns current and future auctions * * @param bool $id * * @return array * @static */ static function getAuctions($all = FALSE, $id = FALSE) { $query = "SELECT `id`, `title`, `start_date` FROM `civicrm_auction`"; if (!$all) { $endDate = date('YmdHis'); $query .= " WHERE `end_date` >= {$endDate} OR end_date IS NULL"; } if ($id) { $query .= " WHERE `id` = {$id}"; } $query .= " ORDER BY title asc"; $auctions = array(); $dao = &CRM_Core_DAO::executeQuery($query, CRM_Core_DAO::$_nullArray); while ($dao->fetch()) { $auctions[$dao->id] = $dao->title . ' - ' . CRM_Utils_Date::customFormat($dao->start_date); } return $auctions; } }