/** * Retrieve the key's activation count. * * @since 1.0 * * @param array $options * * @return string */ public function activation_count($options = array()) { $defaults = array('format' => 'html', 'label' => __('Active', ITELIC\Plugin::SLUG)); $options = ITUtility::merge_defaults($options, $defaults); if ($this->license) { $format = '%1$d / %2$s'; $max = $this->license->get_max() ? $this->license->get_max() : '∞'; $value = sprintf($format, $this->license->get_active_count(), $max); } else { $value = ''; } switch ($options['format']) { case 'html': return $value; break; case 'value': return $value; break; case 'label': return $options['label']; break; default: return $value; break; } }
/** * Create an activation. * * @param Key $key * @param string $location * @param \DateTime $activation * @param Release $release * @param string $status * * @return Activation * * @throws \LogicException|DB_Exception */ public static function create(Key $key, $location, \DateTime $activation = null, Release $release = null, $status = '') { if (empty($key) || empty($location)) { throw new \InvalidArgumentException(__("The license key and install location are required.", Plugin::SLUG)); } if (strlen($location) > 191) { throw new \LengthException("The location field has a max length of 191 characters."); } if ($key->get_max() && $key->get_active_count() >= $key->get_max()) { throw new \OverflowException(__("This license key has reached it's maximum number of activations.", Plugin::SLUG)); } if ($activation === null) { $activation = make_date_time()->format('Y-m-d H:i:s'); } else { $activation = $activation->format('Y-m-d H:i:s'); } if (empty($status)) { $status = self::ACTIVE; } if ($key->is_online_product()) { $location = itelic_normalize_url($location); } $data = array('lkey' => $key->get_key(), 'location' => $location, 'activation' => $activation, 'deactivation' => null, 'status' => $status); if ($release) { $data['release_id'] = $release->get_pk(); } $db = Manager::make_simple_query_object('itelic-activations'); $existing_activation = itelic_get_activation_by_location($location, $key); if ($existing_activation) { throw new \InvalidArgumentException(__("An activation with this same location already exists.", Plugin::SLUG)); } $id = $db->insert($data); if (!$id) { return null; } $activation = self::get($id); Cache::add($activation); if (!$release) { $latest = $key->get_product()->get_latest_release_for_activation($activation); if ($latest) { $activation->set_release($latest); } } /** * Fires when an activation record is created. * * @since 1.0 * * @param Activation $activation */ do_action('itelic_create_activation', $activation); return $activation; }
/** * Get data to display for a single object. * * @param \ITELIC\Key $object * @param bool $raw * * @return array */ protected function get_fields_for_object(\ITELIC\Key $object, $raw = false) { return array('key' => $object->get_key(), 'status' => $object->get_status(!$raw), 'product' => $raw ? $object->get_product()->ID : $object->get_product()->post_title, 'transaction' => $raw ? $object->get_transaction()->ID : it_exchange_get_transaction_order_number($object->get_transaction()), 'customer' => $raw ? $object->get_customer()->id : $object->get_customer()->wp_user->display_name, 'expires' => $object->get_expires() ? $object->get_expires()->format(DateTime::ISO8601) : '-', 'max' => $object->get_max() ? $object->get_max() : 'Unlimited', 'activations' => $object->get_active_count()); }
/** * Prepare an individual key view. * * @since 1.0 * * @param Key $key * * @return array */ protected function prepare_key(Key $key) { $data = array('key' => $key->get_key(), 'status' => $key->get_status(false), 'product' => '<a href="' . get_edit_post_link($key->get_product()->ID) . '">' . $key->get_product()->post_title . '</a>', 'customer' => $key->get_customer()->wp_user->display_name, 'expires' => $key->get_expires() === null ? __("Never", Plugin::SLUG) : $key->get_expires()->format(get_option('date_format')), 'active_installs' => $key->get_active_count(), 'max_active' => $key->get_max() ? $key->get_max() : '∞', 'transaction' => '<a href="' . get_edit_post_link($key->get_transaction()->ID) . '">' . it_exchange_get_transaction_order_number($key->get_transaction()) . '</a>'); /** * Filter the columns on the license key list table. * * @since 1.0 * * @param array $data * @param Key $key */ $data = apply_filters('itelic_licenses_list_table_columns', $data, $key); return $data; }