public function test_singular()
 {
     $strs = array('tellies' => 'telly', 'smellies' => 'smelly', 'abjectnesses' => 'abjectness', 'smells' => 'smell', 'equipment' => 'equipment');
     foreach ($strs as $str => $expect) {
         $this->assertEquals($expect, singular($str));
     }
 }
Esempio n. 2
0
 /**
  * Remap routes
  *
  * Codeigniter controller routes RESTful remap
  *
  * @return mixed
  */
 public function _remap()
 {
     $http_method = $this->input->method();
     $route = $this->router->method;
     $params = array_slice($this->router->uri->rsegments, 2);
     // We are use PUT, PATCH, DELETE methods
     if (!is_null($this->input->post('_method'))) {
         $http_method = strtolower($this->input->post('_method'));
         $route = isset($this->router->uri->rsegments[2]) ? $this->router->uri->rsegments[2] : $this->router->uri->rsegments[1];
     }
     // Second segment is numeric
     if (is_numeric($route)) {
         $route = singular($this->router->uri->rsegments[1]);
         if (end($this->router->uri->segments) === 'edit') {
             $http_method = 'edit';
         }
         $params = array_slice($this->router->uri->rsegments, 1, 1);
         // Third uri segment is resource $id
         $params = $params[0];
     }
     if ($route === 'create') {
         $http_method = 'create';
         $route = singular($this->router->class);
     }
     $action = "{$http_method}_{$route}";
     if (method_exists($this, $action)) {
         return $this->{$action}($params);
     }
     if (method_exists($this, $route)) {
         return $this->{$route}($params);
     }
     redirect(404);
 }
Esempio n. 3
0
 protected function generate_crud($table, $subject = '')
 {
     // create CRUD object
     $this->load->library('Grocery_CRUD');
     $crud = new grocery_CRUD();
     $crud->set_table($table);
     // auto-generate subject
     if (empty($subject)) {
         $crud->set_subject(humanize(singular($table)));
     }
     // load settings from: application/config/grocery_crud.php
     $this->load->config('grocery_crud');
     $this->mCrudUnsetFields = $this->config->item('grocery_crud_unset_fields');
     if ($this->config->item('grocery_crud_unset_jquery')) {
         $crud->unset_jquery();
     }
     if ($this->config->item('grocery_crud_unset_jquery_ui')) {
         $crud->unset_jquery_ui();
     }
     if ($this->config->item('grocery_crud_unset_print')) {
         $crud->unset_print();
     }
     if ($this->config->item('grocery_crud_unset_export')) {
         $crud->unset_export();
     }
     if ($this->config->item('grocery_crud_unset_read')) {
         $crud->unset_read();
     }
     foreach ($this->config->item('grocery_crud_display_as') as $key => $value) {
         $crud->display_as($key, $value);
     }
     // other custom logic to be done outside
     $this->mCrud = $crud;
     return $crud;
 }
Esempio n. 4
0
 /**
  * Create a controller, set up its name, autoload models if possible
  */
 public function __construct()
 {
     $this->name = trim(get_class($this), 'Controller');
     if (class_exists(singular($this->name))) {
         $this->loadModel(singular($this->name));
     }
     $this->data = array();
     $this->d('Created a controller');
 }
Esempio n. 5
0
 protected function get_common_key()
 {
     $this_class = strtolower(get_class($this));
     // this is to ensure that singular is only called once per model
     if (isset(DataMapper::$common[DMZ_CLASSNAMES_KEY][$this_class])) {
         return DataMapper::$common[DMZ_CLASSNAMES_KEY][$this_class];
     } else {
         return singular($this_class);
     }
 }
