Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Teste Instagram - Entrega 10h | 20/01 #5

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
9 changes: 9 additions & 0 deletions .htaccess
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
RewriteEngine on

# Habilitar o PHP 5.4
# AddHandler application/x-httpd-php54 .php

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?rturl=$1 [L,QSA]
37 changes: 1 addition & 36 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,36 +1 @@
TrabalheNaMktVirtual-BackEnd
-

Aqui temos um projeto para você nos mostrar todo o seu conhecimento no desenvolvimento de um site!

#### Como funciona?

Desenvolva uma cópia do instagram com os seguintes recursos:
* Cadastro do usuário (Pode usar o Facebook).
* Autenticação do usuário (Pode usar o Facebook).
* Upload de fotos (Resize).
* Perfil do usuário.
* Página da foto.

Requisitos obrigatórios:
* PHP 5.
* Orientado a Objeto (OO).
* Não utilizar frameworks prontos.

Requisitos Opcional
* Utilizar OO 100%, utilizar todos os recursos disponiveis. (Interface, SPL, Namespaces e etcs).
* Teste unitário PHPUnit.
* Fazer uso de uma das normas PSR. (PSR-0, PSR1 ou PSR2).
* PDO
* Utilizar alguns Design Patterns

Permitimos:
* Uso de classes prontas para geração de thumbnail e resizer.

Lembre-se, você pode criar a estrutura do zero, com ou sem o Composer ;)

