/** * Cache the model_rwd instance, optionally using the $field * * @param model_rwd $instance with class model_rwd to cache * @param mixed $field to use as key to instance * @since ADD MVC 0.0 */ protected static function cache_instance(model_rwd $instance, $field = NULL) { $class = get_called_class(); $table = static::TABLE; if (!$field) { $field = static::cache_main_key(); $field_value = $instance->cache_main_id(); } else { $field_value = $instance->{$field}; } e_developer::assert(!isset(static::$instances[$class][$table][$field][$field_value]), "Attempt to cache {$class} row ({$table}:{$field}:{$field_value}) twice", NULL, array(static::$instances, get_defined_vars())); static::$instances[$class][$table][$field][$field_value] = $instance; return static::$instances[$class][$table][$field][$field_value]; }
/** * add_new * @param $data * @param string $image_arg the input[type=file][name] * OR * @param resource $image_arg the image resource */ public static function add_new_image($data, $image_arg) { if (!$image_arg) { throw new Exception("Image parameter is empty"); } static::db()->StartTrans(); $image = parent::add_new($data); if ($image) { $image_gd = self::get_gd($image_arg); if (!$image->save_gd($image_gd)) { static::db()->FailTrans(); } } else { throw new e_developer("Failed to insert image " . print_r($data, true)); } static::db()->CompleteTrans(); return $image; }