public function testMakeFormAndSetConfigurationFromForm()
 {
     $billy = User::getByUsername('billy');
     Yii::app()->themeManager->customThemeColorsArray = array('#111111', '#222222', '#333333');
     Yii::app()->themeManager->globalThemeColor = 'custom';
     Yii::app()->themeManager->forceAllUsersTheme = true;
     $logoFileName = 'testLogo.png';
     $logoFilePath = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files') . DIRECTORY_SEPARATOR . $logoFileName;
     ZurmoUserInterfaceConfigurationFormAdapter::resizeLogoImageFile($logoFilePath, $logoFilePath, null, ZurmoUserInterfaceConfigurationForm::DEFAULT_LOGO_HEIGHT);
     $logoFileId = ZurmoUserInterfaceConfigurationFormAdapter::saveLogoFile($logoFileName, $logoFilePath, 'logoFileModelId');
     ZurmoUserInterfaceConfigurationFormAdapter::publishLogo($logoFileName, $logoFilePath);
     ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'logoFileModelId', $logoFileId);
     ZurmoConfigurationUtil::setByModuleName('ZurmoModule', 'logoThumbFileModelId', $logoFileId);
     //Getting values
     $form = ZurmoUserInterfaceConfigurationFormAdapter::makeFormFromGlobalConfiguration();
     $this->assertEquals($logoFileName, $form->logoFileData['name']);
     $this->assertEquals('custom', $form->themeColor);
     $this->assertEquals('#111111', $form->customThemeColor1);
     $this->assertEquals('#222222', $form->customThemeColor2);
     $this->assertEquals('#333333', $form->customThemeColor3);
     $this->assertEquals('1', $form->forceAllUsersTheme);
     //Setting values
     $form->themeColor = 'lime';
     $form->customThemeColor1 = '#999999';
     $form->customThemeColor2 = '#888888';
     $form->customThemeColor3 = '#777777';
     $form->forceAllUsersTheme = false;
     $logoFileName2 = 'testLogo2.png';
     $logoFilePath2 = Yii::getPathOfAlias('application.modules.zurmo.tests.unit.files') . DIRECTORY_SEPARATOR . $logoFileName2;
     copy($logoFilePath2, sys_get_temp_dir() . DIRECTORY_SEPARATOR . $logoFileName2);
     copy($logoFilePath2, sys_get_temp_dir() . DIRECTORY_SEPARATOR . ZurmoUserInterfaceConfigurationForm::LOGO_THUMB_FILE_NAME_PREFIX . $logoFileName2);
     Yii::app()->user->setState('logoFileName', $logoFileName2);
     ZurmoUserInterfaceConfigurationFormAdapter::setConfigurationFromForm($form);
     $form = ZurmoUserInterfaceConfigurationFormAdapter::makeFormFromGlobalConfiguration();
     $this->assertEquals('lime', $form->themeColor);
     $this->assertEquals('#999999', $form->customThemeColor1);
     $this->assertEquals('#888888', $form->customThemeColor2);
     $this->assertEquals('#777777', $form->customThemeColor3);
     $this->assertEquals(false, $form->forceAllUsersTheme);
     $this->assertEquals($logoFileName2, $form->logoFileData['name']);
 }
Example #2
0
 protected function resolveAndRenderLogoContent()
 {
     $homeUrl = Yii::app()->createUrl('home/default');
     $content = null;
     if ($logoFileModelId = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'logoFileModelId')) {
         $logoFileModel = FileModel::getById($logoFileModelId);
         $logoFileSrc = Yii::app()->getAssetManager()->getPublishedUrl(Yii::getPathOfAlias('application.runtime.uploads') . DIRECTORY_SEPARATOR . $logoFileModel->name);
     } else {
         $logoFileSrc = Yii::app()->themeManager->baseUrl . '/default/images/Zurmo_logo.png';
     }
     $logoHeight = ZurmoUserInterfaceConfigurationFormAdapter::resolveLogoHeight();
     $logoWidth = ZurmoUserInterfaceConfigurationFormAdapter::resolveLogoWidth();
     if (Yii::app()->userInterface->isMobile()) {
         //make sure width and height are NEVER defined
         $content .= '<img src="' . $logoFileSrc . '" alt="Zurmo Logo" />';
     } else {
         $content .= '<img src="' . $logoFileSrc . '" alt="Zurmo Logo" height="' . $logoHeight . '" width="' . $logoWidth . '" />';
     }
     if ($this->applicationName != null) {
         $content .= ZurmoHtml::tag('span', array(), $this->applicationName);
     }
     return ZurmoHtml::link($content, $homeUrl, array('class' => 'clearfix', 'id' => 'corp-logo'));
 }
 public function handlePublishLogoAssets($event)
 {
     if (null !== ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'logoFileModelId')) {
         $logoFileModelId = ZurmoConfigurationUtil::getByModuleName('ZurmoModule', 'logoFileModelId');
         $logoFileModel = FileModel::getById($logoFileModelId);
         $logoFileSrc = Yii::app()->getAssetManager()->getPublishedUrl(Yii::getPathOfAlias('application.runtime.uploads') . DIRECTORY_SEPARATOR . $logoFileModel->name);
         //logoFile is either not published or we have dangling url for asset
         if ($logoFileSrc === false || file_exists($logoFileSrc) === false) {
             //Logo file is not published in assets
             //Check if it exists in runtime/uploads
             if (file_exists(Yii::getPathOfAlias('application.runtime.uploads') . DIRECTORY_SEPARATOR . $logoFileModel->name) === false) {
                 $logoFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $logoFileModel->name;
                 file_put_contents($logoFilePath, $logoFileModel->fileContent->content, LOCK_EX);
                 ZurmoUserInterfaceConfigurationFormAdapter::publishLogo($logoFileModel->name, $logoFilePath);
             } else {
                 //Logo File exist in runtime/uploads but not published
                 Yii::app()->getAssetManager()->publish(Yii::getPathOfAlias('application.runtime.uploads') . DIRECTORY_SEPARATOR . $logoFileModel->name);
             }
         }
     }
 }
 public function actionUploadLogo($filesVariableName)
 {
     assert('is_string($filesVariableName)');
     try {
         $uploadedFile = CUploadedFile::getInstanceByName($filesVariableName);
         assert('$uploadedFile instanceof CUploadedFile');
         $logoFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . $uploadedFile->getName();
         $thumbFilePath = sys_get_temp_dir() . DIRECTORY_SEPARATOR . ZurmoUserInterfaceConfigurationForm::LOGO_THUMB_FILE_NAME_PREFIX . $uploadedFile->getName();
         $uploadedFile->saveAs($logoFilePath);
         ZurmoUserInterfaceConfigurationFormAdapter::resizeLogoImageFile($logoFilePath, $thumbFilePath, ZurmoUserInterfaceConfigurationForm::DEFAULT_LOGO_THUMBNAIL_WIDTH, ZurmoUserInterfaceConfigurationForm::DEFAULT_LOGO_THUMBNAIL_HEIGHT);
         Yii::app()->user->setState('logoFileName', $uploadedFile->getName());
         $logoFileData = array('name' => $uploadedFile->getName(), 'type' => $uploadedFile->getType(), 'size' => $uploadedFile->getSize(), 'thumbnail_url' => Yii::app()->createUrl('zurmo/default/thumbnail/', array('filePath' => $thumbFilePath)));
     } catch (FailedFileUploadException $e) {
         $logoFileData = array('error' => Zurmo::t('Core', 'Error') . ' ' . $e->getMessage());
     }
     echo CJSON::encode(array($logoFileData));
     Yii::app()->end(0, false);
 }