Esempio n. 1
0
 public function testColumns()
 {
     $users = User::find('all');
     $cols = User::columns();
     foreach ($cols as $col) {
         $this->assertTrue(array_include($col, $users->columns()));
     }
 }
 public function show()
 {
     require_once FileUtils::join(NIMBLE_ROOT, 'lib', 'markdown.php');
     $filename = $_GET['name'] . '.markdown';
     $this->title = ucwords(Inflector::humanize($_GET['name'] . ' help'));
     Nimble::set_title($this->title);
     if (array_include($filename, array_map(function ($f) {
         return basename($f);
     }, $this->files))) {
         $this->file = file_get_contents(FileUtils::join($this->markdown_dir, $filename));
     } else {
         Nimble::flash('notice', 'No page found for ' . $_GET['name']);
         $this->redirect_to(url_for('HelpController', 'index'));
     }
 }
Esempio n. 3
0
 public static function do_method($method, $class, $table, $options = array())
 {
     if (!array_include($method, static::$methods)) {
         throw new NimbleException("{$method} is not a math method");
     }
     $defaults = array('column' => 'id', 'cache' => true, 'conditions' => NULL);
     $options = array_merge($defaults, $options);
     static::check_args_for_math_functions($options);
     $query = new NimbleQuery();
     $query->select = $method . '(' . $table . '.' . $options['column'] . ') AS ' . $method;
     $query->from = $table;
     if (isset($options['joins']) && !empty($options['joins'])) {
         $query->join = $options['joins'];
     }
     if (isset($options['group']) && !empty($options['group'])) {
         $query->group_by = $options['group'];
     }
     if (isset($options['conditions']) && !empty($options['conditions'])) {
         $query->where = NimbleRecord::build_conditions($options['conditions']);
     }
     $sql = $query->build();
     return $class::execute_query($sql, false, $options['cache'])->{$method};
 }
Esempio n. 4
0
 public function complete_files($files)
 {
     $ordered_files = array();
     foreach ($files as $file) {
         $all_files = $this->complete_file($file);
         foreach ($all_files as $one_file) {
             array_include($ordered_files, $one_file);
         }
     }
     return $ordered_files;
 }
Esempio n. 5
0
 /**
  * Bind the Route object to Nimble's router.
  * @throws NimbleException if the requested HTTP method is invalid.
  */
 function bind()
 {
     if (array_include($this->http_method, self::$allowed_methods)) {
         $parameters = array();
         foreach (array('pattern', 'controller', 'action', 'http_method', 'short_url') as $field) {
             if (isset($this->{$field})) {
                 $parameters[] = $this->{$field};
             } else {
                 break;
             }
         }
         $this->bind_id = call_user_func_array(array(Nimble::getInstance(), 'add_url'), $parameters);
     } else {
         throw new NimbleException('Invalid Request');
     }
 }
Esempio n. 6
0
 public function complete_files($files)
 {
     $ordered_files = array();
     foreach ($files as $file) {
         $requires = $this->get_file_depends($file);
         foreach ($requires as $s) {
             array_include($ordered_files, $s);
         }
         array_include($ordered_files, $file);
     }
     return $ordered_files;
 }
 /**
  * Asserts that the given partial template has been rendered
  * @param string $name the name of the partial template with or without .php extension
  */
 public function assertPartial($name)
 {
     $name = basename($name);
     $name = $this->add_php_extension($name);
     $partials = $this->controller->rendered_partials;
     $base = array();
     foreach ($partials as $partial) {
         $base[] = basename($partial);
     }
     $this->assertTrue(array_include($name, $base), "No partial matching {$name} was found");
 }
Esempio n. 8
0
 private static function build_where_for_magic_find($matches, $args)
 {
     $method_called = array_shift($matches);
     $i = 0;
     $where = array();
     $cols = isset($matches[0]) ? explode('_and_', $matches[0]) : $matches;
     foreach ($cols as $column) {
         if (array_include($column, static::columns())) {
             $col = self::sanatize_input_array($column);
             $val = self::sanatize_input_array($args[$i]);
             $where[$col] = $val;
             $i++;
         }
         return $where;
     }
 }
Esempio n. 9
0
 public function __call($method, $args)
 {
     if (array_include($method, static::$options[$this->type])) {
         $this->{$method} = reset($args);
         return $this;
     } else {
         throw new NimbleRecordException('Property does not exist on this association type only: ' . implode(', ', static::$options[$this->type]));
     }
 }