dhtmlxScheduler + CodeIgniter + custom Model

Hello,

I followed this instructions (docs.dhtmlx.com/doku.php?id=tuto … odeigniter) to have a basic scheduler integrated with a CI application.

But I’d like to customize the queries (joins, aliases, etc) and I think using a custom Model is the good way. The last section of this documentation gives an example of making that but isn’t very documented. I’ve some doubts:

My controller:

$this->load->database(); $this->load->model('calendariprofessional_model'); $conn = new SchedulerConnector($this->db, "PHPCI"); $conn->configure("GT_CalendariProfessional","CalendariProfessionalID","DataInici,DataFi,kk"); $conn->useModel($this->calendariprofessional_model); $conn->render();

  • The get() method in the Model have a parameter “$request”. What’s that?
  • While using a model (userModel), how configure() works? What’s the first parameter? Normally is a table, but it doesn’t have sense using a Model because it can return a join of tables. The get() method have to return all the fields used in configure()?
  • In the example the model have a get_values($action) method. When it is used? Why it is needed?

Are there some detailed documentation about this?

More questions…

  • Is it possible to use a model with the OptionsConnector? For example, I’ve this code:

$necessitats = new OptionsConnector($this->db, "PHPCI"); $necessitats->render_table("GT_Necessitat","NecessitatID","NecessitatID(value),Descripcio(label)");
How can I convert it to use a model? Which methods names have to be in the model? Can I define the methods names or are the same for every connector (get(), …)? In this case I suppose I’ve to create a model per connector…

  1. the get method receives the DataRequestConfig object, which contains details of the connector’s configuration, you can check its API in db_common.php. For common use-case you can just ignore this parameter.

  2. first parameter of “configure” is not used in such case, others works as for any other data source.

The get() method have to return all the fields used in configure()
It is not really necessary, but connector will output all fields defined by “configure”. It will place empty values if real values was not returned from “get” method.

  1. It is used by other model methods, common helper to move data from action object to the model properties.

  2. You can use

$necessitats = new OptionsConnector($this->db, "PHPCI");
$necessitats->configure>render_table("-","value","value,label");
$necessitats->useModel($some);
$necessitats->render();

The “get” method of model will be called. It is expected that it will return array of records with value and label properties.

Thx!! Very interesting information.

  1. I’ve tried, but no luck:

Controller:

$this->load->model('necessitat_model'); $necessitats = new OptionsConnector($this->db, "PHPCI"); $necessitats->configure>render_table("-","value","value,label"); $necessitats->useModel($this->necessitat_model); $necessitats->render();
Model:

function get($request) { return $this->db->select('NecessitatID as value, Descripcio as label') ->from('GT_Necessitat') ->get()->result_array(); }
In the log I see he is trying to do “SELECT value,value,label FROM -”.

I tried other way to use a model and it works:

$necessitats = new OptionsConnector($this->db, "PHPCI"); $data =$this->necessitat_model->get_by_up(124); $necessitats->render_array($data,"NecessitatID","value,label");

Do you think that’s a good way to do that? Is it possible to pass parameters to the model using the useModel() method?

I will double check the options and model functionality, because the above code looks correct and must not cause problems. ( The SQL can be executed if model has not “get” method )

There is no way to pass parameters.
As for your code - this is a good solution, when model used it uses the same logic as in case of render_array, so the both ways must be equal.

Thx Stanislav, all my doubts were solved!

After a deserved holidays I return to this project.

Following the last comments on this thread now I’m getting database data like this:

$data = $this->calendariprofessional_model->get_guardies_by_up($this->up);
//$conn->useModel($this->calendariprofessional_model);
$conn->render_array($data,“CalendariProfessionalID”, “DataInici,DataFi,Text”);

I can avoid $conn->useModel() for getting events, but I don’t know how to treat with db update events. But if I use $conn->useModel() the $conn->render_array() is ignored and the connector is calling the model get() method instead of get_guardies_by_up().

In short, I need to pass parameter to get the events, but I don’t know how to link the connector with the update to database method in my model.

Any idea?

Thx!

You can use classic event handling approach

//will call $class->method_name for updates $conn->event->attach("beforeUpdate", array($class, "method_name")); $conn->render_array($data,"CalendariProfessionalID", "DataInici,DataFi,Text");

docs.dhtmlx.com/doku.php?id=dhtm … t_handling
docs.dhtmlx.com/doku.php?id=dhtm … date_event

Thx Stanislav. Using event->attach I can’t use CI Models. I tried:

$conn->event->attach("beforeUpdate", array("calendariprofessional_model", "update"));

But it loads the CI Model as a normal class, so I can’t use the CI methods.

But attaching events is the way. In the main controller I have:

require_once("scheduler_events.php");

And I define this class as:

class Scheduler_events extends CI_Controller

Inside this class now I can define Updates and Deletes:

public function beforeUpdate($data) {
   $this->load->model('calendariprofessional_model');
   $this->calendariprofessional_model->update($data);
}
public function beforeDelete($data) {
  $this->load->model('calendariprofessional_model');
  $this->calendariprofessional_model->delete($data);
}

If you think thats the correct way for using CI integration passing parameters maybe is a good idea to include that in the wiki.

Thx

Yep, we will update the wiki.