Esempio n. 6
0
 public function up()
 {
     $this->dbforge->modify_column('blog', array('comments_enabled' => array('type' => 'set', 'constraint' => array('no', '1 day', '1 week', '2 weeks', '1 month', '3 months', 'always'), 'null' => false, 'default' => 'always')));
     $this->db->update('blog', array('comments_enabled' => '3 months'));
     // Lets update the comments table with these new awesome fields
     $this->dbforge->modify_column('comments', array('module_id' => array('name' => 'entry_id', 'type' => 'varchar', 'constraint' => 255, 'null' => true), 'name' => array('name' => 'user_name', 'type' => 'varchar', 'constraint' => 255), 'email' => array('name' => 'user_email', 'type' => 'varchar', 'constraint' => 255), 'website' => array('name' => 'user_website', 'type' => 'varchar', 'constraint' => 255, 'null' => true)));
     $this->dbforge->add_column('comments', array('entry_title' => array('type' => 'char', 'constraint' => 255, 'null' => false), 'entry_key' => array('type' => 'varchar', 'constraint' => 100, 'null' => false), 'entry_plural' => array('type' => 'varchar', 'constraint' => 100, 'null' => false), 'uri' => array('type' => 'varchar', 'constraint' => 255, 'null' => true), 'cp_uri' => array('type' => 'varchar', 'constraint' => 255, 'null' => true)));
     $comments = $this->db->get('comments')->result();
     foreach ($comments as &$comment) {
         // What did they comment on
         switch ($comment->module) {
             case 'gallery':
                 $comment->module = plural($comment->module);
                 break;
             case 'gallery-image':
                 $comment->module = 'galleries';
                 $ci->load->model('galleries/gallery_image_m');
                 if ($item = $ci->gallery_image_m->get($comment->module_id)) {
                     continue 2;
                 }
                 break;
         }
         $this->load->model('addons/module_m');
         // Use the old comment logic to grab title names, then we can never have to use this junk again
         if (in_array($comment->module, array('blog', 'pages'))) {
             // Grab an item
             switch ($comment->module) {
                 case 'blog':
                     // Get this one article out of the db
                     $item = $this->db->get_where('blog', array('id' => $comment->entry_id))->row();
                     $comment->entry_title = $item->title;
                     $comment->uri = 'blog/' . date('Y/m', $item->created_on) . '/' . $item->slug;
                     $comment->entry_key = 'blog:post';
                     $comment->entry_plural = 'blog:posts';
                     $comment->cp_uri = 'admin/' . $comment->module . '/preview/' . $item->id;
                     break;
                 case 'pages':
                     // Get this one page out of the db
                     $item = $this->db->get_where('pages', array('id' => $comment->entry_id))->row();
                     $comment->entry_title = $item->title;
                     $comment->uri = $item->uri;
                     $comment->entry_key = 'pages:page';
                     $comment->entry_plural = 'pages:pages';
                     $comment->cp_uri = 'admin/' . $comment->module . '/preview/' . $item->id;
                     break;
             }
         } else {
             $comment->entry_title = $comment->module . ' #' . $comment->entry_id;
             $comment->entry_key = humanize(singular($comment->module));
             $comment->entry_plural = humanize(plural($comment->module));
         }
         // Save this comment again
         $this->db->where('id', $comment->id)->update('comments', $comment);
     }
 }
Esempio n. 7
0
 function build_db_select_with_aliases($array)
 {
     $temp_alias_string = '';
     foreach ($array as $table => $fields) {
         $table_sigular = singular($table);
         foreach ($fields as $field) {
             $temp_alias_string .= $table . '.' . $field . ' AS ' . $table_sigular . '_' . $field . ', ';
         }
     }
     return $temp_alias_string;
 }
Esempio n. 8
0
 /**
  * Prepares the data before generation.
  *
  * @param  array &$data
  * @return void
  */
 public function prepareData(array &$data)
 {
     $data['camel'] = [];
     $data['columns'] = [];
     $data['dropdowns'] = [];
     $data['foreignKeys'] = [];
     $data['models'] = [$data['name']];
     $data['plural'] = plural($data['name']);
     $data['singular'] = singular($data['name']);
     $data['underscore'] = [];
 }
Esempio n. 9
0
 function __construct()
 {
     parent::__construct();
     if (empty($this->element)) {
         $singular = ucfirst(singular($this->ctrlr_name));
         $this->element = new $singular();
     }
     // if ($this->authentication->is_signed_in()) {
     //     $this->_add_menu_item('edit', lang('manage'), array($this->ctrlr_name . '/edit', lang('edit_profile')));
     // }
     // $this->_add_menu_item('view', '', array($this->ctrlr_name . '/view', lang('home')));
 }
Esempio n. 10
0
 public function __construct()
 {
     parent::__construct();
     $this->load->helper('inflector');
     $model = strtolower(singular(get_class($this)));
     if (file_exists(APPPATH . 'models/' . $model . '_model.php')) {
         $this->models[] = $model;
     }
     foreach ($this->models as $model) {
         $this->load->model($model . '_model', $model);
     }
 }
Esempio n. 11
0
 public function makeModel($name)
 {
     $this->load->helper('inflector');
     $name = singular($name);
     $this->model_name = $name;
     // If a table exists, we can build it from that
     if ($this->table_exists) {
         $this->generate("model {$name}", "-table {$name} -primary_key id", TRUE);
     } else {
         $this->generate("model {$name}", "-fields '{$this->fields}'", TRUE);
     }
 }
Esempio n. 12
0
 function __construct()
 {
     parent::__construct();
     $this->redirect_url = "admin/" . $this->ctrlr_name;
     if (empty($this->element)) {
         $this->ctrlr_singular_name = singular($this->ctrlr_name);
         $this->load->model(array('admin/' . $this->ctrlr_singular_name));
     }
     // if ($this->authentication->is_signed_in()) {
     //     $this->_add_menu_item('edit', lang('manage'), array($this->ctrlr_name . '/edit', lang('edit_profile')));
     // }
     // $this->_add_menu_item('view', '', array($this->ctrlr_name . '/view', lang('home')));
 }
