/**
  * Store data
  *
  * @access private
  */
 function storeData($entityName)
 {
     $_entityName = $entityName;
     $_httpRequest =& HttpRequest::instance();
     $_session =& HttpSession::instance();
     $_tagged = $_session->getAttribute('TAGGED');
     $_index = $_session->getAttribute('INDEX');
     $_create = $_index < 0;
     $_next = false;
     if ($_httpRequest->getAttribute('accept')) {
         $_httpRequest->removeAttribute('accept');
         $_new = $_httpRequest->getAttribute('ENTITY');
         foreach ($_session->getAttribute('ENTITY') as $_key => $_value) {
             $_old[$_key] = $_value;
         }
         $_equal = true;
         foreach ($_new as $_key => $_value) {
             if ($_value !== $_old[$_key]) {
                 $_updated[$_key] = $_value;
                 $_equal = false;
             } else {
                 $_updated[$_key] = $_old[$_key];
             }
         }
         if (!$_equal) {
             $_dao =& CopixDAOFactory::create($_entityName);
             if ($_create) {
                 $_entity =& CopixDAOFactory::createRecord($_entityName);
                 foreach ($_updated as $_key => $_value) {
                     $_entity->{$_key} = $_value;
                 }
                 $_dao->insert($_entity);
                 $_connection =& CopixDbFactory::getConnection();
                 $_tagged[] = $_connection->lastId();
             } else {
                 // update
                 $_dlname = 'get' . $_entityName . 'DataList';
                 $_dataList = $this->{$_dlname}();
                 $_idLabel = $_dataList['id']['var'];
                 $_entity = $_dao->get($_updated[$_idLabel]);
                 foreach ($_updated as $_key => $_value) {
                     $_entity->{$_key} = $_value;
                 }
                 $_dao->update($_entity);
             }
         }
         ++$_index;
         // next one ?
         $_next = $_create || $_index < sizeOf($_tagged);
     } elseif ($_httpRequest->getAttribute('cancel')) {
         $_httpRequest->removeAttribute('cancel');
         ++$_index;
         // next one ?
         $_next = !$_create && $_index < sizeOf($_tagged);
     } else {
         // always return to the list
     }
     if ($_next) {
         $_session->setAttribute('INDEX', $_index);
         $_httpRequest->removeAttribute('ENTITY');
         $_forward = $_create ? 'create' : 'update';
         $_httpRequest->setAttribute($_forward, $_forward);
         // $_httpRequest->setAttribute('TAGGED', $_tagged);
         // TODO: la méthode CopixUrl::getUrl ne gère pas correctement les tableaux, d'où :
         foreach ($_tagged as $_key => $_Id) {
             $_httpRequest->setAttribute('TAGGED[' . $_key . ']', $_Id);
         }
         $_requestUrl = new ProjectUrl('manage' . $_entityName . 'Data', null, 'workflow', $_httpRequest->toArray());
     } else {
         $_requestUrl = new ProjectUrl('show' . $_entityName . 'List', null, 'workflow');
     }
     return new CopixActionReturn(COPIX_AR_REDIRECT, $_requestUrl->getUrl(false));
 }
Пример #2
0
 /**
  * Retrieve an HttpSession object.
  * @access public
  * @return HttpSession
  */
 function &getSession()
 {
     return HttpSession::instance();
 }