Exemplo n.º 1
0
 /**
  * Initialises the column collection based on the incoming map array
  * 
  * @param array $map
  * @param mixed $consumer - the source model object
  */
 public function setColumnMap($map, $consumer)
 {
     $sql = sprintf(static::SCHEMA_DESCRIBE_QUERY, $this->tableName);
     $stmt = $this->pdo->query($sql);
     $dbMap = [];
     foreach ($map as $property => $column) {
         if (!is_string($property)) {
             $property = $column;
         }
         $dbMap[$column] = $property;
     }
     while ($row = $stmt->fetch()) {
         $column = new Column(['name' => $row[static::SCHEMA_FIELD_NAME], 'type' => $row[static::SCHEMA_TYPE_NAME], 'pk' => $this->isFieldPrimaryKey($row)]);
         // Only columns in the map get connected to object properties
         if (in_array($row[static::SCHEMA_FIELD_NAME], array_keys($dbMap))) {
             $connectedProperty = new ConnectedProperty($consumer, $dbMap[$row[static::SCHEMA_FIELD_NAME]]);
             $connectedProperty->setAccessible(true);
             $column->setConnectedProperty($connectedProperty);
         }
         $this->columns[$column->getName()] = $column;
         if ($column->isPrimaryKey()) {
             $this->pk = $column;
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Retrieves the value of the object property connected to this column
  * 
  * @return mixed
  */
 public function getPropertyValue()
 {
     if ($this->isConnected) {
         return $this->connectedProperty->getValue();
     }
 }