public function toArray()
 {
     if (!$this->referencedTable) {
         throw new Mesour\Sources\InvalidStateException('Referenced table is required. Use method setReferencedTable.');
     }
     if (!$this->selfColumn) {
         throw new Mesour\Sources\InvalidStateException('Self column is required. Use method setReferencedTable.');
     }
     return array_merge(parent::toArray(), ['referencedTable' => $this->referencedTable, 'selfColumn' => $this->selfColumn]);
 }
Beispiel #2
0
 protected function attachToOneRelation(Columns\BaseTableColumnStructure $columnStructure, $left = false)
 {
     $source = $this->getReferencedSource($columnStructure->getTableStructure()->getName());
     foreach ($this->dataArr as $currentKey => $item) {
         /** @var ISource $currentSource */
         $currentSource = clone $source;
         if (isset($item[$this->getPrimaryKey()])) {
             if (!array_key_exists($columnStructure->getReferencedColumn(), $item)) {
                 throw new InvalidStateException(sprintf('Referenced column "%s" does not exist on "%s" table.', $columnStructure->getReferencedColumn(), $this->getTableName()));
             }
             $innerItem = $currentSource->where($columnStructure->getTableStructure()->getPrimaryKey(), $item[$columnStructure->getReferencedColumn()], Mesour\ArrayManage\Searcher\Condition::EQUAL)->fetch();
             $innerItems = [$innerItem];
             $this->addPatternToRows($columnStructure, $innerItems);
             $this->dataArr[$currentKey][$columnStructure->getName()] = reset($innerItems);
         } elseif ($left) {
             $this->dataArr[$currentKey][$columnStructure->getName()] = null;
         } else {
             throw new Exception('Column ' . $columnStructure->getReferencedColumn() . ' does not exist in data array.');
         }
         unset($currentSource);
     }
 }
Beispiel #3
0
 protected function addPatternToRows(BaseTableColumnStructure $columnStructure, &$items)
 {
     if (is_array($items) || $items instanceof ArrayHash) {
         foreach ($items as $key => $item) {
             if (is_array($item) || $item instanceof ArrayHash) {
                 if ($columnStructure->getPattern()) {
                     $item['_pattern'] = Helpers::parseValue($columnStructure->getPattern(), $item);
                 } else {
                     $item['_pattern'] = null;
                 }
             }
             $items[$key] = $item;
         }
     } else {
         $items = [];
     }
 }