Esempio n. 13
0
 public function get_index($per_page = 0, $page = 0, $category_id = NULL, $order = NULL, $desc = NULL, $enable = TRUE)
 {
     if (isset($category_id)) {
         $this->pdo->where(array($this->table . '.' . singular($this->table) . '_category_id' => $category_id));
         if ($this->input->get('search_type')) {
             $result = $this->get_search($this->input->get('search_type'), $this->input->get('search_word'));
         }
         $result['total'] = $this->pdo->count_all_results($this->table);
     } else {
         if ($this->input->get('search_type')) {
             $result = $this->get_search($this->input->get('search_type'), $this->input->get('search_word'));
         }
         $result['total'] = $this->pdo->count_all_results($this->table);
     }
     if (empty($order)) {
         if (empty($this->order)) {
             $order = $this->order;
         } else {
             $order = 'id';
         }
     }
     if (empty($desc)) {
         if (empty($this->desc)) {
             $desc = $this->desc;
         } else {
             $desc = TRUE;
         }
     }
     if (!is_bool($desc)) {
         throw new Exception("Error Processing Request", 1);
     }
     if ($desc) {
         $desc = 'desc';
     } else {
         $desc = 'asc';
     }
     if (!$result['total']) {
         return $result;
     }
     $this->pdo->select($this->table . '.*');
     if (isset($category_id)) {
         $this->pdo->where(array($this->table . '.' . singular($this->table) . '_category_id' => $category_id));
     }
     if ($this->input->get('search_type')) {
         $this->get_search($this->input->get('search_type'), $this->input->get('search_word'));
     }
     $this->pdo->order_by($order, $desc);
     $query = $this->pdo->get($this->table, $per_page, $page);
     $result['list'] = $query->result_array();
     return $result;
 }
Esempio n. 14
0
 public function __construct()
 {
     parent::__construct();
     // Configure limits on our controller methods
     // Ensure you have created the 'limits' table and enabled 'limits' within application/config/rest.php
     $this->methods['user_get']['limit'] = 500;
     // 500 requests per hour per user/key
     $this->methods['user_post']['limit'] = 100;
     // 100 requests per hour per user/key
     $this->methods['user_delete']['limit'] = 50;
     // 50 requests per hour per user/key
     $this->load->helper('inflector');
     $this->load->model(singular($this->router->fetch_method()));
 }
 public function packageCliAction($path = null)
 {
     $this->load->helper('inflector');
     if (!$path) {
         show_error('Please provide path');
     }
     $path = implode('/', func_get_args());
     $path = '/' . strtolower(trim($path, '/'));
     $dir = dirname($path);
     $filename = basename($path);
     $root = ROOTPATH . '/packages/' . $filename;
     mkdir($root);
     touch($root . '/composer.json');
     mkdir($root . '/public');
     mkdir($root . '/support');
     mkdir($root . '/support/migrations');
     touch($root . '/support/onload.php');
     touch($root . '/support/migrations/v1.0.0-' . $filename . '.php');
     mkdir($root . '/controllers');
     mkdir($root . '/controllers/' . $dir, 0777, true);
     touch($root . '/controllers/' . $dir . '/' . ucfirst($filename) . 'Controller.php');
     mkdir($root . '/helpers');
     mkdir($root . '/language');
     mkdir($root . '/libraries');
     mkdir($root . '/models');
     touch($root . '/models/' . ucfirst($filename) . '_model.php');
     mkdir($root . '/views');
     mkdir($root . '/views/' . $path, 0777, true);
     touch($root . '/views/' . $path . '/index.php');
     touch($root . '/views/' . $path . '/form.php');
     $data = [];
     $this->model($filename, $data);
     $this->view($filename, $data);
     $data['controller'] = ucfirst(strtolower(str_replace('-', '_', $filename)));
     $data['uname'] = ucfirst(strtolower($filename));
     $data['lname'] = strtolower($filename);
     $data['path'] = trim($path, '/');
     $data['model'] = $filename . '_model';
     $data['single'] = singular($filename);
     $data['plural'] = plural($filename);
     $data['name'] = strtolower($filename);
     //var_dump($data);
     file_put_contents($root . '/views/' . $path . '/index.php', $this->merge('index', $data));
     file_put_contents($root . '/views/' . $path . '/form.php', $this->merge('form', $data));
     file_put_contents($root . '/controllers/' . $dir . '/' . ucfirst($filename) . 'Controller.php', $this->merge('controller', $data));
     file_put_contents($root . '/models/' . ucfirst($filename) . '_model.php', $this->merge('model', $data));
     file_put_contents($root . '/support/migrations/v1.0.0-' . $filename . '.php', $this->merge('migration', $data));
     file_put_contents($root . '/composer.json', $this->merge('composer', $data));
 }
function table_torch_title($table)
{
    $CI =& get_instance();
    if ($CI->router->fetch_method() == 'listing') {
        $singular = FALSE;
    } else {
        $singular = TRUE;
    }
    $str = humanize($table);
    if ($singular == TRUE) {
        return singular($str);
    } else {
        return $str;
    }
}
Esempio n. 17
0
 static function parse($tree)
 {
     extract($tree);
     if (!$individual) {
         $individual = preg_match('/^\\$\\w+$/', $iterable) ? '$' . singular(trim($iterable, '$')) : '$item';
     }
     if ($individual == $iterable) {
         $individual = '$item';
     }
     $opening = "<?php foreach({$iterable} as \$i => {$individual}): ?>";
     $node = Block::parse($node);
     $children = Template::parse($children);
     $closing = "<?php endforeach; ?>";
     return $opening . $node . $children . $closing;
 }
