public function loginById($key, $id) { $this->logout(); $this->checkConfig($key); $config = $this->config[$key]; $query = new QueryBuilder(); $user = $query->table($config['table'])->where($config['id'], '=', $id)->first(); if ($user) { Session::push('authentication', ['key' => $key, 'login' => $user->{$config}['login']]); return true; } return false; }
/** * Appel statique */ public static function __callStatic($method, $arguments) { $class = get_called_class(); $dbtable = new $class(); // initialisation du QueryBuilder $query = new QueryBuilder($dbtable->fillable); // definition du nom de la table if (!empty($dbtable->tableName)) { $query->from($dbtable->tableName); } else { $query->from(self::GetTable()); } $query->setModel(get_called_class()); $query->setFieldstoSlugifier($dbtable->slugifiable); return call_user_func_array([$query, $method], $arguments); }
public function belongsToMany($class, $joinTable = null, $localForeignKey = null, $siblingForeignKey = null) { $siblingClassObj = new $class(); $siblingTableName = $siblingClassObj->getTableName(); $siblingPrimaryKey = $siblingClassObj->getPrimaryKey(); if (is_null($joinTable)) { $parentTableName = $this->getTableName(); if (strcmp($parentTableName, $siblingTableName) > 0) { $joinTable = $siblingTableName . '_' . $parentTableName; } elseif (strcmp($siblingTableName, $parentTableName) > 0) { $joinTable = $parentTableName . '_' . $siblingTableName; } else { throw new \LogicException('Unable to determine Join table name.'); } } if (is_null($localForeignKey)) { $localForeignKey = $this->getForeignKey(); } if (is_null($siblingForeignKey)) { $siblingForeignKey = $this->getForeignKey($siblingClassObj); } $primaryKey = $this->getPrimaryKey(); $primaryKeyVal = $this->{$primaryKey}; $condition = [new Where($localForeignKey, $primaryKeyVal)]; $statement = $this->getMapper()->getAll($joinTable, [$siblingForeignKey], $condition); $siblingKeyValues = $statement->fetchAll(\PDO::FETCH_NUM); $conditions = []; foreach ($siblingKeyValues as $index => $value) { $conditions[] = new Where($siblingPrimaryKey, $value[0]); } if (static::$returnRelationsAsBuilder) { return QueryBuilder::make($this->getMapper(), $siblingTableName, [], $conditions)->setModel($class); } else { $statement2 = $this->getStatement($siblingTableName, $conditions); return $statement2->fetchObject($class); } }