Psecio\Gatekeeper\DataSource\Mysql::create PHP Метод

create() публичный Метод

Create the record based on the data from the model
public create ( Modler\Model $model ) : boolean
$model Modler\Model Model instance
Результат boolean Success/fail of create action
    public function create(\Modler\Model $model)
    {
        $relations = array();
        $properties = $model->getProperties();
        $data = $model->toArray();
        // Remove the ones without a column
        foreach ($data as $index => $item) {
            // Check the property to see if it's a relation
            if ($properties[$index]['type'] == 'relation') {
                $relations[$index] = $item;
                unset($data[$index]);
            }
        }
        $data['created'] = date('Y-m-d H:i:s');
        $data['updated'] = date('Y-m-d H:i:s');
        list($columns, $bind) = $this->setup($data);
        foreach ($columns as $index => $column) {
            $colName = $properties[$column]['column'];
            $columns[$index] = $colName;
        }
        $sql = 'insert into ' . $model->getTableName() . ' (' . implode(',', $columns) . ') values (' . implode(',', array_values($bind)) . ')';
        $result = $this->execute($sql, $data);
        if ($result !== false) {
            $model->id = $this->getDb()->lastInsertId();
            // Now handle the relations - for each of them, get the model, make it and save it
            foreach ($relations as $index => $item) {
                $relation = $properties[$index];
                $instance = new $relation['relation']['model']($this);
                $instance->create($model, $item);
            }
        }
        return $result;
    }