Esempio n. 18
0
 /**
  * 格式化为XML数据
  */
 public function toXml($structure = null, $basenode = 'xml')
 {
     $data = $this->data;
     // turn off compatibility mode as simple xml throws a wobbly if you don't.
     if (ini_get('zend.ze1_compatibility_mode') == 1) {
         ini_set('zend.ze1_compatibility_mode', 0);
     }
     if ($structure === null) {
         $structure = simplexml_load_string("<?xml version='1.0' encoding='utf-8'?><{$basenode} />");
     }
     // Force it to be something useful
     if (!is_array($data) and !is_object($data)) {
         $data = (array) $data;
     }
     foreach ($data as $key => $value) {
         // 转换布尔型为数值型 false/true to 0/1
         if (is_bool($value)) {
             $value = (int) $value;
         }
         // no numeric keys in our xml please!
         if (is_numeric($key)) {
             // make string key...
             $key = singular($basenode) != $basenode ? singular($basenode) : 'item';
         }
         // replace anything not alpha numeric
         $key = preg_replace('/[^a-z_\\-0-9]/i', '', $key);
         if ($key === '_attributes' && (is_array($value) || is_object($value))) {
             $attributes = $value;
             if (is_object($attributes)) {
                 $attributes = get_object_vars($attributes);
             }
             foreach ($attributes as $attributeName => $attributeValue) {
                 $structure->addAttribute($attributeName, $attributeValue);
             }
             // if there is another array found recursively call this function
         } elseif (is_array($value) || is_object($value)) {
             $node = $structure->addChild($key);
             // 递归
             $this->toXml($value, $node, $key);
         } else {
             // add single node.
             $value = htmlspecialchars(html_entity_decode($value, ENT_QUOTES, 'UTF-8'), ENT_QUOTES, "UTF-8");
             $structure->addChild($key, $value);
         }
     }
     return $structure->asXML();
 }
Esempio n. 19
0
 public function get_photo_index($per_page = 0, $page = 0, $category_id = NULL, $order = NULL, $desc = NULL, $enable = TRUE)
 {
     if (isset($category_id)) {
         $this->pdo->where(array($this->table . '.' . singular($this->table) . '_category_id' => $category_id));
         $this->pdo->where($this->table . '.photo IS NOT NULL');
         $result['total'] = $this->pdo->count_all_results($this->table);
     } else {
         $this->pdo->where($this->table . '.photo IS NOT NULL');
         $result['total'] = $this->pdo->count_all($this->table);
     }
     if (empty($order)) {
         if (empty($this->order)) {
             $order = $this->order;
         } else {
             $order = 'id';
         }
     }
     if (empty($desc)) {
         if (empty($this->desc)) {
             $desc = $this->desc;
         } else {
             $desc = TRUE;
         }
     }
     if (!is_bool($desc)) {
         throw new Exception("Error Processing Request", 1);
     }
     if ($desc) {
         $desc = 'desc';
     } else {
         $desc = 'asc';
     }
     if (!$result['total']) {
         return $result;
     }
     $this->pdo->select($this->table . '.*,' . $this->table_user . '.nickname');
     $this->pdo->join($this->table_user, $this->table . '.user_id = ' . $this->table_user . '.id', 'left');
     if (isset($category_id)) {
         $this->pdo->where(array($this->table . '.' . singular($this->table) . '_category_id' => $category_id));
     }
     $this->pdo->where(array($this->table . '.enable' => TRUE));
     $this->pdo->where($this->table . '.photo IS NOT NULL');
     $this->pdo->order_by($order, $desc);
     $query = $this->pdo->get($this->table, $per_page, $page);
     $result['list'] = $query->result_array();
     return $result;
 }
