本文整理汇总了PHP中Category_Model类的典型用法代码示例。如果您正苦于以下问题:PHP Category_Model类的具体用法?PHP Category_Model怎么用?PHP Category_Model使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Category_Model类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: view
/**
* Show the profile of a student
*/
public function view($params)
{
$this->setView('view.php');
$is_logged = isset(User_Model::$auth_data);
$is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
$is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
// If the user isn't logged in
if (!$is_logged) {
throw new ActionException('User', 'signin', array('redirect' => $_SERVER['REQUEST_URI']));
}
try {
$student = $this->model->getInfo($params['username']);
$post_model = new Post_Model();
$this->setTitle(htmlspecialchars($student['firstname'] . ' ' . $student['lastname']));
$this->set(array('student' => $student, 'groups' => isset($student['id']) ? Group_Model::getAuth((int) $student['id']) : array(), 'is_owner' => User_Model::$auth_data['username'] == $student['username'], 'is_logged' => true, 'is_student' => $is_student, 'is_admin' => $is_admin, 'username' => User_Model::$auth_data['username']));
if ($is_student) {
$this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
}
// If the student is a user, we show their posts
if (isset($student['id'])) {
$category = isset($params['category']) ? $params['category'] : null;
$category_model = new Category_Model();
$this->set(array('posts' => $post_model->getPosts(array('restricted' => true, 'user_id' => (int) $student['id'], 'category_name' => $category, 'official' => false, 'show_private' => $is_student), Config::POST_DISPLAYED), 'categories' => $category_model->getAll(), 'current_category' => $category));
}
} catch (Exception $e) {
throw new ActionException('Page', 'error404');
}
}
示例2: view
/**
* Show the profile of a group
*/
public function view($params)
{
$this->setView('view.php');
try {
$group = $this->model->getInfoByName($params['group']);
$this->set('group', $group);
} catch (Exception $e) {
throw new ActionException('Page', 'error404');
}
$this->setTitle(__('GROUP_TITLE', array('group' => htmlspecialchars($group['name']))));
$is_logged = isset(User_Model::$auth_data);
$is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
$is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
$category = isset($params['category']) ? $params['category'] : null;
$category_model = new Category_Model();
$post_model = new Post_Model();
$this->set(array('is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin, 'categories' => $category_model->getAll(), 'current_category' => $category, 'posts' => $post_model->getPosts(array('restricted' => true, 'group_id' => (int) $group['id'], 'category_name' => $category, 'official' => $is_logged ? null : true, 'show_private' => $is_student), Config::POST_DISPLAYED)));
// Events
$event_model = new Event_Model();
$this->set(array('events' => $event_model->getByMonth((int) date('Y'), (int) date('n'), array('group_id' => (int) $group['id'], 'official' => $is_logged ? null : true, 'show_private' => $is_student)), 'calendar_month' => (int) date('n'), 'calendar_year' => (int) date('Y')));
// If the user is logged
if ($is_logged) {
$this->set(array('username' => User_Model::$auth_data['username'], 'groups_auth' => Group_Model::getAuth()));
}
if ($is_student) {
$this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
}
}
示例3: run_install
/**
* Creates the required database tables for the sharing module
*/
public function run_install()
{
// Create the database tables
// Include the table_prefix
$this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_site`\n\t\t\t(\n\t\t\t\t`id` INT UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`site_name` varchar(150) NOT NULL COMMENT 'name that appears on the front end',\n\t\t\t\t`site_url` varchar(255) NOT NULL COMMENT 'url of the deployment to share with',\n\t\t\t\t`site_color` varchar(20) DEFAULT 'CC0000' COMMENT 'color that shows the shared reports',\n\t\t\t\t`site_active` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'sharing active or inactive ',\n\t\t\t\t`share_categories` tinyint(4) NOT NULL DEFAULT '0' COMMENT 'sharing active or inactive ',\n\t\t\t\t`share_reports` tinyint(4) NOT NULL DEFAULT '1' COMMENT 'sharing active or inactive ',\n\t\t\t\t`site_username` varchar(150) NOT NULL COMMENT 'username for the remote site',\n\t\t\t\t`site_password` varchar(150) NOT NULL COMMENT 'password for the remote site',\n\t\t\t\tPRIMARY KEY (id)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores sites we are getting shared reports from'\n\t\t\t");
$result = $this->db->query("SHOW COLUMNS FROM `sharing_site` LIKE 'site_username';");
if ($result->count() == 0) {
$this->db->query('
ALTER TABLE `sharing_site`
ADD COLUMN `site_username` varchar(150) NOT NULL COMMENT \'username for the remote site\',
ADD COLUMN `site_password` varchar(150) NOT NULL COMMENT \'password for the remote site\'
');
}
$this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident`\n\t\t\t(\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`location_id` bigint(20) unsigned NOT NULL,\n\t\t\t\t`sharing_site_id` INT UNSIGNED NOT NULL,\n\t\t\t\t`remote_incident_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`updated` datetime DEFAULT NULL,\n\t\t\t\t`incident_title` varchar(255) NOT NULL COMMENT 'title of the report',\n\t\t\t\t`incident_description` longtext,\n\t\t\t\t`incident_date` datetime DEFAULT NULL,\n\t\t\t\t`incident_mode` tinyint(4) NOT NULL DEFAULT '1' COMMENT '1 - WEB, 2 - SMS, 3 - EMAIL, 4 - TWITTER',\n\t\t\t\t`incident_active` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t\t`incident_verified` tinyint(4) NOT NULL DEFAULT '0',\n\t\t\t\tPRIMARY KEY (id),\n\t\t\t\tKEY `location_id` (`location_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores shared reports'\n\t\t\t");
$this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_category` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t `category_id` int(11) unsigned NOT NULL DEFAULT '5',\n\t\t\t PRIMARY KEY (`id`),\n\t\t\t UNIQUE KEY `sharing_incident_category_ids` (`sharing_incident_id`,`category_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores shared reports categories'\n\t\t\t");
$this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_media` (\n\t\t\t `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,\n\t\t\t `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t `media_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t PRIMARY KEY (`id`),\n\t\t\t UNIQUE KEY `sharing_incident_media_ids` (`sharing_incident_id`,`media_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores shared reports media'\n\t\t\t");
$this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_incident_comment` (\n\t\t\t `id` int(11) NOT NULL AUTO_INCREMENT,\n\t\t\t `sharing_incident_id` bigint(20) unsigned NOT NULL DEFAULT '0',\n\t\t\t `comment_id` int(11) unsigned NOT NULL DEFAULT '5',\n\t\t\t PRIMARY KEY (`id`),\n\t\t\t UNIQUE KEY `sharing_incident_comment_ids` (`sharing_incident_id`,`comment_id`)\n\t\t\t) ENGINE=MyISAM AUTO_INCREMENT=14064 DEFAULT CHARSET=utf8 COMMENT='Stores shared reports comments'\n\t\t\t");
$this->db->query("\n\t\t\tCREATE TABLE IF NOT EXISTS `" . Kohana::config('database.default.table_prefix') . "sharing_category`\n\t\t\t(\n\t\t\t\t`id` BIGINT(20) UNSIGNED NOT NULL AUTO_INCREMENT,\n\t\t\t\t`sharing_site_id` INT UNSIGNED NOT NULL,\n\t\t\t\t`category_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`remote_category_id` BIGINT(20) UNSIGNED NOT NULL,\n\t\t\t\t`updated` datetime DEFAULT NULL,\n\t\t\t\tPRIMARY KEY (id),\n\t\t\t UNIQUE KEY `category_id` (`category_id`),\n\t\t\t UNIQUE KEY `remote_category_id` (`sharing_site_id`,`remote_category_id`)\n\t\t\t) ENGINE=MyISAM DEFAULT CHARSET=utf8 COMMENT='Stores shared categories'\n\t\t\t");
// Create view for querying
$this->db->query("\n\t\t\tCREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW `sharing_combined_incident` AS\n\t\t\t\tSELECT `incident`.`id` AS `id`,\n\t\t\t\t\t`incident`.`incident_title` AS `incident_title`,\n\t\t\t\t\t`incident`.`incident_description` AS `incident_description`,\n\t\t\t\t\t`incident`.`incident_date` AS `incident_date`,\n\t\t\t\t\t`incident`.`incident_mode` AS `incident_mode`,\n\t\t\t\t\t`incident`.`location_id` AS `location_id`,\n\t\t\t\t\t`incident`.`incident_active` AS `incident_active`,\n\t\t\t\t\t`incident`.`incident_verified` AS `incident_verified`,\n\t\t\t\t\t'main' AS `source`,\n\t\t\t\t\tNULL AS `source_url`\n\t\t\t\tFROM `incident`\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\t`sharing_incident`.`id` AS `id`,\n\t\t\t\t\t`sharing_incident`.`incident_title` AS `incident_title`,\n\t\t\t\t\t`sharing_incident`.`incident_description` AS `incident_description`,\n\t\t\t\t\t`sharing_incident`.`incident_date` AS `incident_date`,\n\t\t\t\t\t`sharing_incident`.`incident_mode` AS `incident_mode`,\n\t\t\t\t\t`sharing_incident`.`location_id` AS `location_id`,\n\t\t\t\t\t`sharing_incident`.`incident_active` AS `incident_active`,\n\t\t\t\t\t`sharing_incident`.`incident_verified` AS `incident_verified`,\n\t\t\t\t\t`sharing_incident`.`sharing_site_id` AS `source`,\n\t\t\t\t\t`sharing_site`.`site_url` AS `source_url`\n\t\t\t\tFROM `sharing_incident`\n\t\t\t\tLEFT JOIN `sharing_site`\n\t\t\t\t\tON (`sharing_incident`.`sharing_site_id` = `sharing_site`.`id`)\n\t\t\t");
$this->db->query("\n\t\t\tCREATE OR REPLACE ALGORITHM=UNDEFINED DEFINER=CURRENT_USER SQL SECURITY INVOKER VIEW `sharing_combined_incident_category` AS\n\t\t\t\tSELECT `incident_category`.`incident_id` AS `incident_id`,\n\t\t\t\t\tNULL AS `sharing_incident_id`,\n\t\t\t\t\t`incident_category`.`category_id` AS `category_id`\n\t\t\t\tFROM `incident_category`\n\t\t\t\tUNION\n\t\t\t\tSELECT\n\t\t\t\t\tNULL AS `incident_id`,\n\t\t\t\t\t`sharing_incident_category`.`sharing_incident_id` AS `sharing_incident_id`,\n `sharing_incident_category`.`category_id` AS `category_id`\n\t\t\t\tFROM `sharing_incident_category`\n\t\t\t");
//Dump the sharing scheduler item from bundled SQL dump file
$this->db->query("DELETE FROM `" . Kohana::config('database.default.table_prefix') . "scheduler` where scheduler_name = 'Sharing' ");
// Add sharing in to scheduler table
$this->db->query("INSERT IGNORE INTO `" . Kohana::config('database.default.table_prefix') . "scheduler`\n\t\t\t\t(`scheduler_name`,`scheduler_last`,`scheduler_weekday`,`scheduler_day`,`scheduler_hour`,`scheduler_minute`,`scheduler_controller`,`scheduler_active`) VALUES\n\t\t\t\t('Sharing','0','-1','-1','-1','-1','s_sharing','1')");
// Add Other category to the categories list (if it doesn't exist already)
$categoryname = "Other";
$other_category = ORM::factory('category')->where('category_title', $categoryname)->where('parent_id', 0)->find();
$current_other_category_id = Settings_Model::get_setting('sharing_other_category_id');
if ($other_category->loaded && empty($current_other_category_id)) {
// We already have a category "Other", save setting
Settings_Model::save_setting('sharing_other_category_id', $other_category->id);
} else {
// No category named "Other". Do we have an id save though (maybe it's been renamed)
$category = ORM::factory('Category', Settings_Model::get_setting('sharing_other_category_id'));
if (!$category->loaded) {
$this->notices[] = Kohana::lang('import.new_category') . $categoryname;
$category = new Category_Model();
$category->category_title = $categoryname;
// We'll use grey for now. Maybe something random?
$category->category_color = '000000';
$category->category_visible = 1;
// FIXIT: We need to make this zero for non-central deployments?
$category->category_trusted = 1;
// Trusted - can't delete
$category->category_description = "Category with reports that couldn't be categorised from other deployments";
//FIXIT: need to l10n this;
$category->category_position = ORM::factory('category')->count_all();
$category->save();
Settings_Model::save_setting('sharing_other_category_id', $category->id);
}
}
}
示例4: insert
public function insert($category, $username, $value)
{
$cat = new Category_Model();
$category = $cat->get_id($category);
$user = new User_Model();
$username = $user->get_id($username);
$results = $this->db->query("INSERT INTO results SET cat_id = ?, user_id = ?, value = ?, result_date = NOW()", $category, $username, $value);
if ($results) {
return true;
} else {
return false;
}
}
示例5: testIsValidCategory
/**
* Test the is_valid_category method in Category_Model using a
* valid category id
*
* @test
* @dataProvider providerIsValidCategory
* @param int $valid_category_id ID of a category exisitng in the database
* @param int $invalid_category_id ID of a non-existent/non-numeric category
*/
public function testIsValidCategory($valid_category_id, $invalid_category_id)
{
// Test existence of valid category
$this->assertEquals(TRUE, Category_Model::is_valid_category($valid_category_id));
// Assert invalidity and non-existence of invalid category
$this->assertEquals(FALSE, Category_Model::is_valid_category($invalid_category_id));
}
示例6: index
public function index()
{
$this->template->content = new View('mobile/main');
// Get 10 Most Recent Reports
$this->template->content->incidents = ORM::factory('incident')->where('incident_active', '1')->limit('10')->orderby('incident_date', 'desc')->with('location')->find_all();
// Get all active top level categories
$parent_categories = array();
$parentCategoryId = 0;
foreach (Category_Model::getCategories($parentCategoryId) as $category) {
// Get The Children
$children = array();
foreach ($category->children as $child) {
$children[$child->id] = array($child->category_title, $child->category_color, $child->category_image, $this->_category_count($child->id));
}
// Put it all together
$parent_categories[$category->id] = array($category->category_title, $category->category_color, $category->category_image, $this->_category_count($category->id), $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]);
}
}
}
$this->template->content->categories = $parent_categories;
// Get RSS News Feeds
$this->template->content->feeds = ORM::factory('feed_item')->limit('10')->orderby('item_date', 'desc')->find_all();
}
示例7: getInstance
public static function getInstance()
{
if (self::$instance == null) {
self::$instance = new Category_Model();
}
return self::$instance;
}
示例8: GetPanel
public static function GetPanel()
{
$tpl = new Template();
$items = Category_Model::GetCategories();
$tpl->SetParam('cart', $_SESSION['cart']);
return $tpl->Fetch('templates/cart/cart-panel.tpl');
}
示例9: Category_Model
/**
* 单例模式
* @return Category_Model
*/
public static function &instance()
{
if (!isset(self::$instance)) {
// Create a new instance
self::$instance = new Category_Model();
}
return self::$instance;
}
示例10: document
public function document()
{
$allDepartments = Department_Model::getAllDepartments();
$data = array('pageTitle' => 'Document Builder', 'bodyClass' => 'edit', 'builder' => 'document', 'headerModules' => json_decode($this->builder->getModules('header')), 'bodyModules' => json_decode($this->builder->getModules('body')), 'footerModules' => json_decode($this->builder->getModules('footer')), 'draftModules' => json_decode($this->builder->getDraftModules()), 'unpublishedModules' => json_decode($this->builder->getUnpublishedModules()), 'allCategories' => Category_Model::getAllCategories(), 'allDepartments' => Department_Model::getAllDepartments());
$this->load->view('templates/header', $data);
$this->load->view('builder/inner_navbar_view');
$this->load->view('builder/document_builder_view');
$this->load->view('templates/footer');
}
示例11: update
public function update($category)
{
$cat = new Category_Model();
if ($cat->category_exists($category) and apiler::is_authorized()) {
$xml = apiler::get_xml();
$result = new Result_Model();
if ($result->insert($category, $_SERVER['PHP_AUTH_USER'], $xml['value'])) {
print "OK";
die;
} else {
header("HTTP/1.1 400 Bad Request");
echo "Invalid request";
die;
}
} else {
header("HTTP/1.0 404 Not Found");
die('Category not found or not authorized');
}
}
示例12: deleteCategory
public function deleteCategory()
{
$post = $this->input->post();
if (!$this->userObj->admin) {
$error = array('status' => 'error', 'msg' => 'You cannot delete this department.');
echo json_encode($error);
exit;
}
Category_Model::deleteCategory($post['assignId'], $post['deleteId']);
}
示例13: loadData
public function loadData()
{
$currentUserDept = $this->session->department;
//CHM - Pull in the sub-select values
if (!($tName = $this->cache->get('udfFields'))) {
$query = $this->db->select('table_name')->where('field_type', 4)->get('udf');
$tName = array();
foreach ($query->result() as $data) {
$explodeV = explode('_', $data->table_name);
$tName[] = $explodeV[2];
$i++;
}
$this->cache->save('udfFields', $tName, 600);
}
// We need to set a form value for the current user so that
// they can be pre-selected on the form
$availUsers = User_Model::getAllUsers();
$usersArray = array();
foreach ($availUsers as $availUser) {
if ($availUser->id == $this->session->id) {
$availUser->selected = 'checked';
} else {
$availUser->selected = '';
}
array_push($usersArray, $availUser);
}
// We need to set a form value for the current department so that
// it can be pre-selected on the form
$availDepartments = Department_Model::getAllDepartments();
$departmentsArray = array();
foreach ($availDepartments as $availDepartment) {
if ($availDepartment->id == $currentUserDept) {
$availDepartment->selected = 'checked';
} else {
$availDepartment->selected = '';
}
array_push($departmentsArray, $availDepartment);
}
$availCategories = Category_Model::getAllCategories();
$catsArray = array();
foreach ($availCategories as $availCategory) {
array_push($catsArray, $availCategory);
}
//////Populate department perm list/////////////////
$deptPermsArray = array();
foreach ($departmentsArray as $dept) {
$availDeptPerms = new stdClass();
$availDeptPerms->name = $dept->name;
$availDeptPerms->id = $dept->id;
array_push($deptPermsArray, $availDeptPerms);
}
$data = array('tName' => $tName, 'availUsers' => $usersArray, 'allDepartments' => $availDepartments, 'deptPerms' => $departmentsArray, 'availCategories' => $catsArray);
return json_encode($data);
}
示例14: index
public function index($params)
{
$this->setView('index.php');
$is_logged = isset(User_Model::$auth_data);
$is_student = $is_logged && isset(User_Model::$auth_data['student_number']);
$is_admin = $is_logged && User_Model::$auth_data['admin'] == '1';
$category = isset($params['category']) ? $params['category'] : null;
$category_model = new Category_Model();
$this->set(array('is_logged' => $is_logged, 'is_student' => $is_student, 'is_admin' => $is_admin, 'categories' => $category_model->getAll(), 'current_category' => $category));
// If the user is logged
if ($is_logged) {
$this->set(array('username' => User_Model::$auth_data['username'], 'groups_auth' => Group_Model::getAuth(), 'posts' => $this->model->getPosts(array('restricted' => true, 'official' => false, 'category_name' => $category, 'show_private' => $is_student), Config::POST_DISPLAYED)));
}
// If the user is a student
if ($is_student) {
$this->set(array('firstname' => User_Model::$auth_data['firstname'], 'lastname' => User_Model::$auth_data['lastname'], 'avatar_url' => User_Model::$auth_data['avatar_url']));
}
// Official posts
$this->set('official_posts', $this->model->getPosts(array('restricted' => true, 'official' => true, 'category_name' => $category, 'show_private' => $is_student), Config::POST_DISPLAYED));
// Events
$event_model = new Event_Model();
$this->set(array('events' => $event_model->getByMonth((int) date('Y'), (int) date('n'), array('official' => $is_logged ? null : true, 'show_private' => $is_student)), 'calendar_month' => (int) date('n'), 'calendar_year' => (int) date('Y')));
}
示例15: page
public function page($page_no = 1)
{
$items_per_page = 2;
$cat_id = 2;
$offset = ($page_no - 1) * $items_per_page;
$limit = $items_per_page;
$category = new Category_Model($cat_id);
//$category = ORM::factory('category')->with('catagories_description')->find($cat_id); //without the lazy loading
echo $category->name . '<br>';
echo $category->catagories_description->description . '<br>';
$catalog_list = $category->limit($limit, $offset)->products;
//$catalog_list = $category->limit($limit, $offset)->like('products.name', 'ca')->products;
//$catalog_list = $category->limit($limit, $offset)->where('product_id >', 1)->products;
$catalog_total = $category->count_last_query();
echo 'this category has ' . $catalog_total . ' related products';
foreach ($catalog_list as $p) {
echo $p->name . '<br>';
echo $p->products_description->description . '<br>';
print_r($p->attributes);
}
$pagination = new Pagination(array('uri_segment' => 'page', 'total_items' => $catalog_total, 'items_per_page' => $items_per_page, 'style' => 'classic', 'auto_hide' => TRUE));
echo $pagination->render();
$profile = new Profiler();
}