Jump to content


GC Multi Pourpuse Extension - Stackable Callbacks + field types + Extensible Configs

extension

  • Please log in to reply
14 replies to this topic

#1 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 24 April 2013 - 12:57 AM

Hello to you all!

I wanted to share this extension I've made that might help you to speed things up.

 

Quick Documentation: 

 

function field_type_ext( $field, $type, [$extras]):
 - Basically is the same as field_type but let's you set your own types without editing the GC library. For now, the only new type is 'yes_no' that is a dropdown.
 The idea it's to provide a clean and easy way to include personalized and recurrent field_types for the community... maybe join all the field_type extensions and plugins in just one...
 
 
function set_soft_delete([$database_field], [$deteled_value]): 
 - Overrides the delete function with a soft delete function (by default: table column 'deleted' setted to 1).
   If $database_field is set, it uses that one instead of 'deleted'
   If $deleted_value is set, it uses that insead of 1.
 
 
function append_fields($field, [$field2, ...]):
 - Same as fields() from GC with the difference that this one adds the fields passed by parameter to the end of the fields list (auto-eliminates duplicates).
 
function append_add_fields($field, [$field2, ...]):
 - Same as add_fields() from GC with the difference that this one adds the fields passed by parameter to the end of the fields list (auto-eliminates duplicates).
 
function append_edit_fields($field, [$field2, ...]):
 - Same as edit_fields() from GC with the difference that this one adds the fields passed by parameter to the end of the fields list (auto-eliminates duplicates).
 
 
 
function prepend_fields($field, [$field2, ...]):
 - Same as fields() from GC with the difference that this one adds the fields passed by parameter to the beginning of the fields list (auto-eliminates duplicates).
 
function prepend_add_fields($field, [$field2, ...]):
 - Same as add_fields() from GC with the difference that this one adds the fields passed by parameter to the beginning of the fields list (auto-eliminates duplicates).
 
function prepend_edit_fields($field, [$field2, ...]):
 - Same as edit_fields() from GC with the difference that this one adds the fields passed by parameter to the beginning of the fields list (auto-eliminates duplicates).
 
 
 
function append_fields_after($field, $field2, [$field3, ...]):
 - Appends the field2, [field3, ...] fields to the field list (add+edit) after $field. If $field doesn't exist it just appends them at the end of the list (auto-eliminates duplicates).
 
function append_add_fields_after($field, [$field2, ...]):
 - Appends the field2, [field3, ...] fields to the field list (add) after $field. If $field doesn't exist it just appends them at the end of the list (auto-eliminates duplicates).
 
function append_edit_fields_after($field, [$field2, ...]):
 - Appends the field2, [field3, ...] fields to the field list (edit) after $field. If $field doesn't exist it just appends them at the end of the list (auto-eliminates duplicates).
 
 
 
function remove_fields($field, [$field2, ...]):
 - Removes the fields passed as parameters from the fields list (add+edit) (if they are setted).
 
function remove_add_fields($field, [$field2, ...]):
 - Removes the fields passed as parameters from the add fields list(if they are setted).
 
function remove_edit_fields($field, [$field2, ...]):
 - Removes the fields passed as parameters from the edit fields list (if they are setted).
 
 
 
function append_columns($columns, [$columns2, ...]):
 - Appends columns passed as parameters at the end of the existing columns list (auto-eliminates duplicates).
 
function prepend_columns($columns, [$columns2, ...]):
 - Appends columns passed as parameters at the beginning of the existing columns list (auto-eliminates duplicates).
 
function remove_columns($columns, [$columns2, ...]):
 - Removes the columns passed as parameters from the columns list (if they are setted).

 

 

--- Since Last Update ---
 
function callback_before_insert(array($this,'function_name'),[$override_all=0]):
- Same as GC original if override_all is set to 1. Else (default) adds the function to a callback array. The setted callbacks run one after the other in the order they where setted.
 
function callback_after_insert(array($this,'function_name'),[$override_all=0]):
- Same as GC original if override_all is set to 1. Else (default) adds the function to a callback array. The setted callbacks run one after the other in the order they where setted.
 
function callback_before_update(array($this,'function_name'),[$override_all=0]):
- Same as GC original if override_all is set to 1. Else (default) adds the function to a callback array. The setted callbacks run one after the other in the order they where setted.
 
function callback_after_update(array($this,'function_name'),[$override_all=0]):
- Same as GC original if override_all is set to 1. Else (default) adds the function to a callback array. The setted callbacks run one after the other in the order they where setted.
 
function callback_before_delete(array($this,'function_name'),[$override_all=0]):
- Same as GC original if override_all is set to 1. Else (default) adds the function to a callback array. The setted callbacks run one after the other in the order they where setted.
 
