[ Index ] |
PHP Cross Reference of Phabricator |
[Summary view] [Print] [Text view]
1 <?php 2 3 /** 4 * Simple fact engine which counts objects. 5 */ 6 final class PhabricatorFactCountEngine extends PhabricatorFactEngine { 7 8 public function getFactSpecs(array $fact_types) { 9 $results = array(); 10 foreach ($fact_types as $type) { 11 if (!strncmp($type, '+N:', 3)) { 12 if ($type == '+N:*') { 13 $name = 'Total Objects'; 14 } else { 15 $name = 'Total Objects of type '.substr($type, 3); 16 } 17 18 $results[] = id(new PhabricatorFactSimpleSpec($type)) 19 ->setName($name) 20 ->setUnit(PhabricatorFactSimpleSpec::UNIT_COUNT); 21 } 22 23 if (!strncmp($type, 'N:', 2)) { 24 if ($type == 'N:*') { 25 $name = 'Objects'; 26 } else { 27 $name = 'Objects of type '.substr($type, 2); 28 } 29 $results[] = id(new PhabricatorFactSimpleSpec($type)) 30 ->setName($name) 31 ->setUnit(PhabricatorFactSimpleSpec::UNIT_COUNT); 32 } 33 34 } 35 return $results; 36 } 37 38 public function shouldComputeRawFactsForObject(PhabricatorLiskDAO $object) { 39 return true; 40 } 41 42 public function computeRawFactsForObject(PhabricatorLiskDAO $object) { 43 $facts = array(); 44 45 $phid = $object->getPHID(); 46 $type = phid_get_type($phid); 47 48 foreach (array('N:*', 'N:'.$type) as $fact_type) { 49 $facts[] = id(new PhabricatorFactRaw()) 50 ->setFactType($fact_type) 51 ->setObjectPHID($phid) 52 ->setValueX(1) 53 ->setEpoch($object->getDateCreated()); 54 } 55 56 return $facts; 57 } 58 59 public function shouldComputeAggregateFacts() { 60 return true; 61 } 62 63 public function computeAggregateFacts() { 64 $table = new PhabricatorFactRaw(); 65 $table_name = $table->getTableName(); 66 $conn = $table->establishConnection('r'); 67 68 $counts = queryfx_all( 69 $conn, 70 'SELECT factType, SUM(valueX) N FROM %T WHERE factType LIKE %> 71 GROUP BY factType', 72 $table_name, 73 'N:'); 74 75 $facts = array(); 76 foreach ($counts as $count) { 77 $facts[] = id(new PhabricatorFactAggregate()) 78 ->setFactType('+'.$count['factType']) 79 ->setValueX($count['N']); 80 } 81 82 return $facts; 83 } 84 85 86 }
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated: Sun Nov 30 09:20:46 2014 | Cross-referenced by PHPXref 0.7.1 |