Se você ainda não passou pela fase de entrevista, cadastre seu [currículo aqui!](http://www.mktvirtual.com.br/carreira/)

* Faça um pull request até a data estipulada.

#### Estamos torcendo por você!
# PictureIt
59 changes: 59 additions & 0 deletions app/config.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<?php
namespace mktInstagram;

class Config
{
protected $defaultDB = null;

protected $localhost = array(
'host' => 'localhost',
'dbName' => 'picture_it',
'user' => 'root',
'pass' => 'root'
);

protected $producao = array(
'host' => '',
'dbName' => '',
'user' => '',
'pass' => ''
);

public $appId = '333796446826704';
public $secretId = '4f76d934f9fade9e20626b65c1a3dbfb';

public function __construct()
{
switch ($_SERVER['SERVER_NAME']) {
case 'localhost':
case '127.0.0.1':
$this->defaultDB = $this->localhost;
break;
case 'www.metalwingsweb.com':
case 'metalwingsweb.com':
$this->defaultDB = $this->producao;
break;
}
}

public function getDbConfig()
{
return $this->defaultDB;
}

/**
* @return $appId (Facebook App Id)
*/
public function getAppId()
{
return $this->appId;
}

/**
* @return $secretId (Facebook Secret Id)
*/
public function getSecretId()
{
return $this->secretId;
}
}
17 changes: 17 additions & 0 deletions app/controller_base.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
namespace mktInstagram\Controller;

abstract class BaseController
{
protected $registry;

public function __construct($registry)
{
$this->registry = $registry;
}

/*
* @todos os controllers devem ter uma função/método index()
*/
abstract public function index();
}
191 changes: 191 additions & 0 deletions app/db.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,191 @@
<?php
namespace mktInstagram;

use mktInstagram\Config;

class DB extends Config
{
private $connection;

public function __construct($host = null, $dbName = null, $user = null, $pass = null)
{
if (!empty($host)) {
$dbConfig['host'] = $host;
$dbConfig['dbName'] = $dbName;
$dbConfig['user'] = $user;
$dbConfig['pass'] = $pass;
} else {
$dbConfig = new Config();
$dbConfig = $dbConfig->getDbConfig();
}

$this->connection = new \PDO("mysql:host={$dbConfig['host']};dbname={$dbConfig['dbName']}", $dbConfig['user'], $dbConfig['pass']);
}

public function desconectar()
{
$this->connection = null;
}

/**
* Get last insert id from PDO::lastInsertId
*/
public function lastInsertId()
{
return $this->connection->lastInsertId();
}

/**
* Fazer o insert e update de acordo com os argumentos passados
É necessário que $columns e $items estejam em ordem, exemplo:
$columns[0] = 'vc_nome' && $items[0] = 'Meu Nome'
*/
public function saveOrUpdate($table, $columns = array(), $items = array(), $id = null)
{
$statement = '';
# Insert row
if (!empty($columns) && !empty($items) && empty($id)) {
$columns = implode(",", $columns);

$items = $this->addSlashes($items);
$items = '('.implode(",", $items).')';

$statement = "INSERT INTO $table ({$columns}) VALUES {$items};";
}

# Update row
if (!empty($columns) && !empty($items) && !empty($id)) {
$last = count($columns) - 1;
$items = $this->addSlashes($items);
$conditions = '';

foreach ($columns as $key => $col) {
$conditions .= "{$col} = {$items[$key]}";
if ($key < $last) {
$conditions .= ', ';
}
}

$conditions .= " WHERE id = '{$id}';";
$statement = "UPDATE $table SET {$conditions}";
}

$this->executeStatement($statement);
}

/**
* Executa uma busca de acordo com as condições
* @var $table : Nome da table
É necessário que utilize a estrutura abaixo:
array("$table.vc_email" => "[email protected]", "$table.vc_nome LIKE '%M%'");
* @return array | "dados" : PDOStatement::fetchAll, "count" : PDOStatement::rowCount
*/
public function find($table, $conditions = array())
{
if (!empty($conditions) && is_array($conditions)) {
$findCond = '';
$last = count($conditions) - 1;

$pos = 0;
foreach ($conditions as $key => $item) {
$keyType = gettype($key);

if ($key == "integer") {
$findCond .= "{$item}";
} else {
$findCond .= "{$key} = '{$item}'";
}

if ($pos < $last) {
$findCond .= ' AND ';
}

$pos++;
}

$statement = "SELECT * FROM $table WHERE {$findCond};";
$exec = $this->executeStatement($statement);

$retorno["dados"] = $exec->fetchAll();
$retorno["count"] = $exec->rowCount();

return $retorno;
}
}

/**
* Executa uma busca de acordo com o ID
* @var $table : Nome da table
* @return array | "dados" : PDOStatement::fetchAll, "count" : PDOStatement::rowCount
*/
public function findById($table, $id)
{
$conditions = array("$table.id" => $id);
$busca = $this->find($table, $conditions);

return $busca;
}

/**
* Deleta um registro do banco de dados
* @var $table : Nome da table
* @var $conditions : Condições que a query deve considerar
* @return array | "dados" : PDOStatement::fetchAll, "count" : PDOStatement::rowCount
*/
public function delete($table, $conditions = array())
{
if (!empty($conditions) && is_array($conditions)) {
$findCond = '';
$last = count($conditions) - 1;

$pos = 0;
foreach ($conditions as $key => $item) {
$keyType = gettype($key);

if ($key == "integer") {
$findCond .= "{$item}";
} else {
$findCond .= "{$key} = '{$item}'";
}

if ($pos < $last) {
$findCond .= ' AND ';
}

$pos++;
}

$statement = "DELETE FROM $table WHERE {$findCond};";
$exec = $this->executeStatement($statement);

return true;
}

return false;
}

private function executeStatement($statement)
{
try {
return $this->connection->query($statement);
} catch (\PDOException $e) {
print "PDO Exception: " . $e->getMessage() . "<br/>";
die();
}
}

/**
* Adiciona barras invertidas nos itens passados pelo argumento $items
* @return array
**/
public function addSlashes($items = array())
{
if (!empty($items) && is_array($items)) {
foreach ($items as $key => $item) {
$items[$key] = "'".addslashes($item)."'";
}
}

return $items;
}
}
25 changes: 25 additions & 0 deletions app/registry.class.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<?php
namespace mktInstagram;

class Registry
{
private $vars = array();

/*
* @ set undefined variables
*/

public function __set($index, $value)
{
$this->vars[$index] = $value;
}

/*
* @ get variables
*/

public function __get($index)
{
return $this->vars[$index];
}
}
Loading