Thread Rating:
  • 1 Vote(s) - 5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
ItemManager 2.0
#76
500 is very generic, can caused by numerous issues. Looks more like a .htaccess or hosting issue, can you access server logs? like apache error.log


Perhaps, php-gd (GD library) is not installed ?
Reply
#77
PHP version: 5.6.23

I reinstalled and it doesn't happen anymore.
Reply
#78
may I ask a simple question without exploring ItemManager in detail?

I wanna have a datepicker in the sidebar, where it is integrated in a form.
Now I installed ItemManager, created a category "datepicker", created a field with type "Datepicker" and value "show".
How to call the datepicker on a page or in the sidebar component now?

I also tried using the scripts on http://jsfiddle.net/trixta/cc7Rt/embedde...ml,js,css/
but I assume, I need more JS than provided there? At least I get no calendar displayed.
When I put their html (with proper header), css and js files all in root and link to them from the html, only css seems to work.
Reply
#79
NOTE: Datepicker field has a little issue, it seems the date can not be selected in admin (API has no issue) for the first time. Just open the field settings for each date picker field and re-save, it should permanently resolve this issue.

About your questions: ItemManager dies not care about HTML (inputs, forms, etc ) or JavaScript and other stuff on the front-end, it simply stores the data and delivers it in raw format to your when required, so you've full control over the whole markup around.

You need to know the following, If you wish to get your data from a specific item, the first thing you must do is to get your item. Therefor you'll need one attribute of your category (an ID for example) and an attribute of your item. Here's only one of the many ways how you can get a single Item:

PHP Code:
// Initialize your item in the memory. The first parameter is the category ID and the second an item ID
imanager()->getItemMapper()->limitedInit(9469);
// save desired item in $item variable
$item imanager()->getItemMapper()->getItem(469); 

Next, how you can output the data stored in your item. Let's say that your item has a datepicker field named "date", so you can output the field value as follows:

PHP Code:
<form ... >
 
   <input type="text" name="date" value="<?php echo date('Y/m/d', $item->fields->date->value); ?>">
</
form

That's basically all you have to know about the output.


Here is an example how to save data entered into the form field as item field value, if the item already exists and is selected (see example above, how to get an item):

