By giving just the email address you are creating an account with a
Simple Package in accordance with the Terms and Conditions.
If you want to buy the selected package you have to register first.
"And the world was more beautiful than I ever dreamed, but also more dangerous than I ever imagined."Kevin Flynn Tron: Legacy
You draw and robots are
programming for you!
The main page shows a questionnaire that can be fulfilled by the customer..
As you can see, it is a complete questionnaire that can be fulfilled by your
customer, and the data will be saved in the SQL database at once!
The admin panel allows you to view the questionnaires.
Access to them is available to system operators in the admin panel.
Using UX2APP means saving time and reducing costs of project preparation!
Creation of the 'Questionnaire' application took us in total 1 hour and 35 minutes!
This includes time of both the analyst and the admin. There was no need to hire a
software developer. Traditional programming would take about one day.
While creating application, we used such ready-made prototype widgets as:
lists and forms, setting relevant field names and types.
After creating a module for a customer and for an admin, we have added relevant
links between the parties.
All was done in the UX2APP application - without a single code line.
In the end, we generated application, downloaded the code and uploaded it to the
server. This process took us about 1.5 hour : ).
In a short time, we got a fully working application : )
/application/Modules/admin/Operation/Userform10OperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Admin_Operation_Userform10OperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['user_user'])) {
$this->_aWhere[] = array('where' => array("user_user = '{$aParams['user_user']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
if (isset($aParams['user_password'])) {
$this->_aWhere[] = array('where' => array("user_password = '{$aParams['user_password']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultUserTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('user_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'user_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(user_user like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_password like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_id like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'user_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'user_user';
break;
case 1:
$this->_sSort = 'user_password';
break;
case 2:
$this->_sSort = 'user_id';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultUserTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultUserTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/admin/Operation/Userform10OperationForm.php
<?php
class Admin_Operation_Userform10OperationForm extends Common_Operation_Abstract
{
public function save(Zend_Controller_Request_Abstract $oRequest, Common_Form_Abstract_Form $oForm)
{
if (!$oRequest->isPost()) {
return false;
}
if (!$oForm->isValid($oRequest->getPost())) {
throw new Admin_Operation_UserError('Correct the errors in the form.');
}
try {
$aFormData = $oForm->getValues(false, false);
return $this->_saveToDatabase($aFormData);
} catch (Exception $e) {
throw new Admin_Operation_UserError('A form error occurred.');
}
}
private function _saveToDatabase($data)
{
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->beginTransaction();
try {
$oRow = null;
$oTab = $this->_getDefaultUserTab();
$key = $oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))];
if (isset($data[$key]) and !empty($data[$key])) {
$oRow = $this->_getDefaultUserTab()->find($data[$key])->current();
}
$id = $this->_getDefaultUserTab()->save($data);
$db->commit();
return $id;
} catch (Exception $e) {
$db->rollBack();
throw new Admin_Operation_UserError('An error occurred while saving: '.$e->getMessage());
}
}
public function getDefault($id)
{
return $this->_getDefaultUserTab()->find($id)->current()->toArray();
}
}
/application/Modules/admin/Operation/QuestionnaireformOperationForm.php
<?php
class Admin_Operation_QuestionnaireformOperationForm extends Common_Operation_Abstract
{
public function save(Zend_Controller_Request_Abstract $oRequest, Common_Form_Abstract_Form $oForm)
{
if (!$oRequest->isPost()) {
return false;
}
if (!$oForm->isValid($oRequest->getPost())) {
throw new Admin_Operation_QuestionnaireError('Correct the errors in the form.');
}
try {
$aFormData = $oForm->getValues(false, false);
return $this->_saveToDatabase($aFormData);
} catch (Exception $e) {
throw new Admin_Operation_QuestionnaireError('A form error occurred.');
}
}
private function _saveToDatabase($data)
{
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->beginTransaction();
try {
$oRow = null;
$oTab = $this->_getDefaultQuestionnaireTab();
$key = $oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))];
if (isset($data[$key]) and !empty($data[$key])) {
$oRow = $this->_getDefaultQuestionnaireTab()->find($data[$key])->current();
}
$id = $this->_getDefaultQuestionnaireTab()->save($data);
$db->commit();
return $id;
} catch (Exception $e) {
$db->rollBack();
throw new Admin_Operation_QuestionnaireError('An error occurred while saving: '.$e->getMessage());
}
}
public function getDefault($id)
{
return $this->_getDefaultQuestionnaireTab()->find($id)->current()->toArray();
}
}
/application/Modules/admin/Operation/Userform9OperationForm.php
<?php
class Admin_Operation_Userform9OperationForm extends Common_Operation_Abstract
{
public function save(Zend_Controller_Request_Abstract $oRequest, Common_Form_Abstract_Form $oForm)
{
if (!$oRequest->isPost()) {
return false;
}
if (!$oForm->isValid($oRequest->getPost())) {
throw new Admin_Operation_UserError('Correct the errors in the form.');
}
try {
$aFormData = $oForm->getValues(false, false);
return $this->_saveToDatabase($aFormData);
} catch (Exception $e) {
throw new Admin_Operation_UserError('A form error occurred.');
}
}
private function _saveToDatabase($data)
{
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->beginTransaction();
try {
$oRow = null;
$oTab = $this->_getDefaultUserTab();
$key = $oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))];
if (isset($data[$key]) and !empty($data[$key])) {
$oRow = $this->_getDefaultUserTab()->find($data[$key])->current();
}
$id = $this->_getDefaultUserTab()->save($data);
$db->commit();
return $id;
} catch (Exception $e) {
$db->rollBack();
throw new Admin_Operation_UserError('An error occurred while saving: '.$e->getMessage());
}
}
public function getDefault($id)
{
return $this->_getDefaultUserTab()->find($id)->current()->toArray();
}
}
/application/Modules/admin/Operation/UsergridOperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Admin_Operation_UsergridOperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['user_user'])) {
$this->_aWhere[] = array('where' => array("user_user = '{$aParams['user_user']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
if (isset($aParams['user_user'])) {
$this->_aWhere[] = array('where' => array("user_user = '{$aParams['user_user']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
if (isset($aParams['user_password'])) {
$this->_aWhere[] = array('where' => array("user_password = '{$aParams['user_password']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultUserTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('user_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'user_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(user_user like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_password like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_id like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'user_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'user_user';
break;
case 1:
$this->_sSort = 'user_password';
break;
case 2:
$this->_sSort = 'user_id';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultUserTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultUserTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/admin/Operation/QuestionnairegridOperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Admin_Operation_QuestionnairegridOperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['questionnaire_firstname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_firstname = '{$aParams['questionnaire_firstname']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_surname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_surname = '{$aParams['questionnaire_surname']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_age'])) {
$this->_aWhere[] = array('where' => array("questionnaire_age = '{$aParams['questionnaire_age']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_country'])) {
$this->_aWhere[] = array('where' => array("questionnaire_country = '{$aParams['questionnaire_country']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_region'])) {
$this->_aWhere[] = array('where' => array("questionnaire_region = '{$aParams['questionnaire_region']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_city'])) {
$this->_aWhere[] = array('where' => array("questionnaire_city = '{$aParams['questionnaire_city']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_life'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_life = '{$aParams['questionnaire_rating_life']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_ambinet'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_ambinet = '{$aParams['questionnaire_rating_ambinet']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_firstname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_firstname = '{$aParams['questionnaire_firstname']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_surname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_surname = '{$aParams['questionnaire_surname']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_age'])) {
$this->_aWhere[] = array('where' => array("questionnaire_age = '{$aParams['questionnaire_age']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_country'])) {
$this->_aWhere[] = array('where' => array("questionnaire_country = '{$aParams['questionnaire_country']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_region'])) {
$this->_aWhere[] = array('where' => array("questionnaire_region = '{$aParams['questionnaire_region']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_city'])) {
$this->_aWhere[] = array('where' => array("questionnaire_city = '{$aParams['questionnaire_city']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_life'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_life = '{$aParams['questionnaire_rating_life']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_ambinet'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_ambinet = '{$aParams['questionnaire_rating_ambinet']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_email'])) {
$this->_aWhere[] = array('where' => array("questionnaire_email = '{$aParams['questionnaire_email']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultQuestionnaireTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('questionnaire_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'questionnaire_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(questionnaire_firstname like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_surname like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_age like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_country like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_region like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_city like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_rating_life like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_rating_ambinet like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_phone like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_email like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_id like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_accept like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'questionnaire_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'questionnaire_firstname';
break;
case 1:
$this->_sSort = 'questionnaire_surname';
break;
case 2:
$this->_sSort = 'questionnaire_age';
break;
case 3:
$this->_sSort = 'questionnaire_country';
break;
case 4:
$this->_sSort = 'questionnaire_region';
break;
case 5:
$this->_sSort = 'questionnaire_city';
break;
case 6:
$this->_sSort = 'questionnaire_rating_life';
break;
case 7:
$this->_sSort = 'questionnaire_rating_ambinet';
break;
case 8:
$this->_sSort = 'questionnaire_phone';
break;
case 9:
$this->_sSort = 'questionnaire_email';
break;
case 10:
$this->_sSort = 'questionnaire_id';
break;
case 11:
$this->_sSort = 'questionnaire_accept';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultQuestionnaireTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultQuestionnaireTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/admin/Operation/UserformOperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Admin_Operation_UserformOperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['user_user'])) {
$this->_aWhere[] = array('where' => array("user_user = '{$aParams['user_user']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
if (isset($aParams['user_password'])) {
$this->_aWhere[] = array('where' => array("user_password = '{$aParams['user_password']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultUserTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('user_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'user_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(user_user like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_password like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_id like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'user_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'user_user';
break;
case 1:
$this->_sSort = 'user_password';
break;
case 2:
$this->_sSort = 'user_id';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultUserTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultUserTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/admin/Operation/QuestionnaireformOperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Admin_Operation_QuestionnaireformOperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['questionnaire_firstname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_firstname = '{$aParams['questionnaire_firstname']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_surname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_surname = '{$aParams['questionnaire_surname']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_age'])) {
$this->_aWhere[] = array('where' => array("questionnaire_age = '{$aParams['questionnaire_age']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_country'])) {
$this->_aWhere[] = array('where' => array("questionnaire_country = '{$aParams['questionnaire_country']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_region'])) {
$this->_aWhere[] = array('where' => array("questionnaire_region = '{$aParams['questionnaire_region']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_city'])) {
$this->_aWhere[] = array('where' => array("questionnaire_city = '{$aParams['questionnaire_city']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_life'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_life = '{$aParams['questionnaire_rating_life']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_ambinet'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_ambinet = '{$aParams['questionnaire_rating_ambinet']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_phone'])) {
$this->_aWhere[] = array('where' => array("questionnaire_phone = '{$aParams['questionnaire_phone']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_email'])) {
$this->_aWhere[] = array('where' => array("questionnaire_email = '{$aParams['questionnaire_email']}'"));
} else {
throw new Admin_Operation_QuestionnaireError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultQuestionnaireTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('questionnaire_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'questionnaire_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(questionnaire_firstname like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_surname like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_age like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_country like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_region like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_city like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_rating_life like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_rating_ambinet like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_phone like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_email like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_id like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_accept like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'questionnaire_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'questionnaire_firstname';
break;
case 1:
$this->_sSort = 'questionnaire_surname';
break;
case 2:
$this->_sSort = 'questionnaire_age';
break;
case 3:
$this->_sSort = 'questionnaire_country';
break;
case 4:
$this->_sSort = 'questionnaire_region';
break;
case 5:
$this->_sSort = 'questionnaire_city';
break;
case 6:
$this->_sSort = 'questionnaire_rating_life';
break;
case 7:
$this->_sSort = 'questionnaire_rating_ambinet';
break;
case 8:
$this->_sSort = 'questionnaire_phone';
break;
case 9:
$this->_sSort = 'questionnaire_email';
break;
case 10:
$this->_sSort = 'questionnaire_id';
break;
case 11:
$this->_sSort = 'questionnaire_accept';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultQuestionnaireTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultQuestionnaireTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/admin/Operation/UserformOperationForm.php
<?php
class Admin_Operation_UserformOperationForm extends Common_Operation_Abstract
{
public function save(Zend_Controller_Request_Abstract $oRequest, Common_Form_Abstract_Form $oForm)
{
if (!$oRequest->isPost()) {
return false;
}
if (!$oForm->isValid($oRequest->getPost())) {
throw new Admin_Operation_UserError('Correct the errors in the form.');
}
try {
$aFormData = $oForm->getValues(false, false);
return $this->_saveToDatabase($aFormData);
} catch (Exception $e) {
throw new Admin_Operation_UserError('A form error occurred.');
}
}
private function _saveToDatabase($data)
{
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->beginTransaction();
try {
$oRow = null;
$oTab = $this->_getDefaultUserTab();
$key = $oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))];
if (isset($data[$key]) and !empty($data[$key])) {
$oRow = $this->_getDefaultUserTab()->find($data[$key])->current();
}
$id = $this->_getDefaultUserTab()->save($data);
$db->commit();
return $id;
} catch (Exception $e) {
$db->rollBack();
throw new Admin_Operation_UserError('An error occurred while saving: '.$e->getMessage());
}
}
public function getDefault($id)
{
return $this->_getDefaultUserTab()->find($id)->current()->toArray();
}
}
/application/Modules/admin/Operation/UserError.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package error
* @subpackage operation
*/
class Admin_Operation_UserError extends Exception
{
}
/application/Modules/admin/Operation/QuestionnaireError.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package error
* @subpackage operation
*/
class Admin_Operation_QuestionnaireError extends Exception
{
}
/application/Modules/admin/Operation/Userform9OperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Admin_Operation_Userform9OperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['user_user'])) {
$this->_aWhere[] = array('where' => array("user_user = '{$aParams['user_user']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
if (isset($aParams['user_password'])) {
$this->_aWhere[] = array('where' => array("user_password = '{$aParams['user_password']}'"));
} else {
throw new Admin_Operation_UserError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultUserTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('user_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'user_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(user_user like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_password like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(user_id like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'user_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'user_user';
break;
case 1:
$this->_sSort = 'user_password';
break;
case 2:
$this->_sSort = 'user_id';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultUserTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultUserTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/admin/Form/Questionnaireform.php
<?php
class Admin_Form_Questionnaireform extends Common_Form_Abstract_Form
{
public function getIdName()
{
return '';
}
protected function _setElements()
{
$this->addPrefixPath('Custom_Form_Element_', 'Custom/Form/Element/', 'element');
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_firstname', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_surname', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_age', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_country', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_region', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_city', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_rating_life', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_rating_ambinet', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_phone', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('showfield', 'questionnaire_email', array(
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('hidden', 'questionnaire_id', array(
'value' => '',
'required' => 0
));
}
}
/application/Modules/admin/Form/Userform.php
<?php
class Admin_Form_Userform extends Common_Form_Abstract_Form
{
public function getIdName()
{
return '';
}
protected function _setElements()
{
$this->addPrefixPath('Custom_Form_Element_', 'Custom/Form/Element/', 'element');
//--------------------------------------------------------------------------
$this->addElement('text', 'user_user', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'user_user',
'placeholder' => 'Login:'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'user_password', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'user_password',
'placeholder' => 'Password:'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('hidden', 'user_id', array(
'value' => '',
'required' => 0
));
}
}
/application/Modules/admin/Form/Userform9.php
<?php
class Admin_Form_Userform9 extends Common_Form_Abstract_Form
{
public function getIdName()
{
return '';
}
protected function _setElements()
{
$this->addPrefixPath('Custom_Form_Element_', 'Custom/Form/Element/', 'element');
//--------------------------------------------------------------------------
$this->addElement('text', 'user_user', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 0,
'label' => 'user_user',
'placeholder' => 'Login:'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'user_password', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 0,
'label' => 'user_password',
'placeholder' => 'Password:'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('hidden', 'user_id', array(
'value' => '',
'required' => 0
));
}
}
/application/Modules/admin/Form/Userform10.php
<?php
class Admin_Form_Userform10 extends Common_Form_Abstract_Form
{
public function getIdName()
{
return '';
}
protected function _setElements()
{
$this->addPrefixPath('Custom_Form_Element_', 'Custom/Form/Element/', 'element');
//--------------------------------------------------------------------------
$this->addElement('text', 'user_user', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 0,
'label' => 'user_user',
'placeholder' => 'Login'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'user_password', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 0,
'label' => 'user_password',
'placeholder' => 'Password'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('hidden', 'user_id', array(
'value' => '',
'required' => 0
));
}
}
/application/Modules/admin/controllers/QuestionnairegridController.php
<?php
/**
* Controller Grid class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_QuestionnairegridController extends Common_Controllers_View
{
public function questionnaireAction()
{
//$id = $this->getRequest()->getParam('a',0);
$oOperation = new Admin_Operation_QuestionnairegridOperationGrid();
//$oOperation->setParent($id);
$this->view->search = base64_decode($this->getRequest()->getParam('search', ''));
$oOperation->setSearch($this->view->search);
//$this->view->a = $this->getRequest()->getParam('a','');
$this->_addPaginator($oOperation);
//if ($this->view->paginator->count() == 0 AND $this->view->search == '') {
// $this->_helper->redirector->gotoRoute(array('a' => $id), '');
//}
}
public function deleteAction()
{
$oFrontCtrl = $this->getFrontController();
$oFrontCtrl->setParams(array('noViewRenderer' => true, 'neverRender' => true));
$oOperation = new Admin_Operation_QuestionnairegridOperationGrid();
$oOperation->delete($this->getRequest()->getParam('questionnaire_id'));
}
public function editAction()
{
$oFrontCtrl = $this->getFrontController();
$oFrontCtrl->setParams(array('noViewRenderer' => true, 'neverRender' => true));
$oOperation = new Admin_Operation_QuestionnairegridOperationGrid();
$oOperation->edit($this->getRequest()->getParam('questionnaire_id'), $this->getRequest()->getParam('field'), $this->getRequest()->getParam('value'));
}
public function rowAction()
{
$oOperation = new Admin_Operation_QuestionnairegridOperationGrid();
$oOperation->setId($this->getRequest()->getParam('questionnaire_id'));
$oOperation->init();
$this->view->item = $oOperation->getSelect()->query()->fetch();
}
}
/application/Modules/admin/controllers/UserformController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_UserformController extends Common_Controllers_View
{
public function userAction()
{
$id = $this->getRequest()->getParam('user_id', 0);
$idParent = $this->getRequest()->getParam('a', 0);
$oHelper = new Zend_View_Helper_Url();
$oForm = new Admin_Form_Userform(array(
'method' => 'post',
'request' => $this->getRequest(),
'cancel_action' => '',
'cancel_action_value' => array('a' => $idParent ),
'id' => $id,
'action' => $oHelper->url([], ''),
'decorators' => array(
array('ViewScript', array(
'viewScript' => 'userform/form/user.phtml'
))
)
));
try {
if (!$this->getRequest()->isPost() and $id) {
$oOperation = new Admin_Operation_UserformOperationGrid();
$oOperation->setId($id);
$oOperation->setSort($this->getRequest()->getParam('sort', ''));
$oOperation->setOrder($this->getRequest()->getParam('order', 0));
$oOperation->init();
$oRow = $oOperation->getSelect()->query(Zend_Db::FETCH_ASSOC)->fetch();
$oForm->populate($oRow);
} elseif ($this->getRequest()->isPost()) {
$oForm->populate($this->getRequest()->getPost());
$oOperation = new Admin_Operation_UserformOperationForm();
if ($id = $oOperation->save($this->getRequest(), $oForm)) {
Message_Operation_Flash::setMsg("The form was saved correctly.", Message_Operation_Flash::LEVEL_SUCCESS);
$this->_helper->redirector->gotoRoute(array('a' => $idParent), '');
} else {
http_response_code(500);
}
}
} catch (Admin_Operation_UserError $e) {
http_response_code(500);
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->view->form = $oForm;
}
public function checkAction()
{
try {
$oOperation = new Admin_Operation_UserformOperationGrid();
if ($oOperation->check($this->getRequest()->getParams())) {
Message_Operation_Flash::setMsg("Checked.", Message_Operation_Flash::LEVEL_SUCCESS);
} else {
Message_Operation_Flash::setMsg('Not checked', Message_Operation_Flash::LEVEL_DANGER);
}
} catch (Admin_Operation_UserError $e) {
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->_helper->redirector->gotoRoute(array('a' => null), 'admin_userform_user');
}
}
/application/Modules/admin/controllers/QuestionnaireformController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_QuestionnaireformController extends Common_Controllers_View
{
public function questionnaireAction()
{
$id = $this->getRequest()->getParam('questionnaire_id', 0);
$idParent = $this->getRequest()->getParam('a', 0);
$oHelper = new Zend_View_Helper_Url();
$oForm = new Admin_Form_Questionnaireform(array(
'method' => 'post',
'request' => $this->getRequest(),
'cancel_action' => '',
'cancel_action_value' => array('a' => $idParent ),
'id' => $id,
'action' => $oHelper->url([], ''),
'decorators' => array(
array('ViewScript', array(
'viewScript' => 'questionnaireform/form/questionnaire.phtml'
))
)
));
try {
if (!$this->getRequest()->isPost() and $id) {
$oOperation = new Admin_Operation_QuestionnaireformOperationGrid();
$oOperation->setId($id);
$oOperation->setSort($this->getRequest()->getParam('sort', ''));
$oOperation->setOrder($this->getRequest()->getParam('order', 0));
$oOperation->init();
$oRow = $oOperation->getSelect()->query(Zend_Db::FETCH_ASSOC)->fetch();
$oForm->populate($oRow);
} elseif ($this->getRequest()->isPost()) {
$oForm->populate($this->getRequest()->getPost());
$oOperation = new Admin_Operation_QuestionnaireformOperationForm();
if ($id = $oOperation->save($this->getRequest(), $oForm)) {
Message_Operation_Flash::setMsg("The form was saved correctly.", Message_Operation_Flash::LEVEL_SUCCESS);
$this->_helper->redirector->gotoRoute(array('a' => $idParent), '');
} else {
http_response_code(500);
}
}
} catch (Admin_Operation_QuestionnaireError $e) {
http_response_code(500);
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->view->form = $oForm;
}
public function checkAction()
{
try {
$oOperation = new Admin_Operation_QuestionnaireformOperationGrid();
if ($oOperation->check($this->getRequest()->getParams())) {
Message_Operation_Flash::setMsg("Checked.", Message_Operation_Flash::LEVEL_SUCCESS);
} else {
Message_Operation_Flash::setMsg('Not checked', Message_Operation_Flash::LEVEL_DANGER);
}
} catch (Admin_Operation_QuestionnaireError $e) {
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->_helper->redirector->gotoRoute(array('a' => null), 'admin_questionnaireform_questionnaire');
}
}
/application/Modules/admin/controllers/UsergridController.php
<?php
/**
* Controller Grid class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_UsergridController extends Common_Controllers_View
{
public function userAction()
{
//$id = $this->getRequest()->getParam('a',0);
$oOperation = new Admin_Operation_UsergridOperationGrid();
//$oOperation->setParent($id);
$this->view->search = base64_decode($this->getRequest()->getParam('search', ''));
$oOperation->setSearch($this->view->search);
//$this->view->a = $this->getRequest()->getParam('a','');
$this->_addPaginator($oOperation);
//if ($this->view->paginator->count() == 0 AND $this->view->search == '') {
// $this->_helper->redirector->gotoRoute(array('a' => $id), '');
//}
}
public function deleteAction()
{
$oFrontCtrl = $this->getFrontController();
$oFrontCtrl->setParams(array('noViewRenderer' => true, 'neverRender' => true));
$oOperation = new Admin_Operation_UsergridOperationGrid();
$oOperation->delete($this->getRequest()->getParam('user_id'));
}
public function editAction()
{
$oFrontCtrl = $this->getFrontController();
$oFrontCtrl->setParams(array('noViewRenderer' => true, 'neverRender' => true));
$oOperation = new Admin_Operation_UsergridOperationGrid();
$oOperation->edit($this->getRequest()->getParam('user_id'), $this->getRequest()->getParam('field'), $this->getRequest()->getParam('value'));
}
public function rowAction()
{
$oOperation = new Admin_Operation_UsergridOperationGrid();
$oOperation->setId($this->getRequest()->getParam('user_id'));
$oOperation->init();
$this->view->item = $oOperation->getSelect()->query()->fetch();
}
}
/application/Modules/admin/controllers/ViewController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_ViewController extends Common_Controllers_View
{
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function viewAction()
{
}
}
/application/Modules/admin/controllers/UserController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_UserController extends Common_Controllers_View
{
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function userAction()
{
}
}
/application/Modules/admin/controllers/PaneladminController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_PaneladminController extends Common_Controllers_View
{
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function paneladminAction()
{
}
}
/application/Modules/admin/controllers/LoginController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_LoginController extends Common_Controllers_View
{
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function loginAction()
{
}
}
/application/Modules/admin/controllers/QuestionnaireController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_QuestionnaireController extends Common_Controllers_View
{
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function questionnaireAction()
{
}
}
/application/Modules/admin/controllers/Userform10Controller.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_Userform10Controller extends Common_Controllers_View
{
public function userAction()
{
$id = $this->getRequest()->getParam('user_id', 0);
$idParent = $this->getRequest()->getParam('a', 0);
$oHelper = new Zend_View_Helper_Url();
$oForm = new Admin_Form_Userform10(array(
'method' => 'post',
'request' => $this->getRequest(),
'cancel_action' => '',
'cancel_action_value' => array('a' => $idParent ),
'id' => $id,
'action' => $oHelper->url([], ''),
'decorators' => array(
array('ViewScript', array(
'viewScript' => 'userform10/form/user.phtml'
))
)
));
try {
if (!$this->getRequest()->isPost() and $id) {
$oOperation = new Admin_Operation_Userform10OperationGrid();
$oOperation->setId($id);
$oOperation->setSort($this->getRequest()->getParam('sort', ''));
$oOperation->setOrder($this->getRequest()->getParam('order', 0));
$oOperation->init();
$oRow = $oOperation->getSelect()->query(Zend_Db::FETCH_ASSOC)->fetch();
$oForm->populate($oRow);
} elseif ($this->getRequest()->isPost()) {
$oForm->populate($this->getRequest()->getPost());
$oOperation = new Admin_Operation_Userform10OperationForm();
if ($id = $oOperation->save($this->getRequest(), $oForm)) {
Message_Operation_Flash::setMsg("The form was saved correctly.", Message_Operation_Flash::LEVEL_SUCCESS);
$this->_helper->redirector->gotoRoute(array('a' => $idParent), '');
} else {
http_response_code(500);
}
}
} catch (Admin_Operation_UserError $e) {
http_response_code(500);
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->view->form = $oForm;
}
public function checkAction()
{
try {
$oOperation = new Admin_Operation_Userform10OperationGrid();
if ($oOperation->check($this->getRequest()->getParams())) {
Message_Operation_Flash::setMsg("Checked.", Message_Operation_Flash::LEVEL_SUCCESS);
} else {
Message_Operation_Flash::setMsg('Not checked', Message_Operation_Flash::LEVEL_DANGER);
}
} catch (Admin_Operation_UserError $e) {
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->_helper->redirector->gotoRoute(array('a' => null), 'admin_userform10_user');
}
}
/application/Modules/admin/controllers/Userform9Controller.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_Userform9Controller extends Common_Controllers_View
{
public function userAction()
{
$id = $this->getRequest()->getParam('user_id', 0);
$idParent = $this->getRequest()->getParam('a', 0);
$oHelper = new Zend_View_Helper_Url();
$oForm = new Admin_Form_Userform9(array(
'method' => 'post',
'request' => $this->getRequest(),
'cancel_action' => '',
'cancel_action_value' => array('a' => $idParent ),
'id' => $id,
'action' => $oHelper->url([], ''),
'decorators' => array(
array('ViewScript', array(
'viewScript' => 'userform9/form/user.phtml'
))
)
));
try {
if (!$this->getRequest()->isPost() and $id) {
$oOperation = new Admin_Operation_Userform9OperationGrid();
$oOperation->setId($id);
$oOperation->setSort($this->getRequest()->getParam('sort', ''));
$oOperation->setOrder($this->getRequest()->getParam('order', 0));
$oOperation->init();
$oRow = $oOperation->getSelect()->query(Zend_Db::FETCH_ASSOC)->fetch();
$oForm->populate($oRow);
} elseif ($this->getRequest()->isPost()) {
$oForm->populate($this->getRequest()->getPost());
$oOperation = new Admin_Operation_Userform9OperationForm();
if ($id = $oOperation->save($this->getRequest(), $oForm)) {
Message_Operation_Flash::setMsg("The form was saved correctly.", Message_Operation_Flash::LEVEL_SUCCESS);
$this->_helper->redirector->gotoRoute(array('a' => $idParent), '');
} else {
http_response_code(500);
}
}
} catch (Admin_Operation_UserError $e) {
http_response_code(500);
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->view->form = $oForm;
}
public function checkAction()
{
try {
$oOperation = new Admin_Operation_Userform9OperationGrid();
if ($oOperation->check($this->getRequest()->getParams())) {
Message_Operation_Flash::setMsg("Checked.", Message_Operation_Flash::LEVEL_SUCCESS);
} else {
Message_Operation_Flash::setMsg('Not checked', Message_Operation_Flash::LEVEL_DANGER);
}
} catch (Admin_Operation_UserError $e) {
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->_helper->redirector->gotoRoute(array('a' => null), 'admin_userform9_user');
}
}
/application/Modules/admin/controllers/AdminController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Admin_AdminController extends Common_Controllers_LayoutView
{
protected $_sLayout = "layout";
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function adminAction()
{
}
}
/application/Modules/front/Operation/QuestionnaireformOperationForm.php
<?php
class Front_Operation_QuestionnaireformOperationForm extends Common_Operation_Abstract
{
public function save(Zend_Controller_Request_Abstract $oRequest, Common_Form_Abstract_Form $oForm)
{
if (!$oRequest->isPost()) {
return false;
}
if (!$oForm->isValid($oRequest->getPost())) {
throw new Front_Operation_QuestionnaireError('Correct the errors in the form.');
}
try {
$aFormData = $oForm->getValues(false, false);
return $this->_saveToDatabase($aFormData);
} catch (Exception $e) {
throw new Front_Operation_QuestionnaireError('A form error occurred.');
}
}
private function _saveToDatabase($data)
{
$db = Zend_Db_Table_Abstract::getDefaultAdapter();
$db->beginTransaction();
try {
$oRow = null;
$oTab = $this->_getDefaultQuestionnaireTab();
$key = $oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))];
if (isset($data[$key]) and !empty($data[$key])) {
$oRow = $this->_getDefaultQuestionnaireTab()->find($data[$key])->current();
}
$id = $this->_getDefaultQuestionnaireTab()->save($data);
$db->commit();
return $id;
} catch (Exception $e) {
$db->rollBack();
throw new Front_Operation_QuestionnaireError('An error occurred while saving: '.$e->getMessage());
}
}
public function getDefault($id)
{
return $this->_getDefaultQuestionnaireTab()->find($id)->current()->toArray();
}
}
/application/Modules/front/Operation/QuestionnaireformOperationGrid.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package GRID
* @subpackage operation
*/
class Front_Operation_QuestionnaireformOperationGrid extends Common_Operation_Abstract implements Common_Grid_Delegate_Interface
{
private $_oBuilder;
protected $_sSort;
protected $_sOrder;
protected $_sSearch = '';
protected $_idParent = null;
private $_aWhere = array();
/**
* Realizacja Common_Grid_Operation_Interface.
* Odpowiada za pobranie danych
* @return Common_Db_ListResult
*/
public function init()
{
$this->_oBuilder = new Common_Grid_Builder($this);
}
/**
*
* @return type Zend_Db_Select
*/
public function getSelect()
{
return $this->_oBuilder->getSelect();
}
public function getSelectCount()
{
return $this->_oBuilder->getSelectCount();
}
public function getList(array $aParams)
{
$this->_setWhere($aParams);
$this->init();
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Mgr')->newInstance($aParams));
$this->_oBuilder->addPlugin(Common_Class::get('Common_Grid_Filter_Paging')->newInstance($aParams));
return $this->_oBuilder->execute();
}
private function _setWhere($aParams)
{
if (isset($aParams['questionnaire_firstname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_firstname = '{$aParams['questionnaire_firstname']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_surname'])) {
$this->_aWhere[] = array('where' => array("questionnaire_surname = '{$aParams['questionnaire_surname']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_age'])) {
$this->_aWhere[] = array('where' => array("questionnaire_age = '{$aParams['questionnaire_age']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_country'])) {
$this->_aWhere[] = array('where' => array("questionnaire_country = '{$aParams['questionnaire_country']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_region'])) {
$this->_aWhere[] = array('where' => array("questionnaire_region = '{$aParams['questionnaire_region']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_city'])) {
$this->_aWhere[] = array('where' => array("questionnaire_city = '{$aParams['questionnaire_city']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_life'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_life = '{$aParams['questionnaire_rating_life']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_rating_ambinet'])) {
$this->_aWhere[] = array('where' => array("questionnaire_rating_ambinet = '{$aParams['questionnaire_rating_ambinet']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_email'])) {
$this->_aWhere[] = array('where' => array("questionnaire_email = '{$aParams['questionnaire_email']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_accept'])) {
$this->_aWhere[] = array('where' => array("questionnaire_accept = '{$aParams['questionnaire_accept']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
if (isset($aParams['questionnaire_phone'])) {
$this->_aWhere[] = array('where' => array("questionnaire_phone = '{$aParams['questionnaire_phone']}'"));
} else {
throw new Front_Operation_QuestionnaireError("no value");
}
}
/**
* Realizacja Common_Grid_Delegate_Interface.
* Konfiguracja podstawowego SQL'a wg specyfikacji metoda( parametry) itd.
* @return array
*/
public function getMainSelect()
{
$aResult = array(array('from' => array('table' => array($this->_getDefaultQuestionnaireTab()->getTableName()),
'fields' => array('*')
)
)
);
if (count($this->_aWhere)) {
$aResult = array_merge($aResult, $this->_aWhere);
}
if ($this->_sSort) {
$aResult[]['order'] = array($this->_sSort . ' ' . $this->_sOrder);
} else {
$aResult[]['order'] = array('questionnaire_id DESC');
}
if ($this->_id) {
$aResult[]['where'][] = 'questionnaire_id=' . $this->_id;
}
if ($this->_sSearch) {
$aResult[]['ORwhere'][] = "(questionnaire_firstname like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_surname like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_age like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_country like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_region like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_city like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_rating_life like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_rating_ambinet like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_phone like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_email like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_id like '%" . $this->_sSearch . "%')";
$aResult[]['ORwhere'][] = "(questionnaire_accept like '%" . $this->_sSearch . "%')";
}
return $aResult;
}
public function setOrder($iOrder)
{
if ($iOrder) {
$this->_sOrder = 'ASC';
} else {
$this->_sOrder = 'DESC';
}
}
public function setSortAsField($sSort)
{
if ($sSort) {
$this->_sSort = $sSort;
} else {
$this->_sSort = 'questionnaire_id';
}
}
public function setSort($iSort)
{
switch ($iSort) {
case 0:
$this->_sSort = 'questionnaire_firstname';
break;
case 1:
$this->_sSort = 'questionnaire_surname';
break;
case 2:
$this->_sSort = 'questionnaire_age';
break;
case 3:
$this->_sSort = 'questionnaire_country';
break;
case 4:
$this->_sSort = 'questionnaire_region';
break;
case 5:
$this->_sSort = 'questionnaire_city';
break;
case 6:
$this->_sSort = 'questionnaire_rating_life';
break;
case 7:
$this->_sSort = 'questionnaire_rating_ambinet';
break;
case 8:
$this->_sSort = 'questionnaire_phone';
break;
case 9:
$this->_sSort = 'questionnaire_email';
break;
case 10:
$this->_sSort = 'questionnaire_id';
break;
case 11:
$this->_sSort = 'questionnaire_accept';
break;
default:
$this->_sSort = '';
break;
}
}
public function setSearch($sName)
{
$this->_sSearch = $sName;
}
public function setParent($id)
{
$this->_idParent = $id;
}
/**
* @todo mozna zrobic to w transakcji
* @todo powinny usuwac sie powiazania wynikajace z logiki delete cascade
*/
public function delete($id)
{
$this->_getDefaultQuestionnaireTab()->find($id)->current()->delete();
}
public function edit($id, $sField, $vValue)
{
$this->setId($id);
$this->init();
$item = $this->getSelect()->query()->fetch();
$arr = explode('_', $sField);
$idName = $arr[0] . '_id';
$idVal = $item[$idName];
if ($oTab = $this->_getDefaultQuestionnaireTab() and
$oTab->info(Zend_Db_Table_Abstract::PRIMARY)[key($oTab->info(Zend_Db_Table_Abstract::PRIMARY))] == $idName) {
$oRow = $oTab->find($idVal)->current();
}
if ($oRow) {
$oRow->$sField = $vValue;
$oRow->save();
}
}
public function check($aParams)
{
return ($this->getList($aParams)->iCount? true: false);
}
}
/application/Modules/front/Operation/QuestionnaireError.php
<?php
/**
* @author Adam Nielski
* @copyright Future-Soft Sp. z o.o.
* @version 1.0
* @package error
* @subpackage operation
*/
class Front_Operation_QuestionnaireError extends Exception
{
}
/application/Modules/front/Form/Questionnaireform.php
<?php
class Front_Form_Questionnaireform extends Common_Form_Abstract_Form
{
public function getIdName()
{
return '';
}
protected function _setElements()
{
$this->addPrefixPath('Custom_Form_Element_', 'Custom/Form/Element/', 'element');
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_firstname', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'questionnaire_firstname',
'placeholder' => 'First name'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_surname', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'questionnaire_surname',
'placeholder' => 'Surname'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_age', array(
'filters' => array('StringTrim'),
'validators' => array(
array('Digits', true, array('locale' => 'en')),
new Zend_Validate_GreaterThan(17),
new Zend_Validate_LessThan(119),
),
'required' => 1,
'label' => 'questionnaire_age',
'placeholder' => 'Age'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_country', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'questionnaire_country',
'placeholder' => 'Country'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_region', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'questionnaire_region',
'placeholder' => 'Region'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_city', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'questionnaire_city',
'placeholder' => 'City'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('select', 'questionnaire_rating_life', array(
'filters' => array('StringTrim'),
'required' => 1,
'label' => 'questionnaire_rating_life',
'multioptions' => (($oDataSet = new Default_Model_Rowset_QuestionnaireRatingLife(array()))?$oDataSet->getDataToSelect():array()),
'placeholder' => 'Rating life'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('select', 'questionnaire_rating_ambinet', array(
'filters' => array('StringTrim'),
'required' => 1,
'label' => 'questionnaire_rating_ambinet',
'multioptions' => (($oDataSet = new Default_Model_Rowset_QuestionnaireRatingAmbinet(array()))?$oDataSet->getDataToSelect():array()),
'placeholder' => 'Rating ambient'
));
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_email', array(
'filters' => array('StringTrim'),
'validators' => array(
array('StringLength', false, array(0, 100)),
),
'required' => 1,
'label' => 'questionnaire_email',
'placeholder' => 'Email'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('checkbox', 'questionnaire_accept', array(
'filters' => array('StringTrim'),
'validators' => [
new Default_Form_Validate_RequiredIfCheckbox('rrr_ttt')
],
'required' => true,
'label' => 'questionnaire_accept',
'placeholder' => 'I accept the terms and conditions'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('text', 'questionnaire_phone', array(
'filters' => array('StringTrim'),
'validators' => array(
array('Digits', true, array('locale' => 'en')),
),
'required' => 0,
'label' => 'questionnaire_phone',
'placeholder' => 'Phone'
));
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
//--------------------------------------------------------------------------
$this->addElement('hidden', 'questionnaire_id', array(
'value' => '',
'required' => 0
));
}
}
/application/Modules/front/controllers/ThanksController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Front_ThanksController extends Common_Controllers_View
{
public function init()
{
$this->view->aJavaScript = array("form.js");
parent::init();
}
public function thanksAction()
{
}
}
/application/Modules/front/controllers/QuestionnaireformController.php
<?php
/**
* Controller class
*
* @author <autor>
* @copyright (c) <company>, <author>
* @version 1.0.0
*/
class Front_QuestionnaireformController extends Common_Controllers_View
{
public function questionnaireAction()
{
$id = $this->getRequest()->getParam('questionnaire_id', 0);
$idParent = $this->getRequest()->getParam('a', 0);
$oHelper = new Zend_View_Helper_Url();
$oForm = new Front_Form_Questionnaireform(array(
'method' => 'post',
'request' => $this->getRequest(),
'cancel_action' => '',
'cancel_action_value' => array('a' => $idParent ),
'id' => $id,
'action' => $oHelper->url([], ''),
'decorators' => array(
array('ViewScript', array(
'viewScript' => 'questionnaireform/form/questionnaire.phtml'
))
)
));
try {
if (!$this->getRequest()->isPost() and $id) {
$oOperation = new Front_Operation_QuestionnaireformOperationGrid();
$oOperation->setId($id);
$oOperation->setSort($this->getRequest()->getParam('sort', ''));
$oOperation->setOrder($this->getRequest()->getParam('order', 0));
$oOperation->init();
$oRow = $oOperation->getSelect()->query(Zend_Db::FETCH_ASSOC)->fetch();
$oForm->populate($oRow);
} elseif ($this->getRequest()->isPost()) {
$oForm->populate($this->getRequest()->getPost());
$oOperation = new Front_Operation_QuestionnaireformOperationForm();
if ($id = $oOperation->save($this->getRequest(), $oForm)) {
Message_Operation_Flash::setMsg("The form was saved correctly.", Message_Operation_Flash::LEVEL_SUCCESS);
$this->_helper->redirector->gotoRoute(array('a' => $idParent), '');
} else {
http_response_code(500);
}
}
} catch (Front_Operation_QuestionnaireError $e) {
http_response_code(500);
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->view->form = $oForm;
}
public function checkAction()
{
try {
$oOperation = new Front_Operation_QuestionnaireformOperationGrid();
if ($oOperation->check($this->getRequest()->getParams())) {
Message_Operation_Flash::setMsg("Checked.", Message_Operation_Flash::LEVEL_SUCCESS);
} else {
Message_Operation_Flash::setMsg('Not checked', Message_Operation_Flash::LEVEL_DANGER);
}
} catch (Front_Operation_QuestionnaireError $e) {
Message_Operation_Flash::setMsg($e->getMessage(), Message_Operation_Flash::LEVEL_DANGER);
}
$this->_helper->redirector->gotoRoute(array('a' => null), 'front_questionnaireform_questionnaire');
}
}