/**
  * callback for the FHEE__EE_Admin_Page___display_admin_list_table_page__before_list_table__template_arg filter so if displaying events filtered by promotion we add helpful title for viewer.
  *
  * @since 1.0.0
  *
  * @param string $content      Any current content.
  * @param string $page_slug  Page slug of page
  * @param array  $req_data    Incoming request data.
  * @param string $req_action 'action' value for page
  *
  * @return string  If correct page then and conditions are met the new string. Otherwise existing.
  */
 public function before_events_list_table_content($content, $page_slug, $req_data, $req_action)
 {
     if ($page_slug !== 'espresso_events' || $req_action !== 'default' || empty($req_data['PRO_ID'])) {
         return $content;
     }
     $promotion = EEM_Promotion::instance()->get_one_by_ID($req_data['PRO_ID']);
     if ($promotion instanceof EE_Promotion) {
         $query_args = array('action' => 'edit', 'PRO_ID' => $promotion->ID());
         EE_Registry::instance()->load_helper('URL');
         $url = EEH_URL::add_query_args_and_nonce($query_args, admin_url('admin.php?page=espresso_promotions'));
         $pro_linked = '<a href="' . $url . '" title="' . __('Click to view promotion details.', 'event_espresso') . '">' . $promotion->name() . '</a>';
         $content .= '<h3>' . sprintf(__('Viewing Events that the %s promotion applies to.', 'event_espresso'), $pro_linked) . '</h3>';
     }
     return $content;
 }
 /**
  * Adds the function 'promotions' onto each EE_Event object.
  * Gets all the promotions for this event, (but doesn't cache its results or anything).
  * @param array $query_params
  * @return EE_Promotion[]
  */
 public function ext_promotions($query_params = array())
 {
     $query_params = array_replace_recursive(array(array('Promotion_Object.Event.EVT_ID' => $this->_->ID())), $query_params);
     return EEM_Promotion::instance()->get_all($query_params);
 }
 protected function _get_promotions($per_page = 10, $count = FALSE, $trash = FALSE)
 {
     $_where = array();
     $_orderby = !empty($this->_req_data['orderby']) ? $this->_req_data['orderby'] : '';
     switch ($_orderby) {
         case 'name':
             $orderby = 'Price.PRC_name';
             break;
         case 'code':
             $orderby = 'PRO_code';
             break;
         case 'valid_from':
             $orderby = 'PRO_start';
             break;
         case 'valid_until':
             $orderby = 'PRO_end';
             break;
         case 'redeemed':
             $orderby = 'Promotion_Object.POB_used';
             break;
         default:
             $orderby = 'PRO_ID';
             break;
     }
     //search query params?
     if (!empty($this->_req_data['s'])) {
         $s = $this->_req_data['s'];
         $_where = array('OR' => array('Price.PRC_name' => array('LIKE', '%' . $s . '%'), 'Price.PRC_desc' => array('LIKE', '%' . $s . '%'), 'PRO_code' => array('LIKE', '%' . $s . '%')));
     }
     $sort = !empty($this->_req_data['order']) ? $this->_req_data['order'] : 'DESC';
     $current_page = !empty($this->_req_data['paged']) ? $this->_req_data['paged'] : 1;
     $per_page = !empty($per_page) ? $per_page : 10;
     $per_page = !empty($this->_req_data['perpage']) ? $this->_req_data['perpage'] : $per_page;
     $offset = ($current_page - 1) * $per_page;
     $limit = array($offset, $per_page);
     $query_args = array($_where, 'limit' => $limit, 'order_by' => $orderby, 'order' => $sort);
     //possibly modify for caps
     if (!EE_Registry::instance()->CAP->current_user_can('ee_read_others_promotions', 'get_others_promotions')) {
         $query_args = EEM_Promotion::instance()->alter_query_params_to_only_include_mine($query_args);
     }
     if ($trash) {
         $promotions = $count ? EEM_Promotion::instance()->count_deleted(array($_where)) : EEM_Promotion::instance()->get_all_deleted($query_args);
     } else {
         $promotions = $count ? EEM_Promotion::instance()->count(array($_where)) : EEM_Promotion::instance()->get_all($query_args);
     }
     return $promotions;
 }
 /**
  *    get_promotion_from_line_item
  *
  * @access 	public
  * @param EE_Line_Item $promotion_line_item the line item representing the new promotion
  * @return 	EE_Promotion | null
  */
 public function get_promotion_from_line_item(EE_Line_Item $promotion_line_item)
 {
     $promotion = EEM_Promotion::instance()->get_one_by_ID($promotion_line_item->OBJ_ID());
     if (!$promotion instanceof EE_Promotion) {
         EE_Error::add_error(sprintf(apply_filters('FHEE__EED_Promotions__get_promotion_from_line_item__invalid_promotion_notice', __('We\'re sorry, but the %1$s could not be applied because information pertaining to it could not be retrieved from the database.', 'event_espresso')), strtolower($this->_config->label->singular)), __FILE__, __FUNCTION__, __LINE__);
         return null;
     }
     return $promotion;
 }