function callback_after_delete(array($this,'function_name'),[$override_all=0]):
- Same as GC original if override_all is set to 1. Else (default) adds the function to a callback array. The setted callbacks run one after the other in the order they where setted.
 
 
function callback_post_render(array($this,'function_name'),[$override_all=0]):
- Adds a callback function that runs right after the render() function.
 - Example: 
     
$gc->callback_post_render(array($this,'edit_body'));

public function edit_body($output) {
    $output->output.='Lorem ipsum dolor sit amet, 
        consectetur adipisicing elit, sed do 
        eiusmod tempor incididunt ut labore et 
        dolore magna aliqua.'; 
    //This just adds the text to the end of the generated html
    return $output;
}

 

-------------------------------------
 
Why should I use this?
 
So... why all this functions? The idea behind this is to allow the users to create some kind-of extensible configurations. I called them 'basic setups' but it's just a name.
Why a basic setup?
Let's say that almost all of the tables you use, have a creation date, a public field (if the content is or not visible in the public part of the site),a name and use soft_delete. 
 
You just go to your extension_grocery_crud library file (or another that inherits from it) and create something like this:
 
/* EXAMPLE OF BASIC SETUPS USE*/
 
    public function basic_gc_config($table_name, $content_public_name, $template='twitter-bootstrap'){
        $this->set_theme($template);
        
        $this->set_table($table_name)
            ->set_subject($content_public_name);
        $this->set_soft_delete();
        $this->columns('name','created','public');    
        $this->field_type_ext('public','yes_no');
        $this->required_fields('name');
        $this->fields(
            'name',
            'public'
        );
 
    }
 
(Don't worry it's in the attached file to)
 
