public function action_index($modelName) { $model = $this->getClassObject($modelName); $columnModel = $model::first(); Input::flash(); if (Input::get($modelName) != null && $this->addConditions($model, $modelName)->first() != null) { $columnModel = $this->addConditions($model, $modelName)->first(); } if ($columnModel == null) { return Redirect::to("/lara_admin/models/{$modelName}/new"); } $columns = $columnModel->columns(); $sort_options = $this->setOrderOptions($columns); $models = $this->addConditions($model, $modelName)->order_by($sort_options["column_order"], $sort_options["sort_direction"])->paginate($model->perPage); $request_uri = Request::server("REQUEST_URI"); $request_uri = preg_replace("/&order=[^&]*/", "", $request_uri); if (!preg_match("/\\?/i", Request::server("REQUEST_URI"))) { $request_uri .= "?"; } //TODO function getCustomAction $name_custom_action = "lara_admin::" . Str::plural(Str::lower($modelName)) . "." . preg_replace("/action_/", "", __FUNCTION__); if (View::exists($name_custom_action) != false) { $view = View::make($name_custom_action, array("sort_options" => $sort_options, "request_uri" => $request_uri, "modelName" => $modelName, "modelInstance" => $model, "models" => $models, "columns" => $columns)); } else { $view = View::make("lara_admin::models.index", array("sort_options" => $sort_options, "request_uri" => $request_uri, "modelName" => $modelName, "modelInstance" => $model, "models" => $models, "columns" => $columns)); } $this->defaultAttrForLayout($modelName, $view); return $this->response_with(array("xml", "json", "csv"), $this->collectionToArray($models->results), true); }
public static function _validation_unique($val, $options) { list($table, $field) = explode('.', $options); $result = DB::select("LOWER (\"{$field}\")")->where($field, '=', Str::lower($val))->from($table)->execute(); return !($result->count() > 0); Validation::active()->set_message('unique', 'The field :label must be unique, but :value has already been used'); }
public function sendMessage() { $encoded_values = Settings::where('key', 'chat')->first(); $decoded_values = json_decode($encoded_values->value); $v_data = ["thread_id" => Input::get('thread_id'), "user_id" => Input::get('user_id'), "message" => Input::get('message'), "attachment" => Input::hasFile('attachment') ? \Str::lower(Input::file('attachment')->getClientOriginalExtension()) : ""]; $v_rules = ["thread_id" => 'required', "user_id" => 'required', "message" => 'required', "attachment" => 'in:' . $decoded_values->chat_file_types]; $v = Validator::make($v_data, $v_rules); if ($v->passes() && Input::get("user_id") > 0 && Input::get("thread_id") > 0) { $thread_message = new ThreadMessages(); $thread_message->thread_id = Input::get('thread_id'); $thread_message->sender_id = Input::get('user_id'); $thread_message->message = Input::get('message'); $thread_message->save(); if (Input::hasFile('attachment') && Input::file('attachment')->getSize() <= $decoded_values->max_file_size * 1024 * 1024) { $ticket_attachment = new TicketAttachments(); $ticket_attachment->thread_id = Input::get('thread_id'); $ticket_attachment->message_id = $thread_message->id; $ticket_attachment->has_attachment = Input::hasFile('attachment'); $ticket_attachment->attachment_path = Input::hasFile('attachment') ? Utils::fileUpload(Input::file('attachment'), 'attachments') : ''; $ticket_attachment->save(); } return json_encode(["result" => 1]); } else { return json_encode(["result" => 0]); } }
public static function get_action_name($is_api = false) { if ($is_api) { return sprintf('%s_%s', Str::lower(Request::main()->get_method()), Request::active()->action); } return Request::active()->action; }
/** * This method gets called after the action is called. * * @param mixed $response Value returned from the action method. * * @return Response $response */ public function after($response) { // Return if passed a response. if ($response instanceof Response) { return parent::after($response); } if ($this->autorender) { try { $this->view->set_filename(Str::lower(str_replace('_', '/', Inflector::denamespace(str_replace('controller_', '', Str::lower($this->request->controller)))) . DS . str_replace('_', '/', $this->request->action))); } catch (FuelException $e) { } } // Inject view into the layout if the main request. if ($this->layout instanceof View) { if ($this->autorender) { try { // Throws exception if there is no view template found. $this->layout->content = $this->view->render(); } catch (FuelException $e) { } } $this->layout->content_data = $this->view->get(); $this->response->body($this->layout); } else { $this->response->body($this->view); } return parent::after($this->response); }
public function action_edit($id) { $post = \Blog\Models\Post::find($id); if ($post === null) { return Event::first('404'); } if (Str::lower(Request::method()) == "post") { $validator = Validator::make(Input::all(), self::$rules); if ($validator->passes()) { $post->title = Input::get('title'); if (Input::get('slug')) { $post->slug = Str::slug(Input::get('slug')); } else { $post->slug = Str::slug(Input::get('title')); } $post->intro = Input::get('intro'); $post->content = Input::get('content'); $post->author_id = Input::get('author_id'); $post->category_id = Input::get('category_id'); $post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time'); $post->save(); return Redirect::to_action('blog::admin.post@list'); } else { return Redirect::back()->with_errors($validator)->with_input(); } } else { $categories = array(); $originalCategories = \Blog\Models\Category::all(); foreach ($originalCategories as $cat) { $categories[$cat->id] = $cat->name; } return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories); } }
public static function setReplyToEmail($user, $email) { Cache::forget('replyToEmail_' . $user->id); return Cache::rememberForever('replyToEmail_' . $user->id, function () use($email) { return Str::lower($email); }); }
/** * @return mixed */ protected function makeCode() { $charset = "2345678abcdefhijkmnpqrstuvwxyzABCDEFGHJKLMNPQRTUVWXY"; $cWidth = $this->code_width; //画布宽度 $cHeight = $this->code_height; //画布高度 $code = ""; $color = ['#99c525', '#fc9721', '#8c659d', '#00afd8']; $img = Image::canvas($cWidth, $cHeight, '#ccc'); for ($i = 0; $i < $this->code_num; $i++) { //画出干扰线 $img->line(mt_rand(0, $cWidth), mt_rand(0, $cHeight), mt_rand(0, $cWidth), mt_rand(0, $cHeight), function ($draw) use($color) { $draw->color($color[array_rand($color, 1)]); }); //随机取出验证码 $code .= $charset[mt_rand(0, strlen($charset) - 1)]; //画出验证码 $img->text($code[$i], $this->code_width / $this->code_num * $i + 5, 25, function ($font) use($color) { $font->file('static/fonts/arial.ttf'); $font->size(18); $font->color($color[array_rand($color, 1)]); $font->angle(mt_rand(-30, 30)); }); } //在session中放置code Session::put('code', Str::lower($code)); $response = Response::make($img->encode('png')); $response->header('Content-Type', 'image/png'); return $response; }
/** * Handle dynamic static method calls into the method. * * @param string $method * @param array $parameters * @return mixed */ public static function __callStatic($method, $parameters) { $instance = new static(); if (substr($method, 0, 6) == "findBy") { $column = \Str::lower(substr($method, 6)); return $instance::where($column, $parameters)->firstOrFail(); } return call_user_func_array(array($instance, $method), $parameters); }
public static function _validation_unique($val, $table_field, $except = null) { Validation::active()->set_message('unique', ':label \':value\' is already taken.'); list($table, $field) = explode('.', $table_field); $query = DB::select()->from($table)->where(Str::lower($field), Str::lower($val)); if ($except) { $query->where(Str::lower($field), '!=', Str::lower($except)); } return $query->execute()->count() <= 0; }
/** * Forge * * @param array Fields mainly * @param string Subfolder (or admin "theme") where views are held * @return mixed */ public static function forge($args, $subfolder) { $data = array(); $subfolder = trim($subfolder, '/'); if (!is_dir(PKGPATH . 'oil/views/' . static::$view_subdir . $subfolder)) { throw new Exception('The subfolder for admin templates does not exist or is spelled wrong: ' . $subfolder . ' '); } // Go through all arguments after the first and make them into field arrays $data['fields'] = array(); foreach (array_slice($args, 1) as $arg) { // Parse the argument for each field in a pattern of name:type[constraint] preg_match(static::$fields_regex, $arg, $matches); $data['fields'][] = array('name' => \Str::lower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null); } $name = array_shift($args); // Replace / with _ and classify the rest. DO NOT singularize $controller_name = \Inflector::classify(static::$controller_prefix . str_replace(DS, '_', $name), false); // Replace / with _ and classify the rest. Singularize $model_name = \Inflector::classify(static::$model_prefix . str_replace(DS, '_', $name)); // Either foo or folder/foo $view_path = $controller_path = str_replace(array('_', '-'), DS, \Str::lower($controller_name)); // Models are always singular, tough! $model_path = str_replace(array('_', '-'), DS, \Str::lower($model_name)); // uri's have forward slashes, DS is a backslash on Windows $uri = str_replace(DS, '/', $controller_path); $data['include_timestamps'] = !\Cli::option('no-timestamp', false); // If a folder is used, the entity is the last part $name_parts = explode(DS, $name); $data['singular_name'] = \Inflector::singularize(end($name_parts)); $data['plural_name'] = \Inflector::pluralize($data['singular_name']); $data['table'] = \Inflector::tableize($model_name); $data['controller_parent'] = static::$controller_parent; /** Generate the Migration **/ $migration_args = $args; array_unshift($migration_args, 'create_' . \Inflector::pluralize(\Str::lower($name))); Generate::migration($migration_args, false); // Merge some other data in $data = array_merge(compact(array('controller_name', 'model_name', 'model_path', 'view_path', 'uri')), $data); /** Generate the Model **/ $model = \View::forge(static::$view_subdir . $subfolder . '/model', $data); Generate::create(APPPATH . 'classes/model/' . $model_path . '.php', $model, 'model'); /** Generate the Controller **/ $controller = \View::forge(static::$view_subdir . $subfolder . '/controller', $data); $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::forge(static::$view_subdir . $subfolder . '/actions/delete', $data))); Generate::create(APPPATH . 'classes/controller/' . $controller_path . '.php', $controller, 'controller'); // Create each of the views foreach (array('index', 'view', 'create', 'edit', '_form') as $view) { Generate::create(APPPATH . 'views/' . $controller_path . '/' . $view . '.php', \View::forge(static::$view_subdir . $subfolder . '/views/actions/' . $view, $data), 'view'); } // Add the default template if it doesnt exist if (!file_exists($app_template = APPPATH . 'views/template.php')) { Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/' . static::$view_subdir . $subfolder . '/views/template.php'), 'view'); } Generate::build(); }
public function assets($file = null) { if (!is_null($file) && \File::isDirectory($this->themesAssetsPath)) { if (!\File::exists($this->themesAssetsPath . $file)) { return \Response::make("Not found!", 404); } $requestedFile = \File::get($this->themesAssetsPath . $file); return \Response::make($requestedFile, 200, array('Content-Type' => $this->mimeMap[\Str::lower(\File::extension($this->themesAssetsPath . $file))])); } return \Redirect::route('app.home'); }
/** * This method is responsible for generation all * source from the templates, and populating the * files array. * * @return void */ private function _view_generation() { $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_'; $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::'; // set up the markers for replacement within source $markers = array('#LOWERFULL#' => $view_prefix . Str::lower(str_replace('/', '.', $this->class_path) . $this->lower)); // loud our view template $template = Common::load_template('view/view.tpl'); // added the file to be created $this->writer->create_file('View', $this->class_path . $this->lower . EXT, $this->bundle_path . 'views/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template)); }
static function slug($str) { $tr = ["А" => "A", "Б" => "B", "В" => "V", "Г" => "G", "Д" => "D", "Е" => "E", "Ж" => "J", "З" => "Z", "И" => "I", "Й" => "Y", "К" => "K", "Л" => "L", "М" => "M", "Н" => "N", "О" => "O", "П" => "P", "Р" => "R", "С" => "S", "Т" => "T", "У" => "U", "Ф" => "F", "Х" => "H", "Ц" => "TS", "Ч" => "CH", "Ш" => "SH", "Щ" => "SCH", "Ъ" => "", "Ы" => "YI", "Ь" => "", "Э" => "E", "Ю" => "YU", "Я" => "YA", "а" => "a", "б" => "b", "в" => "v", "г" => "g", "д" => "d", "е" => "e", "ж" => "j", "з" => "z", "и" => "i", "й" => "y", "к" => "k", "л" => "l", "м" => "m", "н" => "n", "о" => "o", "п" => "p", "р" => "r", "с" => "s", "т" => "t", "у" => "u", "ф" => "f", "х" => "h", "ц" => "ts", "ч" => "ch", "ш" => "sh", "щ" => "sch", "ъ" => "y", "ы" => "yi", "ь" => "", "э" => "e", "ю" => "yu", "я" => "ya"]; $title = strtr($str, $tr); $separator = '-'; // Replace all separator characters and whitespace by a single separator $title = preg_replace('![' . preg_quote($separator) . '\\s]+!u', $separator, $title); // Trim separators from the beginning and end $title = trim($title, $separator); preg_match_all('/[a-zA-Z0-9' . preg_quote($separator) . ']+/ui', $title, $matches); return \Str::lower(implode('', $matches[0])); }
public function calonCustomerJson() { $term = Input::get('term'); $data = CalonCustomer::distinct()->select('nama', 'id')->where('nama', 'LIKE', '%' . $term . '%')->groupBy('id')->take(15)->get(); $result = []; foreach ($data as $d) { if (strpos(Str::lower($d), $term) !== false) { $result[] = ['value' => $d->nama, 'id' => $d->id]; } } return Response::json($result); }
public function getCancha(Request $request) { $cancha = $request->input('term'); $canchas = Item::all(); $result = []; foreach ($canchas as $sede) { if (strpos(Str::lower($sede), $cancha) !== false) { $result[] = $sede; } } return $result; }
public function bibitParfum() { $term = Input::get('term'); $data = Parfum::distinct()->select('nama', 'id')->where('nama', 'LIKE', '%' . $term . '%')->groupBy('id')->take(15)->get(); $result = []; foreach ($data as $aroma) { if (strpos(Str::lower($aroma), $term) !== false) { $result[] = ['value' => $aroma->nama]; } } return Response::json($result); }
/** * This method is responsible for generation all * source from the templates, and populating the * files array. * * @return void */ private function _model_generation() { $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_'; // set up the markers for replacement within source $markers = array('#CLASS#' => $prefix . $this->class_prefix . $this->class, '#LOWER#' => $this->lower, '#TIMESTAMPS#' => $this->_timestamps); // loud our model template $template = Common::load_template('model/model.tpl'); // holder for relationships source $relationships_source = ''; // loop through our relationships foreach ($this->arguments as $relation) { // if we have a valid relation if (!strstr($relation, ':')) { continue; } // split $relation_parts = explode(':', Str::lower($relation)); // we need two parts if (!count($relation_parts) == 2) { continue; } // markers for relationships $rel_markers = array('#SINGULAR#' => Str::lower(Str::singular($relation_parts[1])), '#PLURAL#' => Str::lower(Str::plural($relation_parts[1])), '#WORD#' => Str::classify(Str::singular($relation_parts[1])), '#WORDS#' => Str::classify(Str::plural($relation_parts[1]))); // start with blank $relationship_template = ''; // use switch to decide which template switch ($relation_parts[0]) { case "has_many": case "hm": $relationship_template = Common::load_template('model/has_many.tpl'); break; case "belongs_to": case "bt": $relationship_template = Common::load_template('model/belongs_to.tpl'); break; case "has_one": case "ho": $relationship_template = Common::load_template('model/has_one.tpl'); break; case "has_and_belongs_to_many": case "hbm": $relationship_template = Common::load_template('model/has_and_belongs_to_many.tpl'); break; } // add it to the source $relationships_source .= Common::replace_markers($rel_markers, $relationship_template); } // add a marker to replace the relationships stub // in the model template $markers['#RELATIONS#'] = $relationships_source; // add the generated model to the writer $this->writer->create_file('Model', $prefix . $this->class_prefix . $this->class, $this->bundle_path . 'models/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template)); }
private function randomStr($length) { if (!is_numeric($length)) { $length = strlen($length); } try { $str = \Str::random($length); } catch (\RuntimeException $e) { $str = \Str::random($length + 2); } return str_replace(str_split('aeiouy10'), '', \Str::lower($str)); }
public function index() { //Set keyword to proper format using Str::lower - it's the same as strtolower $keyword = Str::lower(Input::get('keyword')); //Use Query builder to look for the keyword in various category $data['comics'] = Comicbooks::where('book_name', 'LIKE', '%' . $keyword . '%')->select('book_name')->distinct()->get(); $data['characters'] = Characters::where('character_name', 'LIKE', '%' . $keyword . '%')->select('character_name')->distinct()->get(); $data['authors'] = Authors::where('author_name', 'LIKE', '%' . $keyword . '%')->select('author_name')->distinct()->get(); $data['artists'] = Artists::where('artist_name', 'LIKE', '%' . $keyword . '%')->select('artist_name')->distinct()->get(); $data['publishers'] = Publishers::where('publisher_name', 'LIKE', '%' . $keyword . '%')->select('publisher_name')->distinct()->get(); $this->layout->content = View::make('search', $data); }
function __construct($connName = null) { if (!is_null(static::$tableName)) { $tableName = static::$tableName; } else { $tableName = Str::lower(preg_replace(array('/\\\\/', '/(?<=[a-z])([A-Z])/', '/__/'), array('_', '_$1', '_'), ltrim(get_class($this), '\\'))); } if (is_null($connName) && !is_null(static::$connName)) { $connName = static::$connName; } $this->orm = ORM::make($tableName, $connName); $this->orm->className = get_class($this); }
/** * breadcrumb function * Create breadcrumb * @return string * @author joharijumali **/ public static function breadcrumb() { $Menu = Admin_Menu::menuGenerator(); $butternbread = array(); foreach ($Menu as $floor => $packet) { foreach ($packet->page->action as $key => $action) { if ($packet->packet == Str::lower(URI::segment(1)) && $packet->controller->name == Str::lower(URI::segment(2)) && $action->name == Str::lower(URI::segment(3)) || URI::segment(3) == NULL && $action->name == $packet->controller->name && Str::lower(URI::segment(2)) == $packet->controller->name) { $butternbread[Str::upper($packet->controller->alias)] = '#'; array_push($butternbread, Str::title($action->alias)); } } } return Breadcrumb::create($butternbread); }
/** * Check if a value is unique in column * * @param string $val * @param array $options keys are 0:table, 1:field, 2:id field value, 3:id field. Default id field is id */ public function _validation_unique($val, $options = array()) { Validation::active()->set_message('unique', 'It appears you have already registered using this email address.'); $result = \DB::select("LOWER (\"{$options['1']}\")")->from($options['0'])->where($options['1'], '=', Str::lower($val)); if (!empty($options['2']) && is_numeric($options['2'])) { $id = empty($options['3']) ? 'id' : $options['3']; $result->where($id, '!=', $options['2']); } if (count($result->execute()) > 0) { return false; } else { return true; } }
/** * Check if a value is unique in column * * @param string $val * @param array $options keys are 0:table, 1:field, 2:id field value, 3:id field. Default id field is id */ public function _validation_unique($val, $options = array()) { Validation::active()->set_message('unique', 'The field :label must be unique, but :value has already been used.'); // Validation::active()->set_message('unique', 'It appears the :label has already been taken.'); $result = \DB::select("LOWER (\"{$options['1']}\")")->from($options['0'])->where($options['1'], '=', Str::lower($val)); if (!empty($options['2']) && is_numeric($options['2'])) { $id = empty($options['3']) ? 'id' : $options['3']; $result->where($id, '!=', $options['2']); } if (count($result->execute()) > 0) { return false; } else { return true; } }
/** * Construct * Sets login/register mode (classic|ajax) * Sets register validation rules & messages * * @return void */ public function __construct() { if (Config::get('gotin::gotin.login_mode') == "ajax") { $this->ajax = true; } else { $this->ajax = false; } /** * */ Validator::register('question', function ($attribute, $value) { return Str::lower($value) == Session::get("Register_question"); }); $this->register_rules = array('username-register' => 'required|unique:users,username', 'email-register' => 'unique:users,email|required|email', 'password-register' => 'required|confirmed', 'question' => 'required|question'); $this->register_messages = array('question' => __('gotin::gotin.question_error'), 'email-register_required' => __('gotin::gotin.email-register_required'), 'email-register_unique' => __('gotin::gotin.email-register_unique'), 'username-register_required' => __('gotin::gotin.username-register_required'), 'username-register_unique' => __('gotin::gotin.username-register_unique'), 'password-register_required' => __('gotin::gotin.password-register_required'), 'password-register_confirmed' => __('gotin::gotin.password-register_confirmed')); }
public static function generate($args, $subfolder = 'default') { $subfolder = trim($subfolder, '/'); if (!is_dir(PKGPATH . 'oil/views/' . $subfolder)) { throw new Exception('The subfolder for scaffolding templates doesn\'t exist or is spelled wrong: ' . $subfolder . ' '); } // Do this first as there is the largest chance of error here Generate::model($args, false); // Go through all arguments after the first and make them into field arrays $fields = array(); foreach (array_slice($args, 1) as $arg) { // Parse the argument for each field in a pattern of name:type[constraint] preg_match('/([a-z0-9_]+):([a-z0-9_]+)(\\[([0-9]+)\\])?/i', $arg, $matches); $fields[] = array('name' => \Str::lower($matches[1]), 'type' => isset($matches[2]) ? $matches[2] : 'string', 'constraint' => isset($matches[4]) ? $matches[4] : null); } $full_thing = array_shift($args); $full_underscores = str_replace(DS, '_', $full_thing); // Either something[s] or folder/something[s] $data['controller_uri'] = $controller_uri = \Inflector::pluralize(\Str::lower($full_thing)); $data['controller'] = 'Controller_' . \Inflector::classify(\Inflector::pluralize($full_underscores), false); // If a folder is used, the entity is the last part $parts = explode(DS, $full_thing); $data['singular'] = $singular = \Inflector::singularize(end($parts)); $data['model'] = $model_name = \Inflector::classify($full_underscores); $data['plural'] = $plural = \Inflector::pluralize($singular); $data['fields'] = $fields; $filepath = APPPATH . 'classes/controller/' . trim(str_replace(array('_', '-'), DS, $controller_uri), DS) . '.php'; $controller = \View::forge($subfolder . '/scaffold/controller', $data); $controller->actions = array(array('name' => 'index', 'params' => '', 'code' => \View::forge($subfolder . '/scaffold/actions/index', $data)), array('name' => 'view', 'params' => '$id = null', 'code' => \View::forge($subfolder . '/scaffold/actions/view', $data)), array('name' => 'create', 'params' => '$id = null', 'code' => \View::forge($subfolder . '/scaffold/actions/create', $data)), array('name' => 'edit', 'params' => '$id = null', 'code' => \View::forge($subfolder . '/scaffold/actions/edit', $data)), array('name' => 'delete', 'params' => '$id = null', 'code' => \View::forge($subfolder . '/scaffold/actions/delete', $data))); // Write controller Generate::create($filepath, $controller, 'controller'); // Create each of the views foreach (array('index', 'view', 'create', 'edit', '_form') as $view) { Generate::create(APPPATH . 'views/' . $controller_uri . '/' . $view . '.php', \View::forge($subfolder . '/scaffold/views/' . $view, $data), 'view'); } // Add the default template if it doesnt exist if (!file_exists($app_template = APPPATH . 'views/template.php')) { Generate::create($app_template, file_get_contents(PKGPATH . 'oil/views/default/template.php'), 'view'); } Generate::build(); }
/** * This method is responsible for generation all * source from the templates, and populating the * files array. * * @return void */ private function _controller_generation() { $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_'; $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::'; // set up the markers for replacement within source $markers = array('#CLASS#' => $prefix . $this->class_prefix . $this->class, '#LOWER#' => $this->lower, '#LOWERFULL#' => $view_prefix . Str::lower(str_replace('/', '.', $this->class_path) . $this->lower)); // loud our controller template $template = Common::load_template('controller/controller.tpl'); // holder for actions source, and base templates for actions and views $actions_source = ''; $action_template = Common::load_template('controller/action.tpl'); $view_template = Common::load_template('controller/view.tpl'); $restful = strstr(implode(' ', $this->arguments), ':') ? true : false; array_unshift($this->arguments, 'index'); // loop through our actions foreach ($this->arguments as $action) { $verb = $restful ? 'get' : 'action'; if (strstr($action, ':')) { $parts = explode(':', $action); if (count($parts) == 2) { $verb = Str::lower($parts[0]); $action = Str::lower($parts[1]); } } // add the current action to the markers $markers['#ACTION#'] = Str::lower($action); $markers['#VERB#'] = $verb; // append the replaces source $actions_source .= Common::replace_markers($markers, $action_template); $file_prefix = $restful ? $verb . '_' : ''; // add the file to be created $this->writer->create_file('View', $this->class_path . $this->lower . '/' . $file_prefix . Str::lower($action) . $this->_view_extension, $this->bundle_path . 'views/' . $this->class_path . $this->lower . '/' . $file_prefix . Str::lower($action) . $this->_view_extension, Common::replace_markers($markers, $view_template)); } // add a marker to replace the actions stub in the controller // template $markers['#ACTIONS#'] = $actions_source; $markers['#RESTFUL#'] = $restful ? "\n\tpublic \$restful = true;\n" : ''; // added the file to be created $this->writer->create_file('Controller', $markers['#CLASS#'] . '_Controller', $this->bundle_path . 'controllers/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template)); $this->writer->append_to_file($this->bundle_path . 'routes.php', "\n\n// Route for {$markers['#CLASS#']}_Controller\nRoute::controller('{$markers['#LOWERFULL#']}');"); }
function autocompleteescenario($id, $id2) { $term = Str::lower(Input::get('term')); //convertimos los datos a un arreglo puro $data = DB::table('tescenario')->select('codEscenario', 'nombre', 'lugar')->get(); $arregloDocente = []; foreach ($data as $docente) { $codigo = $docente->codEscenario; $nombre = $docente->nombre; $ap = $docente->lugar; $aux = [$codigo => $codigo . ' ' . $nombre . ' ' . $ap]; $arregloDocente = array_merge($aux, $arregloDocente); } //filtramos $result = []; foreach ($arregloDocente as $valor) { if (strpos(Str::lower($valor), $term) !== false) { $result[] = ['value' => $valor]; } } return Response::json($result); }
/** * This method is responsible for generation all * source from the templates, and populating the * files array. * * @return void */ private function _config_generation() { $prefix = $this->bundle == DEFAULT_BUNDLE ? '' : Str::classify($this->bundle) . '_'; $view_prefix = $this->bundle == DEFAULT_BUNDLE ? '' : $this->bundle . '::'; // loud our config template $template = Common::load_template('config/config.tpl'); // holder for options source, and base template for options $options_source = ''; $option_template = Common::load_template('config/option.tpl'); // loop through our options foreach ($this->arguments as $option) { // add the current option to the markers $markers['#OPTION#'] = Str::lower($option); // append the replaces source $options_source .= Common::replace_markers($markers, $option_template); } // add a marker to replace the options stub in the config // template $markers['#OPTIONS#'] = $options_source; // added the file to be created $this->writer->create_file('Config', $this->lower . EXT, $this->bundle_path . 'config/' . $this->class_path . $this->lower . EXT, Common::replace_markers($markers, $template)); }
public static function _validation_unique($val, $options) { $arrOption = explode('.', $options); $table = $arrOption[0]; $pk = $arrOption[1]; $field = $arrOption[2]; $id = isset($arrOption[3]) ? $arrOption[3] : ''; $result = DB::select("LOWER (\"{$field}\"), {$pk}")->where($field, '=', Str::lower($val))->from($table)->execute()->current(); Validation::active()->set_message('unique', ':labelで存在している値と異なりにするのが必要で、他の値を入力して下さい。'); if (isset($id) && !empty($id)) { $id = str_replace('id_', '', $id); if (empty($result)) { return true; } else { if ($id == $result[$pk]) { return true; } return false; } } else { return empty($result) ? true : false; } }