PHP Code:
// Check form is sent
if(!empty($_POST['submit'])) {
 
   // NOTE: the $picked_date must have a valid format: 2016-09-16, 2016/09/17, ...
 
   $picked_date = !empty($_POST['date']) ? $_POST['date'] : '';
 
   $item->setFieldValue('date'$picked_datetrue);
 
   $item->save();


To save date in a new item:
PHP Code:
// Check form is sent
if(!empty($_POST['submit'])) {
 
   $picked_date = !empty($_POST['date']) ? $_POST['date'] : '';
 
   // Change 9 to your category ID
 
   $item = new Item(9);
 
   $item->name 'My Date';
 
   $item->active 1;
 
   $item->setFieldValue('date'$picked_datetrue);
 
   $item->save();


That's all you have to know about save the data.

The code you can put in your template, to put it in the component you can use DynPages plugin.

All other problems relate not to the ItemManager and resulting from other reasons JavaScript issue or something else. If I have time later I'll look at the link you have given.
Reply
#80
I have looked at the date input at link you pointed out and everything seems to work:
http://im.ehret-studio.com/datepickers/

I have created a category with ID 10 and an item ID 1 with date picker field.

My template.php file looks like this:

Code:
<?php if(!defined('IN_GS')) die(); ?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>HTML5 template</title>
    <link rel="stylesheet" href="http://afarkas.github.io/webshim/js-webshim/minified/shims/styles/forms-picker.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
    <script type="text/javascript" src="http://afarkas.github.io/webshim/js-webshim/minified/polyfiller.js"></script>
    <style>
    .hide-replaced.ws-inputreplace {
        display: none !important;
    }
    </style>
</head>
<body id="home">
    <div id="main-wrapper">
    <div>
        <?php get_page_content(); ?>
    </div>
    <?php get_component('sidebar'); ?>
    </div>
</body>
</html>

functions.php file in the same folder as template.php looks like follows:

PHP Code:
<?php
$imanager 
imanager();
$imanager->getItemMapper()->limitedInit(101);
$item $imanager->getItemMapper()->getItem(1);

if(!empty(
$_POST['submit'])) {
    
$picked_date = !empty($_POST['date']) ? $_POST['date'] : '';
    
$item->setFieldValue('date'$picked_datetrue);
    
$item->save();
    
redirect('./');


And here's my sidebar component:

Code:
<h2>GetSimple Features</h2>
<form method="post" action="./">
   <?php global $item; ?>
    <div class="form-row">
       <input type="date" class="hide-replaced" name="date" value="<?php echo date('Y-m-d', $item->fields->date->value); ?>">
   </div>
  <div class="form-row">
       <input name="submit" type="submit" value="send"/>
   </div>
</form>
<script>
webshim.setOptions('forms-ext', {
   replaceUI: 'auto',
   types: 'date',
   date: {
       startView: 2,
       inlinePicker: true,
       classes: 'hide-inputbtns'
   }
});
webshim.setOptions('forms', {
   lazyCustomMessages: true
});
//start polyfilling
webshim.polyfill('forms forms-ext');
</script>

There is no need any extra plugins
Reply
#81
FieldDatepicker bug

Hi,

after clean install I've tried to assign two datepicker fields. Calendars stop working. After quick inspection I've found out that datepickers haven't unique ids. So I've replaced code as:

fields\FieldDatepicker.php

Old:
Code:
        $output = $this->tpl->render($textfield, array(
                'name' => $this->name,
                'class' => $this->class,
                'style' => !empty($this->style) ? ' style="'.$this->style.'" ' : '',
                'id' => 'datepicker',
                'value' => $value), true, array()
        );

        $output .= '
        <script>
            $(function() {
                $( "#datepicker" ).datepicker({
                    dateFormat: "'. $format .'"
                });
            });
        </script>';
New:
Code:
        $output = $this->tpl->render($textfield, array(
                'name' => $this->name,
                'class' => $this->class,
                'style' => !empty($this->style) ? ' style="'.$this->style.'" ' : '',
                'id' => $this->id,
                'value' => $value), true, array()
        );

        $output .= '
        <script>
            $(function() {
                $( "#'.$this->id.'" ).datepicker({
                    dateFormat: "'. $format .'"
                });
            });
        </script>';

Now I can have as much datepickers I want.

Best regards, T
Reply
#82
Big thx again, fixed!
Reply
#83
Hi, I was using the imanager and I created a File upload field for one of the items. Now I am getting the following message when I try to upload any image in that field:"Error Failed to resize image (thumbnail)", what seems to be the issue? Thanks in advance.
Reply
#84
First thing that comes into my mind is: wrong server configuration, maybe PHP does not have the write permission to image files?
"/data/uploads/imanager" and "data/imanager" should be writable for PHP

Or maybe PHP GD extension isn't installed? http://stackoverflow.com/questions/22831...without-gd
Reply
#85
Hi Bigin,

small issue here, not sure if it's caused by my localhost config or it's a "feature". I've just installed you Item Manager for the first time, created a category, added some fields, created an item, updated it and it shows wrong times.

Created date
2016-11-29 11:11:40 (it was created on 11:40:xx)
Updated date
2016-11-29 11:11:23 (it was updated on 11:41:xx)
Reply
#86
Hi Morvy,
strange, I can't reproduce the issue here. Can you see what is entered in "Date and time format" under IM settings?
Try to re-save settings and then to overwrite your item.

You can also check your item file, whether the time stamp "updated" is correct under: /data/imanager/items/1.11.im.item.xml
Where the first character before the point is the item id and the second a category id
Reply
#87
format is default (Y-m-d h:m: s)

also timestamps are correct when I check them in files and convert them with for example epochconverter.com it only shows wrong time. Instead of 18:49:35 it shows 06:11:35 (I think)
Reply
#88
(2016-11-30, 03:51:10)morvy Wrote: format is default (Y-m-d h:m: s)

Yes, that's wrong should look as follows:


Code:
Y-m-d h:i:s


just change that, is a typo.

Thanx for reporting this issue
Reply
#89
omg, you're right, didn't think about "m" being there twice Big Grin
Reply
#90
(2015-05-22, 00:42:40)Bigin Wrote: There is another example (it outputs Items in frontend/theme):

Let's say we have a category named 'Fruits' and have created the following fields for it 'color' and 'image'
Next, create 3 fruits with the title: 'Bananas', 'Oranges', 'Cherries' 
color field values: 'yellow', 'orange', 'red'
and finally upload three pictures.

Now you go to your theme and add this code there:
PHP Code:
<?php
// get ItemManager instance
$manager = new IManager();
// check ItemManager installed
if(!$manager){die('ItemManager not installed!');}
// get ImCategory instance
$fruitsCategory $manager->category->getCategory('name=Fruits');
// check Fruits category exists
if(!$fruitsCategory){die('Fruits category does not exist!');}
// get ImItems class instance
$itemClass $manager->getItemClass();
// initialise all items of the category Fruits
$itemClass->init($fruitsCategory->get('id'));


/********** That's all, now we can work with Items! **********/

// Now, all your item data in: $itemClass->items Object

foreach($itemClass->items as $item)
{
 
   // Output item name
 
   echo 'Item Name: ' htmlspecialchars($item->name) . ' ';

 
   // Output image Nr 1
 
   if(!empty($item->fields->image->imagefullurl[0]))
 
   {
 
       echo '<img alt="" src="'htmlspecialchars($item->fields->image->imagefullurl[0]). '" width="200" >';
 
   }

 
   // output color field value
 
   if(!empty($item->fields->color->value))
 
   {
 
       echo ' Item color: 'htmlspecialchars($item->fields->color->value) . '<br /><br />';
 
   }
}
?>

I do not think that it's very difficult?! Someone with little or no PHP knowledge should be able to vaguely understand that.

Hello and thank you for your great plug in,

I've tried your example but with no success so far... I copied your code into my template but I get the following error:

PHP Code:
NoticeUndefined propertyIManager::$category in D:\xampp\htdocs\test-gs\theme\Mode\item-details.php on line 51

Fatal error
Call to a member function getCategory() on a non-object in D:\xampp\htdocs\test-gs\theme\Mode\item-details.php on line 51 

What do I do wrong?

Thank you in advance.
Reply
#91
Have you already created a category?

By default, ItemManager do not contain any categories and items, so you will need to create any that you want to use.

To do this, in GS admin go to "Manager tab" > "Categories" > Add new category.
Next, go to the "Fields" there select your category in drop down field and add some fields to your category.
Then create your items for that category.

Then you will be able to access of these items in your template using API

Code:
$imanager = imanager();
// to get a specific item by "category id" and "item id" use
$item = $imanager->getItem(1, 1);
// to get multiple items of your category do this
$items = $imanager->getItems(1, 'active=1');
Reply
#92
But you are right, I have just tried that snippet and it doesn't seem to work, because the call of the category accessor is wrong.
To get it working just change the line:

Code:
$fruitsCategory = $manager->category->getCategory('name=Fruits');

to
Code:
$fruitsCategory = $manager->getCategoryMapper()->getCategory('name=Fruits');

This should fix that

I'll fix that example, Thanks for your help!
Reply
#93
Great, it works! Thank you so much for your quick response!

One more question... Is it possible to change an item's category to another category or do I have to create a new item in the category I wish to move it to?

I am trying to work with your great plug in and might come back for a little more advice.

Thank you again!
Reply
#94
(2017-01-04, 18:36:55)smsHH Wrote: One more question... Is it possible to change an item's category to another category or do I have to create a new item in the category I wish to move it to?

There is no GUI for that, but you can do it by using API, or create your own GUI for it. For this, however, you have to take care of the item fields, they have to be identical or you'll lose the data. It's always best practice to do it manually. So, for your example above, you can create a simple script like follows.

Let's say, that your want to change an item's category id-1 to category id-2 and your item is "1"

PHP Code:
// get the item you want to change the category
$item $manager->getItemMapper()->findItem(1, array(1));
if(
$item) {
 
   // create new item in category "2"
 
   $newItem = new Item(2);
 
   //  copies the item name of the old item
 
   $newItem->name $item->name;
 
   //  copies the item field "color" value
 
   $newItem->setFieldValue('color'$item->fields->color->value);
 
   // ...
 
   // Let's save new item
 
   if($newItem->save()) {
 
       echo 'The item is created';
    
// remove the old item
    
$manager->deleteItem($item->id$item->categoryid);
 
   
    else {
 
       echo 'The item could not be saved';
 
   }


;-)
Reply
#95
Thank you very much again. I will try that and hope I understand it :-)
Reply
#96
Wink 
I really begin to love your plug in! Things can be done so easily with a bit of PHP knowledge and following this thread.

One question though...

For example

Category 1
  Item 1
  Item 2

Category 2
  Item 1
  Item 2

...

How can I show the Items of Category 2 only?

It's probably in this line:

// initialise all items of the category 'Kategorie'
$itemClass->init($kategorie->get('id'));

But I don't know how to change it.

Thank you for your help. :-)
Reply
#97
Hi,

ItemManager saves RAM and loads its item-objects only when these are really required. There are a lot of
multiple "init(), quickInit(), limitedInit(), initAll() ..." functions that you can use to instruct ItemManager to load the items in the memory (RAM). For example, you can tell ItemManager to load all items of a specific category, or load just one specific item, or even load all the items of all categories at once (this could be very memory- and time-intensive if you have thousands of items)

Here're a few examples to get you started.

The first thing you need for getting working with items, is the "Item Accessor" variable - call it what you want, I call it "$itemMapper":

Code:
$itemMapper = $manager->getItemMapper();

In the above example you posted (it's just an older method call), it is this line:

Code:
$itemClass = $manager->getItemClass();

There I have named it different "$itemClass", but it means the same thing like "$itemMapper".

So, now, you can use that $itemMapper/$itemClass to working with your items. If you already know a category's id for the items you want to show, you can do following, to init all the items of this category:

Code:
$itemMapper->init($category_id);

or even (in your above example):

Code:
$itemClass->init($category_id);

There you tells ItemManager to initialize all the items of a category $category_id. The $category_id is the "id" of your existing category, it can be 1, 2, 3 etc ...

You have now all the item-objects in the memory and you can working with these:

Code:
$items = $itemMapper->items;

or in your example:

Code:
$items = $itemClass->items;

you can loop through the items and output each values you like:

Code:
foreach($items as $item) {
    echo $item->name . "<br>";
    ...
}

or you can even search for a specific item in the memory:

Code:
$my_item = $itemClass->getItem('name= Your item name');

or search for multiple items that are created after $timestamp (Unix timestamp):

Code:
$my_items = $itemClass->getItems('created >'.$tilemtamp);

etc ...


I hope this has given you an idea of some of the methods.

If you have any further questions - just ask. Good luck!
Reply
#98
I am not a real PHP programmer but I think I understand. Thank you very much, I will test it right away :-)
Reply
#99
Hello Bigin,

thank you again for your help. I think I understand it so far.

I hope you can help me with this piece of code

PHP Code:
<?php
$slug 
get_page_slug(false);

$manager = new IManager();
if(!
$manager){die('ItemManager not installed!');}
$kategorie $manager->getCategoryMapper()->getCategory('name=Kategorie');
if(!
$kategorie){die('Category -Kategorie- does not exist!');}
$itemClass $manager->getItemClass();
$itemClass->init($kategorie->get('id'));
$itemClass->filterItems('position''ASC');

foreach(
$itemClass->items as $item)
{
 
   $entries strtolower($item->fields->art->value);

 
   if($entries == $slug)
 
   {
 
       if(!empty($item->fields->image->imagefullurl[0])) // Output image Nr 1
 
       {
 
           echo '<img alt="'.$item->fields->image->imagetitle[0].'" src="'htmlspecialchars($item->fields->image->imagefullurl[0]). '" />';
 
       }
 
   }
}
?>

This works great until I re-sort the items in the item manager. After doing that, the path (src) to the image changes from originally:

PHP Code:
http://localhost/test-gs/data/uploads/imanager/2.2/Fingerprint.png 

to:

PHP Code:
http://localhost/test-gs/http://localhost/test-gs/http://localhost/test-gs/http://localhost/test-gs/http://localhost/test-gs/data/uploads/imanager/2.2/Fingerprint.png 

Depending on how often I re-sort the items the item manager repeats the part 'http://localhost/test-gs'.

After I just save the item again everything is fine. Is this a bug or simply my poor knowledge of programming? :-)

One more question: how can I - based on my code - show/display only the enabled items? I've tried with active=1 but with no success.

Thank you again for your great plug in and have a relaxed sunday :-)
Reply
Hi smsHH,

