Overview

Namespaces

  • None
  • swag

Classes

  • H5pSwagifact
  • H5pUtil
  • SettingsPageController
  • ShortcodeUtil
  • swag\ArrayUtil
  • swag\Singleton
  • swag\WpUtil
  • SwagMapController
  • SwagPageController
  • Swagpath
  • SwagpathController
  • SwagpathSyncer
  • SwagPlugin
  • SwagPostItem
  • SwagTgmpaController
  • SwagTrack
  • SwagTrackController
  • SwagUser
  • Template
  • Xapi
  • Overview
  • Namespace
  • Class
  1:   2:   3:   4:   5:   6:   7:   8:   9:  10:  11:  12:  13:  14:  15:  16:  17:  18:  19:  20:  21:  22:  23:  24:  25:  26:  27:  28:  29:  30:  31:  32:  33:  34:  35:  36:  37:  38:  39:  40:  41:  42:  43:  44:  45:  46:  47:  48:  49:  50:  51:  52:  53:  54:  55:  56:  57:  58:  59:  60:  61:  62:  63:  64:  65:  66:  67:  68:  69:  70:  71:  72:  73:  74:  75:  76:  77:  78:  79:  80:  81:  82:  83:  84:  85:  86:  87:  88:  89:  90:  91:  92:  93:  94:  95:  96:  97:  98:  99: 100: 101: 102: 103: 104: 105: 106: 107: 108: 109: 110: 111: 112: 113: 114: 115: 116: 
<?php

/**
 * Represents a SwagTrack
 */
class SwagTrack {

    const DEFAULT_COLOR="#339933";

    private $term;

    /**
     * Construct.
     */
    private function __construct($term) {
        $this->term=$term;
    }

    /**
     * Get id.
     */
    public function getId() {
        return $this->term->term_id;
    }

    /**
     * Get underlying taxonomy term.
     */
    public function getTerm() {
        return $this->term;
    }

    /**
     * Get display color.
     */
    public function getDisplayColor() {
        if ($this->getColor())
            return $this->getColor();

        $parent=$this->getParent();
        if ($parent && $parent->getColor())
            return $parent->getColor();

        return SwagTrack::DEFAULT_COLOR;
    }

    /**
     * Get color.
     */
    public function getColor() {
        if (!isset($this->color))
            $this->color=get_term_meta($this->getId(),"color",TRUE);

        return $this->color;
    }

    /**
     * Get parent.
     */
    public function getParent() {
        return SwagTrack::getById($this->getTerm()->parent);
    }

    /**
     * Get children for a specified parent.
     */
    public static function getByParentId($parentTrackId) {
        $terms=get_terms(array(
            "taxonomy"=>"swagtrack",
            "hide_empty"=>FALSE,
            "parent"=>$parentTrackId,
        ));

        $res=array();
        foreach ($terms as $term)
            $res[]=new SwagTrack($term);

        return $res;
    }

    /**
     * Get by slug.
     * Should we use term_id or term_taxonomy_id?
     * What is term_taxonomy_id and where is it used?
     */
    public static function getBySlug($trackSlug) {
        if (!$trackSlug)
            return NULL;

        $t=get_terms(array(
            "taxonomy"=>"swagtrack",
            "slug"=>$trackSlug,
            "hide_empty"=>FALSE,
        ));

        if (!$t)
            return NULL;

        return new SwagTrack($t[0]);
    }

    /**
     * Get by id.
     */
    public static function getById($trackId) {
        if (!$trackId)
            return NULL;

        $t=get_term($trackId);

        if (!$t)
            return NULL;

        return new SwagTrack($t);
    }
}
Swag API documentation generated by ApiGen