Overview

Packages

  • application
    • commands
    • components
      • actions
      • filters
      • leftWidget
      • permissions
      • sortableWidget
      • util
      • webupdater
      • x2flow
        • actions
        • triggers
      • X2GridView
      • X2Settings
    • controllers
    • models
      • embedded
    • modules
      • accounts
        • controllers
        • models
      • actions
        • controllers
        • models
      • calendar
        • controllers
        • models
      • charts
        • models
      • contacts
        • controllers
        • models
      • docs
        • components
        • controllers
        • models
      • groups
        • controllers
        • models
      • marketing
        • components
        • controllers
        • models
      • media
        • controllers
        • models
      • mobile
        • components
      • opportunities
        • controllers
        • models
      • products
        • controllers
        • models
      • quotes
        • controllers
        • models
      • services
        • controllers
        • models
      • template
        • models
      • users
        • controllers
        • models
      • workflow
        • controllers
        • models
      • x2Leads
        • controllers
        • models
  • None
  • system
    • base
    • caching
    • console
    • db
      • ar
      • schema
    • validators
    • web
      • actions
      • auth
      • helpers
      • widgets
        • captcha
        • pagers
  • zii
    • widgets
      • grid

Classes

  • BaseDocsMassAction
  • CommonFieldsBehavior
  • Expression
  • MassAction
  • MassAddToList
  • MassCompleteAction
  • MassMoveFileSysObjToFolder
  • MassRemoveFromList
  • MassRenameFileSysObj
  • MassUncompleteAction
  • MobileRecentItems
  • ModulePanelItem
  • NewListFromSelection
  • PanelItem
  • QuickCRUDBehavior
  • RecentItemPanelItem
  • ServiceRoutingBehavior
  • SettingsPanelItem
  • X2AddressBehavior
  • X2AuthCache
  • X2BaseListViewBehavior