yes, that's a known bug with image upload field and that is why I recommend to use a file upload field instead. The file upload field have the same function as an image upload, but it is less bugged and is much quicker. Just change your image field to file upload field in admin and re-save all your items with API or manually. The field attributes of the file upload field are a little different, so you'll need to use "fullurl" instead "imagefullurl" or "title" instead "imagetitle". There's is a comparison of the field attributes, just search for "field attributes" in the description: http://get-simple.info/extend/plugin/im-...elds/1057/

The snippet you posted is OK, but it's a bit messy and could be slow if you have many items. If you want to show only a single item you don't need to loop through all the items to find what you need, the ItemManager does that already. After the init() function is executed, you can simple call getItem() function with a custom selector, here's an example:

Code:
$item = $itemClass->getItem('art=Your Art Value');

I don't know what of field type is the "art" field in your code, probably a "slug" field, if so, you don't need to use strtolower(), because slug field value is always lower case.

The selector "active=1" work well if you use that selector a correct way, see my example bellow.

For example, if you want to get only one item by page slug you can do it as follows (I use file upload field in my example):

PHP Code:
$slug get_page_slug(false);
$manager = new IManager();
if(!
$manager){die('ItemManager not installed!');}
$kategorie $manager->getCategoryMapper()->getCategory('name=Kategorie');

if(!
$kategorie){die('Category -Kategorie- does not exist!');}
$itemClass $manager->getItemClass();
$itemClass->init($kategorie->id);

$item $itemClass->getItem('art='.$manager->sanitizer->pageName($slug));
// If you want to get only active item, your selector could be ('art=Your Art && active=1'):
//$item = $itemClass->getItem('art='.$manager->sanitizer->pageName($slug).' && active=1');

if($item) {
    
$imageTitle $manager->sanitizer->text($item->fields->image->title[0]);
    
$imageUrl $manager->sanitizer->text($item->fields->image->fullurl[0]);
    echo 
'<img alt="'.$imageTitle.'" src="'.$imageUrl.'" />';


Have a nice day!
Reply




Users browsing this thread: 2 Guest(s)