/**
  * Render a hidden input, a text input with an auto-complete
  * event, and a select button. These three items together
  * form the Opportunity Editable Element
  * @return The element's content as a string.
  */
 protected function renderControlEditable()
 {
     $content = null;
     $content .= ZurmoHtml::textField('stageToProbabilityMapping_notUsed', null, array('id' => $this->getEditableInputId(), 'style' => "display:none;"));
     $fieldData = CustomFieldData::getByName('SalesStages');
     if ($fieldData->serializedData != null) {
         $values = unserialize($fieldData->serializedData);
         if (!is_array($values)) {
             $values = array();
         }
     } else {
         $values = array();
     }
     $stagesToProbabilities = OpportunitiesModule::getStageToProbabilityMappingData();
     foreach ($values as $value) {
         if (isset($stagesToProbabilities[$value])) {
             $probability = $stagesToProbabilities[$value];
         } else {
             $probability = 0;
         }
         $htmlOptions = array('name' => $this->getNameForInputField($value), 'value' => $probability);
         $element = $this->form->textField($this->model, $this->attribute, $htmlOptions);
         $element .= ZurmoHtml::tag('span', array(), $value);
         $content .= ZurmoHtml::tag('div', array('class' => 'has-lang-label'), $element);
     }
     return $content;
 }
 protected function processUpdate($id, $data)
 {
     $automaticMappingDisabled = OpportunitiesModule::isAutomaticProbabilityMappingDisabled();
     if ($automaticMappingDisabled === false) {
         // discard probability from $data
         unset($data['probability']);
     }
     return parent::processUpdate($id, $data);
 }
 protected function registerStageToProbabilityMappingScript($form)
 {
     $stageInputId = Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'stage', 'value'));
     $probabilityInputId = Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'probability'));
     $mappingData = OpportunitiesModule::getStageToProbabilityMappingData();
     if (count($mappingData) > 0) {
         $jsonEncodedMapping = CJSON::encode($mappingData);
         Yii::app()->clientScript->registerScript('stageToProbabilityMapping', "\n                \$('#" . $stageInputId . "').unbind('change');\n                \$('#" . $stageInputId . "').bind('change', function()\n                    {\n                        stageToProbabilityMapping(\$(this));\n                    }\n                );\n                function stageToProbabilityMapping(stageInput)\n                {\n                    var value  = stageInput.val();\n                    var result = \$.parseJSON('" . $jsonEncodedMapping . "');\n                    \$('#" . $probabilityInputId . "').val(0);\n                    \$.each(result, function(stage, probability)\n                    {\n                        if (value == stage)\n                        {\n                            \$('#" . $probabilityInputId . "').val(probability);\n                            return false;\n                        }\n                    });\n                 }\n                 stageToProbabilityMapping(\$('#" . $stageInputId . "'));\n                ");
     }
 }
예제 #4
0
 private function resolveStageToProbability()
 {
     if ($this->stage === null) {
         throw new NotSupportedException();
     } else {
         $this->probability = OpportunitiesModule::getProbabilityByStageValue($this->stage->value);
     }
 }