Esempio n. 20
0
 /**
  * Generates set of code based on data.
  *
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $this->data['camel'][$field] = $this->transformField($field, 'camelize');
         $this->data['underscore'][$field] = $this->transformField($field, 'underscore');
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = plural($referencedTable);
             $singular = $field . '_singular';
             $this->data['foreignKeys'][$singular] = singular($referencedTable);
             $this->data = $this->getPrimaryKey($this->data, $field, $referencedTable);
         }
     }
     return $this->data;
 }
Esempio n. 21
0
 /**
  * [view description]
  *
  * @param string  $object_type [description]
  * @param integer $group_id    [description]
  * @param string  $time_range  [description]
  * @param boolean $start_date  [description]
  * @param boolean $end_date    [description]
  *
  * @return [type] [description]
  *
  * @author Ken Auberry <*****@*****.**>
  */
 public function view($object_type, $group_id, $time_range = '1-month', $start_date = FALSE, $end_date = FALSE)
 {
     $object_type = singular($object_type);
     $accepted_object_types = array('instrument', 'proposal', 'user');
     if (!in_array($object_type, $accepted_object_types)) {
         redirect('reporting/view/instrument/{$time_range}');
     }
     $this->page_data['page_header'] = 'MyEMSL Uploads per ' . ucwords($object_type);
     $this->page_data['my_object_type'] = $object_type;
     $this->page_data['css_uris'] = array('/resources/stylesheets/status_style.css', '/resources/scripts/select2/select2.css', '/resources/scripts/bootstrap/css/bootstrap.css', '/resources/scripts/bootstrap-daterangepicker/daterangepicker.css', APPPATH . 'resources/stylesheets/reporting.css');
     $this->page_data['script_uris'] = array('/resources/scripts/spinner/spin.min.js', '/resources/scripts/spinner/jquery.spin.js', '/resources/scripts/moment.min.js', '/resources/scripts/bootstrap-daterangepicker/daterangepicker.js', '/resources/scripts/jquery-typewatch/jquery.typewatch.js', '/resources/scripts/highcharts/js/highcharts.js', APPPATH . 'resources/scripts/reporting.js');
     $this->page_data['js'] = "var object_type = '{$object_type}'; var time_range = '{$time_range}'";
     $time_range = str_replace(array('-', '_', '+'), ' ', $time_range);
     $my_object_list = $this->rep->get_selected_objects($this->user_id, $object_type, $group_id);
     if (empty($my_object_list)) {
         $examples = add_objects_instructions($object_type);
         $this->page_data['examples'] = $examples;
         $this->page_data['js'] .= "\n            \$(function(){\n              \$('#object_search_box').focus();\n            });\n            ";
         $this->page_data['content_view'] = 'object_types/select_some_objects_insert.html';
     } else {
         $this->page_data['my_objects'] = '';
         $object_list = array_map('strval', array_keys($my_object_list[$object_type]));
         if (!empty($default_object_id) && in_array($default_object_id, $object_list)) {
             $object_list = array(strval($default_object_id));
         }
         $object_info = $this->eus->get_object_info($object_list, $object_type);
         foreach ($object_list as $object_id) {
             $valid_date_range = $this->rep->earliest_latest_data($object_type, $object_id);
             $my_times = $this->fix_time_range($time_range, $start_date, $end_date, $valid_date_range);
             $latest_available_date = new DateTime($valid_date_range['latest']);
             $earliest_available_date = new DateTime($valid_date_range['earliest']);
             $valid_range = array('earliest' => $earliest_available_date->format('Y-m-d H:i:s'), 'latest' => $latest_available_date->format('Y-m-d H:i:s'), 'earliest_available_object' => $earliest_available_date, 'latest_available_object' => $latest_available_date);
             if ($my_times['start_time_object']->getTimestamp() < $valid_range['earliest_available_object']->getTimestamp()) {
                 $my_times['start_time_object'] = clone $valid_range['earliest_available_object'];
             }
             if ($my_times['end_time_object']->getTimestamp() > $valid_range['latest_available_object']->getTimestamp()) {
                 $my_times['end_time_object'] = clone $valid_range['latest_available_object'];
             }
             $my_times = array_merge($my_times, $valid_range);
             $this->page_data['placeholder_info'][$object_id] = array('object_type' => $object_type, 'object_id' => $object_id, 'time_range' => $time_range, 'times' => $my_times);
         }
         $this->page_data['my_objects'] = $object_info;
         $this->page_data['content_view'] = 'object_types/object.html';
     }
     $this->load->view('reporting_view.html', $this->page_data);
 }
 public function get_index($per_page = 0, $page = 0, $category_id = NULL, $order = 'id', $desc = 'desc', $enable = TRUE)
 {
     if (isset($category_id)) {
         $this->pdo->where(array($this->table . '.' . singular($this->table) . '_category_id' => $category_id));
         $result['total'] = $this->pdo->count_all_results($this->table);
     } else {
         $result['total'] = $this->pdo->count_all($this->table);
     }
     if (!$result['total']) {
         return $result;
     }
     $this->pdo->select($this->table . '.*');
     $this->pdo->where(array($this->table . '.enable' => TRUE));
     $this->pdo->order_by($order, $desc);
     $query = $this->pdo->get($this->table, $per_page, $page);
     $result['list'] = $query->result_array();
     return $result;
 }
Esempio n. 23
0
 public function parse($source)
 {
     $this->source = $source;
     $source = str_replace(['<', '/>', '</', '>'], '', $source);
     $this->tagSource = $this->attrSource = $source;
     $this->parseName();
     $this->parseAttributes();
     // Loading the handler
     $handler = $this->getHandler();
     $attr = json_encode($this->attributes);
     if ($handler == NULL && $this->parent != NULL) {
         $propertyName = strtolower($this->name);
         $handlerName = $this->parent->name;
         $value = $this->parent->{$propertyName};
         $iteratorName = $this->parent->getNativeCodeIteratorName();
         if (!empty($iteratorName)) {
             $nativeItem = "\${$iteratorName}";
         } else {
             $nativeItem = "Ionize::{$handlerName}()";
         }
         $this->nativeCodeOpening = "<?php echo {$nativeItem}->item('{$propertyName}', '{$attr}'); ?>";
     } else {
         if (strpos($this->source, '/>') !== FALSE) {
             $this->nativeCodeOpening = "<?php echo Ionize::{$this->name}('{$attr}')->getOutput(); ?>";
         } elseif (\singular($this->name) == $this->name) {
             if ($this->parent != NULL) {
                 $iteratorName = $this->nativeCodeIteratorName = $this->parent->getNativeCodeIteratorName();
                 if (!empty($iteratorName)) {
                     $this->nativeCodeOpening = "<?php if(\${$iteratorName}->attr('{$attr}') != FALSE): ?>";
                     $this->nativeCodeClosing = "<?php endif; ?>";
                 }
             }
             if (empty($this->nativeCodeOpening)) {
                 $this->nativeCodeOpening = "<?php if(Ionize::{$this->name}()->attr('{$attr}')->getOutput() != FALSE): ?>";
                 $this->nativeCodeClosing = "<?php endif; ?>";
             }
         } else {
             $iteratorName = $this->nativeCodeIteratorName = \singular($this->name);
             $this->nativeCodeOpening = "<?php foreach(Ionize::{$this->name}()->attr('{$attr}')->getItems() as \${$iteratorName}): ?>";
             $this->nativeCodeClosing = "<?php endforeach; ?>";
         }
     }
     return $this;
 }
