public function events()
 {
     WaxEvent::add("cms.model.columns", function () {
         $obj = WaxEvent::data();
         $obj->scaffold_columns['preview'] = true;
     });
     parent::events();
 }
 public function controller_global()
 {
     WaxEvent::add("cms.cms_stack_set", function () {
         $obj = WaxEvent::data();
         array_unshift($obj->cms_stack, $obj->controller);
     });
     parent::controller_global();
 }
Esempio n. 3
0
 /**
  * Partial Helper Function
  * Renders a partial from path $path into the current view
  * To inherit an existing view use this method: eg.....
  * 
  *  <?=partial("mypartial", $this);?>
  *
  * Alternate syntax allows standalone execution that runs the partialname() method
  *  <?=partial("mypartial")?>
  *
  * @param string $path 
  * @param array $extra_vals 
  * @param string $format 
  */
 public function partial($path, $extra_vals = array(), $format = "html")
 {
     $partial = new WaxPartial($path, $extra_vals, $format);
     WaxEvent::run("wax.partial", $partial);
     $res = $partial->render();
     WaxEvent::run("wax.partial_render", $partial);
     return $res;
 }
Esempio n. 4
0
 public function get_choices()
 {
     if ($this->choices && $this->choices instanceof WaxRecordset) {
         foreach ($this->choices as $row) {
             $choices[$row->{$row->primary_key}] = $row->{$row->identifier};
         }
         $this->choices = $choices;
         return true;
     }
     $this->link = new $this->target_model();
     WaxEvent::run("wax.choices.filter", $this);
     //filter choices hook
     $this->choices[""] = "Select";
     foreach ($this->link->all() as $row) {
         $this->choices[$row->{$row->primary_key}] = $row->{$row->identifier};
     }
     return $this->choices;
 }
Esempio n. 5
0
WaxEvent::add(DEALER_MODEL . ".user_creation", function () {
    $dealer = WaxEvent::data();
    $dealer->wu->dealer = $dealer;
});
WaxEvent::add("cms.save.after", function () {
    $data = WaxEvent::data();
    if ($data->model_class == DEALER_MODEL && ($model = $data->model) && $model->primval) {
        if ($model->create_site) {
            $model->dealer_creation();
        }
        if ($model->create_user) {
            $model->user_creation();
        }
        if ($model->columns['create_branch'] && $model->create_branch) {
            $model->branch_creation();
        }
    }
});
WaxEvent::add("wax.action", function () {
    WaxEvent::add("cms.layout.sublinks", function () {
        $obj = WaxEvent::data();
        if ($obj->module_name == "home") {
            $obj->quick_links = array();
        } elseif ($obj->current_user) {
            $can = $obj->current_user->restricted_tree($obj->model_class);
            if ($can) {
                $obj->quick_links = array("create new " . $obj->module_name => '/admin/' . $obj->module_name . "/create/?wildfire_content[parent_id]=" . $can[0]);
            }
        }
    });
});
Esempio n. 6
0
 public function after_delete()
 {
     WaxEvent::run(get_class($this) . ".after_delete", $this);
     WaxEvent::run("model." . get_class($this) . ".delete.after", $this);
 }
<?php

