/application/modules/geocontexter/controllers/KeywordEditController.php
PHP | 303 lines | 185 code | 58 blank | 60 comment | 17 complexity | c1b79da858ea2f4d94229a63ff8637f5 MD5 | raw file
- <?php
- /**
- * GeoContexter
- * @link http://code.google.com/p/geocontexter/
- * @package GeoContexter
- */
- /**
- * Edit keyword
- *
- * @package GeoContexter
- * @license http://www.opensource.org/licenses/bsd-license.php New BSD License
- * @author Armand Turpel <geocontexter@gmail.com>
- * @version $Rev: 828 $ / $LastChangedDate: 2011-02-27 10:30:28 +0100 (Sun, 27 Feb 2011) $ / $Author: armand.turpel $
- */
- class Geocontexter_KeywordEditController extends Mozend_Controller_Action_AbstractAdmin
- {
- public function preDispatch()
- {
- // set view. we keep allways the index view
- //
- $this->_helper->viewRenderer->setScriptAction('index');
- $this->id_keyword =$this->request->getParam('id_keyword');
- if((null === $this->id_keyword) || (0 == $this->id_keyword))
- {
- return $this->error( '0 or no id_keyword request parameter defined.', __file__, __line__ );
- }
- $this->view->partialData['active_page'] = 'edit';
- $this->view->partialData['id_keyword'] = $this->id_keyword;
- $this->view->id_keyword = $this->id_keyword;
- $this->view->keyword_branch_result = array();
- $this->view->attribute_groups = array();
- $this->view->attribute_id_group = '';
- $this->view->keyword_name = '';
- $this->view->keyword_description = '';
- $this->view->keyword_id_status = 100;
- $this->view->keyword_lang = 'en';
- $this->view->tabindex_after_attributes = 8;
- $this->view->error = array();
- $session = Zend_Registry::get('session');
- $this->register_model_callbacks( $session );
- }
- public function indexAction()
- {
- $this->init_data();
- }
- private function init_data()
- {
- // get keyword branch
- //
- $keyword_branch = new Geocontexter_Model_KeywordGetBranch;
- $params = array('id_keyword' => $this->id_keyword) ;
- $result_branch = $keyword_branch->get( $params );
- if($result_branch instanceof Mozend_ModelError)
- {
- return $this->error( $result_branch->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->keyword_branch_result = $result_branch;
- }
- // get availaible languages
- //
- $languages = new Geocontexter_Model_LanguagesGet;
- // optional
- $params = array('enable' => 'true');
- $lang_result = $languages->get( $params );
- if($lang_result instanceof Mozend_ModelError)
- {
- return $this->error( $lang_result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->languages = $lang_result;
- }
- // get all keyword related attribute groups
- //
- $attribute_groups = new Geocontexter_Model_AttributeGroupsGet;
- $params = array('id_table' => 4);
- $attribute_result = $attribute_groups->get( $params );
- if($attribute_result instanceof Mozend_ModelError)
- {
- return $this->error( $attribute_result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->attribute_groups = $attribute_result;
- }
- // get keyword
- //
- $keyword = new Geocontexter_Model_KeywordGet;
- $params = array('id_keyword' => $this->id_keyword);
- $result = $keyword->get( $params );
- if($result instanceof Mozend_ModelError)
- {
- return $this->error( $result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->result = $result;
- // assign html head title
- //
- $this->view->headTitle('Edit keyword ' . $result['title'], 'PREPEND');
- }
- // Assign additional attributes with values
- //
- if($result['id_attribute_group'] != null)
- {
- $attributes_values = new Geocontexter_Model_AttributeAssignKeyValue;
- // we pass this array to the partial view helper "_additional_attributes.phtml"
- //
- $this->view->additionalAttributes = array();
- $this->view->additionalAttributes['attributes'] = $attributes_values->get( $result );
- $this->view->additionalAttributes['id_attribute_group'] = $result['id_attribute_group'];
- $this->view->additionalAttributes['tabindex'] = 7;
- // get tabindex after the aaditional attribute fields
- //
- $this->view->tabindex_after_attributes += count($this->view->additionalAttributes['attributes']) - 1;
- }
- }
- /**
- * update keyword
- */
- public function updateAction()
- {
- // check on cancel action
- //
- $cancel = $this->request->getPost('cancel');
- if($cancel !== null)
- {
- $this->_redirect($this->view->adminAreaToken .
- '/geocontexter/keyword/index/id_keyword/' . $this->request->getPost('keyword_id_parent'));
- }
- $params = array();
- $attribute_id_group = $this->request->getPost('attribute_group');
- // fetch addditional attributes values if set
- //
- if(!empty($attribute_id_group))
- {
- $attributes_values = new Geocontexter_Model_AttributeAssignKeyValue;
- $this->view->attribute_id_group = $attribute_id_group;
- // we pass this array to the partial view helper "_additional_attributes.phtml"
- //
- $this->view->additionalAttributes = array();
- $_attr_result = $this->view->additionalAttributes['attributes']
- = $attributes_values->getAttributesWithValuesByOrder( $attribute_id_group, $this->request->getPost() );
- if($attr_result instanceof Mozend_ModelError)
- {
- return $this->error( $attr_result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->view->additionalAttributes['id_attribute_group'] = $attribute_id_group;
- $this->view->additionalAttributes['tabindex'] = 7;
- // get tabindex after the additional attribute fields
- //
- $this->view->tabindex_after_attributes += count($this->view->additionalAttributes['attributes']) - 1;
- }
- // fetch attribute values and prepare/convert it in postgresql array format for insert as new keyword
- //
- $assign_result = $attributes_values->assign( $attribute_id_group, $this->request->getPost() );
- if($assign_result instanceof Mozend_ModelError)
- {
- return $this->error( $assign_result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $params['data'] = $assign_result;
- $params['data']['id_attribute_group'] = $attribute_id_group;
- }
- }
- else
- {
- // remove reference to attribute group
- // and delete any additional attribute values
- //
- $params['data']['attribute_value'] = null;
- }
- $this->view->error = array();
- $this->view->result = array();
- $params['id_keyword'] = $this->id_keyword;
- $this->view->result['title'] =
- $params['data']['title'] = $this->request->getPost('keyword_title');
- $this->view->result['description'] =
- $params['data']['description'] = $this->request->getPost('keyword_description');
- $this->view->result['id_parent'] =
- $params['data']['id_parent'] = $this->request->getPost('keyword_id_parent');
- $this->view->result['id_status'] =
- $params['data']['id_status'] = $this->request->getPost('keyword_id_status');
- $this->view->result['lang'] =
- $params['data']['lang'] = $this->request->getPost('keyword_lang');
- if(empty($params['data']['title']))
- {
- $this->view->error[] = 'Keyword title is empty';
- $this->view->headTitle('Error: keyword title field is empty', 'PREPEND');
- }
- if(count($this->view->error) > 0)
- {
- $this->init_data();
- return;
- }
- // add item attribute
- //
- $keyword = new Geocontexter_Model_KeywordUpdate;
- $result = $keyword->update( $params );
- if($result instanceof Mozend_ModelError)
- {
- return $this->error( $result->getErrorString(), __file__, __line__ );
- }
- else
- {
- $this->_redirect($this->view->adminAreaToken .
- '/geocontexter/keyword/index/id_keyword/' . $this->view->result['id_parent']);
- }
- }
- /**
- * Register of model callback classes
- *
- * @param object $session
- */
- private function register_model_callbacks( & $session )
- {
- $action_callback = new Geocontexter_Model_ModelCallback( $session );
- // url to reload after a model callback was done
- //
- $this->opener_url = $this->view->baseUrl().'/'.$this->view->adminAreaToken.'/geocontexter/keyword-edit/index/id_keyword/'.$this->id_keyword;
- //
- // item_keywords
- //
- $params_keyword =
- array('model_class' => 'Geocontexter_Model_KeywordUpdate',
- 'model_class_methode' => 'updateKeywordParent',
- 'model_field' => 'id_parent',
- 'check_circular' => true,
- 'id_name' => 'id_keyword',
- 'id_value' => $this->id_keyword,
- 'input_type' => 'radio',
- 'opener_url' => $this->opener_url);
- $callback_number = $action_callback->register( $params_keyword );
- if($callback_number instanceof Mozend_ModelError)
- {
- return $this->error( $callback_number->getErrorString(), __file__, __line__ );
- }
- $this->view->keyword_callback_number = $callback_number;
- }
- }