Esempio n. 24
0
File: id.php Progetto: uaBirder/SRA
	/**
	* Generate a new ID and check that its not in use within a given table
	* This function uses the default CI DB system to query the table until a unique ID is found
	* @param string $table The table to search (e.g. 'users')
	* @param string $column The column name to search (if null this is assumed to be the none-plural version of $table with 'id' appended e.g. 'userid')
	* @return The unique ID for the table
	*/
	function Create($table, $column = null) {
		if (!$column) { // Determine $column as singular($table) . 'id'
			$this->load->helper('inflector');
			$column = singular($table) .  'id';
		}

		$try = 0;
		while ($try++ < $this->maxtries) {
			$id = $this->Generate();
			$this->db->select('COUNT(*) AS count');
			$this->db->where($column, $id);
			$this->db->from($table);
			$result = $this->db->get()->row_array();
			if ($result['count'] == 0)
				return $id;
		}
		trigger_error("Cannot find unique ID for table $table.$column after $try tries");
		return FALSE;
	}
Esempio n. 25
0
 function table($action, $table, $omit = array())
 {
     $this->CI->load->database();
     $sql = "DESCRIBE `{$table}`";
     $desc = $this->CI->db->query($sql)->result_array();
     $str = $this->open($action);
     foreach ($desc as $field) {
         if (!in_array($field['Key'], $omit)) {
             if ($field['Key'] == 'PRI') {
                 $str .= $this->hidden($field['Field']);
             } else {
                 if (strpos($field['Type'], '(') !== FALSE) {
                     $arr = explode('(', $field['Type']);
                     $type = $arr[0];
                 } else {
                     $type = $field['Type'];
                 }
                 switch ($type) {
                     case 'blob':
                     case 'longtext':
                     case 'text':
                         $str .= $this->textarea($field['Field'], humanize($field['Field']));
                         break;
                     case 'enum':
                     case 'tinyint':
                         $default = FALSE;
                         if (!empty($field['Default'])) {
                             $default = TRUE;
                         }
                         $str .= $this->checkbox($field['Field'], humanize($field['Field']), TRUE, $default);
                         break;
                     default:
                         $str .= $this->text($field['Field'], humanize($field['Field']));
                         break;
                 }
             }
         }
     }
     $str .= $this->submit('submit', 'Save ' . ucwords(singular(humanize($table))));
     $str .= $this->close();
     return $str;
 }
Esempio n. 26
0
 /**
  * Executes the command.
  *
  * @param \Symfony\Component\Console\Input\InputInterface   $input
  * @param \Symfony\Component\Console\Output\OutputInterface $output
  * @return object|\Symfony\Component\Console\Output\OutputInterface
  */
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     $fileName = ucfirst(singular($input->getArgument('name')));
     $path = APPPATH . 'models' . DIRECTORY_SEPARATOR . $fileName . '.php';
     $info = ['name' => $fileName, 'type' => 'model', 'path' => $path];
     $validator = new ModelValidator($input->getOption('camel'), $info);
     if ($validator->fails()) {
         $message = $validator->getMessage();
         return $output->writeln('<error>' . $message . '</error>');
     }
     $data = ['file' => $info, 'isCamel' => $input->getOption('camel'), 'name' => $input->getArgument('name'), 'type' => $validator->getLibrary()];
     $generator = new ModelGenerator($this->describe, $data);
     $result = $generator->generate();
     $model = $this->renderer->render('Model.tpl', $result);
     $message = 'The model "' . $fileName . '" has been created successfully!';
     $file = new File($path);
     $file->putContents($model);
     $file->close();
     return $output->writeln('<info>' . $message . '</info>');
 }