CMSApplication::register_module("advertising", array('plugin_name' => 'wildfire.advertising.advanced', 'assets_for_cms' => true, "display_name" => "Advertising", "link" => "/admin/advertising/", 'split' => true));
if (!defined("CONTENT_MODEL")) {
    $con = new ApplicationController(false, false);
    define("CONTENT_MODEL", $con->cms_content_class);
}
WaxEvent::add(CONTENT_MODEL . ".setup", function () {
    $model = WaxEvent::data();
    if (!$model->columns['ads']) {
        $model->define("ads", "ManyToManyField", array('target_model' => 'WildfireAdvertAdvanced', "eager_loading" => true, "join_model_class" => "WaxModelWeightedJoin", "join_order" => "weight DESC", 'group' => 'advertising', 'module' => 'advertising', 'extra_fields_view' => '_advertising_extra_fields', 'existing_media_list' => '_existing_ad_list'));
    }
});
Esempio n. 8
0
 public function dealer_creation()
 {
     $class = CONTENT_MODEL;
     $dealer_class = get_class($this);
     $model = new $class("live");
     $url = $dealer_class::$dealer_section . Inflections::to_url($this->title) . "/";
     if (($pages = $this->pages) && $pages->count() || $model->filter("permalink", $url)->first()) {
         return true;
     } else {
         //find dealers section
         if ($dealers = $model->filter("permalink", $dealer_class::$dealer_section)->first()) {
             $model = $model->clear();
             //create the first level of this dealer
             $dealer_data = array('title' => $this->title, 'layout' => 'dealer', 'page_type' => $dealer_class::$dealer_homepage_partial, 'content' => $this->content, 'parent_id' => $dealers->primval);
             //create the dealer skel
             if ($saved = $model->update_attributes($dealer_data)) {
                 $saved = $saved->generate_permalink()->map_live()->children_move()->show()->save();
                 $saved->dealers = $this;
                 $this->pages = $saved;
                 $subs = array();
                 //copy the national main pages
                 $i = 0;
                 foreach ($dealer_class::$dealer_top_pages as $title => $skel) {
                     $look = new $class("live");
                     if ($found = $look->filter("permalink", $skel)->first()) {
                         $info = $found->row;
                         unset($info['id'], $info['permalink']);
                         $info['parent_id'] = $saved->primval;
                         $info['sort'] = $i;
                         //custom names
                         if (!is_numeric($title)) {
                             $info['title'] = $title;
                         } else {
                             $info['title'] = str_replace("Latest ", "", $info['title']);
                         }
                         $info['dealer_content_id'] = $found->primval;
                         $subs[] = $page = $look->update_attributes($info)->generate_permalink()->map_live()->children_move()->show()->save();
                         //manytomany copy
                         foreach ($found->columns as $name => $info) {
                             if ($info[0] == "ManyToManyField") {
                                 foreach ($found->{$name} as $assoc) {
                                     $page->{$name} = $assoc;
                                 }
                             }
                         }
                         $i++;
                     }
                 }
                 foreach ($dealer_class::$dealer_extra_pages as $info) {
                     $pg = new $class();
                     $info['parent_id'] = $saved->primval;
                     $info['date_start'] = date("Y-m-d", strtotime("now-1 day"));
                     $info['sort'] = $i;
                     $extras[] = $pg->update_attributes($info)->generate_permalink()->map_live()->children_move()->show()->save();
                     $i++;
                 }
             }
         }
         $class = get_class($this);
         WaxEvent::run($class . ".dealer_creation", $this);
     }
     return array("subs" => $subs, "extras" => $extras);
 }
