public function validateModelName($attr) { $value = $this->{$attr}; $modules = MobileModule::supportedModules(new CDbCriteria(array('condition' => 'editable'))); $validNames = array_map(function ($module) { return X2Model::getModelName($module->name); }, $modules); if (!in_array($value, $validNames)) { $this->addError($attr, Yii::t('app', 'Invalid model name')); } }
/** * Get a data provider for members of a given type in a given stage * @param string $type {'contacts', 'opportunities', 'accounts'} */ public function getStageMemberDataProvider($type, $workflowId, $dateRange, $expectedCloseDateDateRange, $stage, $user, $perStageWorkflowView = true) { $modelName = X2Model::getModelName($type); $model = X2Model::model($modelName); $tableName = $model->tableName(); $params = array(':workflowId' => $workflowId, ':stage' => $stage, ':start' => $dateRange['start'], ':end' => $dateRange['end'], ':type' => $type); if ($expectedCloseDateDateRange['range'] !== 'all') { $params = array_merge($params, array(':expectedCloseDateStart' => $expectedCloseDateDateRange['end'], ':expectedCloseDateEnd' => $expectedCloseDateDateRange['end'])); } if (!empty($user)) { $userString = " AND x2_actions.assignedTo=:user "; $params[':user'] = $user; } else { $userString = ""; } list($accessCondition, $accessConditionParams) = $modelName::model()->getAccessSQLCondition($tableName); $params = array_merge($params, $accessConditionParams); $stageMemberSql = Yii::app()->db->createCommand()->select("{$tableName}.*, x2_actions.lastUpdated as actionLastUpdated")->from($tableName)->join('x2_actions', "{$tableName}.id = x2_actions.associationId")->where(($expectedCloseDateDateRange['range'] !== 'all' ? $tableName . '.expectedCloseDate BETWEEN :expectedCloseDateStart AND :expectedCloseDateEnd AND ' : '') . "x2_actions.workflowId=:workflowId AND x2_actions.stageNumber=:stage AND\n x2_actions.associationType=:type AND complete!='Yes' AND \n (completeDate IS NULL OR completeDate=0) AND \n x2_actions.createDate BETWEEN :start AND :end " . $userString . " AND " . $accessCondition)->getText(); $memberCount = Yii::app()->db->createCommand()->select("COUNT(*)")->from($tableName)->join('x2_actions', "{$tableName}.id = x2_actions.associationId")->where(($expectedCloseDateDateRange['range'] !== 'all' ? $tableName . '.expectedCloseDate BETWEEN :expectedCloseDateStart AND :expectedCloseDateEnd AND ' : '') . "x2_actions.workflowId=:workflowId AND x2_actions.stageNumber=:stage AND\n x2_actions.associationType=:type AND complete!='Yes' AND \n (completeDate IS NULL OR completeDate=0) AND \n x2_actions.createDate BETWEEN :start AND :end " . $userString . ' AND ' . $accessCondition, $params)->queryScalar(); $membersDataProvider = new CSqlDataProvider($stageMemberSql, array('totalItemCount' => $memberCount, 'sort' => array('defaultOrder' => 'lastUpdated DESC'), 'pagination' => !$perStageWorkflowView ? false : array('pageSize' => 20), 'params' => $params)); return $membersDataProvider; }
</td> </tr> <tr class="formSectionRow"> <td style="width: 300px"> <div class="formItem leftLabel"> <label><?php echo Yii::t('media', 'Association Name'); ?> </label> <div class="formInputBox" style="width: 200px; height: auto;"> <?php if ($model->associationType && $model->associationType != 'bg') { ?> <?php if (!empty($model->associationId) && is_numeric($model->associationId) && ($modelName = X2Model::getModelName($model->associationType))) { $linkModel = X2Model::model($modelName)->findByPk($model->associationId); if (isset($linkModel)) { echo CHtml::link(CHtml::encode($linkModel->name), array('/' . $model->associationType . '/' . $model->associationId)); } else { echo ''; } } else { echo ''; } ?> <?php } ?> </div> </div>
public static function getModelOfTypeWithName($type, $name) { $modelName = X2Model::getModelName($type); // both ID and type must be set if (!(empty($type) || empty($name)) && $modelName) { // both ID and type must be set $model = X2Model::model($modelName); if ($model->hasAttribute('name')) { return $model->findByAttributes(array('name' => $name)); } } return null; // invalid type or invalid name }
echo ($legacy ? '<br />' : '') . CHtml::link(Yii::t('app', '[View email]'), '#', array('onclick' => 'return false;', 'id' => $data->id, 'class' => 'email-frame')); } elseif ($data->type == 'quotesDeleted') { echo $data->actionDescription; } elseif ($data->type == 'quotes') { $data->renderInlineViewLink(); } else { echo Yii::app()->controller->convertUrls(CHtml::encode($data->actionDescription)); } } // convert LF and CRLF to <br /> ?> </div> <div class="footer"> <?php if (isset($relationshipFlag) && $relationshipFlag && $data->associationId !== 0 && X2Model::getModelName($data->associationType) !== false) { $relString = " | " . X2Model::getModelLink($data->associationId, X2Model::getModelName($data->associationType)); } else { $relString = ""; } if (empty($data->type) || $data->type == 'weblead' || $data->type == 'workflow') { if ($data->complete == 'Yes') { echo Yii::t('actions', 'Completed by {name}', array('{name}' => User::getUserLinks($data->completedBy))) . $relString; } else { $userLink = User::getUserLinks($data->assignedTo); $userLink = empty($userLink) ? Yii::t('actions', 'Anyone') : $userLink; echo Yii::t('actions', 'Assigned to {name}', array('{name}' => $userLink)) . $relString; } } else { if (in_array($data->type, array('note', 'call', 'emailOpened', 'time'))) { echo $data->completedBy == 'Guest' ? "Guest" : User::getUserLinks($data->completedBy) . $relString; // echo ' '.Formatter::formatDate($data->completeDate);
/** * Legacy function kept for backwards compatibility. * * Moved from {@link Admin} and renamed from getModelList because it doesn't * make sense to put it there; it doesn't fit in a model intended for * managing system settings, but it does in this model, which is intended * for managing data models themselves. * * @return array */ public static function getDisplayedModelNamesList() { $modelList = array(); foreach (X2Model::model('Modules')->findAllByAttributes(array('editable' => true, 'visible' => 1)) as $module) { if ($modelName = X2Model::getModelName($module->name)) { $modelName = $module->name; } else { $modelName = ucfirst($module->name); } if (Yii::app()->user->checkAccess(ucfirst($module->name) . 'Index', array())) { $modelList[$modelName] = $module->title; } } return array_map(function ($term) { return Yii::t('app', $term); }, $modelList); }
public function actionParseType() { if (isset($_POST['Actions']['associationType'])) { $type = $_POST['Actions']['associationType']; if ($modelName = X2Model::getModelName($type)) { $linkModel = $modelName; if (class_exists($linkModel)) { if ($linkModel == "X2Calendar") { $linkSource = ''; } else { $linkSource = $this->createUrl(X2Model::model($linkModel)->autoCompleteSource); } } else { $linkSource = ""; } echo $linkSource; } else { echo ''; } } else { echo ''; } }
/** * Get number of records at each stage * @param array $workflowStatus * @param array $dateRange return value of WorkflowController::getDateRange () * @param string $users users filter * @param string $modelType model type filter * @return array number of records at each stage subject to specified filters */ public static function getStageCounts(&$workflowStatus, $dateRange, $expectedCloseDateDateRange, $users = '', $modelType = '') { $stageCount = count($workflowStatus['stages']); if ($users !== '') { $userString = " AND x2_actions.assignedTo='{$users}' "; } else { $userString = ""; } $params = array(':start' => $dateRange['start'], ':end' => $dateRange['end'], ':workflowId' => $workflowStatus['id']); if ($expectedCloseDateDateRange['range'] !== 'all') { $params = array_merge($params, array(':expectedCloseDateStart' => $expectedCloseDateDateRange['end'], ':expectedCloseDateEnd' => $expectedCloseDateDateRange['end'])); } $stageCounts = array(); $models = self::getModelsFromTypesArr($modelType); for ($i = 1; $i <= $stageCount; $i++) { $recordsAtStage = 0; foreach ($models as $type => $model) { $tableName = $model->tableName(); $modelName = X2Model::getModelName($type); list($accessCondition, $accessConditionParams) = $modelName::model()->getAccessSQLCondition($tableName); $countParams = array_merge($params, $accessConditionParams); $recordsAtStage += Yii::app()->db->createCommand()->select("COUNT(*)")->from($tableName)->join('x2_actions', 'x2_actions.associationId=' . $tableName . '.id')->where("x2_actions.complete != 'Yes' {$userString} AND \n (x2_actions.completeDate IS NULL OR x2_actions.completeDate = 0) AND \n x2_actions.createDate BETWEEN :start AND :end AND\n x2_actions.type='workflow' AND workflowId=:workflowId AND \n stageNumber=" . $i . " AND associationType='" . $type . "'" . ' AND ' . $accessCondition . ($expectedCloseDateDateRange['range'] !== 'all' ? ' AND ' . $tableName . '.expectedCloseDate BETWEEN :expectedCloseDateStart AND :expectedCloseDateEnd' : ''), $countParams)->queryScalar(); } $stageCounts[] = $recordsAtStage; } return $stageCounts; }
/** * Get number of records at each stage * @param array $workflowStatus * @param array $dateRange return value of WorkflowController::getDateRange () * @param string $users users filter * @param string $modelType model type filter * @return array number of records at each stage subject to specified filters */ public static function getStageCounts(&$workflowStatus, $dateRange, $expectedCloseDateDateRange, $users = '', $modelType = 'contacts') { $stageCount = count($workflowStatus['stages']); if ($users !== '') { $userString = " AND x2_actions.assignedTo='{$users}' "; } else { $userString = ""; } $params = array(':start' => $dateRange['start'], ':end' => $dateRange['end'], ':workflowId' => $workflowStatus['id']); if ($expectedCloseDateDateRange['range'] !== 'all') { $params = array_merge($params, array(':expectedCloseDateStart' => $expectedCloseDateDateRange['end'], ':expectedCloseDateEnd' => $expectedCloseDateDateRange['end'])); } $stageCounts = array(); $modelName = X2Model::getModelName($modelType); $model = X2Model::model($modelName); $tableName = $model->tableName(); list($accessCondition, $accessConditionParams) = $modelName::model()->getAccessSQLCondition($tableName); $allParams = array_merge($params, $accessConditionParams); $recordsAtStages = Yii::app()->db->createCommand()->select("stageNumber, COUNT(*)")->from($tableName)->join('x2_actions', 'x2_actions.associationId=' . $tableName . '.id')->where("x2_actions.complete != 'Yes' {$userString} AND \n (x2_actions.completeDate IS NULL OR x2_actions.completeDate = 0) AND \n x2_actions.createDate BETWEEN :start AND :end AND\n x2_actions.type='workflow' AND workflowId=:workflowId AND \n associationType='" . $modelType . "' AND " . $accessCondition . ($expectedCloseDateDateRange['range'] !== 'all' ? ' AND ' . $tableName . '.expectedCloseDate BETWEEN :expectedCloseDateStart AND :expectedCloseDateEnd' : ''), $allParams)->group('stageNumber')->queryAll(); foreach ($recordsAtStages as $row) { $stage = WorkflowStage::model()->findByPK($row['stageNumber']); if ($stage) { $stageCounts[$stage->stageNumber - 1] = $row['COUNT(*)']; } } for ($i = 0; $i < $stageCount; $i++) { if (!isset($stageCounts[$i])) { $stageCounts[$i] = 0; } } ksort($stageCounts); return $stageCounts; }
/** * Returns array of tooltips to be applied to quick create buttons for each model * @param array $models * @param string $modelName * @return array */ public static function getDialogTooltipsForModels($models, $modelName) { $tooltips = array_flip($models); array_walk($tooltips, function (&$val, $key) use($modelName) { $val = Yii::t('app', 'Create a new {relatedModelClass} associated with this {modelClass}', array('{relatedModelClass}' => X2Model::getRecordName($key), '{modelClass}' => X2Model::getRecordName(X2Model::getModelName($modelName)))); }); return $tooltips; }
} } // At this stage, all nameId fields have been created and populated. // // Now it's time to update the referencing columns: $linkFields = Yii::app()->db->createCommand()->select('modelName,fieldName,linkType')->from('x2_fields')->where('type="link" AND linkType IS NOT NULL AND linkType != ""')->queryAll(true); foreach ($linkFields as $field) { if ($debug) { echo "updating refs for field {$field['modelName']}.{$field['fieldName']}\n"; } $class = X2Model::getModelName($field['modelName']); if (empty($class) || !class_exists($class)) { continue; } $model = X2Model::model($class); $referencedClass = X2Model::getModelName($field['linkType']); if (empty($referencedClass) || !class_exists($referencedClass)) { continue; } $referencedModel = X2Model::model($referencedClass); if ($referencedModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) { // Referenced model exists and is linkable. Update refs: $table = $model->tableName(); $referencedTable = $referencedModel->tableName(); $column = $field['fieldName']; $query = "UPDATE `{$table}` AS `t1`\n INNER JOIN `{$referencedTable}` AS `t2`\n ON CAST(`t1`.`{$column}` AS CHAR)=`t2`.`id`\n SET `t1`.`{$column}`=CAST(`t2`.`nameId` AS CHAR)"; if ($debug) { echo "Running: {$query}\n"; } Yii::app()->db->createCommand($query)->execute(); }
* 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". *****************************************************************************************/ ?> <div class='stage-member-container stage-member-id-<?php echo $data['id']; ?> stage-member-type-<?php echo $recordType; ?> '> <?php $modelName = X2Model::getModelName($recordType); ?> <div class='stage-icon-container' title='<?php echo Yii::t('workflow', '{recordName}', array('{recordName}' => $modelName)); ?> '> <img src='<?php if (file_exists(substr(Yii::app()->theme->getBaseUrl() . '/images/workflow_stage_' . $recordType . '.png', 1))) { echo Yii::app()->theme->getBaseUrl() . '/images/workflow_stage_' . $recordType . '.png'; } else { echo Yii::app()->theme->getBaseUrl() . '/images/workflow_stage_model.png'; } ?> '
* 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". *****************************************************************************************/ ?> <div class='stage-member-container stage-member-id-<?php echo $data['id']; ?> stage-member-type-<?php echo $data['recordType']; ?> '> <?php $modelName = X2Model::getModelName($data['recordType']); $recordName = $recordNames[$modelName]; ?> <div class='stage-icon-container' title='<?php echo Yii::t('workflow', '{recordName}', array('{recordName}' => $recordName)); ?> '> <img src='<?php echo Yii::app()->theme->getBaseUrl() . '/images/workflow_stage_' . $data['recordType'] . '.png'; ?> ' class='stage-member-type-icon left' alt=''> </div> <div class='stage-member-name left'><?php
public function getStageMembers($workflowId, $stage, $start, $end, $range, $expectedCloseDateStart, $expectedCloseDateEnd, $expectedCloseDateRange, $users, $modelType = '') { $params = array(); $dateRange = self::getDateRange(); $expectedCloseDateDateRange = self::getDateRange('expectedCloseDateStart', 'expectedCloseDateEnd', 'expectedCloseDateRange'); if (!is_numeric($workflowId) || !is_numeric($stage)) { return new CActiveDataProvider(); } $dataProvider = $this->getStageMemberDataProvider($modelType, $workflowId, $dateRange, $expectedCloseDateDateRange, $stage, $users); $gridConfig = array('baseScriptUrl' => Yii::app()->theme->getBaseUrl() . '/css/gridview', 'template' => '<div class="page-title">{title}{buttons}' . '</div>{items}{pager}', 'fixedHeader' => false, 'fullscreen' => false, 'buttons' => array('columnSelector', 'autoResize')); $modelName = X2Model::getModelName($modelType); $this->renderPartial('_ajaxRequestedStageMembers', array('gridConfig' => array_merge($gridConfig, array('gvSettingsName' => $modelType . '-stageMembers', 'viewName' => $modelType . '-workflowView', 'defaultGvSettings' => array('name' => 125, 'lastUpdated' => 80, 'assignedTo' => 80), 'dataProvider' => $dataProvider, 'id' => 'workflow-stage-grid', 'ajaxUpdate' => 'workflow-stage-grid', 'modelName' => $modelName, 'title' => Modules::displayName(true, $modelType), 'specialColumns' => array('name' => array('name' => 'name', 'header' => Yii::t('app', 'Name'), 'value' => 'X2Model::getModelLinkMock ( "' . $modelName . '", $data[\'nameId\'], array ( \'data-qtip-title\' => $data[\'name\'] ) )', 'type' => 'raw', 'htmlOptions' => array('width' => '30%')), 'lastUpdated' => array('name' => 'lastUpdated', 'header' => X2Model::model($modelName)->getAttributeLabel('lastUpdated'), 'value' => 'Formatter::formatDate($data["lastUpdated"])', 'type' => 'raw', 'htmlOptions' => array('width' => '15%')), 'assignedTo' => array('header' => X2Model::model($modelName)->getAttributeLabel('assignedTo'), 'name' => 'assignedTo', 'value' => 'empty($data["assignedTo"])?' . 'Yii::t("app","Anyone"):User::getUserLinks($data["assignedTo"])', 'type' => 'raw'))))), false, true); }
<?php echo $form->errorSummary($model); ?> <div class="row"> <div class="cell"> <?php echo $form->labelEx($model, 'name'); echo $form->textField($model, 'name', array('maxlength' => 250, 'class' => 'x2-wide-input')); echo $form->error($model, 'name'); ?> </div> <div class="cell"> <?php $moduleOptions = array(Workflow::DEFAULT_ALL_MODULES => Yii::t('workflow', 'All Modules')) + Modules::getDropdownOptions('id', function ($record) { $modelName = X2Model::getModelName($record['name']); return $modelName && $modelName::model() instanceof X2Model && $modelName::model()->supportsWorkflow; }); echo $form->labelEx($model, 'isDefaultFor'); echo $form->dropDownList($model, 'isDefaultFor', $moduleOptions, array('multiple' => 'multiple', 'class' => 'x2-multiselect-dropdown', 'style' => 'display: none', 'data-selected-text' => Yii::t('workflow', 'module(s)'))); ?> </div> <div class="cell"> <?php echo $form->labelEx($model, 'financial'); echo $form->checkBox($model, 'financial'); echo $form->error($model, 'financial'); ?> </div> <div class="cell" id="financialModel" style="<?php echo $model->financial ? '' : 'display:none;';
public function init() { $this->disableTemplates = $this->disableTemplates || in_array($this->associationType, array_keys(Docs::modelsWhichSupportEmailTemplates())); // Prepare the model for initially displayed input: $this->model = new InlineEmail(); if (isset($this->targetModel)) { $this->model->targetModel = $this->targetModel; } if (!$this->associationType) { $this->associationType = X2Model::getModelName(Yii::app()->controller->module->name); } // Bring in attributes set in the configuration: $this->model->attributes = $this->attributes; if (empty($this->template)) { // check for a default template $defaultTemplateId = Yii::app()->params->profile->getDefaultEmailTemplate(Yii::app()->controller->module->name); // if there's a default set for this module if ($defaultTemplateId !== null) { $defaultTemplateDoc = Docs::model()->findByPk($defaultTemplateId); // ensure that template is still a valid default if ($defaultTemplateDoc && ($defaultTemplateDoc->associationType === $this->associationType || $defaultTemplateDoc->type === 'quote' && $this->model->targetModel instanceof Quote)) { $this->template = $defaultTemplateId; } } } if (empty($this->template)) { if (empty($this->model->message)) { $this->model->message = InlineEmail::emptyBody(); } $this->model->insertSignature(); } else { // Fill in the body with a template: $this->model->scenario = 'template'; if (!empty($this->template)) { $this->model->template = $this->template; } $this->model->prepareBody(); } // If insertable attributes aren't set, use the inline email model's // getInsertableAttributes() method to generate them. if ((bool) $this->model->targetModel && !isset($this->insertableAttributes)) { $this->insertableAttributes = $this->model->insertableAttributes; } $this->registerJSClassInstantiation(); // Load resources: Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/ckeditor/ckeditor.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/ckeditor/adapters/jquery.js'); Yii::app()->clientScript->registerScriptFile(Yii::app()->getBaseUrl() . '/js/emailEditor.js'); if (!empty($this->insertableAttributes)) { Yii::app()->clientScript->registerScript('setInsertableAttributes', 'x2.insertableAttributes = ' . CJSON::encode($this->insertableAttributes) . ';', CClientScript::POS_HEAD); } Yii::app()->clientScript->registerScript('storeOriginalInlineEmailMessage', 'x2.inlineEmailOriginalBody = $("#email-message").val();', CClientScript::POS_READY); //'.CJSON::encode($this->model->message).';',CClientScript::POS_READY); Yii::app()->clientScript->registerScript('toggleEmailForm', $this->startHidden ? "window.hideInlineEmail = true;\n" : "window.hideInlineEmail = false;\n", CClientScript::POS_HEAD); $this->registerPackages(); parent::init(); }
<div class='cell'> <?php echo $form->label($model, 'associationType', array('class' => 'action-associationType-label')); echo $form->dropDownList($model, 'associationType', $associationTypeOptions, array('class' => 'action-associationType-dropdown')); ?> <div id='<?php echo $this->resolveId('association-type-autocomplete-container'); ?> ' <?php echo $model->associationType === 'calendar' ? 'style="display: none;"' : ''; ?> > <?php echo CHtml::label(Yii::t('app', 'Association Name'), 'associationName', array('class' => 'action-associationName-label')); $autocomplete = X2Model::renderModelAutocomplete(X2Model::getModelName($model->associationType), false, array('name' => 'Actions[associationName]')); if ($autocomplete !== 'failure') { echo $autocomplete; } else { // dummy input to be replaced with autocomplete echo '<input disabled="disabled">'; } echo $form->hiddenField($model, 'associationId', array('data-default' => '')); ?> </div> <?php echo CHtml::hiddenField('calendarEventTab', true); ?> </div> <?php }
public static function getCurrencyFields($model = 'contacts') { $ret = array(); if (X2Model::getModelName($model)) { $financialFields = Fields::model()->findAllByAttributes(array('modelName' => X2Model::getModelName($model), 'type' => 'currency')); foreach ($financialFields as $field) { $ret[$field->fieldName] = $field->attributeLabel; } asort($ret); } return $ret; }
<?php if (!empty($model->associationType) && is_numeric($model->associationId) && !is_null(X2Model::getAssociationModel($model->associationType, $model->associationId)) && ($publisher == 'false' || !$publisher)) { ?> <div id="recordBody" class="form"> <?php echo '<div class="page-title"><h3>' . Yii::t('actions', 'Associated Record') . '</h3></div>'; ?> <?php if ($model->associationType == 'contacts') { $this->widget('DetailView', array('model' => X2Model::model('Contacts')->findByPk($model->associationId), 'scenario' => 'Inline', 'nameLink' => true)); // $this->renderPartial('application.modules.contacts.views.contacts._@DETAILVIEWMini', array( // 'model' => X2Model::model('Contacts')->findByPk($model->associationId), // 'actionModel' => $model, // )); } else { echo ucwords(Events::parseModelName(X2Model::getModelName($model->associationType))) . ": <span class='model-link'>" . X2Model::getModelLink($model->associationId, X2Model::getModelName($model->associationType)) . "</span>"; } ?> </div> <?php } ?> </div> <div id="actionFooter"> </div> </body> </html> <script> $(document).on('ready',function(){ $.datepicker.setDefaults( $.datepicker.regional[ '<?php echo $language;
private function createAttachmentAction($model) { if (!empty($model->associationType) && !empty($model->associationId) && is_numeric($model->associationId)) { $note = new Actions(); $note->createDate = time(); $note->dueDate = time(); $note->completeDate = time(); $note->complete = 'Yes'; $note->visibility = '1'; $note->completedBy = Yii::app()->user->getName(); if ($model->private) { $note->assignedTo = Yii::app()->user->getName(); $note->visibility = '0'; } else { $note->assignedTo = 'Anyone'; } $note->type = 'attachment'; $note->associationId = $model->associationId; $note->associationType = $model->associationType; if ($modelName = X2Model::getModelName($model->associationType)) { $association = X2Model::model($modelName)->findByPk($model->associationId); if ($association != null) { $note->associationName = $association->name; } } $note->actionDescription = $model->fileName . ':' . $model->id; return $note->save(); } return false; }
* 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". *****************************************************************************************/ if (class_exists($data->associationType)) { if (count(X2Model::model($data->associationType)->findAllByPk($data->associationId)) > 0) { $associatedModel = X2Model::model($data->associationType)->findByPk($data->associationId); if (!$this->checkPermissions($associatedModel, 'view')) { return; } if ($associatedModel instanceof Actions) { $modelName = X2Model::getModelName($associatedModel->associationType, true); if ($modelName) { if (count(X2Model::model($modelName)->findAllByPk($associatedModel->associationId)) > 0) { $actionModel = X2Model::model($modelName)->findByPk($associatedModel->associationId); if (!$this->checkPermissions($actionModel, 'view')) { return; } } } } } } Yii::app()->params->isAdmin = Yii::app()->user->checkAccess('AdminIndex'); $avatar = Yii::app()->db->createCommand()->select('avatar')->from('x2_profile')->where('username=:user', array(':user' => $data->user))->queryScalar(); $themeUrl = Yii::app()->theme->getBaseUrl(); $typeFile = $data->type;
<div class="row"> <div class="cell"> <?php echo $form->label($actionModel, 'associationType'); echo $form->dropDownList($actionModel, 'associationType', array_merge(array('none' => Yii::t('app', 'None')), $modelList), array('ajax' => array('type' => 'POST', 'url' => CController::createUrl('/actions/actions/parseType'), 'update' => '#', 'success' => 'function(data){ if(data){ $("#auto_select").autocomplete("option","source",data); $("#auto_select").val(""); $("#auto_complete").show(); }else{ $("#auto_complete").hide(); } }'))); echo $form->error($actionModel, 'associationType'); if ($actionModel->associationType != 'none') { $linkModel = X2Model::getModelName($actionModel->associationType); } else { $linkModel = null; } if (!empty($linkModel) && class_exists($linkModel)) { if ($linkModel == 'X2Calendar') { $linkSource = ''; } else { $linkSource = $this->createUrl(X2Model::model($linkModel)->autoCompleteSource); } } else { $linkSource = ""; } ?> </div> <div class="cell" id="auto_complete"
public function getText(array $params = array(), array $htmlOptions = array()) { $truncated = array_key_exists('truncated', $params) ? $params['truncated'] : false; $requireAbsoluteUrl = array_key_exists('requireAbsoluteUrl', $params) ? $params['requireAbsoluteUrl'] : false; $text = ""; $authorText = ""; if (Yii::app()->user->getName() == $this->user) { $authorText = CHtml::link(Yii::t('app', 'You'), Yii::app()->controller->createAbsoluteUrl('/profile/view', array('id' => Yii::app()->user->getId())), $htmlOptions); } else { $authorText = User::getUserLinks($this->user); } if (!empty($authorText)) { $authorText .= " "; } switch ($this->type) { case 'notif': $parent = X2Model::model('Notification')->findByPk($this->associationId); if (isset($parent)) { $text = $parent->getMessage(); } else { $text = Yii::t('app', "Notification not found"); } break; case 'record_create': $actionFlag = false; if (class_exists($this->associationType)) { if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { if ($this->associationType == 'Actions') { $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action) && (strcasecmp($action->associationType, 'contacts') === 0 || in_array($action->type, array('call', 'note', 'time')))) { // Special considerations for publisher-created actions, i.e. call, // note, time, and anything associated with a contact $actionFlag = true; // Retrieve the assigned user from the related action $relatedAction = Actions::model()->findByPk($this->associationId); if ($authorText) { $authorText = User::getUserLinks($relatedAction->assignedTo); } } } if ($actionFlag) { $authorText = empty($authorText) ? Yii::t('app', 'Someone') : $authorText; switch ($action->type) { case 'call': $text = Yii::t('app', '{authorText} logged a call ({duration}) with {modelLink}: "{logAbbrev}"', array('{authorText}' => $authorText, '{duration}' => empty($action->dueDate) || empty($action->completeDate) ? Yii::t('app', 'duration unknown') : Formatter::formatTimeInterval($action->dueDate, $action->completeDate, '{hoursMinutes}'), '{modelLink}' => X2Model::getModelLink($action->associationId, ucfirst($action->associationType), $requireAbsoluteUrl), '{logAbbrev}' => CHtml::encode($action->actionDescription))); break; case 'note': $text = Yii::t('app', '{authorText} posted a comment on {modelLink}: "{noteAbbrev}"', array('{authorText}' => $authorText, '{modelLink}' => X2Model::getModelLink($action->associationId, ucfirst($action->associationType), $requireAbsoluteUrl), '{noteAbbrev}' => CHtml::encode($action->actionDescription))); break; case 'time': $text = Yii::t('app', '{authorText} logged {time} on {modelLink}: "{noteAbbrev}"', array('{authorText}' => $authorText, '{time}' => Formatter::formatTimeInterval($action->dueDate, $action->dueDate + $action->timeSpent, '{hoursMinutes}'), '{modelLink}' => X2Model::getModelLink($action->associationId, ucfirst($action->associationType)), '{noteAbbrev}' => CHtml::encode($action->actionDescription))); break; default: if (!empty($authorText)) { $text = Yii::t('app', "A new {actionLink} associated with the contact {contactLink} has been assigned to " . $authorText, array('{actionLink}' => CHtml::link(Events::parseModelName($this->associationType), '#', array_merge($htmlOptions, array('class' => 'action-frame-link', 'data-action-id' => $this->associationId))), '{contactLink}' => X2Model::getModelLink($action->associationId, ucfirst($action->associationType), $requireAbsoluteUrl))); } else { $text = Yii::t('app', "A new {actionLink} associated with the contact {contactLink} has been created.", array('{actionLink}' => CHtml::link(Events::parseModelName($this->associationType), '#', array_merge($htmlOptions, array('class' => 'action-frame-link', 'data-action-id' => $this->associationId))), '{contactLink}' => X2Model::getModelLink($action->associationId, ucfirst($action->associationType), $requireAbsoluteUrl))); } } } else { if (!empty($authorText)) { $modelLink = X2Model::getModelLink($this->associationId, $this->associationType, $requireAbsoluteUrl); if (isset($action) && $this->user !== $action->assignedTo) { // Include the assignee if this is for an action assigned to someone other than the creator $translateText = "created a new {modelName} for {assignee}, {modelLink}"; } elseif ($modelLink !== '') { $translateText = "created a new {modelName}, {modelLink}"; } else { $translateText = "created a new {modelName}"; } $text = $authorText . Yii::t('app', $translateText, array('{modelName}' => Events::parseModelName($this->associationType), '{modelLink}' => $modelLink, '{assignee}' => isset($action) ? User::getUserLinks($action->assignedTo) : null)); } else { $text = Yii::t('app', "A new {modelName}, {modelLink}, has been created.", array('{modelName}' => Events::parseModelName($this->associationType), '{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType, $requireAbsoluteUrl))); } } } else { $deletionEvent = X2Model::model('Events')->findByAttributes(array('type' => 'record_deleted', 'associationType' => $this->associationType, 'associationId' => $this->associationId)); if (isset($deletionEvent)) { if (!empty($authorText)) { $text = $authorText . Yii::t('app', "created a new {modelName}, {deletionText}. It has been deleted.", array('{modelName}' => Events::parseModelName($this->associationType), '{deletionText}' => $deletionEvent->text)); } else { $text = Yii::t('app', "A {modelName}, {deletionText}, was created. It has been deleted.", array('{modelName}' => Events::parseModelName($this->associationType), '{deletionText}' => $deletionEvent->text)); } } else { if (!empty($authorText)) { $text = $authorText . Yii::t('app', "created a new {modelName}, but it could not be found.", array('{modelName}' => Events::parseModelName($this->associationType))); } else { $text = Yii::t('app', "A {modelName} was created, but it could not be found.", array('{modelName}' => Events::parseModelName($this->associationType))); } } } } break; case 'weblead_create': if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $text = Yii::t('app', "A new web lead has come in: {modelLink}", array('{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); } else { $deletionEvent = X2Model::model('Events')->findByAttributes(array('type' => 'record_deleted', 'associationType' => $this->associationType, 'associationId' => $this->associationId)); if (isset($deletionEvent)) { $text = Yii::t('app', "A new web lead has come in: {deletionText}. It has been deleted.", array('{deletionText}' => $deletionEvent->text)); } else { $text = Yii::t('app', "A new web lead has come in, but it could not be found."); } } break; case 'record_deleted': if (class_exists($this->associationType)) { if (Yii::app()->params->profile !== null && Yii::app()->params->profile->language != 'en' && !empty(Yii::app()->params->profile->language) || Yii::app()->params->profile === null && Yii::app()->language !== 'en' || strpos($this->associationType, 'A') !== 0 && strpos($this->associationType, 'E') !== 0 && strpos($this->associationType, 'I') !== 0 && strpos($this->associationType, 'O') !== 0 && strpos($this->associationType, 'U') !== 0) { if (!empty($authorText)) { $text = $authorText . Yii::t('app', "deleted a {modelType}, {text}", array('{modelType}' => Events::parseModelName($this->associationType), '{text}' => $this->text)); } else { $text = Yii::t('app', "A {modelType}, {text}, was deleted", array('{modelType}' => Events::parseModelName($this->associationType), '{text}' => $this->text)); } } else { if (!empty($authorText)) { $text = $authorText . Yii::t('app', "deleted an {modelType}, {text}.", array('{modelType}' => Events::parseModelName($this->associationType), '{text}' => $this->text)); } else { $text = Yii::t('app', "An {modelType}, {text}, was deleted.", array('{modelType}' => Events::parseModelName($this->associationType), '{text}' => $this->text)); } } } break; case 'workflow_start': $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action)) { $record = X2Model::model(ucfirst($action->associationType))->findByPk($action->associationId); if (isset($record)) { $stages = Workflow::getStages($action->workflowId); if (isset($stages[$action->stageNumber - 1])) { $text = $authorText . Yii::t('app', 'started the process stage "{stage}" for the {modelName} {modelLink}', array('{stage}' => $stages[$action->stageNumber - 1], '{modelName}' => Events::parseModelName($action->associationType), '{modelLink}' => X2Model::getModelLink($action->associationId, $action->associationType))); } else { $text = $authorText . Yii::t('app', "started a process stage for the {modelName} {modelLink}, but the process stage could not be found.", array('{modelName}' => Events::parseModelName($action->associationType), '{modelLink}' => X2Model::getModelLink($action->associationId, $action->associationType))); } } else { $text = $authorText . Yii::t('app', "started a process stage, but the associated {modelName} was not found.", array('{modelName}' => Events::parseModelName($action->associationType))); } } else { $text = $authorText . Yii::t('app', "started a process stage, but the process record could not be found."); } break; case 'workflow_complete': $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action)) { $record = X2Model::model(ucfirst($action->associationType))->findByPk($action->associationId); if (isset($record)) { $stages = Workflow::getStages($action->workflowId); if (isset($stages[$action->stageNumber - 1])) { $text = $authorText . Yii::t('app', 'completed the process stage "{stageName}" for the {modelName} {modelLink}', array('{stageName}' => $stages[$action->stageNumber - 1], '{modelName}' => Events::parseModelName($action->associationType), '{modelLink}' => X2Model::getModelLink($action->associationId, $action->associationType))); } else { $text = $authorText . Yii::t('app', "completed a process stage for the {modelName} {modelLink}, but the process stage could not be found.", array('{modelName}' => Events::parseModelName($action->associationType), '{modelLink}' => X2Model::getModelLink($action->associationId, $action->associationType))); } } else { $text = $authorText . Yii::t('app', "completed a process stage, but the associated {modelName} was not found.", array('{modelName}' => Events::parseModelName($action->associationType))); } } else { $text = $authorText . Yii::t('app', "completed a process stage, but the process record could not be found."); } break; case 'workflow_revert': $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action)) { $record = X2Model::model(ucfirst($action->associationType))->findByPk($action->associationId); if (isset($record)) { $stages = Workflow::getStages($action->workflowId); $text = $authorText . Yii::t('app', 'reverted the process stage "{stageName}" for the {modelName} {modelLink}', array('{stageName}' => $stages[$action->stageNumber - 1], '{modelName}' => Events::parseModelName($action->associationType), '{modelLink}' => X2Model::getModelLink($action->associationId, $action->associationType))); } else { $text = $authorText . Yii::t('app', "reverted a process stage, but the associated {modelName} was not found.", array('{modelName}' => Events::parseModelName($action->associationType))); } } else { $text = $authorText . Yii::t('app', "reverted a process stage, but the process record could not be found."); } break; case 'feed': if (Yii::app()->user->getName() == $this->user) { $author = CHtml::link(Yii::t('app', 'You'), Yii::app()->controller->createAbsoluteUrl('/profile/view', array('id' => Yii::app()->user->getId())), $htmlOptions) . " "; } else { $author = User::getUserLinks($this->user); } $recipUser = Yii::app()->db->createCommand()->select('username')->from('x2_users')->where('id=:id', array(':id' => $this->associationId))->queryScalar(); $modifier = ''; $recipient = ''; if ($this->user != $recipUser && $this->associationId != 0) { if (Yii::app()->user->getId() == $this->associationId) { $recipient = Yii::t('app', 'You'); } else { $recipient = User::getUserLinks($recipUser); } if (!empty($recipient)) { $modifier = ' » '; } } $text = $author . $modifier . $recipient . ": " . ($truncated ? strip_tags(Formatter::convertLineBreaks(x2base::convertUrls($this->text), true, true), '<a></a>') : $this->text); break; case 'email_sent': if (class_exists($this->associationType)) { $model = X2Model::model($this->associationType)->findByPk($this->associationId); if (!empty($model)) { switch ($this->subtype) { case 'quote': $text = $authorText . Yii::t('app', "issued the {transModelName} \"{modelLink}\" via email", array('{transModelName}' => Yii::t('quotes', 'quote'), '{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); break; case 'invoice': $text = $authorText . Yii::t('app', "issued the {transModelName} \"{modelLink}\" via email", array('{transModelName}' => Yii::t('quotes', 'invoice'), '{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); break; default: $text = $authorText . Yii::t('app', "sent an email to the {transModelName} {modelLink}", array('{transModelName}' => Events::parseModelName($this->associationType), '{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); break; } } else { $deletionEvent = X2Model::model('Events')->findByAttributes(array('type' => 'record_deleted', 'associationType' => $this->associationType, 'associationId' => $this->associationId)); switch ($this->subtype) { case 'quote': if (isset($deletionEvent)) { $text = $authorText . Yii::t('app', "issued a quote by email, but that record has been deleted."); } else { $text = $authorText . Yii::t('app', "issued a quote by email, but that record could not be found."); } break; case 'invoice': if (isset($deletionEvent)) { $text = $authorText . Yii::t('app', "issued an invoice by email, but that record has been deleted."); } else { $text = $authorText . Yii::t('app', "issued an invoice by email, but that record could not be found."); } break; default: if (isset($deletionEvent)) { $text = $authorText . Yii::t('app', "sent an email to a {transModelName}, but that record has been deleted.", array('{transModelName}' => Events::parseModelName($this->associationType))); } else { $text = $authorText . Yii::t('app', "sent an email to a {transModelName}, but that record could not be found.", array('{transModelName}' => Events::parseModelName($this->associationType))); } break; } } } break; case 'email_opened': switch ($this->subtype) { case 'quote': $emailType = Yii::t('app', 'a quote email'); break; case 'invoice': $emailType = Yii::t('app', 'an invoice email'); break; default: $emailType = Yii::t('app', 'an email'); break; } if (X2Model::getModelName($this->associationType) && count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $text = X2Model::getModelLink($this->associationId, $this->associationType) . Yii::t('app', ' has opened {emailType}!', array('{emailType}' => $emailType, '{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); } else { $text = Yii::t('app', "A contact has opened {emailType}, but that contact cannot be found.", array('{emailType}' => $emailType)); } break; case 'email_clicked': if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $text = X2Model::getModelLink($this->associationId, $this->associationType) . Yii::t('app', ' opened a link in an email campaign and is visiting your website!', array('{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); } else { $text = Yii::t('app', "A contact has opened a link in an email campaign, but that contact cannot be found."); } break; case 'web_activity': if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $text = ""; $text .= X2Model::getModelLink($this->associationId, $this->associationType) . " " . Yii::t('app', "is currently on your website!"); } else { $text = Yii::t('app', "A contact was on your website, but that contact cannot be found."); } break; case 'case_escalated': if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $case = X2Model::model($this->associationType)->findByPk($this->associationId); $text = $authorText . Yii::t('app', "escalated service case {modelLink} to {userLink}", array('{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType), '{userLink}' => User::getUserLinks($case->escalatedTo))); } else { $text = $authorText . Yii::t('app', "escalated a service case but that case could not be found."); } break; case 'calendar_event': $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action)) { $text = Yii::t('app', "{calendarText} event: {actionDescription}", array('{calendarText}' => CHtml::link(Yii::t('calendar', 'Calendar'), Yii::app()->controller->createAbsoluteUrl('/calendar/calendar/index'), $htmlOptions), '{actionDescription}' => CHtml::encode($action->actionDescription))); } else { $text = Yii::t('app', "{calendarText} event: event not found.", array('{calendarText}' => CHtml::link(Yii::t('calendar', 'Calendar'), Yii::app()->controller->createAbsoluteUrl('/calendar/calendar/index'), $htmlOptions))); } break; case 'action_reminder': $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action)) { $text = Yii::t('app', "Reminder! The following {action} is due now: {transModelLink}", array('{transModelLink}' => X2Model::getModelLink($this->associationId, $this->associationType), '{action}' => strtolower(Modules::displayName(false, 'Actions')))); } else { $text = Yii::t('app', "An {action} is due now, but the record could not be found.", array('{action}' => strtolower(Modules::displayName(false, 'Actions')))); } break; case 'action_complete': $action = X2Model::model('Actions')->findByPk($this->associationId); if (isset($action)) { $text = $authorText . Yii::t('app', "completed the following {action}: {actionDescription}", array('{actionDescription}' => X2Model::getModelLink($this->associationId, $this->associationType, $requireAbsoluteUrl), '{action}' => strtolower(Modules::displayName(false, 'Actions')))); } else { $text = $authorText . Yii::t('app', "completed an {action}, but the record could not be found.", array('{action}' => strtolower(Modules::displayName(false, 'Actions')))); } break; case 'doc_update': $text = $authorText . Yii::t('app', 'updated a document, {docLink}', array('{docLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); break; case 'email_from': if (class_exists($this->associationType)) { if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $text = $authorText . Yii::t('app', "received an email from a {transModelName}, {modelLink}", array('{transModelName}' => Events::parseModelName($this->associationType), '{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); } else { $deletionEvent = X2Model::model('Events')->findByAttributes(array('type' => 'record_deleted', 'associationType' => $this->associationType, 'associationId' => $this->associationId)); if (isset($deletionEvent)) { $text = $authorText . Yii::t('app', "received an email from a {transModelName}, but that record has been deleted.", array('{transModelName}' => Events::parseModelName($this->associationType))); } else { $text = $authorText . Yii::t('app', "received an email from a {transModelName}, but that record could not be found.", array('{transModelName}' => Events::parseModelName($this->associationType))); } } } break; case 'voip_call': if (count(X2Model::model($this->associationType)->findAllByPk($this->associationId)) > 0) { $text = Yii::t('app', "{modelLink} called.", array('{modelLink}' => X2Model::getModelLink($this->associationId, $this->associationType))); } else { $deletionEvent = X2Model::model('Events')->findByAttributes(array('type' => 'record_deleted', 'associationType' => $this->associationType, 'associationId' => $this->associationId)); if (isset($deletionEvent)) { $text = $authorText . Yii::t('app', "A contact called, but the contact record has been deleted."); } else { $text = $authorText . Yii::t('app', "Call from a contact whose record could not be found."); } } break; case 'media': $media = X2Model::model('Media')->findByPk($this->associationId); $text = substr($authorText, 0, -1) . ": " . $this->text; if (isset($media)) { if (!$truncated) { $text .= "<br>" . Media::attachmentSocialText($media->getMediaLink(), true, true); } else { $text .= "<br>" . Media::attachmentSocialText($media->getMediaLink(), true, false); } } else { $text .= "<br>Media file not found."; } break; case 'topic_reply': $reply = TopicReplies::model()->findByPk($this->associationId); if (isset($reply)) { $topicLink = X2Html::link($reply->topic->name, Yii::app()->controller->createUrl('/topics/topics/view', array('id' => $reply->topic->id, 'replyId' => $reply->id))); $text = Yii::t('topics', '{poster} posted a new reply to {topic}.', array('{poster}' => $authorText, '{topic}' => $topicLink)); } else { $text = Yii::t('topics', '{poster} posted a new reply to a topic, but that reply has been deleted.', array('{poster}' => $authorText)); } break; default: $text = $authorText . CHtml::encode($this->text); break; } if ($truncated && mb_strlen($text, 'UTF-8') > 250) { $text = mb_substr($text, 0, 250, 'UTF-8') . "..."; } return $text; }
public static function getCriteria($associationId, $associationType, $relationships, $historyType) { // Based on our filter, we need a particular additional criteria $historyCriteria = array('all' => '', 'action' => ' AND type IS NULL', 'overdueActions' => ' AND type IS NULL AND complete="NO" AND dueDate <= ' . time(), 'incompleteActions' => ' AND type IS NULL AND complete="NO"', 'call' => ' AND type="call"', 'note' => ' AND type="note"', 'attachments' => ' AND type="attachment"', 'event' => ' AND type="event"', 'email' => ' AND type IN ("email","email_staged",' . '"email_opened","email_clicked","email_unsubscribed")', 'marketing' => ' AND type IN ("email","webactivity","weblead","email_staged",' . '"email_opened","email_clicked","email_unsubscribed","event")', 'quotes' => 'AND type like "quotes%"', 'time' => ' AND type="time"', 'webactivity' => 'AND type IN ("weblead","webactivity")', 'workflow' => ' AND type="workflow"'); $multiAssociationIds = array($associationId); if ($relationships) { // Add association conditions for our relationships $type = $associationType; $model = X2Model::model($type)->findByPk($associationId); if (count($model->relatedX2Models) > 0) { $associationCondition = "((associationId={$associationId} AND " . "associationType='{$associationType}')"; // Loop through related models and add an association type OR for each foreach ($model->relatedX2Models as $relatedModel) { if ($relatedModel instanceof X2Model) { $multiAssociationIds[] = $relatedModel->id; $associationCondition .= " OR (associationId={$relatedModel->id} AND " . "associationType='{$relatedModel->myModelName}')"; } } $associationCondition .= ")"; } else { $associationCondition = 'associationId=' . $associationId . ' AND ' . 'associationType="' . $associationType . '"'; } } else { $associationCondition = 'associationId=' . $associationId . ' AND ' . 'associationType="' . $associationType . '"'; } /* Fudge replacing Opportunity and Quote because they're stored as plural in the actions table */ $associationCondition = str_replace('Opportunity', 'opportunities', $associationCondition); $associationCondition = str_replace('Quote', 'quotes', $associationCondition); $visibilityCondition = ''; $module = isset(Yii::app()->controller->module) ? Yii::app()->controller->module->getId() : Yii::app()->controller->getId(); // Apply history privacy settings so that only allowed actions are viewable. if (!Yii::app()->user->checkAccess(ucfirst($module) . 'Admin')) { if (Yii::app()->settings->historyPrivacy == 'user') { $visibilityCondition = ' AND (assignedTo="' . Yii::app()->user->getName() . '")'; } elseif (Yii::app()->settings->historyPrivacy == 'group') { $visibilityCondition = ' AND ( t.assignedTo IN ( SELECT DISTINCT b.username FROM x2_group_to_user a INNER JOIN x2_group_to_user b ON a.groupId=b.groupId WHERE a.username="******") OR (t.assignedTo="' . Yii::app()->user->getName() . '"))'; } else { $visibilityCondition = ' AND (visibility="1" OR assignedTo="' . Yii::app()->user->getName() . '")'; } } $orderStr = 'IF(complete="No", GREATEST(createDate, IFNULL(dueDate,0), ' . 'IFNULL(lastUpdated,0)), GREATEST(createDate, ' . 'IFNULL(completeDate,0), IFNULL(lastUpdated,0))) DESC'; $mainCountCmd = Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions t')->where($associationCondition . $visibilityCondition . $historyCriteria[$historyType]); $mainCmd = Yii::app()->db->createCommand()->select('*')->from('x2_actions t')->where($associationCondition . $visibilityCondition . $historyCriteria[$historyType])->order($orderStr); $multiAssociationIdParams = AuxLib::bindArray($multiAssociationIds); $associationCondition = '((' . $associationCondition . ') OR ' . 'x2_action_to_record.recordId in ' . AuxLib::arrToStrList(array_keys($multiAssociationIdParams)) . ')'; $associationCondition = 'x2_action_to_record.recordId in ' . AuxLib::arrToStrList(array_keys($multiAssociationIdParams)); $joinCountCmd = Yii::app()->db->createCommand()->select('COUNT(*)')->from('x2_actions t')->join('x2_action_to_record', 'actionId=t.id')->where($associationCondition . $visibilityCondition . $historyCriteria[$historyType] . ' AND x2_action_to_record.recordType=:recordType'); $joinCmd = Yii::app()->db->createCommand()->select('t.*')->from('x2_actions t')->join('x2_action_to_record', 'actionId=t.id')->where($associationCondition . $visibilityCondition . $historyCriteria[$historyType] . ' AND x2_action_to_record.recordType=:recordType'); $count = $mainCountCmd->union($joinCountCmd->getText())->queryScalar(array_merge(array(':recordType' => X2Model::getModelName($associationType)), $multiAssociationIdParams)); return array('cmd' => $mainCmd->union($joinCmd->getText()), 'count' => $count, 'params' => array_merge(array(':recordType' => X2Model::getModelName($associationType)), $multiAssociationIdParams)); }
public function formatActionToEvent($action, $id) { if (!($action->visibility >= 1 || $action->assignedTo == Yii::app()->user->name || Yii::app()->params->isAdmin)) { // admin sees all return false; } $linked = !empty($action->associationType) && strtolower($action->associationType) != 'none' && class_exists(X2Model::getModelName($action->associationType)); if ($linked) { $associatedModel = X2Model::getMOdelOfTypeWithId(X2Model::getModelName($action->associationType), $action->associationId); if ($associatedModel) { $associationUrl = $associatedModel->getUrl(); } else { $associationUrl = ''; } } $title = $action->shortActionText; //Email formatting $title = preg_replace('/<b>/', '', $title); $title = preg_replace('/<\\/b>/', '', $title); $title = preg_replace('/\\n\\n/', "\n", $title); $title = preg_replace('/<!--EndSig-->/', '', $title); $title = preg_replace('/<!--BeginOpenedEmail-->/', '', $title); $title = preg_replace('/<!--BeginSignature-->/', '', $title); if (in_array($action->type, array('email', 'emailFrom', 'email_quote', 'email_invoice', 'emailOpened', 'emailOpened_quote', 'emailOpened_invoice'))) { $title = 'Email: ' . $title; } $event = array('title' => $title, 'description' => $title, 'start' => date('Y-m-d H:i', $action->dueDate), 'id' => $action->id, 'complete' => $action->complete, 'calendarAssignment' => $id, 'allDay' => false); if ($action->allDay) { $event['allDay'] = $action->allDay; } if ($action->color) { $event['color'] = $action->color; } else { $event['color'] = '#6389de'; // old default color //$event['color'] = '#3a87ad'; } static $brightnesses = array(); if (!isset($brightnesses[$event['color']])) { $brightnesses[$event['color']] = X2Color::getColorBrightness($event['color']); } if ($brightnesses[$event['color']] < 115) { $event['textColor'] = 'white'; } if ($action->type == 'event') { if ($action->completeDate) { $event['end'] = date('Y-m-d H:i', $action->completeDate); } $event['type'] = 'event'; $event['associationType'] = $action->associationType; } $event['linked'] = $linked; if ($linked) { $event['associationType'] = $action->associationType; $event['associationUrl'] = $associationUrl; $event['associationName'] = $action->associationName; } $editable = X2CalendarPermissions::getEditableUserCalendarNames(); // If it is a group id, we don't need to check this $userEditable = !is_int($id) && isset($editable[$id]); $event['editable'] = $userEditable && Yii::app()->user->checkAccess('ActionsUpdate', array('X2Model' => $action)); return $event; }
/** * Saves a default template for the specified module into the users profile settings * @param string $moduleName * @param int $templateId */ public function actionAjaxSaveDefaultEmailTemplate($moduleName, $templateId) { $profile = Yii::app()->params->profile; $errors = false; $message = ''; if (isset($profile)) { $defaultEmailTemplates = CJSON::decode($profile->defaultEmailTemplates); if ($templateId !== '') { $template = Docs::model()->findByPk($templateId); if (!$this->checkPermissions($template, 'view')) { $errors = true; $message = Yii::t('profile', 'You do not have permission to view that template'); } else { // check that template exists, that it's of the correct doc type, and is // associated with the correct model type if ($template && ($template->type === 'email' && $template->associationType === X2Model::getModelName($moduleName) || $template->type === 'quote' && $moduleName === 'quotes')) { $defaultEmailTemplates[$moduleName] = $templateId; $profile->defaultEmailTemplates = CJSON::encode($defaultEmailTemplates); $profile->save(); } else { $errors = true; $message = Yii::t('profile', 'Invalid template'); } } } else { // remove default if (isset($defaultEmailTemplates[$moduleName])) { unset($defaultEmailTemplates[$moduleName]); } $profile->defaultEmailTemplates = CJSON::encode($defaultEmailTemplates); $profile->save(); } } else { $message = Yii::t('profile', 'Profile not found'); } echo CJSON::encode(array('success' => !$errors, 'message' => $message)); }
/** * @return array names of models associated with each module */ public static function getNamesOfModelsOfModules() { $moduleNames = array_map(function ($record) { return $record->name; }, Modules::model()->findAll(array('select' => 'name'))); $models = array(); foreach ($moduleNames as $name) { $modelName = X2Model::getModelName($name); if ($modelName && is_subclass_of($modelName, 'X2Model')) { $models[] = $modelName; } } return $models; }
private function getDragAndDropViewParams($id, $users = '') { $model = $this->loadModel($id); if (isset($_GET['modelType'])) { $modelType = $_GET['modelType']; } elseif (!empty($model->financialModel)) { if (X2Model::getModelName($model->financialModel)) { $modelType = $model->financialModel; } else { $modelType = 'contacts'; } } else { $modelType = 'contacts'; } $dateRange = self::getDateRange(); $memberListContainerSelectors = array(); $stageCount = count($model->stages); for ($i = 1; $i <= $stageCount; $i++) { $memberListContainerSelectors[] = '#workflow-stage-' . $i . ' .items'; } $workflowStatus = Workflow::getWorkflowStatus($id); $stagePermissions = Workflow::getStagePermissions($workflowStatus); $stagesWhichRequireComments = Workflow::getStageCommentRequirements($workflowStatus); $stageNames = Workflow::getStageNames($workflowStatus); $colors = $model->getWorkflowStageColors($stageCount, true); $stageCounts = Workflow::getStageCounts($workflowStatus, $dateRange, $users, $modelType); $stageValues = Workflow::getStageValues($workflowStatus, $dateRange, $users, $modelType); return array('model' => $model, 'modelType' => $modelType, 'dateRange' => $dateRange, 'users' => $users, 'colors' => $colors, 'listItemColors' => Workflow::getPipelineListItemColors($colors), 'memberListContainerSelectors' => $memberListContainerSelectors, 'stagePermissions' => $stagePermissions, 'stagesWhichRequireComments' => $stagesWhichRequireComments, 'stageNames' => $stageNames, 'stageCounts' => $stageCounts, 'stageValues' => $stageValues); }