Example #1
0
 public function recruitment()
 {
     $this->rec_form = new WaxForm();
     $this->rec_form->add_element("age", "TextInput");
     $this->rec_form->add_element("english_level", "TextInput", array('label' => 'How well do you speak english'));
     $this->rec_form->add_element("name", "TextInput", array("label" => "Character Name"));
     $this->rec_form->add_element("class", "TextInput", array('label' => "Character Class"));
     $this->rec_form->add_element("level", "TextInput", array('label' => "Character Level"));
     $this->rec_form->add_element("gear", "TextInput", array("label" => "Average gear level (heroic/naxx10/25/uld10/25)"));
     $this->rec_form->add_element("attendance", "TextInput", array("label" => "Can you attend 2 of our weekly planned raids every week"));
     $this->rec_form->add_element("talents", "TextareaInput", array("label" => "Your chosen raid talents and why you chose them"));
     $this->rec_form->add_element("previous_guild", "TextareaInput", array("label" => "Reason for leaving your previous guild"));
     $this->rec_form->add_element("raid_experience", "TextareaInput", array("label" => "Previous raiding experience (which classes have you played in raids, and to what level of raid)"));
     $this->rec_form->add_element("internet", "TextareaInput", array("label" => "What kind of internet connection do you have. (Please mention anything about regular lags here)"));
     $this->rec_form->add_element("other_members", "TextareaInput", array("label" => "Do you know any other members in Deja Vu and what is your replationship to them"));
     $this->rec_form->add_element("about", "TextareaInput", array("label" => "About Yourself"));
     $this->rec_form->submit_text = "Apply to Guild";
     if ($this->rec_form->save()) {
         $notifier = new Notifier();
         $notifier->send_recruitment($this->rec_form);
         $forum_data_row = array("user_id" => "1", "status" => "0", "forum_id" => "7", "thread" => "0", "parent_id" => "0", "thread_count" => "0", "author" => "Paracetamol", "ip" => "127.0.0.1", "status" => "2", "modifystamp" => time(), "subject" => "Application from " . $this->rec_form->handler->elements['name']->value, "body" => "");
         foreach ($this->rec_form as $name => $element) {
             $forum_data_row['body'] .= "[b][size=large]" . $element->label . " :[/size][/b]\n" . $element->value . "\n\n";
         }
         $forum_model = new WaxModel();
         $forum_model->table = "phorum_messages";
         $forum_model->row = $forum_data_row;
         $forum_model->primary_key = "message_id";
         $forum_model->save();
         $forum_model->thread = $forum_model->message_id;
         $forum_model->save();
         $this->recruitment_message = 'Thanks for your application, we\'ll get back to your shortly. Please check our <a href="/forum/list.php?7">recruitment forum</a> for an assessment from our members.';
     }
 }
Example #2
0
 /**
  * internal pagination function so it returns only 
  * the row, not the entire model
  * @param string $WaxModel 
  * @return array
  */
 public function paginate(WaxModel $model)
 {
     $rows = $model->rows();
     foreach ($rows as $row) {
         $ids[] = $row[$model->primary_key];
     }
     return $ids;
 }
 /**
  * the constructor takes the model and values passes in, assigns values to internal
  * vars, sets up the offset and limit on the model and use this->paginate
  * calls parent __construct
  * @param string $WaxModel 
  * @param string $page 
  * @param string $per_page 
  */
 public function __construct(WaxModel $model, $page, $per_page)
 {
     $this->per_page = $per_page;
     $this->current_page = $page;
     //setup model
     $this->model = $model;
     $this->model->_offset = ($page - 1) * $per_page;
     $this->model->_limit = $per_page;
     //paginate the model
     $rowset = $model->rows();
     $this->set_count($model->total_without_limits);
     parent::__construct($model, $rowset);
 }
Example #4
0
 public function add(WaxModel $model)
 {
     $this->load();
     //reassigning so that changes in the model reflect correctly
     foreach ($this as $index => $row) {
         if ($row->{$model->primary_key} && $row->{$model->primary_key} == $model->pk()) {
             $reassign = $index;
         }
     }
     if ($reassign) {
         $this->rowset[$reassign] = new WaxModelProxy($model);
     } else {
         $this->rowset[] = new WaxModelProxy($model);
     }
 }
Example #5
0
 public static function load_adapter($db_settings)
 {
     if ($db_settings["dbtype"] == "none") {
         return true;
     }
     $adapter = "Wax" . ucfirst($db_settings["dbtype"]) . "Adapter";
     self::$adapter = $adapter;
     self::$db_settings = $db_settings;
 }