Esempio n. 27
0
 public function getFormFields()
 {
     if (is_array($this->aFormData)) {
         foreach ($this->aFormData as $k => $aVals) {
             $sPostString = 'data[' . ucfirst(singular($this->sTableName)) . '][' . $k . ']';
             $sFormData = '$aFormData[\'' . ucfirst(singular($this->sTableName)) . '\'][\'' . $k . '\']';
             $sOut .= '<div class="' . $aVals['_type'] . '_field">' . PHP_EOL;
             switch ($aVals['_type']) {
                 case 'text':
                     $sOut .= $this->getLabelString($k);
                     $sOut .= "<input type=\"text\" name=\"" . $sPostString . "\" id=\"" . $k . "\" value=\"<?= " . $sFormData . "; ?>\" />" . PHP_EOL;
                     $sOut .= "<?= \$aError['" . $k . "']; ?>" . PHP_EOL;
                     break;
                 case 'select':
                     //** Where is our select data coming from ?
                     $oSource = !empty($aVals['model']) ? new $aVals['model']() : show_error('formbuilder::getFormFields no select data source', 500);
                     $oData = $oSource->load()->get();
                     foreach ($oData->all as $obj) {
                         $aSource[$obj->id] = $obj->name;
                         $sSource .= "\"" . $obj->id . "\" => " . "\"" . $obj->name . "\", ";
                     }
                     $sOut .= $this->getLabelString($k);
                     $sOut .= "<? \$aSource = array( {$sSource} ); ?>" . PHP_EOL;
                     $sOut .= "<?=form_dropdown( '" . $sPostString . "', \$aSource, " . $sFormData . ", ' id=\"{$k}\"')?>" . PHP_EOL;
                     break;
                 case 'textarea':
                     $sOut .= $this->getLabelString($k);
                     $sOut .= "<textarea name=\"" . $sPostString . "\" id=\"" . $k . "\"><?=" . $sFormData . "?></textarea>";
                     break;
                 case 'date':
                     $sOut .= $this->getLabelString($k);
                     $sOut .= "Not implemented";
                     break;
             }
             $sOut .= '</div>' . PHP_EOL . PHP_EOL;
         }
     }
     return $sOut . $this->s__IncludeForm;
 }
Esempio n. 28
0
 /**
  * Generates set of code based on data.
  * 
  * @return array
  */
 public function generate()
 {
     $this->prepareData($this->data);
     foreach ($this->data['columns'] as $column) {
         $field = strtolower($column->getField());
         $accessor = 'get_' . $field;
         $mutator = 'set_' . $field;
         $this->data['camel'][$field] = ['field' => lcfirst(camelize($field)), 'accessor' => lcfirst(camelize($accessor)), 'mutator' => lcfirst(camelize($mutator))];
         $this->data['underscore'][$field] = ['field' => lcfirst(underscore($field)), 'accessor' => lcfirst(underscore($accessor)), 'mutator' => lcfirst(underscore($mutator))];
         if ($column->isForeignKey()) {
             $referencedTable = Tools::stripTableSchema($column->getReferencedTable());
             $this->data['foreignKeys'][$field] = plural($referencedTable);
             $singular = $field . '_singular';
             $this->data['foreignKeys'][$singular] = singular($referencedTable);
             $this->data['primaryKeys'][$field] = 'get_' . $this->describe->getPrimaryKey($referencedTable);
             if ($this->data['isCamel']) {
                 $this->data['primaryKeys'][$field] = camelize($this->data['primaryKeys'][$field]);
             }
         }
     }
     return $this->data;
 }
 function enable_crud($table = '')
 {
     // get config file
     $this->config->load('crud');
     $params = $this->config->item('grocery_crud');
     // create CRUD object
     $this->load->library('grocery_CRUD');
     $crud = new grocery_CRUD();
     // basic settings
     if (!empty($table)) {
         $crud->set_table($table);
         $crud->set_subject(humanize(singular($table)));
     }
     // general settings
     $crud->unset_jquery();
     $crud->unset_print();
     $crud->unset_export();
     // hide fields from CRUD form
     $crud->unset_fields($params['unset_fields']);
     // other custom logic to be done in child controllers
     return $crud;
 }
