public static function create($aspect_type = '', $aspect_data = '') { $output_object = null; if (is_numeric($aspect_type)) { // a number got passed in, so we'll try to go from aspect_type_id // aha, it looks like we'll need to look up what the name should be // if we get passed an ID only. $db = Database::get_instance(); $sql = "SELECT id, aspect_name FROM aspect_types WHERE id = :id"; $stmt = $db->prepare($sql); $stmt->bindParam(':id', $aspect_type, PDO::PARAM_STR); if ($stmt->execute()) { $row = $stmt->fetchObject(); $cleaned_class_name = code_safe_name($row->aspect_name); $class_name = $cleaned_class_name . 'Aspect'; if (class_exists($class_name)) { // a custom class DOES exist, so create one. $new_aspect = new $class_name(); $new_aspect->aspect_type = $aspect_type; } else { $new_aspect = new Aspect(); $new_aspect->aspect_type = $aspect_type; } } else { return false; } } else { // we got a string, so we'll try to create a custom aspect of that type, // if such a class is defined. $db = Database::get_instance(); $sql = "SELECT id, aspect_name FROM aspect_types WHERE aspect_name = :name"; $stmt = $db->prepare($sql); $stmt->bindParam(':name', $aspect_type, PDO::PARAM_STR); if ($stmt->execute()) { $row = $stmt->fetchObject(); $cleaned_class_name = code_safe_name($row->aspect_name); $class_name = $cleaned_class_name . 'Aspect'; if (class_exists($class_name)) { // a custom class DOES exist, so create one. $new_aspect = new $class_name(); $new_aspect->aspect_type = $row->id; } else { $new_aspect = new Aspect(); $new_aspect->aspect_type = $row->id; } } else { return false; } } if ($aspect_data != '') { $new_aspect->aspect_data = $aspect_data; } return $new_aspect; }
public function create_custom_aspect_class() { echo "entered Custom Class" . PHP_EOL; $app = App::get_instance(); $new_classname = code_safe_name($this->aspect_name); $new_classname = $new_classname . 'Aspect'; $output = "// default custom class created automatically." . PHP_EOL . PHP_EOL; $output .= 'class ' . $new_classname . ' extends Aspect{' . PHP_EOL; $output .= "\t" . 'public function display_aspect(){' . PHP_EOL; $output .= "\t" . "\t" . '$output = parent::display_aspect();' . PHP_EOL; $output .= "\t" . "\t" . 'return $output;' . PHP_EOL; $output .= '}' . PHP_EOL; $output .= "\t" . 'public function parse(){}' . PHP_EOL; $output .= '}' . PHP_EOL; $output .= PHP_EOL . PHP_EOL; $output .= '// end file'; $path_to_custom_aspects = $app['model_path'] . '/CustomAspects_class.php'; $file_contents = file_get_contents($path_to_custom_aspects); $file_contents = str_replace('// end file', $output, $file_contents); if (file_put_contents($path_to_custom_aspects, $file_contents)) { return "Put properly."; } else { return "did not put properly."; } }