Example #6
0
 public function eager_load($target)
 {
     $cache = WaxModel::get_cache($this->target_model . ":" . md5(serialize($target->filters)), $this->field, $this->model->primval, false);
     if (is_array($cache)) {
         return new WaxModelAssociation($this->model, $target, $cache, $this->field);
     }
     $vals = $target->filter(array($this->join_field => $this->model->primval))->all();
     WaxModel::set_cache($this->target_model . ":" . md5(serialize($target->filters)), $this->field, $this->model->primval, $vals->rowset);
     return new WaxModelAssociation($this->model, $target, $vals->rowset, $this->field);
 }
Example #7
0
 public function __get($name)
 {
     if ($this->rename_mappings && $this->row[$this->rename_mappings[$name]]) {
         return $this->row[$this->rename_mappings[$name]];
     } elseif ($this->rename_mappings) {
         $flip = array_flip($this->rename_mappings);
         if ($flip[$name] && $this->{$flip[$name]}) {
             return $this->{$flip[$name]};
         }
     }
     return parent::__get($name);
 }
Example #8
0
 public function set($value)
 {
     if ($value instanceof WaxModel) {
         $this->model->{$this->col_name} = $value->{$value->primary_key};
         return $this->model->save();
     } elseif (is_numeric($value)) {
         $this->model->{$this->col_name} = $value;
         return $this->model->save();
     }
     $class = get_class($this->model);
     WaxModel::unset_cache($class, $this->field, $this->model->{$this->col_name});
 }
 public function setup()
 {
     $this->define("first_name", "CharField", array('required' => true));
     $this->define("last_name", "CharField", array('required' => true));
     $this->define("email_address", "EmailField", array('required' => true));
     $this->define("telephone", "CharField");
     $this->define("message", "TextField");
     $this->define("dealership", "ForeignKey", array('target_model' => 'Dealer', 'widget' => 'HiddenInput'));
     //analytics tracking of urls
     $this->define("utm_source", "CharField", array('widget' => 'HiddenInput'));
     $this->define("utm_campaign", "CharField", array('widget' => 'HiddenInput'));
     $this->define("utm_medium", "CharField", array('widget' => 'HiddenInput'));
     parent::setup();
 }
Example #10
0
 public function set($value)
 {
     if ($value instanceof WaxModel) {
         $this->model->{$this->col_name} = $value->{$value->primary_key};
         return $this->model->save();
     } else {
         $obj = new $this->target_model($value);
         if ($obj->primval) {
             $this->model->{$this->col_name} = $value;
             return $this->model->save();
         }
     }
     $class = get_class($this->model);
     WaxModel::unset_cache($class, $this->field, $this->model->{$this->col_name});
 }
 public function setup()
 {
     $this->define("title", "CharField", array("required" => 1, 'scaffold' => true, 'export' => true, 'widget' => 'SelectInput', 'choices' => array('mr' => 'Mr', 'miss' => 'Miss', 'mrs' => 'Mrs')));
     $this->define("first_name", "CharField", array("required" => 1, 'scaffold' => true, 'export' => true));
     $this->define("last_name", "CharField", array("required" => 1, 'scaffold' => true, 'export' => true));
     $this->define("postcode", "CharField", array("required" => 1, 'scaffold' => true, 'export' => true));
     $this->define("address", "TextField", array('export' => true, 'required' => true));
     $this->define("email_address", "CharField", array("required" => 1, 'export' => true));
     $this->define("telephone_number", "CharField", array("required" => 1, 'export' => true));
     $this->define("purchase_estimation", "CharField", array("label" => "I am thinking of purchasing my next vehicle in:", 'export' => true));
     $this->define("contact", "BooleanField", array("widget" => "CheckboxInput", "label" => "I would like you to inform me about its vehicles by email", 'export' => true));
     $this->define("model", "ForeignKey", array("required" => 1, "widget" => "HiddenInput", 'target_model' => 'Model', 'scaffold' => true, 'export' => true));
     $this->define("dealer", "ForeignKey", array('target_model' => 'Dealer', 'widget' => 'HiddenInput', 'scaffold' => true, 'export' => true));
     //analytics tracking of urls
     $this->define("utm_source", "CharField", array('widget' => 'HiddenInput'));
     $this->define("utm_campaign", "CharField", array('widget' => 'HiddenInput'));
     $this->define("utm_medium", "CharField", array('widget' => 'HiddenInput'));
     parent::setup();
 }
Example #12
0
 /**
  * filter on the join_model
  * IMPORTANT: will only work with array filters, text filters are passed on to the target model as usual
  * ALSO IMPORTANT: will not work if any of the defined filters are on columns not in the join model, in that case it will also pass on to the target model as usual
  *
  * @return WaxModelAssociation
  */
 public function filter($params, $value = NULL, $operator = "=")
 {
     if (is_array($params)) {
         foreach ($params as $column => $value) {
             if (!$this->join_model->columns[$column]) {
                 return $this->__call("filter", array($params, $value, $operator));
             }
         }
         $this->join_model->filter($params, $value, $operator);
         WaxModel::unset_cache(get_class($this->model), $this->field);
         return $this->get();
     } else {
         return $this->__call("filter", array($params, $value, $operator));
     }
 }
