本文整理汇总了PHP中Category::exists方法的典型用法代码示例。如果您正苦于以下问题:PHP Category::exists方法的具体用法?PHP Category::exists怎么用?PHP Category::exists使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Category
的用法示例。
在下文中一共展示了Category::exists方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
list($params, $id, $slug) = $this->parse_params(func_get_args());
// Create or update
if ($this->method != 'get') {
$c = new Content();
switch ($this->method) {
case 'post':
case 'put':
if ($this->method == 'put') {
// Update
$c->get_by_id($id);
if (!$c->exists()) {
$this->error('404', "Content with ID: {$id} not found.");
return;
}
$c->old_published_on = $c->published_on;
$c->old_captured_on = $c->captured_on;
$c->old_uploaded_on = $c->uploaded_on;
if (isset($_POST['slug'])) {
$c->current_slug = $c->slug;
}
}
if (isset($_REQUEST['name'])) {
if (isset($_REQUEST['upload_session_start'])) {
$s = new Setting();
$s->where('name', 'last_upload')->get();
if ($s->exists() && $s->value != $_REQUEST['upload_session_start']) {
$s->value = $_REQUEST['upload_session_start'];
$s->save();
}
}
$file_name = $c->clean_filename($_REQUEST['name']);
$chunk = isset($_REQUEST["chunk"]) ? $_REQUEST["chunk"] : 0;
$chunks = isset($_REQUEST["chunks"]) ? $_REQUEST["chunks"] : 0;
$tmp_dir = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'tmp';
$tmp_path = $tmp_dir . DIRECTORY_SEPARATOR . $file_name;
make_child_dir($tmp_dir);
if ($chunks == 0 || $chunk == $chunks - 1) {
if (isset($_REQUEST['text'])) {
$path = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'custom' . DIRECTORY_SEPARATOR;
$internal_id = false;
} else {
if (isset($_REQUEST['plugin'])) {
$info = pathinfo($_REQUEST['name']);
$path = FCPATH . 'storage' . DIRECTORY_SEPARATOR . 'plugins' . DIRECTORY_SEPARATOR . $_REQUEST['plugin'] . DIRECTORY_SEPARATOR . 'storage' . DIRECTORY_SEPARATOR;
$file_name = $_REQUEST['basename'] . '.' . $info['extension'];
$internal_id = false;
} else {
list($internal_id, $path) = $c->generate_internal_id();
}
}
if ($path) {
$path .= $file_name;
if ($chunks == 0) {
$tmp_path = $path;
}
} else {
$this->error('500', 'Unable to create directory for upload.');
return;
}
}
// Look for the content type header
if (isset($_SERVER["HTTP_CONTENT_TYPE"])) {
$contentType = $_SERVER["HTTP_CONTENT_TYPE"];
} else {
if (isset($_SERVER["CONTENT_TYPE"])) {
$contentType = $_SERVER["CONTENT_TYPE"];
} else {
$contentType = '';
}
}
if (strpos($contentType, "multipart") !== false) {
if (isset($_FILES['file']['tmp_name']) && is_uploaded_file($_FILES['file']['tmp_name'])) {
$out = fopen($tmp_path, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
$in = fopen($_FILES['file']['tmp_name'], "rb");
if ($in) {
while ($buff = fread($in, 4096)) {
fwrite($out, $buff);
}
} else {
$this->error('500', 'Unable to read input stream.');
return;
}
fclose($out);
unlink($_FILES['file']['tmp_name']);
} else {
$this->error('500', 'Unable to write to output file.');
return;
}
} else {
$this->error('500', 'Unable to move uploaded file.');
return;
}
} else {
$out = fopen($tmp_path, $chunk == 0 ? "wb" : "ab");
if ($out) {
// Read binary input stream and append it to temp file
//.........这里部分代码省略.........
示例2: update
public function update()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('category[name]', 'lang:admin_categories_form_field_category_name', 'required');
$this->form_validation->set_rules('category[parent_id]', 'lang:admin_categories_form_field_parent_category', 'required');
$this->form_validation->set_rules('category_id', 'id', 'required');
if ($this->form_validation->run()) {
$categori_id = $this->input->post('category_id');
$category = new Category();
$category->get_by_id($categori_id);
if ($category->exists()) {
$category_data = $this->input->post('category');
$category->name = $category_data['name'];
$this->_transaction_isolation();
$this->db->trans_begin();
$cansave = TRUE;
if ($category_data['parent_id'] == 'root') {
$category->parent_id = NULL;
} else {
$parent = new Category();
$parent->get_by_id(intval($category_data['parent_id']));
if (!$parent->exists()) {
$cansave = FALSE;
} else {
$category->parent_id = intval($category_data['parent_id']);
}
}
if ($cansave && $category->save() && $this->db->trans_status()) {
$this->db->trans_commit();
$this->messages->add_message('lang:admin_categories_flash_message_save_successful', Messages::MESSAGE_TYPE_SUCCESS);
} else {
$this->db->trans_rollback();
$this->messages->add_message('lang:admin_categories_flash_message_save_failed', Messages::MESSAGE_TYPE_ERROR);
}
} else {
$this->messages->add_message('lang:admin_categories_error_category_not_found', Messages::MESSAGE_TYPE_ERROR);
}
redirect(create_internal_url('admin_categories/index'));
} else {
$this->edit();
}
}
示例3: listing
function listing($params, $id = false)
{
$sort = $this->_get_site_order('content');
$options = array('order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'search' => false, 'search_filter' => false, 'tags' => false, 'tags_not' => false, 'page' => 1, 'match_all_tags' => false, 'limit' => 100, 'include_presets' => true, 'featured' => null, 'types' => false, 'auth' => false, 'favorites' => null, 'before' => false, 'after' => false, 'after_column' => 'uploaded_on', 'before_column' => 'uploaded_on', 'category' => false, 'category_not' => false, 'year' => false, 'year_not' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'in_album' => false, 'reduce' => false, 'is_cover' => true, 'independent' => false);
$options = array_merge($options, $params);
if (isset($params['order_by']) && !isset($params['order_direction'])) {
$options['order_direction'] = in_array($params['order_by'], array('title', 'filename')) ? 'ASC' : 'DESC';
}
Shutter::hook('content.listing', array($this, $options));
if ($options['featured'] == 1 && !isset($params['order_by'])) {
$options['order_by'] = 'featured_on';
} else {
if ($options['favorites'] == 1 && !isset($params['order_by'])) {
$options['order_by'] = 'favorited_on';
}
}
if ($options['auth']) {
if (isset($options['visibility']) && $options['visibility'] !== 'album') {
$values = array('public', 'unlisted', 'private');
if (in_array($options['visibility'], $values)) {
$options['visibility'] = array_search($options['visibility'], $values);
} else {
if ($options['visibility'] === 'any') {
$options['visibility'] = false;
} else {
$options['visibility'] = 0;
}
}
} else {
if (!isset($options['visibility']) || $options['visibility'] !== 'album') {
$options['visibility'] = 0;
}
}
} else {
if ($options['in_album']) {
$options['visibility'] = 'album';
} else {
$options['visibility'] = 0;
}
}
if ($options['visibility'] > 0 && $options['order_by'] === 'published_on') {
$options['order_by'] = 'captured_on';
}
if ($options['order_by'] == 'dimension') {
$options['order_by'] = 'width * height';
}
if (is_numeric($options['limit']) && $options['limit'] > 0) {
$options['limit'] = min($options['limit'], 100);
} else {
$options['limit'] = 100;
}
if ($options['independent']) {
$this->where_related('album', 'id', null);
}
if ($options['types']) {
$types = explode(',', str_replace(' ', '', $options['types']));
$this->group_start();
foreach ($types as $t) {
switch ($t) {
case 'photo':
$this->or_where('file_type', 0);
break;
case 'video':
$this->or_where('file_type', 1);
break;
case 'audio':
$this->or_where('file_type', 2);
break;
}
}
$this->group_end();
}
if ($options['search'] && $options['search_filter'] === 'tags') {
$options['tags'] = $options['search'];
$options['search'] = false;
}
if ($options['search']) {
$term = urldecode($options['search']);
if ($options['search_filter']) {
if ($options['search_filter'] === 'category') {
$cat = new Category();
$cat->where('title', $term)->get();
if ($cat->exists()) {
$this->where_related('category', 'id', $cat->id);
} else {
$this->where_related('category', 'id', 0);
}
} else {
$this->group_start();
$this->like($options['search_filter'], $term, 'both');
$this->group_end();
}
} else {
$this->group_start();
$this->like('title', $term, 'both');
$this->or_like('caption', $term, 'both');
$t = new Tag();
$t->where('name', $term)->get();
if ($t->exists()) {
$this->or_where_related('tag', 'id', $t->id);
//.........这里部分代码省略.........
示例4: index
function index()
{
list($params, $id, $slug) = $this->parse_params(func_get_args());
// Create or update
if ($this->method != 'get') {
$c = new Category();
switch ($this->method) {
case 'post':
case 'put':
if ($this->method == 'put') {
if (is_null($id)) {
$this->error('403', 'Required parameter "id" not present.');
return;
}
// Update
$c->get_by_id($id);
if (!$c->exists()) {
$this->error('404', "Category with ID: {$id} not found.");
return;
}
}
// Don't allow these fields to be saved generically
$private = array('album_count', 'content_count', 'text_count');
foreach ($private as $p) {
unset($_POST[$p]);
}
if (!$c->from_array($_POST, array(), true)) {
// TODO: More info
$this->error('500', 'Save failed.');
return;
}
$this->redirect("/categories/{$c->id}");
break;
case 'delete':
if (is_null($id)) {
$this->error('403', 'Required parameter "id" not present.');
return;
} else {
if (is_numeric($id)) {
$category = $c->get_by_id($id);
$title = $category->title;
if ($category->exists()) {
$s = new Slug();
$this->db->query("DELETE FROM {$s->table} WHERE id = 'category.{$category->slug}'");
if (!$category->delete()) {
// TODO: More info
$this->error('500', 'Delete failed.');
return;
}
$id = null;
} else {
$this->error('404', "Category with ID: {$id} not found.");
return;
}
} else {
$id = explode(',', $id);
$c->where_in('id', $id);
$cats = $c->get_iterated();
foreach ($cats as $c) {
if ($c->exists()) {
$s = new Slug();
$this->db->query("DELETE FROM {$s->table} WHERE id = 'category.{$c->slug}'");
$c->delete();
}
}
}
}
exit;
break;
}
}
$c = new Category();
// No id, so we want a list
if (is_null($id) && !$slug) {
$final = $c->listing($params);
} else {
if (!is_null($id)) {
$category = $c->get_by_id($id);
} else {
if ($slug) {
$category = $c->where('slug', $slug)->get();
}
}
if ($category->exists()) {
$options = array('page' => 1, 'limit' => 50);
$options = array_merge($options, $params);
$category_arr = $category->to_array($options);
$options['category'] = $category->id;
list($final, $counts) = $this->aggregate('category', $options);
$prev = new Category();
$next = new Category();
$prev->where('title <', $category->title)->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '>', 0), null)->order_by('title DESC, id DESC');
$next->where('title >', $category->title)->where_func('', array('@content_count', '+', '@text_count', '+', '@album_count', '>', 0), null)->order_by('title ASC, id ASC');
$max = $next->get_clone()->count();
$min = $prev->get_clone()->count();
$context = array('total' => $max + $min + 1, 'position' => $min + 1);
$prev->limit(1)->get();
$next->limit(1)->get();
unset($options['category']);
if ($prev->exists()) {
//.........这里部分代码省略.........
示例5: listing
function listing($params)
{
$sort = $this->_get_site_order('album');
$options = array('trash' => false, 'page' => 1, 'order_by' => $sort['by'], 'order_direction' => $sort['direction'], 'search' => false, 'search_filter' => false, 'tags' => false, 'tags_not' => false, 'match_all_tags' => false, 'limit' => false, 'include_empty' => true, 'types' => false, 'featured' => false, 'category' => false, 'category_not' => false, 'year' => false, 'year_not' => false, 'month' => false, 'month_not' => false, 'day' => false, 'day_not' => false, 'flat' => false, 'reduce' => false, 'id_not' => false, 'auth' => false);
$options = array_merge($options, $params);
if (isset($params['order_by']) && !isset($params['order_direction'])) {
$options['order_direction'] = in_array($params['order_by'], array('created_on', 'modified_on', 'published_on', 'total_count', 'image_count', 'video_count')) ? 'DESC' : 'ASC';
}
$options = Shutter::filter('api.albums.listing.options', $options);
Shutter::hook('albums.listing', array($this, $options));
if ($options['order_by'] === 'manual') {
$options['order_by'] = 'left_id';
if (!isset($params['order_direction'])) {
$options['order_direction'] = 'asc';
}
}
if ($options['featured'] == 1 && !isset($params['order_by'])) {
$options['order_by'] = 'featured_on';
}
if (!is_numeric($options['limit'])) {
$options['limit'] = false;
}
if ($options['types']) {
$types = explode(',', str_replace(' ', '', $options['types']));
$this->group_start();
foreach ($types as $t) {
switch ($t) {
case 'set':
$this->or_where('album_type', 2);
break;
case 'smart':
$this->or_where('album_type', 1);
break;
case 'standard':
$this->or_where('album_type', 0);
break;
}
}
$this->group_end();
}
if ($options['search'] && $options['search_filter'] === 'tags') {
$options['tags'] = $options['search'];
$options['search'] = false;
}
if ($options['search']) {
$term = urldecode($options['search']);
if ($options['search_filter']) {
if ($options['search_filter'] === 'category') {
$cat = new Category();
$cat->where('title', $term)->get();
if ($cat->exists()) {
$this->where_related('category', 'id', $cat->id);
} else {
$this->where_related('category', 'id', 0);
}
} else {
$this->group_start();
$this->like($options['search_filter'], $term, 'both');
$this->group_end();
}
} else {
$this->group_start();
$this->like('title', $term, 'both');
$this->or_like('description', $term, 'both');
$t = new Tag();
$t->where('name', $term)->get();
if ($t->exists()) {
$this->or_where_related('tag', 'id', $t->id);
}
$this->group_end();
}
} else {
if ($options['tags'] || $options['tags_not']) {
$this->_do_tag_filtering($options);
}
}
if ($options['id_not']) {
$this->where_not_in('id', explode(',', $options['id_not']));
}
$sub_list = false;
if ($this->exists()) {
$sub_list = true;
$this->where('left_id >', $this->left_id)->where('right_id <', $this->right_id)->where('level', $this->level + 1)->where('visibility', $this->visibility);
$options['visibility'] = $this->visibility;
} else {
if ($options['auth']) {
if (isset($options['visibility'])) {
$values = array('public', 'unlisted', 'private');
if (in_array($options['visibility'], $values)) {
$options['visibility'] = array_search($options['visibility'], $values);
} else {
$options['visibility'] = 0;
}
} else {
$options['visibility'] = 0;
}
} else {
$options['visibility'] = 0;
}
}
//.........这里部分代码省略.........
示例6: index
function index()
{
list($params, $id, $slug) = $this->parse_params(func_get_args());
$params['auth'] = $this->auth;
// Create or update
if ($this->method != 'get') {
$t = new Text();
switch ($this->method) {
case 'post':
case 'put':
if ($id) {
$t->get_by_id($id);
$t->old_published = $t->published;
$t->current_slug = $t->slug;
if (isset($_POST['unpublish'])) {
$_POST['published'] = 0;
$_POST['published_on'] = null;
}
} else {
if (isset($_POST['page_type']) && $_POST['page_type'] === 'page') {
$_POST['published'] = 1;
}
}
$arr = $_POST;
global $raw_input_data;
if (isset($raw_input_data['content'])) {
$arr['content'] = $raw_input_data['content'];
}
if (isset($raw_input_data['draft'])) {
$arr['draft'] = $raw_input_data['draft'];
}
// Little hack here to make sure content validation is always run
// (newline gets stripped in text->_format_content)
if (isset($arr['content'])) {
$arr['content'] .= "\n";
}
try {
$t->from_array($arr, array(), true);
} catch (Exception $e) {
$this->error('400', $e->getMessage());
return;
}
if (isset($_POST['tags'])) {
$t->_format_tags($_POST['tags']);
} else {
if ($this->method === 'put' && isset($_POST['published'])) {
$t->_update_tag_counts();
}
}
$arr = $t->to_array(array('expand' => true));
if ($id) {
Shutter::hook('text.update', $arr);
} else {
Shutter::hook('text.create', $arr);
}
$this->redirect("/text/{$t->id}" . (isset($params['render']) ? '/render:' . $params['render'] : ''));
break;
case 'delete':
if (is_null($id)) {
$this->error('403', 'Required parameter "id" not present.');
return;
} else {
if (is_numeric($id)) {
$id = array($id);
} else {
$id = explode(',', $id);
}
$tags = array();
foreach ($id as $text_id) {
$text = $t->get_by_id($text_id);
if ($text->exists()) {
$tags = array_merge($tags, $text->tags);
$s = new Slug();
$prefix = $text->page_type == 0 ? 'essay' : 'page';
$this->db->query("DELETE FROM {$s->table} WHERE id = '{$prefix}.{$text->slug}'");
Shutter::hook('text.delete', $text->to_array(array('auth' => true)));
if (!$text->delete()) {
// TODO: More info
$this->error('500', 'Delete failed.');
return;
}
}
}
}
exit;
break;
}
}
$p = new Text();
// No id, so we want a list
if (is_null($id) && !$slug) {
$params['state'] = 'published';
$final = $p->listing($params);
} else {
if (!is_null($id)) {
if (is_numeric($id)) {
$page = $p->get_by_id($id);
} else {
$this->auth = $params['auth'] = true;
$page = $p->get_by_internal_id($id);
//.........这里部分代码省略.........
示例7: delete
function delete($id = NULL)
{
//filter & Sanitize $id
$id = $id != 0 ? filter_var($id, FILTER_VALIDATE_INT) : NULL;
//redirect if it´s no correct
if (!$id) {
$this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exit')));
redirect('admin/categories/');
}
//search the item to delete
if (Category::exists($id)) {
$category = Category::find($id);
} else {
$this->session->set_flashdata('message', array('type' => 'warning', 'text' => lang('web_object_not_exit')));
redirect('admin/categories/');
}
//delete the item
if ($category->delete() == TRUE) {
$this->session->set_flashdata('message', array('type' => 'success', 'text' => lang('web_delete_success')));
} else {
$this->session->set_flashdata('message', array('type' => 'error', 'text' => lang('web_delete_failed')));
}
if ($category->category_id) {
redirect('admin/categories/' . $category->category_id);
} else {
redirect('admin/categories');
}
}
示例8: testComplexBuild
/**
* Will test the build of the more comples many-to-many and the case where there is more than one relationships.
*/
public function testComplexBuild()
{
self::reset();
fFixture::setDatabase(fORMDatabase::retrieve());
$fixture = fFixture::create(FIXTURES_ROOT);
// includes: categories.json, products.json, users.json, shops.json and the join table categories_products.json
$fixture->build();
$shop = new Shop(1);
$user = new User(1);
$category = new Category(1);
$product = new Product(1);
$this->assertTrue($shop->exists());
$this->assertTrue($user->exists());
$this->assertTrue($category->exists());
$this->assertTrue($product->exists());
// Shop has manu users and products
$this->assertEquals(1, $shop->buildUsers()->count());
$this->assertEquals(1, $shop->buildProducts()->count());
// User and product has a shop
$this->assertTrue($user->createShop()->exists());
$this->assertTrue($product->createShop()->exists());
// Product and category has many of eachother
$this->assertEquals(1, $product->buildCategories()->count());
$this->assertEquals(1, $category->buildProducts()->count());
}
示例9: list_import_lamsfet_tasks_labels_relations
function list_import_lamsfet_tasks_labels_relations($tasks, $labels, $tasks_labels)
{
echo 'Starting task_category_rel import (' . count($tasks_labels) . ') [';
if (count($tasks_labels)) {
foreach ($tasks_labels as $relation) {
$task_id = $tasks[$relation->task_id]->_list_id;
$category_id = $labels[$relation->label_id]->_list_id;
$task = new Task();
$task->get_by_id(intval($task_id));
$category = new Category();
$category->get_by_id(intval($category_id));
if ($task->exists() && $category->exists()) {
$task->save($category);
} else {
echo ' ( CATEGORY OR TASK NOT FOUND ' . $task_id . '(' . $relation->task_id . ')/' . $category_id . '(' . $relation->label_id . ') ) ';
}
echo '.';
}
}
echo '] ... done' . "\n";
}