public static function getAliases(X2Model $model, $aliasType = null) { $params = array(':type' => get_class($model), ':recordId' => $model->id); if ($aliasType) { $params[':aliasType'] = $aliasType; } $aliases = RecordAliases::model()->findAll(array('condition' => 'recordType=:type AND recordId=:recordId' . ($aliasType ? ' AND aliasType=:aliasType' : ''), 'group' => 'aliasType, alias', 'params' => $params)); return $aliases; }
public function run($id) { if (Yii::app()->user->isGuest) { Yii::app()->controller->redirect(Yii::app()->controller->createUrl('/site/login')); } $recordAlias = RecordAliases::model()->findByPk($id); if (!$recordAlias) { throw new CHttpException(404, CHtml::encode(Yii::t('app', 'Record does not exist'))); } $model = $recordAlias->getModel(); if ($model) { if (!Yii::app()->params->isAdmin && !Yii::app()->controller->checkPermissions($model, 'delete')) { Yii::app()->controller->denied(); } if ($recordAlias->delete()) { echo 'success'; Yii::app()->end(); } } echo 'failure'; }
/** * Runs when a model is deleted. * Clears any entries in <tt>x2_phone_numbers</tt>. * Fires onAfterDelete event. */ public function afterDelete() { // Clear out old tags: $class = get_class($this); Tags::model()->deleteAllByAttributes(array('type' => $class, 'itemId' => $this->id)); // Clear out old phone numbers X2Model::model('PhoneNumber')->deleteAllByAttributes(array('modelId' => $this->id, 'modelType' => $class)); RecordAliases::model()->deleteAllByAttributes(array('recordId' => $this->id, 'recordType' => $class)); // Change all references to this record so that they retain the name but // exclude the ID: if ($this->hasAttribute('nameId') && $this->hasAttribute('name')) { $this->_oldAttributes = $this->getAttributes(); $this->nameId = $this->name; $this->updateNameIdRefs(); } // clear out associated actions Actions::model()->deleteAllByAttributes(array('associationType' => strtolower(self::getAssociationType(get_class($this))), 'associationId' => $this->id)); if ($this->hasEventHandler('onAfterDelete')) { $this->onAfterDelete(new CEvent($this)); } }
* 02110-1301 USA. * * You can contact X2Engine, Inc. P.O. Box 66752, Scotts Valley, * California 95067, USA. or at email address contact@x2engine.com. * * The interactive user interfaces in modified source and object code versions * of this program must display Appropriate Legal Notices, as required under * Section 5 of the GNU Affero General Public License version 3. * * In accordance with Section 7(b) of the GNU Affero General Public License version 3, * these Appropriate Legal Notices must retain the display of the "Powered by * X2Engine" logo. If the display of the logo is not reasonably feasible for * technical reasons, the Appropriate Legal Notices must display the words * "Powered by X2Engine". *****************************************************************************************/ $aliasTypeOptions = RecordAliases::model()->getAliasTypeOptions(); Yii::app()->clientScript->registerCssFile(Yii::app()->theme->baseUrl . '/css/components/views/recordAliasesWidget.css'); Yii::app()->clientScript->registerScriptFile('http://www.skypeassets.com/i/scom/js/skype-uri.js'); Yii::app()->clientScript->registerScript('recordAliasesWidgetJS', "\n\n\$(function () {\n new x2.RecordAliasesWidget ({\n element: '.record-aliases-dropdown-container',\n aliasOptions: " . CJSON::encode($aliasTypeOptions) . ",\n aliasTypeIcons: " . CJSON::encode($aliasModel->getAllIcons()) . ",\n baseUrl: yii.scriptUrl + \n '/" . Yii::app()->controller->module->name . "/" . Yii::app()->controller->module->name . "',\n translations: " . CJSON::encode(array('dialogTitle' => Yii::t('app', 'Create Social Profile'), 'cancel' => Yii::t('app', 'Cancel'), 'create' => Yii::t('app', 'Create'), 'confirmDeletion' => Yii::t('app', 'Are you sure you want to delete this social profile?'), 'confirmDeletionTitle' => Yii::t('app', 'Delete social profile?'), 'OK' => Yii::t('app', 'OK'), 'skypeQtipLoadingText' => Yii::t('app', 'Loading...'))) . ",\n recordId: " . $this->model->id . "\n });\n});\n\n", CClientScript::POS_END); if (!$this->formOnly) { echo CHtml::tag('button', array('id' => 'view-aliases-button', 'class' => 'x2-button right view-aliases-button icon', 'title' => Yii::t('app', 'Add social profile')), ''); ?> <div class='record-aliases-dropdown-container'> <ul class='alias-dropdown x2-dropdown-list' style='display: none;'> <span> <?php foreach ($this->getAliases() as $alias) { ?> <li data-alias-type='<?php echo CHtml::encode($aliasTypeOptions[$alias->aliasType]); ?>