Path: blob/master/src/infrastructure/customfield/standard/PhabricatorStandardCustomFieldDate.php
12242 views
<?php12final class PhabricatorStandardCustomFieldDate3extends PhabricatorStandardCustomField {45public function getFieldType() {6return 'date';7}89public function buildFieldIndexes() {10$indexes = array();1112$value = $this->getFieldValue();13if (strlen($value)) {14$indexes[] = $this->newNumericIndex((int)$value);15}1617return $indexes;18}1920public function buildOrderIndex() {21return $this->newNumericIndex(0);22}2324public function getValueForStorage() {25$value = $this->getFieldValue();26if (strlen($value)) {27return (int)$value;28} else {29return null;30}31}3233public function setValueFromStorage($value) {34if (strlen($value)) {35$value = (int)$value;36} else {37$value = null;38}39return $this->setFieldValue($value);40}4142public function renderEditControl(array $handles) {43return $this->newDateControl();44}4546public function readValueFromRequest(AphrontRequest $request) {47$control = $this->newDateControl();48$control->setUser($request->getUser());49$value = $control->readValueFromRequest($request);5051$this->setFieldValue($value);52}5354public function renderPropertyViewValue(array $handles) {55$value = $this->getFieldValue();56if (!$value) {57return null;58}5960return phabricator_datetime($value, $this->getViewer());61}6263private function newDateControl() {64$control = id(new AphrontFormDateControl())65->setLabel($this->getFieldName())66->setName($this->getFieldKey())67->setUser($this->getViewer())68->setCaption($this->getCaption())69->setAllowNull(!$this->getRequired());7071// If the value is already numeric, treat it as an epoch timestamp and set72// it directly. Otherwise, it's likely a field default, which we let users73// specify as a string. Parse the string into an epoch.7475$value = $this->getFieldValue();76if (!ctype_digit($value)) {77$value = PhabricatorTime::parseLocalTime($value, $this->getViewer());78}7980// If we don't have anything valid, make sure we pass `null`, since the81// control special-cases that.82$control->setValue(nonempty($value, null));8384return $control;85}8687public function readApplicationSearchValueFromRequest(88PhabricatorApplicationSearchEngine $engine,89AphrontRequest $request) {9091$key = $this->getFieldKey();9293return array(94'min' => $request->getStr($key.'.min'),95'max' => $request->getStr($key.'.max'),96);97}9899public function applyApplicationSearchConstraintToQuery(100PhabricatorApplicationSearchEngine $engine,101PhabricatorCursorPagedPolicyAwareQuery $query,102$value) {103104$viewer = $this->getViewer();105106if (!is_array($value)) {107$value = array();108}109110$min_str = idx($value, 'min', '');111if (strlen($min_str)) {112$min = PhabricatorTime::parseLocalTime($min_str, $viewer);113} else {114$min = null;115}116117$max_str = idx($value, 'max', '');118if (strlen($max_str)) {119$max = PhabricatorTime::parseLocalTime($max_str, $viewer);120} else {121$max = null;122}123124if (($min !== null) || ($max !== null)) {125$query->withApplicationSearchRangeConstraint(126$this->newNumericIndex(null),127$min,128$max);129}130}131132public function appendToApplicationSearchForm(133PhabricatorApplicationSearchEngine $engine,134AphrontFormView $form,135$value) {136137if (!is_array($value)) {138$value = array();139}140141$form142->appendChild(143id(new AphrontFormTextControl())144->setLabel(pht('%s After', $this->getFieldName()))145->setName($this->getFieldKey().'.min')146->setValue(idx($value, 'min', '')))147->appendChild(148id(new AphrontFormTextControl())149->setLabel(pht('%s Before', $this->getFieldName()))150->setName($this->getFieldKey().'.max')151->setValue(idx($value, 'max', '')));152}153154public function getApplicationTransactionTitle(155PhabricatorApplicationTransaction $xaction) {156$author_phid = $xaction->getAuthorPHID();157$old = $xaction->getOldValue();158$new = $xaction->getNewValue();159160$viewer = $this->getViewer();161162$old_date = null;163if ($old) {164$old_date = phabricator_datetime($old, $viewer);165}166167$new_date = null;168if ($new) {169$new_date = phabricator_datetime($new, $viewer);170}171172if (!$old) {173return pht(174'%s set %s to %s.',175$xaction->renderHandleLink($author_phid),176$this->getFieldName(),177$new_date);178} else if (!$new) {179return pht(180'%s removed %s.',181$xaction->renderHandleLink($author_phid),182$this->getFieldName());183} else {184return pht(185'%s changed %s from %s to %s.',186$xaction->renderHandleLink($author_phid),187$this->getFieldName(),188$old_date,189$new_date);190}191}192193public function getApplicationTransactionTitleForFeed(194PhabricatorApplicationTransaction $xaction) {195196$viewer = $this->getViewer();197198$author_phid = $xaction->getAuthorPHID();199$object_phid = $xaction->getObjectPHID();200201$old = $xaction->getOldValue();202$new = $xaction->getNewValue();203204if (!$old) {205return pht(206'%s set %s to %s on %s.',207$xaction->renderHandleLink($author_phid),208$this->getFieldName(),209phabricator_datetime($new, $viewer),210$xaction->renderHandleLink($object_phid));211} else if (!$new) {212return pht(213'%s removed %s on %s.',214$xaction->renderHandleLink($author_phid),215$this->getFieldName(),216$xaction->renderHandleLink($object_phid));217} else {218return pht(219'%s changed %s from %s to %s on %s.',220$xaction->renderHandleLink($author_phid),221$this->getFieldName(),222phabricator_datetime($old, $viewer),223phabricator_datetime($new, $viewer),224$xaction->renderHandleLink($object_phid));225}226}227228protected function newConduitSearchParameterType() {229// TODO: Build a new "pair<epoch|null, epoch|null>" type or similar.230return null;231}232233protected function newConduitEditParameterType() {234return id(new ConduitEpochParameterType())235->setAllowNull(!$this->getRequired());236}237238protected function newExportFieldType() {239return new PhabricatorEpochExportField();240}241242}243244245