function populate() { $pl = new PageList('bank_accounts'); $cbaccounts = new CBAccountCollection(); $sh = new SearchHandler($cbaccounts, false); $this->setSearchLimit($sh); $sh->setOrderBy('name'); $cbaccounts->load($sh); // $pl->addFromCollection($cbaccounts,array('module'=>'cashbook','controller'=>'bankaccounts','action'=>'view'),array('id'),'','name'); // $this->contents=$pl->getPages()->toArray(); $this->contents = $cbaccounts; }
public function save() { if (!$this->CheckParams($this->modeltype)) { sendBack(); } $flash = Flash::Instance(); $errors = array(); $db = DB::Instance(); $db->StartTrans(); if (parent::save_model($this->modeltype, $this->_data[$this->modeltype], $errors)) { if (isset($this->_data[$this->modeltype]['primary_account']) && $this->_data[$this->modeltype]['primary_account'] == 'on') { $cbaccounts = new CBAccountCollection($this->_templateobject); $sh = new SearchHandler($cbaccounts, FALSE); $sh->addConstraint(new Constraint('id', '!=', $this->saved_model->id)); if ($cbaccounts->update('primary_account', FALSE, $sh) === FALSE) { $errors[] = 'Error updating bank accounts'; } } else { // Check that there is only one primary account $cc = new ConstraintChain(); $cc->add(new Constraint('primary_account', 'is', TRUE)); $count = $this->_templateobject->getCount($cc); if ($count == 0) { $flash->addWarning('No primary account defined'); } elseif ($count > 1) { $flash->addWarning('Multiple primary accounts defined'); } } } else { $errors[] = 'Error saving Bank Account details : ' . $db->ErrorMsg(); } if (count($errors) > 0) { $flash->addErrors($errors); $db->FailTrans(); } if ($db->CompleteTrans()) { sendTo($this->name, 'index', $this->_modules); } $this->refresh(); }