[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Settings/LayoutEditor/actions/ -> Block.php (source)

   1  <?php
   2  
   3  /*+**********************************************************************************
   4   * The contents of this file are subject to the vtiger CRM Public License Version 1.1
   5   * ("License"); You may not use this file except in compliance with the License
   6   * The Original Code is:  vtiger CRM Open Source
   7   * The Initial Developer of the Original Code is vtiger.
   8   * Portions created by vtiger are Copyright (C) vtiger.
   9   * All Rights Reserved.
  10   ************************************************************************************/
  11  
  12  class Settings_LayoutEditor_Block_Action extends Settings_Vtiger_Index_Action {
  13      
  14      public function __construct() {
  15          $this->exposeMethod('save');
  16          $this->exposeMethod('updateSequenceNumber');
  17          $this->exposeMethod('delete');
  18      }
  19      
  20      public function save(Vtiger_Request $request) {
  21          $blockId = $request->get('blockid');
  22          $sourceModule = $request->get('sourceModule');
  23          $modueInstance = Vtiger_Module_Model::getInstance($sourceModule);
  24  
  25          if(!empty($blockId)) {
  26              $blockInstance = Settings_LayoutEditor_Block_Model::getInstance($blockId);
  27              $blockInstance->set('display_status',$request->get('display_status'));
  28              $isDuplicate = false;
  29          } else {
  30              $blockInstance = new Settings_LayoutEditor_Block_Model();
  31              $blockInstance->set('label', $request->get('label'));
  32              $blockInstance->set('iscustom', '1');
  33               //Indicates block id after which you need to add the new block
  34              $beforeBlockId = $request->get('beforeBlockId');
  35              if(!empty($beforeBlockId)) {
  36                  $beforeBlockInstance = Vtiger_Block_Model::getInstance($beforeBlockId);
  37                  $beforeBlockSequence = $beforeBlockInstance->get('sequence');
  38                  $newBlockSequence = ($beforeBlockSequence+1);
  39                  //To give sequence one more than prev block 
  40                  $blockInstance->set('sequence', $newBlockSequence);
  41                  //push all other block down so that we can keep new block there
  42                  Vtiger_Block_Model::pushDown($beforeBlockSequence, $modueInstance->getId());
  43              }
  44              $isDuplicate = Vtiger_Block_Model::checkDuplicate($request->get('label'), $modueInstance->getId());
  45          }
  46  
  47          $response = new Vtiger_Response();
  48          if (!$isDuplicate) {
  49              try{
  50                  $id = $blockInstance->save($modueInstance);
  51                  $responseInfo = array('id'=>$id,'label'=>$blockInstance->get('label'),'isCustom'=>$blockInstance->isCustomized(), 'beforeBlockId'=>$beforeBlockId, 'isAddCustomFieldEnabled'=>$blockInstance->isAddCustomFieldEnabled());
  52                  if(empty($blockId)) {
  53                      //if mode is create add all blocks sequence so that client will place the new block correctly
  54                      $responseInfo['sequenceList'] = Vtiger_Block_Model::getAllBlockSequenceList($modueInstance->getId());
  55                  }
  56                  $response->setResult($responseInfo);
  57              } catch(Exception $e) {
  58                  $response->setError($e->getCode(),$e->getMessage());
  59              }
  60          } else {
  61              $response->setError('502', vtranslate('LBL_DUPLICATES_EXIST', $request->getModule(false)));
  62          }
  63          $response->emit();
  64      }
  65      
  66      public function updateSequenceNumber(Vtiger_Request $request) {
  67          $response = new Vtiger_Response();
  68          try{
  69              $sequenceList = $request->get('sequence');
  70              Vtiger_Block_Model::updateSequenceNumber($sequenceList);
  71              $response->setResult(array('success'=>true));
  72          }catch(Exception $e) {
  73              $response->setError($e->getCode(),$e->getMessage());
  74          }
  75          $response->emit();
  76      }
  77      
  78      
  79      public function delete(Vtiger_Request $request) {
  80          $response = new Vtiger_Response();
  81          $blockId = $request->get('blockid');
  82          $checkIfFieldsExists = Vtiger_Block_Model::checkFieldsExists($blockId);
  83          if($checkIfFieldsExists) {
  84              $response->setError('502','Fields exists for the block');
  85              $response->emit();
  86              return;
  87          }
  88          $blockInstance = Vtiger_Block_Model::getInstance($blockId);
  89          if(!$blockInstance->isCustomized()) {
  90              $response->setError('502','Cannot delete non custom blocks');
  91              $response->emit();
  92              return;
  93          }
  94          try{
  95              $blockInstance->delete(false);
  96              $response->setResult(array('success'=>true));
  97          }catch(Exception $e) {
  98              $response->setError($e->getCode(),$e->getMessage());
  99          }
 100          $response->emit();
 101      }
 102      
 103      public function validateRequest(Vtiger_Request $request) { 
 104          $request->validateWriteAccess(); 
 105      } 
 106  
 107  }


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1