예제 #5
0
 /**
  * This test shows that accents are maybe not in the right encoding in the message file. This is just an example
  * of something that was not working in windows correctly. The result was the label would not display in the
  * input box in the browser in the module general in designer.
  */
 public function testAccentsAreEncodingProperly()
 {
     $this->assertEquals('Opportunité', ZurmoHtml::encode('Opportunité'));
     //First we need to activate French, to import the message
     Yii::app()->languageHelper->load();
     Yii::app()->languageHelper->activateLanguagesForTesting();
     Yii::app()->languageHelper->importMessagesForTesting();
     $label = OpportunitiesModule::getModuleLabelByTypeAndLanguage('SingularLowerCase', 'fr');
     $this->assertEquals('opportunité', $label);
     $this->assertEquals('opportunité', ZurmoHtml::encode($label));
 }
 /**
  * @depends testListOpportunities
  */
 public function testUnprivilegedUserViewUpdateDeleteOpportunities()
 {
     Yii::app()->user->userModel = User::getByUsername('super');
     $notAllowedUser = UserTestHelper::createBasicUser('Steven');
     $notAllowedUser->setRight('UsersModule', UsersModule::RIGHT_LOGIN_VIA_WEB_API);
     $saved = $notAllowedUser->save();
     // Test with unprivileged user to view, edit and delete account.
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $everyoneGroup = Group::getByName(Group::EVERYONE_GROUP_NAME);
     $this->assertTrue($everyoneGroup->save());
     $opportunities = Opportunity::getByName('Michael with owner only permissions');
     $this->assertEquals(1, count($opportunities));
     $data['description'] = "description 20";
     $response = $this->createApiCallWithRelativeUrl('read/' . $opportunities[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     $response = $this->createApiCallWithRelativeUrl('update/' . $opportunities[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     $response = $this->createApiCallWithRelativeUrl('delete/' . $opportunities[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have rights to perform this action.', $response['message']);
     //now check if user have rights, but no permissions.
     $notAllowedUser->setRight('OpportunitiesModule', OpportunitiesModule::getAccessRight());
     $notAllowedUser->setRight('OpportunitiesModule', OpportunitiesModule::getCreateRight());
     $notAllowedUser->setRight('OpportunitiesModule', OpportunitiesModule::getDeleteRight());
     $saved = $notAllowedUser->save();
     $this->assertTrue($saved);
     $response = $this->createApiCallWithRelativeUrl('read/' . $opportunities[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     $response = $this->createApiCallWithRelativeUrl('update/' . $opportunities[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     $response = $this->createApiCallWithRelativeUrl('delete/' . $opportunities[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
     $this->assertEquals('You do not have permissions for this action.', $response['message']);
     // Update unprivileged user permissions
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     unset($data);
     $data['explicitReadWriteModelPermissions'] = array('type' => ExplicitReadWriteModelPermissionsUtil::MIXED_TYPE_EVERYONE_GROUP);
     $response = $this->createApiCallWithRelativeUrl('update/' . $opportunities[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $authenticationData = $this->login('steven', 'steven');
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     $response = $this->createApiCallWithRelativeUrl('read/' . $opportunities[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     unset($data);
     $data['description'] = "description 21";
     $response = $this->createApiCallWithRelativeUrl('update/' . $opportunities[0]->id, 'PUT', $headers, array('data' => $data));
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $this->assertEquals('description 21', $response['data']['description']);
     // Test with privileged user
     $authenticationData = $this->login();
     $headers = array('Accept: application/json', 'ZURMO_SESSION_ID: ' . $authenticationData['sessionId'], 'ZURMO_TOKEN: ' . $authenticationData['token'], 'ZURMO_API_REQUEST_TYPE: REST');
     //Test Delete
     $response = $this->createApiCallWithRelativeUrl('delete/' . $opportunities[0]->id, 'DELETE', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_SUCCESS, $response['status']);
     $response = $this->createApiCallWithRelativeUrl('read/' . $opportunities[0]->id, 'GET', $headers);
     $response = json_decode($response, true);
     $this->assertEquals(ApiResponse::STATUS_FAILURE, $response['status']);
 }
예제 #7
0
 /**
  * Action called in the event that the mass delete quantity is larger than the pageSize.
  * This action is called after the pageSize quantity has been delted and continues to be
  * called until the mass delete action is complete.  For example, if there are 20 records to delete
  * and the pageSize is 5, then this action will be called 3 times.  The first 5 are updated when
  * the actionMassDelete is called upon the initial form submission.
  */
 public function actionMassDeleteProgress()
 {
     $pageSize = Yii::app()->pagination->resolveActiveForCurrentUserByType('massDeleteProgressPageSize');
     $opportunity = new Opportunity(false);
     $dataProvider = $this->getDataProviderByResolvingSelectAllFromGet(new OpportunitiesSearchForm($opportunity), $pageSize, Yii::app()->user->userModel->id, null, 'OpportunitiesSearchView');
     $this->processMassDeleteProgress('Opportunity', $pageSize, OpportunitiesModule::getModuleLabelByTypeAndLanguage('Plural'), $dataProvider);
 }
예제 #8
0
 public function testGetModelClassNames()
 {
     $modelClassNames = OpportunitiesModule::getModelClassNames();
     $this->assertEquals(1, count($modelClassNames));
     $this->assertEquals('Opportunity', $modelClassNames[0]);
 }
 public function testSuperUserOpportunityDefaultControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Default Controller actions requiring some sort of parameter via POST or GET
     //Load Opportunity Modules Menu.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/modulesMenu');
     //Load AttributesList for Opportunity module.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/attributesList');
     //Load ModuleLayoutsList for Opportunity module.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleLayoutsList');
     //Load ModuleEdit view for each applicable module.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/moduleEdit');
     //Now validate save with failed validation.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'OpportunitiesModuleForm' => $this->createModuleEditBadValidationPostData()));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertTrue(strlen($content) > 50);
     //approximate, but should definetely be larger than 50.
     //Now validate save with successful validation.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->setPostArray(array('ajax' => 'edit-form', 'OpportunitiesModuleForm' => $this->createModuleEditGoodValidationPostData('opp new name')));
     $content = $this->runControllerWithExitExceptionAndGetContent('designer/default/moduleEdit');
     $this->assertEquals('[]', $content);
     //Now save successfully.
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule'));
     $this->setPostArray(array('save' => 'Save', 'OpportunitiesModuleForm' => $this->createModuleEditGoodValidationPostData('opp new name')));
     $this->runControllerWithRedirectExceptionAndGetContent('designer/default/moduleEdit');
     //Now confirm everything did in fact save correctly.
     $this->assertEquals('Opp New Name', OpportunitiesModule::getModuleLabelByTypeAndLanguage('Singular'));
     $this->assertEquals('Opp New Names', OpportunitiesModule::getModuleLabelByTypeAndLanguage('Plural'));
     $this->assertEquals('opp new name', OpportunitiesModule::getModuleLabelByTypeAndLanguage('SingularLowerCase'));
     $this->assertEquals('opp new names', OpportunitiesModule::getModuleLabelByTypeAndLanguage('PluralLowerCase'));
     //Load LayoutEdit for each applicable module and applicable layout
     $this->resetPostArray();
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunitiesListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunitiesModalListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunitiesModalSearchView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunitiesMassEditView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunitiesRelatedListView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunitiesSearchView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
     $this->setGetArray(array('moduleClassName' => 'OpportunitiesModule', 'viewClassName' => 'OpportunityEditAndDetailsView'));
     $this->runControllerWithNoExceptionsAndGetContent('designer/default/LayoutEdit');
 }
 protected function resolveConfirmAlertInHtmlOptions($htmlOptions)
 {
     $htmlOptions['confirm'] = Zurmo::t('Core', 'Are you sure you want to delete this {modelLabel}?', array('{modelLabel}' => OpportunitiesModule::getModuleLabelByTypeAndLanguage('SingularLowerCase')));
     return $htmlOptions;
 }