So, when you go to your controller, you just call the library, make an instance (let's call it $c) and then $c->basic_gc_config('table_name', 'my_content');
After that you use the functions that the extension includes to add, move, remove, or adapt the columns and fields you need for that specific content type.
Of course, this is just a very minimal example of what you could pre-set in this "basic setups".
 
Also, fell completely free to add stuff to it, modify it, remove stuff from it and whatever you like. You may (if you want) post the modifications here or send them to my mail (greysama86@gmail.com - Only English or Spanish plz) and I promise to include them (as long as they are not repeated :P) in future updates.
You may also publish your on "basic setups" if you want.
 
I will try to update it at least once or twice a month (if there is something to update). 
 
---------------------------------------------------------------------------------
 
How can I add stuff?
 
Well, you can use anything available at the GC documentation. You should also be able to use many of the internal GC library functions and variables, since this is an extension to the library itself.
 
---------------------------------------------------------------------------------
 
Instalation:
 
Just copy this file in your libraries folder and call it on your controller after GC.
 
Example:

 

$this->load->library('grocery_crud');
$this->load->library('extension_grocery_CRUD');


$crud = new Extension_grocery_CRUD(); //This goes INSTEAD of the "new Grocery_CRUD();"

 

With this, you will have all the GC functions plus the ones listed above.

 

---------------------------------------------------------------------------------

 

GitHub Repository:
 

https://github.com/g...on_grocery_crud

 

---------------------------------------------------------------------------------

 
Hope you like this little extension. I am open to suggestions for any functionality you may want to add, modify or whatever.
 
Bye!
 
VERY IMPORTANT: This works "out of the box" with the last GitHub version of GC. If you want to use it with 1.3.3 (stable) you only need to change the $columns variable from private to protected on the GC library file. You may use this extension even without that, but all the columns related functions will not work and even crash :(

Attached Files



#2 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 24 April 2013 - 05:40 AM

Ohhhh! This sounds very interesting! When I will have time I will test it!

web-johnny have a look!


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#3 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 24 April 2013 - 06:23 AM

He already did! :P

I wanted his authorization before posting it so...

This goes without saying but if someone has any doubt about the documentation, functions or whatever, just ask!



#4 web-johnny

web-johnny

    grocery CRUD Author

  • Administrators
  • 1,150 posts
  • LocationLondon

Posted 24 April 2013 - 06:49 AM

Ohhhh! This sounds very interesting! When I will have time I will test it!

web-johnny have a look!

 

I already did ;-) . This extension is now pinned and it seems that it is cool. The main functionality is that this extension is giving to users is the "everyday grocery CRUD issues" solution without breaking any code and rules.

 

Good news:

  - The extension is GC 1.4 compatible and it will probably will be compatible with the next versions of grocery CRUD as it is well extended

  - You can create your own extension by extending the functions of this library. This extension is actually the right way to extend functionalities in grocery CRUD so it is a good practice for users to organize better their codes. For example this the way that I extend is_unique for GC 1.3.3 ( http://stackoverflow...3547244/2282575 )

 

Well done Zalo ;-)


Posted Image

#5 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 24 April 2013 - 07:25 AM

Thank you very much web-johnny! It's really nice to hear that I did a good job! :D

 

----  To the community:  ----

 

Guys... Right now, this library has just a few functions to use in the traditional way (like set_soft_delete, or field_type_ext) and it's more focused on letting you reuse your GC-configurations.

But it's just the tip of the ice.  

I would love to turn this into something like a "community" extension. I mean, everyone can contribute... either ideas, code, whatever you want/can. I really want no credit whatsoever (you'll see that there is no credit/license info in the uploaded file), I just want to help the GroceryCrud project and it's community since it's been a real life saver for me in more than one project.

It would be awesome to include more field types, more functions, even some standard GC-configurations.

We have lots of skilled programmers, so we should be able to make this a pretty complete extension.

 

So, if anyone wants to contribute, you can either post here, send me a pm or an e-mail (it's in the first post).

 

That also goes to all the people that already made extensions and may want to include them here (so it's all in just one file). Just let me know that you are interested and you give me your authorization to include your code.

 

I hope this extension helps!



#6 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 25 April 2013 - 01:45 PM

Zalo make a github. Then everything is going to be easier!


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#7 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 26 April 2013 - 04:04 AM

Yeah, I know but (and this is a little embarrassing   :( ) I don't actually know how to manage a github project...

I have to search for a good tutorial but I really won't have time until next week (with luck) so...



#8 davidoster

davidoster

    Grocery CRUD Ninja

  • Advanced Member
  • PipPipPip
  • 1,068 posts
  • LocationAthens, Greece

Posted 26 April 2013 - 10:48 AM

Zalo check your private messages!


____________________________________________________________

 

rtfm_small.jpg---!!!Please read these guidelines before asking to the forums!!!---

____________________________________________________________

 

David Oster aka George Pasparakis,
http://odphotography.com
http://eletter.gr


#9 Zalo

Zalo

    Advanced Member

  • Members
  • PipPipPip
  • 31 posts

Posted 28 April 2013 - 04:09 PM

Hello Everyone!

The project is now on GitHub too! (Link on the first post) Thanks to davidoster for helping me with this!

This should make easier for anyone who wants to collaborate, but keep in mind that it's just another option. I am still available by pm, email or this thread for any questions, suggestions, ideas or code you may want to help us with! 

 

On other news, I have some new features in my head so as soon as I get some free time, I'll implement them and upload the new version.

I'll keep you posted!

 

Edit: Quick update on the set_soft_delete function. Now you can set the field and the field value. Documentation updated accordingly.

 

Edit 2: Added some new functions. They allow you to create "callback stacks" so you can run more than one callback function (useful for example if you want to add a callback after insert for tags, another for an image gallery and one more to create a log.)

Also created a post_render callback that let's you set a callback to edit the return of the render function.


Edited by Zalo, 28 April 2013 - 08:54 PM.


#10 ssfthurber

ssfthurber

    Member

  • Members
  • PipPip
  • 27 posts

Posted 17 June 2013 - 02:11 PM

"VERY IMPORTANT: This works "out of the box" with the last GitHub version of GC. If you want to use it with 1.3.3 (stable) you only need to change the $columns variable from private to protected on the GC library file. You may use this extension even without that, but all the columns related functions will not work and even crash  :('

 

sorry but where in the 1.3.3 library file to change the $column variable?



#11 ssfthurber

ssfthurber

    Member

  • Members
  • PipPip
  • 27 posts

Posted 17 June 2013 - 02:14 PM

ok i got it at 2997, right?



#12 Robert

Robert

    Advanced Member

  • Members
  • PipPipPip
  • 220 posts

Posted 12 July 2013 - 07:07 AM

yes ssfthurber its very easy to add... I wanted to ask how exactly to you use the soft_delete ?

do i use callback_before_delete from GC and then create a function with set_soft_delete ? and how can i remove the soft delete from filter ? If you can help me with 1 example of the function will be great

 

 
Thanks for your time.



#13 Robert

Robert

    Advanced Member

  • Members
  • PipPipPip
  • 220 posts

Posted 12 July 2013 - 08:11 AM

I got it now jest used the default setting for the table and only $crud->set_soft_delete(); but how can i remove then from view and from search filters ? 

 

 

Some ideas ?



#14 Roeland W

Roeland W

    Newbie

  • Members
  • Pip
  • 4 posts

Posted 31 March 2014 - 09:36 AM

This great stuff, thank you v much.



#15 Amit Shah

Amit Shah

    grocery CRUD Master

  • Advanced Member
  • PipPipPip
  • 1,192 posts
  • LocationMumbai, India

Posted 01 April 2014 - 08:41 AM

Sorry for the delay but yes this is truely cool. I too will comment much after i put to use. But my hearty regards to you for your wonderful

 contribution to this wonderful library and wonderful community







Also tagged with one or more of these keywords: extension

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users