示例#1
0
 public static function set_categories($map_controller, $on_backend = false, $group = false)
 {
     // Check for localization of parent category
     // Get locale
     $l = Kohana::config('locale.language.0');
     $parent_categories = array();
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //Check to see if we're dealing with a group, and thus
     //should show group specific categories
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     if ($group != false) {
         //check and make sure the simpel groups category is installed
         $plugin = ORM::factory('plugin')->where('plugin_name', 'simplegroups')->where('plugin_active', '1')->find();
         if (!$plugin) {
             throw new Exception("A group was set in adminmap_helper::set_categories() when the SimpleGroupl plugin is not installed");
         }
         $cats = ORM::factory('simplegroups_category');
         if (!$on_backend) {
             $cats = $cats->where('category_visible', '1');
         }
         $cats = $cats->where('parent_id', '0');
         $cats = $cats->where('applies_to_report', 1);
         $cats = $cats->where('simplegroups_groups_id', $group->id)->find_all();
         foreach ($cats as $category) {
             /////////////////////////////////////////////////////////////////////////////////////////////
             // Get the children
             /////////////////////////////////////////////////////////////////////////////////////////////
             $children = array();
             foreach ($category->children as $child) {
                 // Check for localization of child category
                 $translated_title = Simplegroups_category_lang_Model::simplegroups_category_title($child->id, $l);
                 if ($translated_title) {
                     $display_title = $translated_title;
                 } else {
                     $display_title = $child->category_title;
                 }
                 $children["sg_" . $child->id] = array($display_title, $child->category_color, $child->category_image);
             }
             $translated_title = Simplegroups_category_lang_Model::simplegroups_category_title($category->id, $l);
             if ($translated_title) {
                 $display_title = $translated_title;
             } else {
                 $display_title = $category->category_title;
             }
             // Put it all together
             $parent_categories["sg_" . $category->id] = array($display_title, $category->category_color, $category->category_image, $children);
         }
     }
     /////////////////////////////////////////////////////////////////////////////////////////////
     // Get all active top level categories
     /////////////////////////////////////////////////////////////////////////////////////////////
     $cats = ORM::factory('category');
     if (!$on_backend) {
         $cats = $cats->where('category_visible', '1');
     }
     $cats = $cats->where('parent_id', '0')->find_all();
     foreach ($cats as $category) {
         /////////////////////////////////////////////////////////////////////////////////////////////
         // Get the children
         /////////////////////////////////////////////////////////////////////////////////////////////
         $children = array();
         foreach ($category->children as $child) {
             // Check for localization of child category
             $translated_title = Category_Lang_Model::category_title($child->id, $l);
             if ($translated_title) {
                 $display_title = $translated_title;
             } else {
                 $display_title = $child->category_title;
             }
             $children[$child->id] = array($display_title, $child->category_color, $child->category_image);
             if ($child->category_trusted) {
                 // Get Trusted Category Count
                 $trusted = ORM::factory("incident")->join("incident_category", "incident.id", "incident_category.incident_id")->where("category_id", $child->id);
                 if (!$trusted->count_all()) {
                     unset($children[$child->id]);
                 }
             }
         }
         $translated_title = Category_Lang_Model::category_title($category->id, $l);
         if ($translated_title) {
             $display_title = $translated_title;
         } else {
             $display_title = $category->category_title;
         }
         // Put it all together
         $parent_categories[$category->id] = array($display_title, $category->category_color, $category->category_image, $children);
         if ($category->category_trusted) {
             // Get Trusted Category Count
             $trusted = ORM::factory("incident")->join("incident_category", "incident.id", "incident_category.incident_id")->where("category_id", $category->id);
             if (!$trusted->count_all()) {
                 unset($parent_categories[$category->id]);
             }
         }
     }
     $map_controller->template->content->categories = $parent_categories;
 }
 /**
  * Function: set_categories
  *
  * Description: Sets up the UI element that displays the boolean (and/or) filter
  *
  * @param boolean $on_backend - True if the output of this function will grace a page on the backend
  * @param int $group - The database ID of a Simple Group group, or false if there isn't one.
  * @param string $categories_view - Path to the view that will render this filter
  * @param string $categories_view_id - HTML element ID of the UI for this filter
  * @param bool $alphabetize - True if the categories should be listed in alphabetical order, false they'll be listed in the order they are set on the manage page.
  * @throws Exception - If you provide a group id in $group, but the simple group plugin isn't installed
  * @return obj - The view all ready to be inserted into your template of choice.
  *
  * Views: depends on what the user passes in
  *
  * Results:  Returns a view all ready to be inserted into your template of choice.
  */
 public static function set_categories($on_backend = false, $group = false, $categories_view = "enhancedmap/categories_filter", $categories_view_id = "category_switch", $alphabetize = false)
 {
     $view = new View($categories_view);
     // Check for localization of parent category
     // Get locale
     $l = Kohana::config('locale.language.0');
     $parent_categories = array();
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     //Check to see if we're dealing with a group, and thus
     //should show group specific categories
     ///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
     if ($group != false) {
         //check and make sure the simpel groups category is installed
         $plugin = ORM::factory('plugin')->where('plugin_name', 'simplegroups')->where('plugin_active', '1')->find();
         if (!$plugin) {
             throw new Exception("A group was set in enhancedmap_helper::set_categories() when the SimpleGroupl plugin is not installed");
         }
         $cats = ORM::factory('simplegroups_category');
         if (!$on_backend or ORM::factory('enhancedmap_settings')->where('key', 'show_hidden_categories_backend')->find()->value != 'true') {
             $cats = $cats->where('category_visible', '1');
         }
         $cats = $cats->where('parent_id', '0');
         $cats = $cats->where('applies_to_report', 1);
         $cats = $cats->where('simplegroups_groups_id', $group->id);
         if ($alphabetize) {
             $cats = $cats->orderby('category_title', 'ASC');
         }
         $cats = $cats->find_all();
         foreach ($cats as $category) {
             /////////////////////////////////////////////////////////////////////////////////////////////
             // Get the children
             /////////////////////////////////////////////////////////////////////////////////////////////
             $children = array();
             foreach ($category->children as $child) {
                 // Check for localization of child category
                 $translated_title = Simplegroups_category_lang_Model::simplegroups_category_title($child->id, $l);
                 if ($translated_title) {
                     $display_title = $translated_title;
                 } else {
                     $display_title = $child->category_title;
                 }
                 $children["sg_" . $child->id] = array($display_title, $child->category_color, $child->category_image);
             }
             $translated_title = Simplegroups_category_lang_Model::simplegroups_category_title($category->id, $l);
             if ($translated_title) {
                 $display_title = $translated_title;
             } else {
                 $display_title = $category->category_title;
             }
             // Put it all together
             $parent_categories["sg_" . $category->id] = array($display_title, $category->category_color, $category->category_image, $children);
         }
     }
     /////////////////////////////////////////////////////////////////////////////////////////////
     // Get all active top level categories
     /////////////////////////////////////////////////////////////////////////////////////////////
     $cats = ORM::factory('category');
     if (!$on_backend or ORM::factory('enhancedmap_settings')->where('key', 'show_hidden_categories_backend')->find()->value != 'true') {
         $cats = $cats->where('category_visible', '1');
     }
     $cats = $cats->where('parent_id', '0');
     if ($alphabetize) {
         $cats = $cats->orderby('category_title', 'ASC');
     } else {
         $cats = $cats->orderby('category_position', 'asc');
     }
     $cats = $cats->find_all();
     foreach ($cats as $category) {
         /////////////////////////////////////////////////////////////////////////////////////////////
         // Get the children
         /////////////////////////////////////////////////////////////////////////////////////////////
         $children = array();
         foreach ($category->children as $child) {
             // Check for localization of child category
             $translated_title = Category_Lang_Model::category_title($child->id, $l);
             if ($translated_title) {
                 $display_title = $translated_title;
             } else {
                 $display_title = $child->category_title;
             }
             $children[$child->id] = array($display_title, $child->category_color, $child->category_image);
             if ($child->category_trusted) {
                 // Get Trusted Category Count
                 $trusted = ORM::factory("incident")->join("incident_category", "incident.id", "incident_category.incident_id")->where("category_id", $child->id);
                 if (!$trusted->count_all()) {
                     unset($children[$child->id]);
                 }
             }
         }
         $translated_title = Category_Lang_Model::category_title($category->id, $l);
         if ($translated_title) {
             $display_title = $translated_title;
         } else {
             $display_title = $category->category_title;
         }
         // Put it all together
         $parent_categories[$category->id] = array($display_title, $category->category_color, $category->category_image, $children);
         if ($category->category_trusted) {
             // Get Trusted Category Count
             $trusted = ORM::factory("incident")->join("incident_category", "incident.id", "incident_category.incident_id")->where("category_id", $category->id);
             if (!$trusted->count_all()) {
                 unset($parent_categories[$category->id]);
             }
         }
     }
     $view->categories = $parent_categories;
     $view->categories_view_id = $categories_view_id;
     return $view;
 }