protected function check_ingot_id() { if (!isset($this->cookie['ingot_id'])) { $ingot_id = session::find_ingot_id(get_current_user_id(), ingot_get_ip()); $this->cookie['ingot_id'] = $ingot_id; } }
/** * Set class properties * * @since 0.3.0 * * @access private * * @param $id */ private function set_up_session($id) { if (is_null($id) || !\ingot\testing\crud\session::valid(\ingot\testing\crud\session::read($id))) { $this->ID = \ingot\testing\crud\session::create(['uID' => get_current_user_id(), 'IP' => ingot_get_ip()], true); } else { $this->ID = $id; } $this->session = \ingot\testing\crud\session::read($this->ID); $this->ID = $this->session['ID']; $this->ingot_id = $this->session['ingot_ID']; }
/** * @param \WP_REST_Request $request Full data about the request. * * @return array|mixed|null|object|void */ protected function get_session_by_url_params($request) { $url = $request->get_url_params(); $id = helpers::v('id', $url, 0); if (0 != absint($id) && is_array($session = \ingot\testing\crud\session::read($id))) { return $session; } else { return new \WP_Error('ingot-invalid-session'); } }
/** * Check if all tables exists * * @since 1.1.0 * @since 0.3.0 in class ingot_boostrap * * @access protected * * @return bool */ public static function check_if_tables_exist() { if (!self::table_exists(\ingot\testing\crud\tracking::get_table_name()) || !self::table_exists(\ingot\testing\crud\group::get_table_name()) || !self::table_exists(\ingot\testing\crud\session::get_table_name()) || !self::table_exists(\ingot\testing\crud\variant::get_table_name())) { return false; } return true; }
/** * Find number of sessions in a range * * @access protected * * @since 1.1.0 * * @param int $max Max range timestamp * @param int $min Min range timestap * @param bool $unique Optional. To get unique values or not. Default is true. * * @return int */ protected function find_range($max, $min, $unique = true) { $min = $this->time_to_string($min); $max = $this->time_to_string($max); global $wpdb; $table_name = session::get_table_name(); if ($unique) { $select = 'DISTINCT `ingot_ID`'; } else { $select = '`ID`'; } $sql = sprintf('SELECT %s FROM `%s` WHERE `created` BETWEEN "%s" AND "%s"', $select, $table_name, $min, $max); $results = $wpdb->query($sql, ARRAY_A); if (is_int($results)) { return $results; } elseif (is_array($results) && !empty($results)) { return count($results); } else { return 0; } }
/** * Test item exists method * * @since 1.1.0 * * @group session * @group session_crud * @group crud * * @covers \ingot\testing\crud\group::session() */ public function testExists() { $id = \ingot\testing\crud\session::create([], true); $this->assertTrue(is_numeric($id)); $this->assertTrue(\ingot\testing\crud\session::exists($id)); $this->assertFalse(\ingot\testing\crud\session::exists(99999)); \ingot\testing\crud\session::delete($id); $this->assertFalse(\ingot\testing\crud\session::exists($id)); }
/** * Register a conversion * * @since 0.4.0 * * @param int $variant_ID ID of variant to register conversion for * @param int $session_ID Optional. Session ID. If a valid session ID is passed, that session will be marked as having converted with this vartiant ID. */ function ingot_register_conversion($variant_ID, $session_ID = 0) { $variant = \ingot\testing\crud\variant::read($variant_ID); if (is_array($variant)) { $bandit = new \ingot\testing\bandit\content($variant['group_ID']); $bandit->record_victory($variant_ID); if (0 < absint($session_ID) && is_array($session = \ingot\testing\crud\session::read($session_ID))) { $session['click_ID'] = $variant_ID; $session['used'] = true; if (0 !== ($userID = get_current_user_id())) { $session['click_url'] = $userID; } \ingot\testing\crud\session::update($session, $session['ID'], true); } } }
/** * Test that we can mark a session as used * * @since 0.3.0 * * @group session * @group crud * * @covers \ingot\testing\crud\session::mark_used() */ public function testMarkUsed() { $id = \ingot\testing\crud\session::create(array()); $this->assertTrue(is_numeric($id)); \ingot\testing\crud\session::mark_used($id); $session = \ingot\testing\crud\session::read($id); $this->assertSame('1', $session['used']); }
/** * Register a conversion * * @since 0.4.0 * * @param int|array $variant Variant config or Variant ID to register conversion for * @param int $session_ID Optional. Session ID. If a valid session ID is passed, that session will be marked as having converted with this vartiant ID. */ function ingot_register_conversion($variant, $session_ID = 0) { if (is_numeric($variant)) { $variant = \ingot\testing\crud\variant::read($variant); } if (\ingot\testing\crud\variant::valid($variant)) { $bandit = new \ingot\testing\bandit\content($variant['group_ID']); $bandit->record_victory($variant['ID']); if (0 < absint($session_ID) && is_array($session = \ingot\testing\crud\session::read($session_ID))) { } else { $session = \ingot\testing\ingot::instance()->get_current_session()['session']; } if (\ingot\testing\crud\session::valid($session)) { $session['click_ID'] = $variant['ID']; $session['used'] = true; if (0 !== ($userID = get_current_user_id())) { $session['click_url'] = $userID; } \ingot\testing\crud\session::update($session, $session['ID'], true); } } }