Exceptions

  • TwitterFeedWidgetException
  • Overview
  • Package
  • Class
  • Tree
  1: <?php
  2: /*****************************************************************************************
  3:  * X2Engine Open Source Edition is a customer relationship management program developed by
  4:  * X2Engine, Inc. Copyright (C) 2011-2016 X2Engine Inc.
  5:  * 
  6:  * This program is free software; you can redistribute it and/or modify it under
  7:  * the terms of the GNU Affero General Public License version 3 as published by the
  8:  * Free Software Foundation with the addition of the following permission added
  9:  * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
 10:  * IN WHICH THE COPYRIGHT IS OWNED BY X2ENGINE, X2ENGINE DISCLAIMS THE WARRANTY
 11:  * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
 12:  * 
 13:  * This program is distributed in the hope that it will be useful, but WITHOUT
 14:  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 15:  * FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for more
 16:  * details.
 17:  * 
 18:  * You should have received a copy of the GNU Affero General Public License along with
 19:  * this program; if not, see http://www.gnu.org/licenses or write to the Free
 20:  * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 21:  * 02110-1301 USA.
 22:  * 
 23:  * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley,
 24:  * California 95067, USA. or at email address contact@x2engine.com.
 25:  * 
 26:  * The interactive user interfaces in modified source and object code versions
 27:  * of this program must display Appropriate Legal Notices, as required under
 28:  * Section 5 of the GNU Affero General Public License version 3.
 29:  * 
 30:  * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
 31:  * these Appropriate Legal Notices must retain the display of the "Powered by
 32:  * X2Engine" logo. If the display of the logo is not reasonably feasible for
 33:  * technical reasons, the Appropriate Legal Notices must display the words
 34:  * "Powered by X2Engine".
 35:  *****************************************************************************************/
 36: 
 37: class MassMoveFileSysObjToFolder extends BaseDocsMassAction {
 38: 
 39:     public $hasButton = true;
 40: 
 41:     /**
 42:      * Renders the mass action dialog, if applicable
 43:      * @param string $gridId id of grid view
 44:      */
 45:     public function renderDialog ($gridId, $modelName) {
 46:         echo "
 47:             <div class='mass-action-dialog' 
 48:              id='".$this->getDialogId ($gridId)."' style='display: none;'>
 49:                 <span>".
 50:                     Yii::t('app', 'Move to')."
 51:                 </span>
 52:                 <span style='display: none;'>".
 53:                     Yii::t('app', 'Move to')."
 54:                 </span>
 55:                 <span class='target-folder'>".CHtml::encode (Yii::t('docs', 'Docs'))."</span>
 56:                 <input name='targetFolderId' type='hidden' val='' />
 57:                 <br/>
 58:                 <div class='folder-selector'>
 59:                 </div>
 60:             </div>";
 61:     }
 62: 
 63:     /**
 64:      * Renders the mass action button, if applicable
 65:      */
 66:     public function renderButton () {
 67:         if (!$this->hasButton) return;
 68:         
 69:         echo "
 70:             <a href='#' title='".CHtml::encode ($this->getLabel ())."'
 71:              data-mass-action='".get_class ($this)."'
 72:              data-allow-multiple='".($this->allowMultiple ? 'true' : 'false')."'
 73:              class='fa fa-folder fa-lg mass-action-button x2-button mass-action-button-".
 74:                 get_class ($this)."'>
 75:             </a>";
 76:     }
 77: 
 78: 
 79:     /**
 80:      * @return string label to display in the dropdown list
 81:      */
 82:     public function getLabel () {
 83:         if (!isset ($this->_label)) {
 84:             $this->_label = Yii::t('app', 'Move to');
 85:         }
 86:         return $this->_label;
 87:     }
 88: 
 89:     public function getPackages () {
 90:         return array_merge (parent::getPackages (), array (
 91:             'X2MassMoveFileSysObjToFolder' => array(
 92:                 'baseUrl' => Yii::app()->request->baseUrl,
 93:                 'js' => array(
 94:                     'js/X2GridView/MassMoveFileSysObjToFolder.js',
 95:                 ),
 96:                 'depends' => array ('X2MassAction', 'BaseDocsMassActionJS'),
 97:             ),
 98:         ));
 99:     }
100: 
101:     /**
102:      * @param array $gvSelection array of ids of records to perform mass action on
103:      */
104:     public function execute (array $gvSelection) {
105:         if (Yii::app()->controller->modelClass !== 'Docs' ||
106:             !isset ($_POST['selectedObjs']) || !is_array ($_POST['selectedObjs']) ||
107:             count ($_POST['selectedObjs']) !== count ($gvSelection) ||
108:             !isset ($_POST['selectedObjTypes']) || !is_array ($_POST['selectedObjTypes']) ||
109:             count ($_POST['selectedObjTypes']) !== count ($gvSelection)) {
110:             
111:             throw new CHttpException (400, Yii::t('app', 'Bad Request'));
112:         }
113:         $selectedObjs = $_POST['selectedObjs'];
114:         $selectedObjTypes = $_POST['selectedObjTypes'];
115: 
116:         if (!isset ($_POST['targetFolder']) || $_POST['targetFolder'] === '') {
117:             $destination = null;
118:         } else  {
119:             $targetFolder = $_POST['targetFolder'];
120:             $destination = DocFolders::model ()->findByPk ($targetFolder);
121:             if (!$destination)
122:                 throw new CHttpException (400, Yii::t('app', 'Folder not found'));
123:             if (!Yii::app()->controller->checkPermissions ($destination, 'edit')) {
124:                 self::$errorFlashes[] = 
125:                     Yii::t('app', 'You do not have permission to edit this folder.');
126:                 return 0;
127:             }
128:         }
129: 
130:         $objCount = count ($gvSelection);
131:         $successes = 0;
132:         for ($i = 0; $i < $objCount; $i++) {
133:             $id = $selectedObjs[$i];
134:             if (((int) $id) === DocFolders::TEMPLATES_FOLDER_ID) {
135:                 continue;
136:             }
137:             $type = $selectedObjTypes[$i];
138:             if ($type === 'doc') {
139:                 $obj = Docs::model ()->findByPk ($id);
140:             } elseif ($type === 'folder') {
141:                 $obj = DocFolders::model ()->findByPk ($id);
142:             } else {
143:                 self::$errorFlashes[] = Yii::t('app', 'Invalid object type.');
144:                 continue;
145:             }
146:             if (!$obj) {
147:                 self::$errorFlashes[] = 
148:                     Yii::t('app', 'Selected {type} does not exist', array (
149:                         '{type}' => $type === 'doc' ? ucfirst ($type) : $type,
150:                     ));
151:                 continue;
152:             }
153:             if (!Yii::app()->controller->checkPermissions ($obj, 'edit')) {
154:                 self::$errorFlashes[] = 
155:                     Yii::t('app', 'You do not have permission to edit this {type}.', array (
156:                         '{type}' => $type === 'doc' ? ucfirst ($type) : $type,
157:                     ));
158:                 continue;
159:             }
160:             if ($obj instanceof DocFolders && $destination && $obj->id === $destination->id) {
161:                 self::$errorFlashes[] = 
162:                     Yii::t('app', 'Cannot move "{name}" to a folder inside itself.', array (
163:                         '{name}' => $obj->name
164:                     ));
165:                 continue;
166:             }
167:             if ($obj->moveTo ($destination)) {
168:                 $successes++;
169:             } else {
170:                 self::$errorFlashes[] = 
171:                     Yii::t('app', 'Failed to move "{name}"', array (
172:                         '{name}' => $obj->name
173:                     ));
174:             }
175:         }
176:         if ($successes) {
177:             self::$successFlashes[] = Yii::t(
178:                 'app', 
179:                 '{n} object moved to "{destination}"|{n} objects moved to "{destination}"', array(
180:                     $successes,
181:                     '{destination}' => $destination ?  
182:                         $destination->name :
183:                         Yii::t('docs', 'Docs') 
184:                 )
185:             );
186:         }
187:         return $successes;
188:     }
189: 
190: }
191: 
192: ?>
193: 
X2CRM Documentation API documentation generated by ApiGen 2.8.0