Example #13
0
 /**
  * Fultext search on columns
  *
  * @param string $text 
  * @param array $columns 
  * @return $this
  */
 public function search(WaxModel $model, $text, $columns = array())
 {
     // First up try to add the fulltext index. Do nothing if errors
     $cols = array_keys($columns);
     $index_name = implode("_", $cols);
     foreach ($cols as $col) {
         $sql = "ALTER TABLE `" . $model->table . "` ADD FULLTEXT " . $col . " ({$col});";
         $stmt = $this->db->prepare($sql);
         $this->exec($stmt, array(), true);
     }
     $text = $this->db->quote($text);
     // Run the query adding the weighting supplied in the columns array
     $model->select_columns = "SQL_CALC_FOUND_ROWS * ,(";
     foreach ($columns as $name => $weighting) {
         $model->select_columns .= "({$weighting} * (MATCH({$name}) AGAINST ({$text})) ) +";
     }
     $model->select_columns = rtrim($model->select_columns, "+");
     $model->select_columns .= ") AS relevance ";
     $model->filter("MATCH(" . implode(",", $cols) . ") AGAINST ({$text} IN BOOLEAN MODE)");
     $model->having = "relevance > 0";
     $model->order = "relevance DESC";
     // Add an arbitrary limit to force found_rows to run
     if (!$model->limit) {
         $model->limit(1000);
     }
     return $model;
 }
Example #14
0
 protected function configure()
 {
     $this["config"] = $this->compat($this["config"]);
     \WaxModel::load_adapter($this["config"]["db"]);
 }
Example #15
0
 public function syncdb()
 {
     if (get_class($this) == "WaxTreeModel") {
         return;
     }
     parent::syncdb();
 }
Example #16
0
 public function test_many_many_one_side()
 {
     $model = $this->model->create($this->get_fixture("user1"));
     $props = new ExampleOneWayProperty();
     $prop1 = $props->create(array("name" => "Property 1"));
     $prop2 = $props->create(array("name" => "Property 2"));
     $prop3 = $props->create(array("name" => "Property 3"));
     $model->oneWayProperties = $prop1;
     $model->oneWayProperties = $prop2;
     $model->oneWayProperties = $prop3;
     $prop2->delete();
     $counter = 0;
     foreach ($model->oneWayProperties as $property) {
         $counter++;
     }
     $this->assertEqual($counter, 2);
     $this->assertEqual($model->oneWayProperties->count(), 2);
     $rand_sql = new WaxModel();
     $rand_sql->query('delete from example_one_way_property where name = "Property 3"');
     $counter = 0;
     foreach ($model->oneWayProperties as $property) {
         $counter++;
     }
     $this->assertEqual($counter, 1);
     $this->assertEqual($model->oneWayProperties->count(), 1);
 }
Example #17
0
 public function cache_whole_tree()
 {
     $class = get_class($this);
     $all_nodes = $this->all();
     //index the rows by their ids, as well as parents and children ids
     $indexed_rowset = array();
     foreach ($all_nodes->rowset as $row) {
         if (!$indexed_rowset[$row['id']]['children']) {
             $indexed_rowset[$row['id']]['children'] = array();
         }
         //cache empty children arrays too
         $indexed_rowset[$row['id']]['row'] = $row;
         $indexed_rowset[$row['id']]['parent_id'] = $row['parent_id'];
         $indexed_rowset[$row['parent_id']]['children'][] = $row;
     }
     foreach ($indexed_rowset as $id => $entry) {
         //set parent cache
         $parent = new $class();
         $parent->set_attributes($indexed_rowset[$entry['parent_id']]['row']);
         WaxModel::set_cache($class, $this->parent_column, $id, $parent);
         //set children cache
         WaxModel::set_cache($class, $this->children_column, $id, $entry['children']);
     }
 }
Example #18
0
 /**
  *	Instantiates a database connection. It requires PDO which is available in PHP 5.1
  *  It then passes this information to the ActiveRecord object.
  *
  *  A few defaults are allowed in case you are too lazy to specify.
  *  Dbtype defaults to mysql
  *  Host defaults to localhost
  *  Port defaults to 3306
  *  
  *
  *  @access private
  *  @return void
  */
 private function initialise_database()
 {
     if ($db = WXConfiguration::get('db')) {
         if ($db['dbtype'] == "none") {
             return false;
         }
         if (!$db['host']) {
             $db['host'] = "localhost";
         }
         if (!$db['port']) {
             $db['port'] = "3306";
         }
         /****** Deprecated support for WXActiveRecord only around for one more version *****/
         WXActiveRecord::$pdo_settings = $db;
         /**********************************************************/
         WaxModel::load_adapter($db);
     }
 }