コード例 #1
0
 /**
  *		This function is a singleton method used to instantiate the EEM_Attendee object
  *
  *		@access public
  *		@return EEM_Extra_Meta instance
  */
 public static function instance()
 {
     // check if instance of EEM_Attendee already exists
     if (self::$_instance === NULL) {
         // instantiate Espresso_model
         self::$_instance = new self();
     }
     return self::$_instance;
 }
コード例 #2
0
 /**
  * Deletes all the extra meta rows for this record as specified by key. If $meta_value
  * is specified, only deletes extra meta records with that value.
  * @param string $meta_key
  * @param string $meta_value
  * @return int number of extra meta rows deleted
  */
 public function delete_extra_meta($meta_key, $meta_value = NULL)
 {
     $query_params = array(array('EXM_key' => $meta_key, 'OBJ_ID' => $this->ID(), 'EXM_type' => $this->get_model()->get_this_model_name()));
     if ($meta_value !== NULL) {
         $query_params[0]['EXM_value'] = $meta_value;
     }
     $count_deleted = EEM_Extra_Meta::instance()->delete($query_params);
     return $count_deleted;
 }
コード例 #3
0
 /**
  * This determines if there are any saved filters for the given Promotion ID and if needed will overload the
  * $_REQUEST global for those filter values for use elsewhere in the promotion ui.
  *
  * @since 1.0.0
  *
  * @param int $PRO_ID
  * @return bool true when there were saved filters, false when not.
  */
 protected function _maybe_overload_request_with_saved_filters($PRO_ID = 0)
 {
     //any saved filters (only on non-ajax requests)?
     if (!empty($PRO_ID) && !defined('DOING_AJAX')) {
         $set_filters = EEM_Extra_Meta::instance()->get_one(array(0 => array('OBJ_ID' => $PRO_ID, 'EXM_type' => 'Promotion', 'EXM_key' => 'promo_saved_filters')));
         $set_filters = $set_filters instanceof EE_Extra_Meta ? $set_filters->get('EXM_value') : array();
         //overload $_REQUEST global
         foreach ($set_filters as $filter_key => $filter_value) {
             if ($filter_value) {
                 $_REQUEST[$filter_key] = $filter_value;
             }
         }
         if (!empty($set_filters)) {
             return true;
         }
     }
     return false;
 }
コード例 #4
0
 /**
  * @todo: if a foreign key can point to multiple models, only use mappings
  * that apply
  */
 public function test_save_data_array_to_db__from_other_site__fks_that_point_to_multiple_models()
 {
     //multiple types of fks that point ot multiple models: ones accompanied by a model name field and ones without
     //using model name field: extra metas
     //sans-model name field: term-relationships
     $extra_meta_id = 1;
     $extra_meta_id2 = 4;
     $imaginary_txn_or_reg_id = 2;
     $an_event_id = 3;
     $csv_data = array('Extra_Meta' => array(array('EXM_ID' => $extra_meta_id, 'OBJ_ID' => $imaginary_txn_or_reg_id, 'EXM_type' => 'Transaction', 'EXM_key' => 'foo', 'EXM_value' => 'bar'), array('EXM_ID' => $extra_meta_id2, 'OBJ_ID' => $imaginary_txn_or_reg_id, 'EXM_type' => 'Registration', 'EXM_key' => 'foo', 'EXM_value' => 'bar')), 'Term_Relationship' => array(array('object_id' => $an_event_id, 'term_taxonomy_id' => 0, 'term_order' => 1)));
     $mapped_txn_id = 4;
     $mapped_reg_id = 124;
     $mapped_event_id = 322;
     $mappings = array('Transaction' => array($imaginary_txn_or_reg_id => $mapped_txn_id), 'Registration' => array($imaginary_txn_or_reg_id => $mapped_reg_id), 'Event' => array($an_event_id => $mapped_event_id));
     //start test
     $new_mappings = EE_Import::instance()->save_data_rows_to_db($csv_data, true, $mappings);
     //ok, so we should have inserted 3 things,
     $this->assertEquals(2, count($new_mappings['Extra_Meta']));
     $this->assertEquals(1, count($new_mappings['Term_Relationship']));
     //check that they correctly used the mappings that previously existed
     $inserted_extra_meta_1_id = $new_mappings['Extra_Meta'][$extra_meta_id];
     $inserted_extra_meta_1 = EEM_Extra_Meta::instance()->get_one_by_ID($inserted_extra_meta_1_id);
     $this->assertEquals('Transaction', $inserted_extra_meta_1->get('EXM_type'));
     $this->assertEquals($mapped_txn_id, $inserted_extra_meta_1->get('OBJ_ID'));
     $inserted_extra_meta_2_id = $new_mappings['Extra_Meta'][$extra_meta_id2];
     $inserted_extra_meta_2 = EEM_Extra_Meta::instance()->get_one_by_ID($inserted_extra_meta_2_id);
     $this->assertEquals('Registration', $inserted_extra_meta_2->get('EXM_type'));
     $this->assertEquals($mapped_reg_id, $inserted_extra_meta_2->get('OBJ_ID'));
     $inserted_term_r_id = $new_mappings['Term_Relationship'][EEM_Term_Relationship::instance()->get_index_primary_key_string($csv_data['Term_Relationship'][0])];
     $term_r = EEM_Term_Relationship::instance()->get_one_by_ID($inserted_term_r_id);
     $this->assertInstanceOf('EE_Term_Relationship', $term_r);
     $this->assertEquals($mapped_event_id, $term_r->get('object_id'));
 }