atk4/atk4 — pull request #320 by DarkSide666 (2013-05-31 22:24:04+00:00)
Title: Array controller upgrade and more. See comments.

CHANGES MADE:
=============
1) Model->set(): fix for array controller.
If we use array controller for model where data source is array, then inserting NULL values for fields don't create appropriate array key.
That's because $value === $this->data[$name] if $this->data[$name] silently fails and as result is cast to NULL too. So NULL === NULL and field value equal NULL is not set (and as result - not saved).

2) Model->count(): better support for count() method in controller

3) Paginator_Basic->recursiveRender():
- if not pages at all then destroy paginator earlier.
- not only Mongo_Model uses count() method. In fact - every Model use this method which can be implemented in appropriate controller.
- paginator now works correctly with Model + Controller_Data_Array (and should work for simple arrays too). See more comments below.

4) Controller_Data_Array:
- implemented count() method (in fact this was already commited some days ago).
- implemented setLimit() method, changed rewind() and next() methods to take limiting (if enabled) into account !!! All of this is needed for Paginator to work correctly with Controller_Data_Array. BTW, setLimit works fine together with setOrder too :)

5) Controller_Data_ArrayAssoc: removed old commented code. For some time almost everything is in Controller_Data_Array.

COMPLETE TESTCASE:
=================

class page_arraytest extends Page_Basic {
public $data = array(
array('CustCode'=>'C01','CustName'=>'Romans','Salary'=>1234),
array('CustCode'=>'C02','CustName'=>'Imants','Salary'=>666),
array('CustCode'=>'C03','CustName'=>'Janis','Salary'=>null),
array('CustCode'=>'C04','CustName'=>'Peteris','Salary'=>null),
array('CustCode'=>'C05','CustName'=>'Juris','Salary'=>555),
);

function init(){
parent::init();

// add model
$m = $this->add('Model_ArrayTest');

// delete data button
$b_del = $this->add('Button')->set('Delete');
if($b_del->isClicked()){
$m->deleteAll();
$this->js()->univ()->successMessage('Data deleted')->execute();
}

// insert data button
$b_ins = $this->add('Button')->set('Insert');
if($b_ins->isClicked()){
foreach($this->data as $row) {
$m->set($row);
$m->saveAndUnload();
}
$this->js()->univ()->successMessage('Data inserted')->execute();
}

// add data grid with paginator
$g = $this->add('Grid');
$g->setModel($m);
$g->addPaginator(2);
}
}

class Model_ArrayTest extends Model {
public $table = 'tmp_arraytest';
function init(){
parent::init();
// add fields
$this->addField('CustCode')->mandatory(true)->sortable(true);
$this->addField('CustName')->mandatory(true)->sortable(true);
$this->addField('Salary')->type('int')->sortable(true);
// add Session controller
$this->c = $this->add('Controller_Data_Session');
$this->setSource($this->c);
}
}