Esempio n. 30
0
 /**
  * protected function join_temporary_results($data)
  * Joins the subquery results to the main $data
  * @param $data
  * @return mixed
  */
 protected function join_temporary_results($data)
 {
     $order_by = array();
     foreach ($this->_requested as $requested_key => $request) {
         $pivot_table = NULL;
         $relation = $this->_relationships[$request['request']];
         $this->load->model($relation['foreign_model']);
         $foreign_key = $relation['foreign_key'];
         $local_key = $relation['local_key'];
         $foreign_table = $relation['foreign_table'];
         $type = $relation['relation'];
         $relation_key = $relation['relation_key'];
         if ($type == 'has_many_pivot') {
             $pivot_table = $relation['pivot_table'];
             $pivot_local_key = $relation['pivot_local_key'];
             $pivot_foreign_key = $relation['pivot_foreign_key'];
             $get_relate = $relation['get_relate'];
         }
         $local_key_values = array();
         foreach ($data as $key => $element) {
             if (isset($element[$local_key]) and !empty($element[$local_key])) {
                 $id = $element[$local_key];
                 $local_key_values[$key] = $id;
             }
         }
         if (!$local_key_values) {
             $data[$key][$relation_key] = NULL;
             continue;
         }
         if (!isset($pivot_table)) {
             $sub_results = $this->{$relation['foreign_model']};
             $select = array();
             $select[] = '`' . $foreign_table . '`.`' . $foreign_key . '`';
             if (!empty($request['parameters'])) {
                 if (array_key_exists('fields', $request['parameters'])) {
                     if ($request['parameters']['fields'] == '*count*') {
                         $the_select = '*count*';
                         $sub_results = isset($the_select) ? $sub_results->fields($the_select) : $sub_results;
                         $sub_results = $sub_results->fields($foreign_key);
                     } else {
                         $fields = explode(',', $request['parameters']['fields']);
                         foreach ($fields as $field) {
                             $select[] = '`' . $foreign_table . '`.`' . trim($field) . '`';
                         }
                         $the_select = implode(',', $select);
                         $sub_results = isset($the_select) ? $sub_results->fields($the_select) : $sub_results;
                     }
                 }
                 if (array_key_exists('fields', $request['parameters']) && $request['parameters']['fields'] == '*count*') {
                     $sub_results->group_by('`' . $foreign_table . '`.`' . $foreign_key . '`');
                 }
                 if (array_key_exists('where', $request['parameters']) || array_key_exists('non_exclusive_where', $request['parameters'])) {
                     $the_where = array_key_exists('where', $request['parameters']) ? 'where' : 'non_exclusive_where';
                 }
                 $sub_results = isset($the_where) ? $sub_results->where($request['parameters'][$the_where], NULL, NULL, FALSE, FALSE, TRUE) : $sub_results;
             }
             $sub_results = $sub_results->where($foreign_key, $local_key_values)->get_all();
         } else {
             $this->_database->join($pivot_table, $foreign_table . '.' . $foreign_key . ' = ' . $pivot_table . '.' . $pivot_foreign_key, 'left');
             $this->_database->join($this->table, $pivot_table . '.' . $pivot_local_key . ' = ' . $this->table . '.' . $local_key, 'left');
             $this->_database->select($foreign_table . '.' . $foreign_key);
             $this->_database->select($pivot_table . '.' . $pivot_local_key);
             if (!empty($request['parameters'])) {
                 if (array_key_exists('fields', $request['parameters'])) {
                     if ($request['parameters']['fields'] == '*count*') {
                         $this->_database->select('COUNT(`' . $foreign_table . '`*) as counted_rows, `' . $foreign_table . '`.`' . $foreign_key . '`', FALSE);
                     } else {
                         $fields = explode(',', $request['parameters']['fields']);
                         $select = array();
                         foreach ($fields as $field) {
                             $select[] = '`' . $foreign_table . '`.`' . trim($field) . '`';
                         }
                         $the_select = implode(',', $select);
                         $this->_database->select($the_select);
                     }
                 }
                 if (array_key_exists('where', $request['parameters']) || array_key_exists('non_exclusive_where', $request['parameters'])) {
                     $the_where = array_key_exists('where', $request['parameters']) ? 'where' : 'non_exclusive_where';
                     $this->_database->where($request['parameters'][$the_where], NULL, NULL, FALSE, FALSE, TRUE);
                 }
             }
             $this->_database->where_in($pivot_table . '.' . $pivot_local_key, $local_key_values);
             $sub_results = $this->_database->get($foreign_table)->result_array();
             $this->_database->reset_query();
         }
         if (isset($sub_results) && !empty($sub_results)) {
             $subs = array();
             foreach ($sub_results as $result) {
                 $result_array = (array) $result;
                 $the_foreign_key = $result_array[$foreign_key];
                 if (isset($pivot_table)) {
                     $the_local_key = $result_array[singular($this->table) . '_' . $local_key];
                     if (isset($get_relate) and $get_relate === TRUE) {
                         $subs[$the_local_key][$the_foreign_key] = $this->{$relation['foreign_model']}->where($local_key, $result[$local_key])->get();
                     } else {
                         $subs[$the_local_key][$the_foreign_key] = $result;
                     }
                 } else {
                     if ($type == 'has_one') {
                         $subs[$the_foreign_key] = $result;
                     } else {
                         $subs[$the_foreign_key][] = $result;
                     }
                 }
             }
             $sub_results = $subs;
             foreach ($local_key_values as $key => $value) {
                 if (array_key_exists($value, $sub_results)) {
                     $data[$key][$relation_key] = $sub_results[$value];
                 } else {
                     if (array_key_exists('where', $request['parameters'])) {
                         unset($data[$key]);
                     }
                 }
             }
         } else {
             $data[$key][$relation_key] = NULL;
         }
         if (array_key_exists('order_by', $request['parameters'])) {
             $elements = explode(',', $request['parameters']['order_by']);
             if (sizeof($elements) == 2) {
                 $order_by[$relation_key] = array(trim($elements[0]), trim($elements[1]));
             } else {
                 $order_by[$relation_key] = array(trim($elements[0]), 'desc');
             }
         }
         unset($this->_requested[$requested_key]);
     }
     if ($order_by) {
         foreach ($order_by as $field => $row) {
             list($key, $value) = $row;
             $data = $this->_build_sorter($data, $field, $key, $value);
         }
     }
     return $data;
 }