<?php
class Sakila {
private $server = "localhost";
private $user = "root";
private $password = "";
private $db = "sakila";
public $conn;
function __construct() {
try {
$this->conn = new PDO("mysql:host=$this->server;dbname=$this->db", $this->user, $this->password);
$this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
$this->conn->exec("SET CHARACTER SET utf8");
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
}
}
function pepe(){
return 3;
}
function getActors() {
$sql = "select * from actor where 1=1";
$query = $this->conn->query($sql);
return $query->fetchAll();
}
function getActor($id) {
$sql = "select * from actor where actor_id=$id";
$query = $this->conn->query($sql);
return $query->fetch();
}
/**
*
* @param type $actor array asociativo con los campos del actor
* ejemplo: ['actor_id'=>1,'first_name'=>'Santiago','last_name'=>'Segura']
*/
function updateActor($actor) {
$sql = "update actor set first_name='" . $actor['first_name'] . "', last_name='" . $actor['last_name'] . "'
where actor_id=" . $actor['actor_id'] . ";";
$this->conn->exec($sql);
}
function deleteActor($id) {
$sql = "delete from actor where actor_id=$id";
$this->conn->exec($sql);
}
/**
* Inserta un nuevo actor o devuelve el id si ya existe
* @param string valor de first_name
* @param string valor de last_name
* @return int id
*/
function newActor($first_name, $last_name) {
if (!empty($first_name) && !empty($last_name)) {
$sql = "select * from actor where first_name=:first_name and last_name=:last_name";
$st = $this->conn->prepare($sql);
$st->execute([':first_name' => $first_name, ':last_name' => $last_name]);
if ($actor = $st->fetch()) {
return $actor['actor_id'];
}
$sql = "insert into actor (first_name,last_name) values (:first_name,:last_name)";
$st = $this->conn->prepare($sql);
$st->execute([':first_name' => $first_name, ':last_name' => $last_name]);
return $this->conn->lastInsertId();
} else {
return null;
}
}
/**
* Inserta una película en una categoría
* @param int id de la categoría
* @param string título de la película
*/
function newFilm($category_id, $film) {
$this->conn->beginTransaction();
try {
$sql = "insert into film(title,language_id) values (:film,1)";
$st = $this->conn->prepare($sql);
$st->execute([':film' => $film]);
$film_id = $this->conn->lastInsertId();
$sql = "insert into film_category(film_id,category_id) values($film_id,$category_id)";
$this->conn->exec($sql);
$this->conn->commit();
} catch (PDOException $e) {
echo $e->getMessage();
$this->conn->rollBack();
}
}
/**
* Crea un select con todas las categorías
*/
function selectCategory() {
$sql = "select * from category";
$q = $this->conn->query($sql);
$categorias = $q->fetchAll();
?>
<select name="category">
<?php foreach ($categorias as $categoria) {
?>
<option value="<?= $categoria['category_id'] ?>"><?= $categoria['name'] ?></option>
<?php } ?>
</select>
<?php
}
}
Categoría: Sin categoría
Phonegap
Casino: Diseño
Deberemos construir una página de un casino con los siguientes apartados:
– Inicio
– Registro
– Fotos
Además incluiremos enlaces a los cuatro juegos que se van a jugar:
Slot Machine
Dados
Blackjack
Ruleta
Tendremos una página javascript, allí tendremos una variable ‘saldo’ que es el dinero del jugador y que de momento valdrá 100.
Ejemplo Layout Bootstrap
Examen
Película mp4
Enlaces intra página
Ejemplo promesa
function promiseSqrt(value){
return new Promise(function (fulfill, reject){
console.log(‘START execution with value =’, value);
setTimeout(function() {
fulfill({ value: value, result: value * value });
}, 0 | Math.random() * 1000);
});
}
var p = [0,1,2,3,4,5,6,7,8,9];
p.reduce(
function (sequence, value) {
return sequence.then(function() {
return promiseSqrt(value);
}).then(function(obj) {
console.log(‘END execution with value =’, obj.value,
‘and result =’, obj.result);
});
},
Promise.resolve()
).then(function() {
console.log(‘COMPLETED’);
});
Github y netbeans
Plugin formulario de contacto
Un ejemplo tomado de aquí:
<?php
/*
Plugin Name: Formulario de contacto ejemplo
Plugin URI: http://example.com
Description: Un formulario de contacto de ejemplo para probar plugins
Version: 1.0
Author: Intelisen
Author URI: http://intelisen.com
*/
function html_form_code() {
echo '<form method="post">';
echo '<p>';
echo 'Nombre (requerido) <br/>';
echo '<input type="text" name="cf-name" pattern="[a-zA-Z0-9 ]+" value="' . ( isset( $_POST["cf-name"] ) ? esc_attr( $_POST["cf-name"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Email (requerido) <br/>';
echo '<input type="email" name="cf-email" value="' . ( isset( $_POST["cf-email"] ) ? esc_attr( $_POST["cf-email"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Asunto (requerido) <br/>';
echo '<input type="text" name="cf-subject" pattern="[a-zA-Z ]+" value="' . ( isset( $_POST["cf-subject"] ) ? esc_attr( $_POST["cf-subject"] ) : '' ) . '" size="40" />';
echo '</p>';
echo '<p>';
echo 'Mensaje (requerido) <br/>';
echo '<textarea rows="10" cols="35" name="cf-message">' . ( isset( $_POST["cf-message"] ) ? esc_attr( $_POST["cf-message"] ) : '' ) . '</textarea>';
echo '</p>';
echo '<p><input type="submit" name="cf-submitted" value="Enviar"></p>';
echo '</form>';
}
function deliver_mail() {
// Si se han enviado los datos, procesar
if ( isset( $_POST['cf-submitted'] ) ) {
// Sanear valores
$name = sanitize_text_field( $_POST["cf-name"] );
$email = sanitize_email( $_POST["cf-email"] );
$subject = sanitize_text_field( $_POST["cf-subject"] );
$message = esc_textarea( $_POST["cf-message"] );
// Conseguir el mail del administrador
$to = get_option( 'admin_email' );
$headers = "From: $name <$email>" . "\r\n";
// Si todo va bien, mensaje ok
if ( wp_mail( $to, $subject, $message, $headers ) ) {
echo '<div>';
echo '<p>Gracias por contactar.</p>';
echo '</div>';
} else {
echo 'Error inesperado';
}
}
}
function cf_shortcode() {
deliver_mail();
html_form_code();
}
add_shortcode( 'intelisen_contact_form', 'cf_shortcode' );