예제 #1
0
 /**
  * Get by name_short
  *
  * @access public
  * @return Language
  * @param string $name_short
  */
 public static function get_by_name_short($name)
 {
     $db = Database::Get();
     $id = $db->get_one('SELECT id FROM language WHERE name_short=?', [$name]);
     if ($id === null) {
         throw new \Exception('No such language');
     }
     return self::get_by_id($id);
 }
예제 #2
0
 /**
  * Get last by transaction
  *
  * @access public
  * @param Transaction $transaction
  * @return array $transaction_logs
  */
 public static function get_last_by_transaction(Transaction $transaction)
 {
     $db = Database::Get();
     $id = $db->get_one('SELECT id FROM transaction_log WHERE transaction_id=? ORDER BY created DESC LIMIT 1', [$transaction->id]);
     if ($id === null) {
         throw new \Exception('No transaction_log yet');
     }
     return self::get_by_id($id);
 }
예제 #3
0
 /**
  * Get by Shipment
  *
  * @access public
  * @param Shipment $shipment
  * @return array $shipment_items
  */
 public static function get_by_shipment(Shipment $shipment)
 {
     $db = Database::Get();
     $ids = $db->get_column('SELECT id FROM shipment_item WHERE shipment_id=?', [$shipment->id]);
     $objects = [];
     foreach ($ids as $id) {
         $objects[] = self::get_by_id($id);
     }
     return $objects;
 }
예제 #4
0
 /**
  * Migrate up
  *
  * @access public
  */
 public function up()
 {
     $db = Database::Get();
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `language` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t  `name_local` varchar(64) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t  `name_short` varchar(2) COLLATE utf8_unicode_ci NOT NULL DEFAULT '',\n\t\t\t  `name_ogone` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  FULLTEXT KEY `name_short` (`name_short`)\n\t\t\t) ENGINE=MyISAM AUTO_INCREMENT=1 DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;\n\t\t", []);
     $db->query("\n\t\t\tINSERT INTO `language` VALUES (1,'English','English','en','en_US'),(2,'French','Français','fr','fr_FR'),(3,'Dutch','Nederlands','nl','nl_NL');\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `log` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `user_id` int(11) NOT NULL,\n\t\t\t  `classname` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `object_id` int(11) NOT NULL,\n\t\t\t  `content` text COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `created` datetime NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  KEY `classname` (`classname`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `file` (\n\t\t\t  `id` int(11) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t  `name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `unique_name` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `mime_type` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `size` int(11) NOT NULL,\n\t\t\t  `created` datetime NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `picture` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `file_id` int(11) NOT NULL,\n\t\t\t  `width` int(11) NOT NULL,\n\t\t\t  `height` int(11) NOT NULL,\n\t\t\t  PRIMARY KEY (`id`),\n\t\t\t  KEY `file_id` (`file_id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `user` (\n\t\t\t  `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t  `firstname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `lastname` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `email` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `username` varchar(32) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `password` varchar(255) COLLATE utf8_unicode_ci NOT NULL,\n\t\t\t  `admin` tinyint(1) NOT NULL,\n\t\t\t  `created` datetime NOT NULL,\n\t\t\t  PRIMARY KEY (`id`)\n\t\t\t) ENGINE=MyISAM  DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci AUTO_INCREMENT=1 ;\n\t\t", []);
     $db->query("\n\t\t\tALTER TABLE  `file` ADD  `md5sum` VARCHAR( 32 ) NOT NULL AFTER  `name`;\n\t\t", []);
     $db->query("\n\t\t\tALTER TABLE  `file` DROP  `unique_name`;\n\t\t", []);
     $db->query("\n\t\t\tALTER TABLE  `file` ADD `expiration_date` datetime NULL AFTER `size`;\n\t\t", []);
 }
예제 #5
0
파일: User.php 프로젝트: tigron/skeleton
 /**
  * Fetch a user by email
  *
  * @access public
  * @param string $email
  * @return User $user
  */
 public static function get_by_email($email)
 {
     $db = Database::Get();
     $id = $db->get_one('SELECT id FROM user WHERE email = ?', [$email]);
     if ($id === null) {
         throw new \Exception('User not found');
     }
     return self::get_by_id($id);
 }
예제 #6
0
 /**
  * Get by delivery
  *
  * @access public
  * @param Delivery $delivery
  * @return array $delivery_items
  */
 public static function get_by_delivery(Delivery $delivery)
 {
     $db = Database::Get();
     $ids = $db->get_column('SELECT id FROM delivery_item WHERE delivery_id=?', [$delivery->id]);
     $objects = [];
     foreach ($ids as $id) {
         $objects[] = self::get_by_id($id);
     }
     return $objects;
 }
예제 #7
0
    /**
     * Get runnable transactions
     *
     * @return array
     * @access public
     */
    public static function get_runnable()
    {
        $db = \Skeleton\Database\Database::Get();
        $transactions = [];
        $trans = $db->get_column('
			SELECT id FROM
				(SELECT id, frozen, failed, locked, created FROM transaction WHERE scheduled_at < NOW() AND completed=0) AS transaction
			WHERE 1
			AND frozen = 0
			AND failed = 0
			AND locked = 0
			ORDER BY created');
        foreach ($trans as $id) {
            $transactions[] = self::get_by_id($id);
        }
        return $transactions;
    }
예제 #8
0
 /**
  * Get classnames
  *
  * @access public
  * @return array $classnames
  */
 public static function get_classnames()
 {
     $db = Database::Get();
     $classnames = $db->get_column('SELECT DISTINCT(classname) FROM object_text', array());
     return $classnames;
 }
예제 #9
0
 /**
  * Delete the image and its cache
  *
  * @access public
  */
 public function delete()
 {
     foreach (Config::$resize_configurations as $name => $configuration) {
         if (file_exists(Config::$tmp_dir . $name . '/' . $this->id)) {
             unlink(Config::$tmp_dir . $name . '/' . $this->id);
         }
     }
     $db = Database::Get();
     $db->query('DELETE FROM picture WHERE file_id=?', [$this->id]);
     parent::delete();
 }