[ Index ]

PHP Cross Reference of Phabricator

title

Body

[close]

/src/applications/nuance/storage/ -> NuanceItem.php (source)

   1  <?php
   2  
   3  final class NuanceItem
   4    extends NuanceDAO
   5    implements PhabricatorPolicyInterface {
   6  
   7    const STATUS_OPEN     = 0;
   8    const STATUS_ASSIGNED = 10;
   9    const STATUS_CLOSED   = 20;
  10  
  11    protected $status;
  12    protected $ownerPHID;
  13    protected $requestorPHID;
  14    protected $sourcePHID;
  15    protected $sourceLabel;
  16    protected $data;
  17    protected $mailKey;
  18    protected $dateNuanced;
  19  
  20    public static function initializeNewItem(PhabricatorUser $user) {
  21      return id(new NuanceItem())
  22        ->setDateNuanced(time())
  23        ->setStatus(NuanceItem::STATUS_OPEN);
  24    }
  25  
  26    public function getConfiguration() {
  27      return array(
  28        self::CONFIG_AUX_PHID => true,
  29        self::CONFIG_SERIALIZATION => array(
  30          'data' => self::SERIALIZATION_JSON,
  31        ),
  32        self::CONFIG_COLUMN_SCHEMA => array(
  33          'ownerPHID' => 'phid?',
  34          'sourceLabel' => 'text255?',
  35          'status' => 'uint32',
  36          'mailKey' => 'bytes20',
  37          'dateNuanced' => 'epoch',
  38        ),
  39        self::CONFIG_KEY_SCHEMA => array(
  40          'key_source' => array(
  41            'columns' => array('sourcePHID', 'status', 'dateNuanced', 'id'),
  42          ),
  43          'key_owner' => array(
  44            'columns' => array('ownerPHID', 'status', 'dateNuanced', 'id'),
  45          ),
  46          'key_contacter' => array(
  47            'columns' => array('requestorPHID', 'status', 'dateNuanced', 'id'),
  48          ),
  49        ),
  50      ) + parent::getConfiguration();
  51    }
  52  
  53    public function generatePHID() {
  54      return PhabricatorPHID::generateNewPHID(
  55        NuanceItemPHIDType::TYPECONST);
  56    }
  57  
  58    public function save() {
  59      if (!$this->getMailKey()) {
  60        $this->setMailKey(Filesystem::readRandomCharacters(20));
  61      }
  62      return parent::save();
  63    }
  64  
  65    public function getURI() {
  66      return '/nuance/item/view/'.$this->getID().'/';
  67    }
  68  
  69    public function getLabel(PhabricatorUser $viewer) {
  70      // this is generated at the time the item is created based on
  71      // the configuration from the item source. It is typically
  72      // something like 'Twitter'.
  73      $source_label = $this->getSourceLabel();
  74  
  75      return pht(
  76        'Item via %s @ %s.',
  77        $source_label,
  78        phabricator_datetime($this->getDateCreated(), $viewer));
  79    }
  80  
  81    public function getRequestor() {
  82      return $this->assertAttached($this->requestor);
  83    }
  84  
  85    public function attachRequestor(NuanceRequestor $requestor) {
  86      return $this->requestor = $requestor;
  87    }
  88  
  89    public function getSource() {
  90      return $this->assertAttached($this->source);
  91    }
  92  
  93    public function attachSource(NuanceSource $source) {
  94      $this->source = $source;
  95    }
  96  
  97    public function getCapabilities() {
  98      return array(
  99        PhabricatorPolicyCapability::CAN_VIEW,
 100        PhabricatorPolicyCapability::CAN_EDIT,
 101      );
 102    }
 103  
 104    public function getPolicy($capability) {
 105      // TODO - this should be based on the queues the item currently resides in
 106      return PhabricatorPolicies::POLICY_USER;
 107    }
 108  
 109    public function hasAutomaticCapability($capability, PhabricatorUser $viewer) {
 110      // TODO - requestors should get auto access too!
 111      return $viewer->getPHID() == $this->ownerPHID;
 112    }
 113  
 114    public function describeAutomaticCapability($capability) {
 115      switch ($capability) {
 116        case PhabricatorPolicyCapability::CAN_VIEW:
 117          return pht('Owners of an item can always view it.');
 118        case PhabricatorPolicyCapability::CAN_EDIT:
 119          return pht('Owners of an item can always edit it.');
 120      }
 121      return null;
 122    }
 123  
 124    public function toDictionary() {
 125      return array(
 126        'id' => $this->getID(),
 127        'phid' => $this->getPHID(),
 128        'ownerPHID' => $this->getOwnerPHID(),
 129        'requestorPHID' => $this->getRequestorPHID(),
 130        'sourcePHID' => $this->getSourcePHID(),
 131        'sourceLabel' => $this->getSourceLabel(),
 132        'dateCreated' => $this->getDateCreated(),
 133        'dateModified' => $this->getDateModified(),
 134        'dateNuanced' => $this->getDateNuanced(),
 135      );
 136    }
 137  }


Generated: Sun Nov 30 09:20:46 2014 Cross-referenced by PHPXref 0.7.1