Esempio n. 9
0
 public function select(WaxModel $model)
 {
     $params = array();
     if ($model->sql) {
         $sql = $model->sql;
     } else {
         $sql .= $this->select_sql($model);
         $join = $this->left_join($model);
         $sql .= $join["sql"];
         $params = $join["params"];
         $filters = $this->filter_sql($model);
         if ($filters["sql"]) {
             $sql .= " WHERE ";
         }
         $sql .= $filters["sql"];
         if ($params) {
             $params = array_merge($params, $filters["params"]);
         } else {
             $params = $filters["params"];
         }
         //add filters from the other side of the join
         if ($model->is_left_joined && $model->left_join_target instanceof WaxModel) {
             $join_filters = $this->filter_sql($model->left_join_target);
             if ($join_filters["sql"]) {
                 if (strpos($sql, "WHERE") === false) {
                     $sql .= " WHERE ";
                 } else {
                     $sql .= " AND ";
                 }
             }
             $sql .= $join_filters["sql"];
             if ($params) {
                 $params = array_merge($params, $join_filters["params"]);
             } else {
                 $params = $join_filters["params"];
             }
         }
         if ($group = $this->group($model)) {
             $sql .= $group['sql'];
             $params = array_merge($params, $group['params']);
         }
         $sql .= $this->having($model);
         if ($order = $this->order($model)) {
             $sql .= $order['sql'];
             $params = array_merge($params, $order['params']);
         }
         $this->sql_without_limit = $sql;
         $sql .= $this->limit($model);
     }
     $stmt = $this->prepare($sql);
     $event_data = array("stmt" => $stmt, "params" => $params);
     WaxEvent::run("wax.db_query", $event_data);
     $this->exec($stmt, $params);
     $this->row_count_query($model);
     $res = $stmt->fetchAll(PDO::FETCH_ASSOC);
     WaxEvent::run("wax.db_query_end", $event_data);
     return $res;
 }
 protected function event_setup()
 {
     parent::event_setup();
     //look for cms content by calling functions etc
     WaxEvent::clear("cms.content.lookup");
     WaxEvent::add("cms.content.lookup", function () {
         $obj = WaxEvent::data();
         $dealer_lookup = false;
         //check domain name
         $server = $_SERVER['HTTP_HOST'];
         if ($server != Config::get("domains/live") && $server != Config::get("domains/dev")) {
             $dclass = $obj->domain_class;
             $domain = new $dclass();
             if (($found = $domain->filter("webaddress", $server)->filter("status", 1)->first()) && ($dealer = $found->dealers) && ($dealer = $dealer->first()) && ($page = $dealer->pages) && ($page = $page->scope("live")->first())) {
                 $dealer_lookup = $page;
                 $obj->setup_dealer_vars($page, $dealer);
             }
         }
         if (!$dealer_lookup) {
             $obj->content_lookup($obj);
             if (in_array("dealers", $obj->cms_stack) && count($obj->cms_stack) > 1) {
                 $obj->dealer_checked = "/" . trim(implode("/", array_slice($obj->cms_stack, 0, 2)), "/") . "/";
                 $obj->dealer_check();
             }
         }
         //lookin for dealer, so push the dealer urls on to the stack
         if ($dealer_lookup) {
             $obj->dealer_checked = $dealer_lookup->permalink;
             $original_stack = $obj->cms_stack;
             foreach (array_reverse(explode("/", trim($dealer_lookup->permalink, "/"))) as $push) {
                 array_unshift($obj->cms_stack, $push);
             }
             $obj->content_lookup($obj);
             //this might be one of those magic internal pages then...
             if ($obj->cms_throw_missing_content) {
                 $obj->cms_throw_missing_content = false;
                 $obj->cms_stack = $original_stack;
                 $obj->content_lookup($obj);
                 $obj->canonical_url = "/" . trim(implode("/", $original_stack), "/") . "/";
             }
         }
         //check for dealer urls /dealer/xx
         if ($obj->cms_throw_missing_content) {
             $stack = $obj->cms_stack;
             //if this is a dealer url, then pop off the first 2
             if (array_shift($stack) == "dealers" && count($stack)) {
                 $dealer = array_shift($stack);
                 $obj->cms_stack = $stack;
                 if (!$obj->dealer_checked) {
                     $obj->dealer_checked = "/dealers/" . $dealer . "/";
                 }
                 $obj->cms_throw_missing_content = false;
                 $obj->canonical_url = "/" . trim(implode("/", $stack), "/") . "/";
                 WaxEvent::run("cms.content.lookup", $obj);
             }
         }
         if (($dealer_model = $obj->dealer_model) && defined("UVL")) {
             WaxEvent::add("uvl.vehicle.filters", function () use($dealer_model) {
                 $model = WaxEvent::data();
                 $model->filter("dealer_id", $dealer_model->id);
             });
         }
     });
 }