/**
  * Convert the given producer DAO to an array and prepend metadata.
  *
  * @param Tracker_ProducerDao $producerDao producer DAO
  * @return array associative array representation of the producer DAO with metadata prepended
  */
 protected function _toArray($producerDao)
 {
     $producerArray = array('_id' => $producerDao->getKey(), '_type' => 'Tracker_Producer');
     return array_merge($producerArray, $producerDao->toArray());
 }
示例#2
0
 /**
  * Return all trends corresponding to the given producer. They will be grouped by distinct
  * config/test/truth dataset combinations.
  *
  * @param Tracker_ProducerDao $producerDao producer DAO
  * @return array array of associative arrays with keys "configItem", "testDataset", "truthDataset", and "trends"
  */
 public function getTrendsGroupByDatasets($producerDao)
 {
     $sql = $this->database->select()->setIntegrityCheck(false)->from($this->_name, array('config_item_id', 'test_dataset_id', 'truth_dataset_id'))->where('producer_id = ?', $producerDao->getKey())->distinct();
     /** @var ItemModel $itemModel */
     $itemModel = MidasLoader::loadModel('Item');
     $results = array();
     $rows = $this->database->fetchAll($sql);
     /** @var Zend_Db_Table_Row_Abstract $row */
     foreach ($rows as $row) {
         $configItemDao = $row['config_item_id'] == null ? null : $itemModel->load($row['config_item_id']);
         $testDatasetItemDao = $row['test_dataset_id'] == null ? null : $itemModel->load($row['test_dataset_id']);
         $truthDatasetItemDao = $row['truth_dataset_id'] == null ? null : $itemModel->load($row['truth_dataset_id']);
         $result = array('configItem' => $configItemDao, 'testDataset' => $testDatasetItemDao, 'truthDataset' => $truthDatasetItemDao);
         $result['trends'] = $this->getAllByParams(array('producer_id' => $producerDao->getKey(), 'config_item_id' => $row['config_item_id'], 'test_dataset_id' => $row['test_dataset_id'], 'truth_dataset_id' => $row['truth_dataset_id']));
         $results[] = $result;
     }
     return $results;
 }
示例#3
0
 /**
  * Return the submission with the given UUID (creating one if necessary).
  *
  * @param Tracker_ProducerDao $producerDao the producer
  * @param string $uuid the uuid of the submission
  * @return Tracker_SubmissionDao
  */
 public function getOrCreateSubmission($producerDao, $uuid)
 {
     $sql = $this->database->select()->setIntegrityCheck(false)->from('tracker_submission')->where('uuid = ?', $uuid)->where('producer_id = ?', $producerDao->getKey());
     $res = $this->database->fetchAll($sql);
     if (count($res) === 1) {
         $submissionDao = $this->initDao('Submission', $res[0], $this->moduleName);
     } else {
         $doc = array();
         $doc['uuid'] = $uuid;
         $doc['producer_id'] = $producerDao->getKey();
         /** @var Tracker_SubmissionDao $submissionDao */
         $submissionDao = $this->initDao('Submission', $doc, $this->moduleName);
         $this->save($submissionDao);
         $submissionId = $submissionDao->getSubmissionId();
         $submissionDao = $this->load($submissionId);
     }
     return $submissionDao;
 }