Пример #1
0
 public function validateAttribute($model, $attribute, $params = array())
 {
     list($name, $id) = Fields::nameAndId($model->{$attribute});
     if (!ctype_digit($id)) {
         $model->addError($attribute, Yii::t('app', '{attr} does not refer to any existing record', array('{attr}' => $model->getAttributeLabel($attribute))));
     }
 }
Пример #2
0
 public function renderLink($field, array $htmlOptions = array())
 {
     $fieldName = $field->fieldName;
     $linkId = '';
     $name = '';
     $linkSource = null;
     // TODO: move this code and duplicate code in X2Model::renderModelInput into a helper
     // method. Might be able to use X2Model::getLinkedModel.
     if (class_exists($field->linkType)) {
         if (!empty($this->owner->{$fieldName})) {
             list($name, $linkId) = Fields::nameAndId($this->owner->{$fieldName});
             $linkModel = X2Model::getLinkedModelMock($field->linkType, $name, $linkId, true);
         } else {
             $linkModel = X2Model::model($field->linkType);
         }
         if ($linkModel instanceof X2Model && $linkModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) {
             $linkSource = Yii::app()->controller->createAbsoluteUrl($linkModel->autoCompleteSource);
             $linkId = $linkModel->id;
             $oldLinkFieldVal = $this->owner->{$fieldName};
             $this->owner->{$fieldName} = $name;
         }
     }
     $input = CHtml::hiddenField($field->modelName . '[' . $fieldName . '_id]', $linkId, array());
     $input .= CHtml::activeTextField($this->owner, $field->fieldName, array_merge(array('title' => $field->attributeLabel, 'data-x2-link-source' => $linkSource, 'class' => 'x2-mobile-autocomplete', 'autocomplete' => 'off'), $htmlOptions));
     return $input;
 }
Пример #3
0
 /**
  * Displays a particular model.
  * @param integer $id the ID of the model to be displayed
  */
 public function actionView($id)
 {
     $type = 'quotes';
     $model = $this->getModel($id);
     if (!$this->checkPermissions($model, 'view')) {
         $this->denied();
     }
     $quoteProducts = $model->lineItems;
     // add quote to user's recent item list
     User::addRecentItem('q', $id, Yii::app()->user->getId());
     $contactNameId = Fields::nameAndId($model->associatedContacts);
     $contactId = $contactNameId[1];
     parent::view($model, $type, array('orders' => $quoteProducts, 'contactId' => $contactId));
 }
