Example #1
0
 private function update(array $data)
 {
     $db = Model::factory();
     $files = $data['files'];
     unset($data['files']);
     //update a site
     if (isset($data['id'])) {
         $db->update('Site', $data, 'id');
     } else {
         $data['id'] = $db->insert('Site', $data);
     }
     //files
     $data['files'] = Controller::upload($files, $data['id']);
     return $data;
 }
Example #2
0
 /**
  * Upload a files and write records to db.
  * @param  array $data    An array of file data.
  * @param  integer $site_id The site to link up with the uploaded file.
  * @return array          Returns an array of results.
  */
 public static function upload(array $data, $site_id)
 {
     $res = array();
     $db = Model::factory();
     foreach ($data as $file) {
         if ($file['error'] != 0) {
             continue;
         }
         $orig = $file['tmp_name'];
         $dest = self::uniqueName(REUSINGDUBLIN_UPLOADS . '/' . $file['name']);
         $fileInfo = pathinfo($dest);
         if (!move_uploaded_file($orig, $dest)) {
             $res[] = new Error('Unable to move uploaded file: ' . $file['name']);
             continue;
         }
         //insert record into db
         $db->insert('File', array('file' => $fileInfo['basename'], 'ext' => $fileInfo['extension'], 'site_id' => $site_id, 'ip' => self::getIp()));
         $res[] = pathinfo($dest);
     }
     return $res;
 }
Example #3
0
    ini_set('display_errors', 'on');
}
// end debug
/**
 * Autoloader.
 * @param string $class The class name including namespace
 */
spl_autoload_register(function ($class) {
    $file = REUSINGDUBLIN_DIR . '/lib/' . str_replace("ReusingDublin\\", "", $class) . '.php';
    if (is_readable($file)) {
        require_once $file;
    }
});
require_once REUSINGDUBLIN_DIR . '/vendor/autoload.php';
/**
 * Configuration
 */
try {
    new \ReusingDublin\Config(require_once REUSINGDUBLIN_DIR . '/config.php');
} catch (Exception $e) {
    if (!is_readable(REUSINGDUBLIN_DIR . '/config.php')) {
        die("Can't read config.php file. Please see README.md for installation instructions");
    }
    die($e->message);
}
/**
 * Model object
 */
global $db;
$db = Model::factory();
Example #4
0
 /**
  * Update a row.
  * @param  string $table The table name
  * @param  array $data  An array of column=>value pairs
  * @param  string $where The column to check against
  */
 public function update($table, $data, $where)
 {
     $where_value = $data[$where];
     unset($data[$where]);
     $db = Model::factory();
     $sql = "UPDATE {$table} SET ";
     $sets = array();
     //build statement
     foreach ($data as $key => $value) {
         $sets[] = "{$key}=:{$key}";
     }
     $sql .= implode(", ", $sets) . " WHERE {$where}=:{$where}";
     $stmt = $this->db->prepare($sql);
     //bind values
     foreach ($data as $field => $value) {
         $stmt->bindParam(":{$field}", ${$field});
         ${$field} = $value;
     }
     $stmt->bindParam(":{$where}", ${$where});
     ${$where} = $where_value;
     $stmt->execute();
 }