/** * displays a user */ function view() { $id = $this->param('j_user_login'); if ($id === null) { $rep = $this->getResponse('redirect'); jMessage::add(jLocale::get('crud.message.bad.id', 'null'), 'error'); $rep->action = 'default:index'; return $rep; } $dao = jDao::create($this->dao, $this->dbProfile); $daorec = $dao->get($id); if (!$daorec) { $rep = $this->getResponse('redirect'); jMessage::add(jLocale::get('crud.message.bad.id', $id), 'error'); $rep->action = 'default:index'; return $rep; } $rep = $this->getResponse('html'); // we're using a form to display a record, to have the portunity to have // labels with each values. $form = jForms::create($this->form, $id); $form->initFromDao($this->dao, $id, $this->dbProfile); $tpl = new jTpl(); $tpl->assign('id', $id); $tpl->assign('form', $form); $tpl->assign('otherInfo', jEvent::notify('jauthdbAdminGetViewInfo', array('form' => $form, 'tpl' => $tpl, 'himself' => false))->getResponse()); $form->deactivate('password'); $form->deactivate('password_confirm'); $tpl->assign('canDelete', jAuth::getUserSession()->login != $id && jAcl2::check('auth.users.delete')); $tpl->assign('canUpdate', jAcl2::check('auth.users.modify')); $tpl->assign('canChangePass', jAcl2::check('auth.users.change.password')); $rep->body->assign('MAIN', $tpl->fetch('crud_view')); return $rep; }
/** * save data of a control using a dao. * * The control must be a container like checkboxes or listbox with multiple attribute. * If the form contain a new record (no formId), you should call saveToDao before * in order to get a new id (the primary key of the new record), or you should get a new id * by an other way. then you must pass this primary key in the third argument. * If the form has already a formId, then it will be used as a primary key, unless * you give one in the third argument. * * The Dao should map to an "association table" : its primary key should be * the primary key stored in the formId + the field which will contain one of * the values of the control. If this order is not the same as defined into the dao, * you should provide the list of property names which corresponds to the primary key * in this order : properties for the formId, followed by the property which contains * the value. * All existing records which have the formid in their keys are deleted * before to insert new values. * * @param string $controlName the name of the control * @param string $daoSelector the selector of a dao file * @param mixed $primaryKey the primary key if the form have no id. (optional) * @param mixed $primaryKeyNames list of field corresponding to primary keys (optional) * @param string $dbProfile the jDb profile to use with the dao * @see jDao */ public function saveControlToDao($controlName, $daoSelector, $primaryKey = null, $primaryKeyNames = null, $dbProfile = '') { if (!$this->controls[$controlName]->isContainer()) { throw new jExceptionForms('jelix~formserr.control.not.container', array($controlName, $this->sel)); } $values = $this->container->data[$controlName]; if (!is_array($values) && $values != '') { throw new jExceptionForms('jelix~formserr.value.not.array', array($controlName, $this->sel)); } if (!$this->container->formId && !$primaryKey) { throw new jExceptionForms('jelix~formserr.formid.undefined.for.dao', array($controlName, $this->sel)); } if ($primaryKey === null) { $primaryKey = $this->container->formId; } if (!is_array($primaryKey)) { $primaryKey = array($primaryKey); } $dao = jDao::create($daoSelector, $dbProfile); $daorec = jDao::createRecord($daoSelector, $dbProfile); $conditions = jDao::createConditions(); if ($primaryKeyNames) { $pkNamelist = $primaryKeyNames; } else { $pkNamelist = $dao->getPrimaryKeyNames(); } foreach ($primaryKey as $k => $pk) { $conditions->addCondition($pkNamelist[$k], '=', $pk); $daorec->{$pkNamelist[$k]} = $pk; } $dao->deleteBy($conditions); if (is_array($values)) { $valuefield = $pkNamelist[$k + 1]; foreach ($values as $value) { $daorec->{$valuefield} = $value; $dao->insert($daorec); } } }
function testBinaryField() { $this->emptyTable('jsessions'); $dao = jDao::create('jelix~jsession', $this->dbProfile); $sess1 = jDao::createRecord('jelix~jsession', $this->dbProfile); $sess1->id = 'sess_02939873A32B'; $sess1->creation = '2010-02-09 10:28'; $sess1->access = '2010-02-09 11:00'; $sess1->data = chr(0) . chr(254) . chr(1); $res = $dao->insert($sess1); $this->assertEqual($res, 1, 'jDaoBase::insert does not return 1'); $sess2 = $dao->get('sess_02939873A32B'); $this->assertEqualOrDiff($sess2->id, $sess1->id, 'jDao::get : bad id on record'); $this->assertEqualOrDiff(bin2hex($sess2->data), bin2hex($sess1->data), 'jDao::get : bad binary data'); }