Пример #4
0
 /**
  * An AJAX called function which exports data to a CSV via pagination.
  * This is a generalized version of the Contacts export.
  * @param int $page The page of the data provider to export
  */
 public function actionExportModelRecords($page, $model)
 {
     X2Model::$autoPopulateFields = false;
     $file = $this->safePath($_SESSION['modelExportFile']);
     $staticModel = X2Model::model(str_replace(' ', '', $model));
     $fields = $staticModel->getFields();
     $fp = fopen($file, 'a+');
     // Load data provider based on export criteria
     $excludeHidden = !isset($_GET['includeHidden']) || $_GET['includeHidden'] === 'false';
     if ($page == 0 && $excludeHidden && isset($_SESSION['exportModelCriteria']) && $_SESSION['exportModelCriteria'] instanceof CDbCriteria) {
         // Save hidden condition in criteria
         $hiddenConditions = $staticModel->getHiddenCondition();
         $_SESSION['exportModelCriteria']->addCondition($hiddenConditions);
     }
     $dp = new CActiveDataProvider($model, array('criteria' => isset($_SESSION['exportModelCriteria']) ? $_SESSION['exportModelCriteria'] : array(), 'pagination' => array('pageSize' => 100)));
     // Flip through to the right page.
     $pg = $dp->getPagination();
     $pg->setCurrentPage($page);
     $dp->setPagination($pg);
     $records = $dp->getData();
     $pageCount = $dp->getPagination()->getPageCount();
     // Retrieve specified export delimeter and enclosure
     $delimeter = isset($_GET['delimeter']) ? $_GET['delimeter'] : ',';
     $enclosure = isset($_GET['enclosure']) ? $_GET['enclosure'] : '"';
     // We need to set our data to be human friendly, so loop through all the
     // records and format any date / link / visibility fields.
     foreach ($records as $record) {
         foreach ($fields as $field) {
             $fieldName = $field->fieldName;
             if ($field->type == 'date' || $field->type == 'dateTime') {
                 if (is_numeric($record->{$fieldName})) {
                     $record->{$fieldName} = Formatter::formatLongDateTime($record->{$fieldName});
                 }
             } elseif ($field->type == 'link') {
                 $name = $record->{$fieldName};
                 if (!empty($field->linkType)) {
                     list($name, $id) = Fields::nameAndId($name);
                 }
                 if (!empty($name)) {
                     $record->{$fieldName} = $name;
                 }
             } elseif ($fieldName == 'visibility') {
                 switch ($record->{$fieldName}) {
                     case 0:
                         $record->{$fieldName} = 'Private';
                         break;
                     case 1:
                         $record->{$fieldName} = 'Public';
                         break;
                     case 2:
                         $record->{$fieldName} = 'User\'s Groups';
                         break;
                     default:
                         $record->{$fieldName} = 'Private';
                 }
             }
         }
         // Enforce metadata to ensure accuracy of column order, then export.
         $combinedMeta = array_combine($_SESSION['modelExportMeta'], $_SESSION['modelExportMeta']);
         $recordAttributes = $record->attributes;
         if ($model === 'Actions') {
             // Export descriptions with Actions
             $actionText = $record->actionText;
             if ($actionText) {
                 $actionDescription = $actionText->text;
                 $recordAttributes = array_merge($recordAttributes, array('actionDescription' => $actionDescription));
             }
         }
         if ($_SESSION['includeTags']) {
             $tags = $record->getTags();
             $recordAttributes = array_merge($recordAttributes, array('tags' => implode(',', $tags)));
         }
         $tempAttributes = array_intersect_key($recordAttributes, $combinedMeta);
         $tempAttributes = array_merge($combinedMeta, $tempAttributes);
         fputcsv($fp, $tempAttributes, $delimeter, $enclosure);
     }
     unset($dp);
     fclose($fp);
     if ($page + 1 < $pageCount) {
         echo $page + 1;
     }
 }
Пример #5
0
    public static function renderModelInput(CModel $model, $field, $htmlOptions = array())
    {
        if (!$field->asa('CommonFieldsBehavior')) {
            throw new Exception('$field must have CommonFieldsBehavior');
        }
        if ($field->required) {
            if (isset($htmlOptions['class'])) {
                $htmlOptions['class'] .= ' x2-required';
            } else {
                $htmlOptions = array_merge(array('class' => 'x2-required'), $htmlOptions);
            }
        }
        $fieldName = $field->fieldName;
        if (!isset($field)) {
            return null;
        }
        switch ($field->type) {
            case 'text':
                return CHtml::activeTextArea($model, $field->fieldName, array_merge(array('title' => $field->attributeLabel), array_merge(array('encode' => false), $htmlOptions)));
            case 'date':
                $oldDateVal = $model->{$fieldName};
                $model->{$fieldName} = Formatter::formatDate($model->{$fieldName}, 'medium');
                Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
                $pickerOptions = array('dateFormat' => Formatter::formatDatePicker(), 'changeMonth' => false, 'changeYear' => true);
                if (Yii::app()->getLanguage() === 'fr') {
                    $pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
                }
                $input = Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => $fieldName, 'mode' => 'date', 'options' => $pickerOptions, 'htmlOptions' => array_merge(array('title' => $field->attributeLabel), $htmlOptions), 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage()), true);
                $model->{$fieldName} = $oldDateVal;
                return $input;
            case 'dateTime':
                $oldDateTimeVal = $model->{$fieldName};
                $pickerOptions = array('dateFormat' => Formatter::formatDatePicker('medium'), 'timeFormat' => Formatter::formatTimePicker(), 'ampm' => Formatter::formatAMPM(), 'changeMonth' => true, 'changeYear' => true);
                if (Yii::app()->getLanguage() === 'fr') {
                    $pickerOptions['monthNamesShort'] = Formatter::getPlainAbbrMonthNames();
                }
                $model->{$fieldName} = Formatter::formatDateTime($model->{$fieldName});
                Yii::import('application.extensions.CJuiDateTimePicker.CJuiDateTimePicker');
                $input = Yii::app()->controller->widget('CJuiDateTimePicker', array('model' => $model, 'attribute' => $fieldName, 'mode' => 'datetime', 'options' => $pickerOptions, 'htmlOptions' => array_merge(array('title' => $field->attributeLabel), $htmlOptions), 'language' => Yii::app()->language == 'en' ? '' : Yii::app()->getLanguage()), true);
                $model->{$fieldName} = $oldDateTimeVal;
                return $input;
            case 'dropdown':
                // Note: if desired to translate dropdown options, change the seecond argument to
                // $model->module
                $om = $field->getDropdownOptions();
                $multi = (bool) $om['multi'];
                $dropdowns = $om['options'];
                $curVal = $multi ? CJSON::decode($model->{$field->fieldName}) : $model->{$field->fieldName};
                $ajaxArray = array();
                if ($field instanceof Fields) {
                    $dependencyCount = X2Model::model('Dropdowns')->countByAttributes(array('parent' => $field->linkType));
                    $fieldDependencyCount = X2Model::model('Fields')->countByAttributes(array('modelName' => $field->modelName, 'type' => 'dependentDropdown', 'linkType' => $field->linkType));
                    if ($dependencyCount > 0 && $fieldDependencyCount > 0) {
                        $ajaxArray = array('ajax' => array('type' => 'GET', 'url' => Yii::app()->controller->createUrl('/site/dynamicDropdown'), 'data' => 'js:{
                                "val":$(this).val(),
                                "dropdownId":"' . $field->linkType . '",
                                "field":true, "module":"' . $field->modelName . '"
                            }', 'success' => '
                                function(data){
                                    if(data){
                                        data=JSON.parse(data);
                                        if(data[0] && data[1]){
                                            $("#' . $field->modelName . '_"+data[0]).html(data[1]);
                                        }
                                    }
                                }'));
                    }
                }
                $htmlOptions = array_merge($htmlOptions, $ajaxArray, array('title' => $field->attributeLabel));
                if ($multi) {
                    $multiSelectOptions = array();
                    if (!is_array($curVal)) {
                        $curVal = array();
                    }
                    foreach ($curVal as $option) {
                        $multiSelectOptions[$option] = array('selected' => 'selected');
                    }
                    $htmlOptions = array_merge($htmlOptions, array('options' => $multiSelectOptions, 'multiple' => 'multiple'));
                } elseif ($field->includeEmpty) {
                    $htmlOptions = array_merge($htmlOptions, array('empty' => Yii::t('app', "Select an option")));
                }
                return CHtml::activeDropDownList($model, $field->fieldName, $dropdowns, $htmlOptions);
            case 'dependentDropdown':
                return CHtml::activeDropDownList($model, $field->fieldName, array('' => '-'), array_merge(array('title' => $field->attributeLabel), $htmlOptions));
            case 'link':
                $linkSource = null;
                $linkId = '';
                $name = '';
                if (class_exists($field->linkType)) {
                    // Create a model for autocompletion:
                    if (!empty($model->{$fieldName})) {
                        list($name, $linkId) = Fields::nameAndId($model->{$fieldName});
                        $linkModel = X2Model::getLinkedModelMock($field->linkType, $name, $linkId, true);
                    } else {
                        $linkModel = X2Model::model($field->linkType);
                    }
                    if ($linkModel instanceof X2Model && $linkModel->asa('X2LinkableBehavior') instanceof X2LinkableBehavior) {
                        $linkSource = Yii::app()->controller->createUrl($linkModel->autoCompleteSource);
                        $linkId = $linkModel->id;
                        $oldLinkFieldVal = $model->{$fieldName};
                        $model->{$fieldName} = $name;
                    }
                }
                static $linkInputCounter = 0;
                $hiddenInputId = $field->modelName . '_' . $fieldName . "_id" . $linkInputCounter++;
                $input = CHtml::hiddenField($field->modelName . '[' . $fieldName . '_id]', $linkId, array('id' => $hiddenInputId)) . Yii::app()->controller->widget('zii.widgets.jui.CJuiAutoComplete', array('model' => $model, 'attribute' => $fieldName, 'source' => $linkSource, 'value' => $name, 'options' => array('minLength' => '1', 'select' => 'js:function( event, ui ) {
                                    $("#' . $hiddenInputId . '").
                                        val(ui.item.id);
                                    $(this).val(ui.item.value);
                                    return false;
                            }', 'create' => $field->linkType == 'Contacts' ? 'js:function(event, ui) {
                                    $(this).data( "uiAutocomplete" )._renderItem = 
                                        function(ul,item) {
                                            return $("<li>").data("item.autocomplete",item).
                                                append(x2.forms.renderContactLookup(item)).
                                                appendTo(ul);
                                        };
                            }' : ($field->linkType == 'BugReports' ? 'js:function(event, ui) {
                                $(this).data( "uiAutocomplete" )._renderItem = 
                                    function( ul, item ) {

                                    var label = "<a style=\\"line-height: 1;\\">" + item.label;

                                    label += "<span style=\\"font-size: 0.6em;\\">";

                                    // add email if defined
                                    if(item.subject) {
                                        label += "<br>";
                                        label += item.subject;
                                    }

                                    label += "</span>";
                                    label += "</a>";

                                    return $( "<li>" )
                                        .data( "item.autocomplete", item )
                                        .append( label )
                                        .appendTo( ul );
                                };
                            }' : '')), 'htmlOptions' => array_merge(array('title' => $field->attributeLabel), $htmlOptions)), true);
                if (isset($oldLinkFieldVal)) {
                    $model->{$fieldName} = $oldLinkFieldVal;
                }
                return $input;
            case 'rating':
                return Yii::app()->controller->widget('X2StarRating', array('model' => $model, 'attribute' => $field->fieldName, 'readOnly' => isset($htmlOptions['disabled']) && $htmlOptions['disabled'], 'minRating' => Fields::RATING_MIN, 'maxRating' => Fields::RATING_MAX, 'starCount' => Fields::RATING_MAX - Fields::RATING_MIN + 1, 'cssFile' => Yii::app()->theme->getBaseUrl() . '/css/rating/jquery.rating.css', 'htmlOptions' => $htmlOptions, 'callback' => 'function(value, link){
                        if (typeof x2 !== "undefined" &&
                            typeof x2.InlineEditor !== "undefined" &&
                            typeof x2.InlineEditor.ratingFields !== "undefined") {

                            x2.InlineEditor.ratingFields["' . $field->modelName . '[' . $field->fieldName . ']"] = value;
                        }
                    }'), true);
            case 'boolean':
                $checkbox = CHtml::openTag('div', X2Html::mergeHtmlOptions($htmlOptions, array('class' => 'checkboxWrapper')));
                $checkbox .= CHtml::activeCheckBox($model, $field->fieldName, array_merge(array('unchecked' => 0, 'title' => $field->attributeLabel), $htmlOptions));
                $checkbox .= CHtml::closeTag('div');
                return $checkbox;
            case 'assignment':
                $oldAssignmentVal = $model->{$fieldName};
                $model->{$fieldName} = !empty($model->{$fieldName}) ? $field->linkType == 'multiple' && !is_array($model->{$fieldName}) ? explode(', ', $model->{$fieldName}) : $model->{$fieldName} : X2Model::getDefaultAssignment();
                $dropdownList = CHtml::activeDropDownList($model, $fieldName, X2Model::getAssignmentOptions(true, true), array_merge(array('title' => $field->attributeLabel, 'id' => $field->modelName . '_' . $fieldName . '_assignedToDropdown', 'multiple' => $field->linkType == 'multiple' ? 'multiple' : null), $htmlOptions));
                $model->{$fieldName} = $oldAssignmentVal;
                return $dropdownList;
            case 'optionalAssignment':
                // optional assignment for users (can be left blank)
                $users = User::getNames();
                unset($users['Anyone']);
                return CHtml::activeDropDownList($model, $fieldName, $users, array_merge(array('title' => $field->attributeLabel, 'empty' => ''), $htmlOptions));
            case 'visibility':
                $permissionsBehavior = Yii::app()->params->modelPermissions;
                return CHtml::activeDropDownList($model, $field->fieldName, $permissionsBehavior::getVisibilityOptions(), array_merge(array('title' => $field->attributeLabel, 'id' => $field->modelName . "_visibility"), $htmlOptions));
                // 'varchar', 'email', 'url', 'int', 'float', 'currency', 'phone'
                // case 'int':
                // return CHtml::activeNumberField($model, $field->fieldNamearray_merge(array(
                // 'title' => $field->attributeLabel,
                // ), $htmlOptions));
            // 'varchar', 'email', 'url', 'int', 'float', 'currency', 'phone'
            // case 'int':
            // return CHtml::activeNumberField($model, $field->fieldNamearray_merge(array(
            // 'title' => $field->attributeLabel,
            // ), $htmlOptions));
            case 'percentage':
                $htmlOptions['class'] = empty($htmlOptions['class']) ? 'input-percentage' : $htmlOptions['class'] . ' input-percentage';
                return CHtml::activeTextField($model, $field->fieldName, array_merge(array('title' => $field->attributeLabel), $htmlOptions));
            case 'currency':
                $fieldName = $field->fieldName;
                $elementId = isset($htmlOptions['id']) ? '#' . $htmlOptions['id'] : '#' . $field->modelName . '_' . $field->fieldName;
                Yii::app()->controller->widget('application.extensions.moneymask.MMask', array('element' => $elementId, 'currency' => Yii::app()->params['currency'], 'config' => array('affixStay' => true, 'decimal' => Yii::app()->locale->getNumberSymbol('decimal'), 'thousands' => Yii::app()->locale->getNumberSymbol('group'))));
                return CHtml::activeTextField($model, $field->fieldName, array_merge(array('title' => $field->attributeLabel, 'class' => 'currency-field'), $htmlOptions));
            case 'credentials':
                $typeAlias = explode(':', $field->linkType);
                $type = $typeAlias[0];
                if (count($typeAlias) > 1) {
                    $uid = Credentials::$sysUseId[$typeAlias[1]];
                } else {
                    $uid = Yii::app()->user->id;
                }
                return Credentials::selectorField($model, $field->fieldName, $type, $uid);
            case 'timerSum':
                // Sorry, no-can-do. This is field derives its value from a sum over timer records.
                return $model->renderAttribute($field->fieldName);
            case 'float':
            case 'int':
                if (isset($model->{$fieldName})) {
                    $oldNumVal = $model->{$fieldName};
                    $model->{$fieldName} = Yii::app()->locale->numberFormatter->formatDecimal($model->{$fieldName});
                }
                $input = CHtml::activeTextField($model, $field->fieldName, array_merge(array('title' => $field->attributeLabel), $htmlOptions));
                if (isset($oldNumVal)) {
                    $model->{$fieldName} = $oldNumVal;
                }
                return $input;
            default:
                return CHtml::activeTextField($model, $field->fieldName, array_merge(array('title' => $field->attributeLabel), $htmlOptions));
                // array(
                // 'tabindex'=>isset($item['tabindex'])? $item['tabindex'] : null,
                // 'disabled'=>$item['readOnly']? 'disabled' : null,
                // 'title'=>$field->attributeLabel,
                // 'style'=>$default?'color:#aaa;':null,
                // ));
        }
    }
Пример #6
0
 public function afterSave($event)
 {
     $oldAttributes = $this->owner->getOldAttributes();
     $linkFields = Fields::model()->findAllByAttributes(array('modelName' => get_class($this->owner), 'type' => 'link'));
     foreach ($linkFields as $field) {
         $nameAndId = Fields::nameAndId($this->owner->getAttribute($field->fieldName));
         $oldNameAndId = Fields::nameAndId(isset($oldAttributes[$field->fieldName]) ? $oldAttributes[$field->fieldName] : '');
         if (!empty($oldNameAndId[1]) && $nameAndId[1] !== $oldNameAndId[1]) {
             $oldTarget = X2Model::model($field->linkType)->findByPk($oldNameAndId[1]);
             $this->owner->deleteRelationship($oldTarget);
         }
         $newTarget = X2Model::model($field->linkType)->findByPk($nameAndId[1]);
         $this->owner->createRelationship($newTarget);
     }
     parent::afterSave($event);
 }
Пример #7
0
 /**
  * @param Array $condition
  * @param Array $params
  * @return bool true for success, false otherwise
  */
 public static function checkCondition($condition, &$params)
 {
     if ($condition['type'] === 'workflow_status') {
         return self::checkWorkflowStatusCondition($condition, $params);
     }
     $model = isset($params['model']) ? $params['model'] : null;
     $operator = isset($condition['operator']) ? $condition['operator'] : '=';
     // $type = isset($condition['type'])? $condition['type'] : null;
     $value = isset($condition['value']) ? $condition['value'] : null;
     // default to a doing basic value comparison
     if (isset($condition['name']) && $condition['type'] === '') {
         if (!isset($params[$condition['name']])) {
             return false;
         }
         return self::evalComparison($params[$condition['name']], $operator, $value);
     }
     switch ($condition['type']) {
         case 'attribute':
             if (!isset($condition['name'], $model)) {
                 return false;
             }
             $attr =& $condition['name'];
             if (null === ($field = $model->getField($attr))) {
                 return false;
             }
             if ($operator === 'changed') {
                 return $model->attributeChanged($attr);
             }
             if ($field->type === 'link') {
                 list($attrVal, $id) = Fields::nameAndId($model->getAttribute($attr));
             } else {
                 $attrVal = $model->getAttribute($attr);
             }
             return self::evalComparison($attrVal, $operator, X2Flow::parseValue($value, $field->type, $params), $field);
         case 'current_user':
             return self::evalComparison(Yii::app()->user->getName(), $operator, X2Flow::parseValue($value, 'assignment', $params));
         case 'month':
             return self::evalComparison((int) date('n'), $operator, $value);
             // jan = 1, dec = 12
         // jan = 1, dec = 12
         case 'day_of_month':
             return self::evalComparison((int) date('j'), $operator, $value);
             // 1 through 31
         // 1 through 31
         case 'day_of_week':
             return self::evalComparison((int) date('N'), $operator, $value);
             // monday = 1, sunday = 7
         // monday = 1, sunday = 7
         case 'time_of_day':
             // - mktime(0,0,0)
             return self::evalComparison(time(), $operator, X2Flow::parseValue($value, 'time', $params));
             // seconds since midnight
             // case 'current_local_time':
         // seconds since midnight
         // case 'current_local_time':
         case 'current_time':
             return self::evalComparison(time(), $operator, X2Flow::parseValue($value, 'dateTime', $params));
         case 'user_active':
             return CActiveRecord::model('Session')->exists('user=:user AND status=1', array(':user' => X2Flow::parseValue($value, 'assignment', $params)));
         case 'on_list':
             if (!isset($model, $value)) {
                 return false;
             }
             $value = X2Flow::parseValue($value, 'link');
             // look up specified list
             if (is_numeric($value)) {
                 $list = CActiveRecord::model('X2List')->findByPk($value);
             } else {
                 $list = CActiveRecord::model('X2List')->findByAttributes(array('name' => $value));
             }
             return $list !== null && $list->hasRecord($model);
         case 'has_tags':
             if (!isset($model, $value)) {
                 return false;
             }
             $tags = X2Flow::parseValue($value, 'tags');
             return $model->hasTags($tags, 'AND');
         case 'workflow_status':
             if (!isset($model, $condition['workflowId'], $condition['stageNumber'])) {
                 return false;
             }
             switch ($operator) {
                 case 'started_workflow':
                     return CActiveRecord::model('Actions')->exists('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId']));
                 case 'started_stage':
                     return CActiveRecord::model('Actions')->exists('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow AND stageNumber=:stage AND (completeDate IS NULL OR completeDate=0)', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId'], ':stageNumber' => $condition['stageNumber']));
                 case 'completed_stage':
                     return CActiveRecord::model('Actions')->exists('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow AND stageNumber=:stage AND completeDate > 0', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId'], ':stageNumber' => $condition['stageNumber']));
                 case 'completed_workflow':
                     $stageCount = CActiveRecord::model('WorkflowStage')->count('workflowId=:id', array(':id' => $condition['workflowId']));
                     $actionCount = CActiveRecord::model('Actions')->count('associationType=:type AND associationId=:modelId AND type="workflow" AND workflowId=:workflow', array(':type' => get_class($model), ':modelId' => $model->id, ':workflow' => $condition['workflowId']));
                     return $actionCount >= $stageCount;
             }
             return false;
         case 'email_open':
             if (isset($params['sentEmails'], $params['sentEmails'][$value])) {
                 $trackEmail = TrackEmail::model()->findByAttributes(array('uniqueId' => $params['sentEmails'][$value]));
                 return $trackEmail && !is_null($trackEmail->opened);
             }
             return false;
     }
     return false;
     // foreach($condition as $key = >$value) {
     // Record attribute (=, <, >, <>, in list, not in list, empty, not empty, contains)
     // Linked record attribute (eg. a contact's account has > 30 employees)
     // Current user
     // Current time (day of week, hours, etc)
     // Current time in record's timezone
     // Is user X logged in
     // Workflow status (in workflow X, started stage Y, completed Y, completed all)
     // }
 }
Пример #8
0
            <?php 
//echo $form->label($this->model, 'subject', array('class' => 'x2-email-label'));
echo $form->textField($this->model, 'subject', array('tabindex' => '4', 'class' => 'x2-default-field', 'data-default-text' => CHtml::encode(Yii::t('app', 'Subject'))));
?>
        </div>
        <?php 
if (!$this->disableTemplates) {
    ?>
        <div class="row email-input-row">
            <?php 
    $templateList = Docs::getEmailTemplates($type, $associationType);
    $target = $this->model->targetModel;
    echo $form->label($this->model, 'template', array('class' => 'x2-email-label'));
    if (!isset($this->template) && $target instanceof Quote && isset($target->template) && !isset($this->model->template)) {
        // When sending an InlineEmail targeting a Quote
        list($templateName, $selectedTemplate) = Fields::nameAndId($target->template);
        $this->model->template = $selectedTemplate;
    }
    echo $form->dropDownList($this->model, 'template', array('0' => Yii::t('docs', 'Custom Message')) + $templateList, array('id' => 'email-template'));
    ?>
        </div>
        <?php 
}
?>
        <div class="row" id="email-message-box">
        <?php 
echo $form->textArea($this->model, 'message', array('id' => 'email-message', 'style' => 'margin:0;padding:0;'));
?>
        </div>
    </div>
    <div class="row bottom-row-outer">
Пример #9
0
 public function getAccountId()
 {
     list($name, $id) = Fields::nameAndId($this->accountName);
     return $id;
 }
Пример #10
0
 public function actionUpdateList($id)
 {
     $list = X2List::model()->findByPk($id);
     if (!isset($list)) {
         throw new CHttpException(400, Yii::t('app', 'This list cannot be found.'));
     }
     if (!$this->checkPermissions($list, 'edit')) {
         throw new CHttpException(403, Yii::t('app', 'You do not have permission to modify this list.'));
     }
     $contactModel = new Contacts();
     $comparisonList = X2List::getComparisonList();
     $fields = $contactModel->getFields(true);
     if ($list->type == 'dynamic') {
         $criteriaModels = X2ListCriterion::model()->findAllByAttributes(array('listId' => $list->id), new CDbCriteria(array('order' => 'id ASC')));
         if (isset($_POST['X2List'], $_POST['X2List']['attribute'], $_POST['X2List']['comparison'], $_POST['X2List']['value'])) {
             $attributes =& $_POST['X2List']['attribute'];
             $comparisons =& $_POST['X2List']['comparison'];
             $values =& $_POST['X2List']['value'];
             if (count($attributes) > 0 && count($attributes) == count($comparisons) && count($comparisons) == count($values)) {
                 $list->attributes = $_POST['X2List'];
                 $list->modelName = 'Contacts';
                 $list->lastUpdated = time();
                 if ($list->save()) {
                     $this->redirect(array('/contacts/contacts/list', 'id' => $list->id));
                 }
             }
         }
     } else {
         //static or campaign lists
         if (isset($_POST['X2List'])) {
             $list->attributes = $_POST['X2List'];
             $list->modelName = 'Contacts';
             $list->lastUpdated = time();
             $list->save();
             $this->redirect(array('/contacts/contacts/list', 'id' => $list->id));
         }
     }
     if (empty($criteriaModels)) {
         $default = new X2ListCriterion();
         $default->value = '';
         $default->attribute = '';
         $default->comparison = 'contains';
         $criteriaModels[] = $default;
     } else {
         if ($list->type = 'dynamic') {
             foreach ($criteriaModels as $criM) {
                 if (isset($fields[$criM->attribute])) {
                     if ($fields[$criM->attribute]->type == 'link') {
                         $criM->value = implode(',', array_map(function ($c) {
                             list($name, $id) = Fields::nameAndId($c);
                             return $name;
                         }, explode(',', $criM->value)));
                     }
                 }
             }
         }
     }
     $this->render('updateList', array('model' => $list, 'criteriaModels' => $criteriaModels, 'users' => User::getNames(), 'comparisonList' => $comparisonList, 'listTypes' => array('dynamic' => Yii::t('contacts', 'Dynamic'), 'static' => Yii::t('contacts', 'Static')), 'itemModel' => $contactModel));
 }
Пример #11
0
 public function getContactId()
 {
     list($name, $id) = Fields::nameAndId($this->associatedContacts);
     return $id;
 }
Пример #12
0
 public function testNameAndId()
 {
     $d = Fields::NAMEID_DELIM;
     $nid = array('My Name', 12345);
     $this->assertEquals($nid, Fields::nameAndId(implode($d, $nid)));
     // This shouldn't affect it...
     $nid[0] .= $d;
     $this->assertEquals($nid, Fields::nameAndId(implode($d, $nid)));
     // Or this...
     $nid[0] = $d . $nid[0];
     $this->assertEquals($nid, Fields::nameAndId(implode($d, $nid)));
     // It should return an array with nameId first and then null for ID:
     $nid[1] = null;
     $this->assertEquals($nid, Fields::nameAndId($nid[0]));
     // Empty in = empty out:
     $nid = array(null, null);
     $this->assertEquals($nid, Fields::nameAndId(null));
 }