protected function renderViewForAgreementWithAgmntProduct(Portlet $portlet)
 {
     if ($this->params['relationModel']->modelClassNameToBean['Agreement']->id != null) {
         $id = $this->params['relationModel']->modelClassNameToBean['Agreement']->id;
         $data = $this::getAllAgreementProducts($this->params['relationModel']->modelClassNameToBean['Agreement']->id);
         if (count($data) > 0) {
             $content = $portlet->renderContent();
             $tableCreation = '<div class="view-toolbar-container clearfix"><div class="panel"><div class="panelTitle">Agreement Products</div>';
             //$tableCreation .= '<div><table style="padding-left: 3%; text-align: right; vertical-align: top;" border="0" cellpadding="0" cellspacing="0"><tbody><tr><td class="pbTitle">&nbsp;</td><td id="thePage:theTable:theSelectedBlock:j_id3" class="pbButton "><input type="submit" name="thePage:theTable:theSelectedBlock:j_id3:j_id5" value="Estimator Summary" onclick="top.location.replace(\'/apex/OpportunitProductsSummary?id=006j000000Ljedx\');return false;" class="btn"></td></tr></tbody></table></div>';
             //$tableCreation .= '<div class="form-toolbar clearfix"><a id="addProduct" name="Add Products" class="attachLoading z-button" href="/app/index.php/agreementProducts/default/AddProductsInAgreement?optId='.$id.'"><span class="z-spinner"></span><span class="z-icon"></span><span class="z-label">Add Product</span></a><div class="post-to-profile clearfix"> <a id="estimateSummary" name="Estimate Summary" class="attachLoading z-button" onclick="/" href="#"><span class="z-spinner"></span><span class="z-icon"></span><span class="z-label">Estimate Summary</span></a></div></div>';
             $tableCreation .= '<table style="padding-left: 3%; text-align: right; vertical-align: top;"  border="0" cellpadding="2" cellspacing="0" width="100%">
                     <colgroup span="5"></colgroup>';
             $tableCreation .= '<thead style="font-weight: bold; background-color:#E6E6E6; color: #999; vertical-align: inherit; padding: 5px;"><th style="font-weight: bold;">Product Code</th><th style="font-weight: bold;">Product</th><th style="font-weight: bold;">Quantity</th><th style="font-weight: bold;">Frequency</th><th style="font-weight: bold;">Unit of Measure</th></thead><tbody>';
             foreach ($data as $row) {
                 $tableCreation .= '<tr><td style="width: 20%;  padding-top: 2px; text-align: left;">' . $row['name'] . '</td><td style="width: 40%;  padding-top: 2px; text-align: left;">' . $row['name'] . '</td><td style="width: 13%;  padding-top: 2px; text-align: center;">' . $row['quantity'] . '</td><td style="width: 13%;  padding-top: 2px; text-align: center;">' . $row['frequency'] . '</td><td style="width: 14%;  padding-top: 2px; text-align: center;">' . $row['total_mhr'] . '</td></tr>';
             }
             $tableCreation .= '</tbody></table></div></div>';
             $content .= $tableCreation;
             return $content;
         } else {
             return $portlet->renderContent();
         }
     } else {
         return $portlet->renderContent();
     }
 }
 protected function renderContent()
 {
     $placedViewTypes = Portlet::getPlacedViewTypesByLayoutIdAndUser($this->uniqueLayoutId, Yii::app()->user->userModel->id);
     $modules = Module::getModuleObjects();
     $sortablePortlets = array();
     foreach ($modules as $module) {
         if ($module->isEnabled()) {
             $p = $module->getParentModule();
             $viewClassNames = $module::getViewClassNames();
             foreach ($viewClassNames as $className) {
                 $viewReflectionClass = new ReflectionClass($className);
                 if (!$viewReflectionClass->isAbstract()) {
                     $portletRules = PortletRulesFactory::createPortletRulesByView($className);
                     if ($viewReflectionClass->implementsInterface('RelatedPortletViewInterface')) {
                         if ($this->resolveLayoutIdInAllowedOnPortletViewClassNames($className) && $className::allowMultiplePlacement() == false && !in_array($portletRules->getType(), $placedViewTypes) && PortletsSecurityUtil::doesCurrentUserHavePermissionToAddPortlet($portletRules) === true) {
                             $metadata = $className::getMetadata();
                             $url = Yii::app()->createUrl($this->moduleId . '/defaultPortlet/add', array('uniqueLayoutId' => $this->uniqueLayoutId, 'modelId' => $this->modelId, 'portletType' => $portletRules->getType()));
                             $title = $metadata['perUser']['title'];
                             MetadataUtil::resolveEvaluateSubString($title);
                             $sortablePortlets[$title] = array('url' => $url, 'title' => $title, 'portletRules' => $portletRules);
                         }
                     }
                 }
             }
         }
     }
     if (empty($sortablePortlets)) {
         $messageView = new NoPortletsToPlaceView();
         return $messageView->render();
     }
     //Sort by title
     ksort($sortablePortlets);
     return PortletUtil::renderAddPortletsContent($sortablePortlets);
 }
 public function testAdditionOfPortletsInEmptyRightPanel()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superLeadId = self::getModelIdByModelNameAndName('Contact', 'superLead superLeadson');
     $marketingListId = self::getModelIdByModelNameAndName('MarketingList', 'MarketingListName');
     $leads = Contact::getAll();
     $this->assertEquals(1, count($leads));
     //Load Model Detail Views
     $this->setGetArray(array('id' => $superLeadId, 'lockPortlets' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('leads/default/details');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('LeadDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(3, count($portlets[1]));
     $this->assertFalse(array_key_exists(3, $portlets));
     $this->assertEquals(2, count($portlets[2]));
     foreach ($portlets[2] as $position => $portlet) {
         $portlet->delete();
     }
     $this->setGetArray(array('modelId' => $superLeadId, 'uniqueLayoutId' => 'LeadDetailsAndRelationsView', 'portletType' => 'MarketingListsForContactRelatedList', 'redirect' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('leads/defaultPortlet/add', true);
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('LeadDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(1, count($portlets[2]));
     //Test subscribe to list link
     $portlet = $portlets[2][1];
     $this->setGetArray(array('portletId' => $portlet->id, 'relationAttributeName' => 'lead', 'relationModelId' => $superLeadId, 'relationModuleId' => 'leads', 'uniqueLayoutId' => $portlet->getUniquePortletPageId(), 'relationModelClassName' => null));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('marketingLists/default/selectFromRelatedList');
     //Test subscribe a marketing list
     $this->setGetArray(array('modelId' => $marketingListId, 'portletId' => $portlet->id, 'relationAttributeName' => 'lead', 'relationModelId' => $superLeadId, 'relationModuleId' => 'leads', 'uniqueLayoutId' => $portlet->getUniquePortletPageId(), 'relationModelClassName' => null));
     $this->resetPostArray();
     $content = $this->runControllerWithRedirectExceptionAndGetContent('marketingLists/defaultPortlet/selectFromRelatedListSave');
 }
 public function testSaveAndRetrievePortlet()
 {
     $user = UserTestHelper::createBasicUser('Billy');
     $contracts = Contract::getByName('superOpp');
     $portlet = new Portlet();
     $portlet->column = 2;
     $portlet->position = 5;
     $portlet->layoutId = 'Test';
     $portlet->collapsed = true;
     $portlet->viewType = 'ContractsForContactRelatedList';
     $portlet->serializedViewData = serialize(array('title' => 'Testing Title'));
     $portlet->user = $user;
     $this->assertTrue($portlet->save());
     $portlet = Portlet::getById($portlet->id);
     $params = array('controllerId' => 'test', 'relationModuleId' => 'test', 'relationModel' => $contracts[0], 'redirectUrl' => 'someRedirect');
     $portlet->params = $params;
     $unserializedViewData = unserialize($portlet->serializedViewData);
     $this->assertEquals(2, $portlet->column);
     $this->assertEquals(5, $portlet->position);
     $this->assertEquals('Testing Title', $portlet->getTitle());
     $this->assertEquals(false, $portlet->isEditable());
     $this->assertEquals('Test', $portlet->layoutId);
     //$this->assertEquals(true,                  $portlet->collapsed); //reenable once working
     $this->assertEquals('ContractsForContactRelatedList', $portlet->viewType);
     $this->assertEquals($user->id, $portlet->user->id);
     $view = $portlet->getView();
 }
Example #5
0
 public function init()
 {
     parent::init();
     $this->defaultSoringSettings['update'] = "js:function(event, ui)\n        {\n            var data = \$(this).nestedSortable('toArray');\n            \$.post('{$this->sortUrl}',\n                {\n                    tree:\$.toJSON(data)\n                },\n                function(data)\n                {\n                    if (data.status == 'ok')\n                    {\n                        alert(3);\n                    }\n                },\n                'json'\n            );\n        }";
     $this->initVars();
     $this->registerScripts();
 }
Example #6
0
 public function onInit($param)
 {
     parent::onInit($param);
     if (!$this->Page->IsPostBack && ($keyword = $this->Request['keyword']) !== null) {
         $this->Keyword->Text = $keyword;
     }
 }
 protected function renderContent()
 {
     $placedViewTypes = Portlet::getPlacedViewTypesByLayoutIdAndUser($this->uniqueLayoutId, Yii::app()->user->userModel->id);
     $content = '<ul class="available-portlets">';
     $modules = Module::getModuleObjects();
     foreach ($modules as $module) {
         if ($module->isEnabled()) {
             $p = $module->getParentModule();
             $viewClassNames = $module::getViewClassNames();
             foreach ($viewClassNames as $className) {
                 $viewReflectionClass = new ReflectionClass($className);
                 if (!$viewReflectionClass->isAbstract()) {
                     $portletRules = PortletRulesFactory::createPortletRulesByView($className);
                     if ($portletRules != null && $portletRules->allowOnDashboard()) {
                         if ($portletRules->allowMultiplePlacementOnDashboard() && PortletsSecurityUtil::doesCurrentUserHavePermissionToAddPortlet($portletRules) === true || !$portletRules->allowMultiplePlacementOnDashboard() && !in_array($portletRules->getType(), $placedViewTypes) && PortletsSecurityUtil::doesCurrentUserHavePermissionToAddPortlet($portletRules) === true) {
                             $metadata = $className::getMetadata();
                             $url = Yii::app()->createUrl($this->moduleId . '/defaultPortlet/add', array('uniqueLayoutId' => $this->uniqueLayoutId, 'dashboardId' => $this->dashboardId, 'portletType' => $portletRules->getType()));
                             $onClick = 'window.location.href = "' . $url . '"';
                             $content .= '<li>';
                             $title = $metadata['perUser']['title'];
                             MetadataUtil::resolveEvaluateSubString($title);
                             $label = '<span>\\</span>' . $title;
                             $content .= ZurmoHtml::link(Zurmo::t('HomeModule', $label), null, array('onclick' => $onClick));
                             $content .= '</li>';
                         }
                     }
                 }
             }
         }
     }
     $content .= '</ul>';
     return $content;
 }
Example #8
0
 public function init()
 {
     if (Yii::app()->hasModule('poll')) {
         $this->_poll = Poll::model()->rand()->active()->find();
         $this->title = $this->_poll->title;
         parent::init();
     }
 }
 public function testSuperUserAllDefaultControllerActions()
 {
     // key used to test persistance of user settings
     $configKey = 'rollup';
     //Set the current user as the super user.
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $accounts = Account::getAll();
     $this->assertEquals(1, count($accounts));
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     //Load Details view to generate the portlets.
     $this->setGetArray(array('id' => $superAccountId));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     //Find the LatestActivity portlet.
     $portletToUse = null;
     $portlets = Portlet::getAll();
     foreach ($portlets as $portlet) {
         if ($portlet->viewType == 'AccountLatestActivitiesForPortlet') {
             $portletToUse = $portlet;
             break;
         }
     }
     $this->assertNotNull($portletToUse);
     $this->assertEquals('AccountLatestActivitiesForPortletView', get_class($portletToUse->getView()));
     //Load the portlet details for latest activity
     $getData = array('id' => $superAccountId, 'portletId' => $portletToUse->id, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_' . $portletToUse->id, 'LatestActivitiesConfigurationForm' => array('filteredByModelName' => 'all', 'rollup' => ''));
     $this->setGetArray($getData);
     $this->resetPostArray();
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     $this->assertTrue(LatestActivitiesPortletPersistentConfigUtil::getForCurrentUserByPortletIdAndKey($getData['portletId'], $configKey) === '');
     //Now add roll up
     $getData['LatestActivitiesConfigurationForm']['rollup'] = '1';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     $this->assertTrue(LatestActivitiesPortletPersistentConfigUtil::getForCurrentUserByPortletIdAndKey($getData['portletId'], $configKey) === '1');
     //Now filter by meeting, task, and note
     $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Meeting';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Note';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Task';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     //Now do the same thing with filtering but turn off rollup.
     $getData['LatestActivitiesConfigurationForm']['rollup'] = '';
     $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Meeting';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     $this->assertTrue(LatestActivitiesPortletPersistentConfigUtil::getForCurrentUserByPortletIdAndKey($getData['portletId'], $configKey) === '');
     $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Note';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
     $getData['LatestActivitiesConfigurationForm']['filteredByModelName'] = 'Task';
     $this->setGetArray($getData);
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/details');
 }
 public function init()
 {
     if (isset($_POST['command']) && $_POST['command'] === 'logout') {
         Yii::app()->user->logout();
         $this->controller->redirect(Yii::app()->homeUrl);
     }
     $this->title = CHtml::encode(Yii::app()->user->name);
     parent::init();
 }
 protected function getPlacedViewTypes()
 {
     $portlets = Portlet::getByLayoutIdAndUserSortedById($this->uniqueLayoutId, Yii::app()->user->userModel->id);
     $placedViewTypes = array();
     foreach ($portlets as $portlet) {
         $placedViewTypes[] = $portlet->viewType;
     }
     return $placedViewTypes;
 }
 public function testRegularUserProductPortletAccess()
 {
     $benny = $this->logoutCurrentUserLoginNewUserAndGetByUsername('nobody');
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', Yii::app()->user->userModel);
     $superAccountId = $account->id;
     $benny->setRight('ProductTemplatesModule', ProductTemplatesModule::getAccessRight(), Right::DENY);
     $this->assertTrue($benny->save());
     $this->assertFalse(RightsUtil::canUserAccessModule('ProductTemplatesModule', $benny));
     $portlet = new Portlet();
     $portlet->column = 1;
     $portlet->position = 1;
     $portlet->layoutId = 'Test';
     $portlet->collapsed = true;
     $portlet->viewType = 'RssReader';
     $portlet->user = $benny;
     $this->assertTrue($portlet->save());
     $this->setGetArray(array('uniqueLayoutId' => 'AccountDetailsAndRelationsView_' . $portlet->id, 'portletId' => $portlet->id, 'relationAttributeName' => 'account', 'relationModelId' => $superAccountId, 'relationModuleId' => 'accounts', 'relationModelClassName' => 'Account'));
     $this->runControllerWithNoExceptionsAndGetContent('productTemplates/default/selectFromRelatedList');
 }
 /**
  * Called using Ajax.
  */
 public function actionModalConfigSave($portletId, $uniqueLayoutId, array $portletParams = array())
 {
     $portlet = Portlet::getById(intval($portletId));
     $this->resolveAddingRelationModelIdToPortletParams($portlet);
     $configurableView = $portlet->getView()->getConfigurationView();
     $portlet->forget();
     $configurableView->setMetadataFromPost($_POST[$configurableView->getPostArrayName()]);
     $this->saveModalConfigPerUserAndRelationModelId($configurableView->getViewMetadata());
     $this->actionModalRefresh($portletId, $uniqueLayoutId, null, $portletParams);
 }
Example #14
0
 protected function getPortlets($uniqueLayoutId, $metadata)
 {
     assert('is_string($uniqueLayoutId)');
     assert('is_array($metadata)');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition($uniqueLayoutId, Yii::app()->user->userModel->id, $this->params);
     if (empty($portlets)) {
         $portlets = Portlet::makePortletsUsingMetadataSortedByColumnIdAndPosition($uniqueLayoutId, $metadata, Yii::app()->user->userModel, $this->params);
         Portlet::savePortlets($portlets);
     }
     return $portlets;
 }
Example #15
0
 public function onLoad($param)
 {
     parent::onLoad($param);
     $cats = $this->Application->getModule('data')->queryCategories();
     foreach ($cats as $cat) {
         $cat->ID = $this->Service->constructUrl('Posts.ListPost', array('cat' => $cat->ID));
         $cat->Name .= ' (' . $cat->PostCount . ')';
     }
     $this->CategoryList->DataSource = $cats;
     $this->CategoryList->dataBind();
 }
Example #16
0
 /**
  * Override to allow for making a default set of portlets
  * via metadata optional.
  *
  */
 protected function getPortlets($uniqueLayoutId, $metadata)
 {
     assert('is_string($uniqueLayoutId)');
     assert('is_array($metadata)');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition($uniqueLayoutId, Yii::app()->user->userModel->id, $this->params);
     if (empty($portlets) && $this->isDefaultDashboard) {
         $portlets = Portlet::makePortletsUsingMetadataSortedByColumnIdAndPosition($uniqueLayoutId, $metadata, Yii::app()->user->userModel, $this->params);
         Portlet::savePortlets($portlets);
     }
     return PortletsSecurityUtil::resolvePortletsForCurrentUser($portlets);
 }
 public function testDashboardGroupByActions()
 {
     $portets = Portlet::getAll();
     $this->assertCount(1, $portets);
     $this->setGetArray(array('portletId' => $portets[0]->id, 'uniqueLayoutId' => 'MarketingDashboard'));
     $this->setPostArray(array('MarketingOverallMetricsForm' => array('groupBy' => MarketingOverallMetricsForm::GROUPING_TYPE_DAY)));
     $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/modalConfigSave');
     $this->setPostArray(array('MarketingOverallMetricsForm' => array('groupBy' => MarketingOverallMetricsForm::GROUPING_TYPE_MONTH)));
     $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/modalConfigSave');
     $this->setPostArray(array('MarketingOverallMetricsForm' => array('groupBy' => MarketingOverallMetricsForm::GROUPING_TYPE_WEEK)));
     $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/modalConfigSave');
 }
Example #18
0
 public function init()
 {
     if (isset($_POST['command']) && $_POST['command'] === 'logout') {
         Yii::app()->user->logout();
         $this->controller->redirect(Yii::app()->homeUrl);
     }
     if (!Yii::app()->user->isGuest) {
         $this->title = CHtml::encode(Yii::app()->user->username);
     }
     parent::init();
     // displays the title
 }
Example #19
0
 public function onLoad($param)
 {
     parent::onLoad($param);
     $commentLimit = TPropertyValue::ensureInteger($this->Application->Parameters['RecentComments']);
     $comments = $this->Application->getModule('data')->queryComments('', 'ORDER BY create_time DESC', "LIMIT {$commentLimit}");
     foreach ($comments as $comment) {
         $comment->ID = $this->Service->constructUrl('Posts.ViewPost', array('id' => $comment->PostID)) . '#c' . $comment->ID;
         if (strlen($comment->Content) > 40) {
             $comment->Content = substr($comment->Content, 0, 40) . ' ...';
         }
     }
     $this->CommentList->DataSource = $comments;
     $this->CommentList->dataBind();
 }
 public function actionDetails($id, $runReport = false)
 {
     $savedReport = SavedReport::getById((int) $id);
     ControllerSecurityUtil::resolveCanCurrentUserAccessModule($savedReport->moduleClassName);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($savedReport, true);
     $report = SavedReportToReportAdapter::makeReportBySavedReport($savedReport);
     $portlet = Portlet::getById(intval($_GET['portletId']));
     $portlet->params = array('controllerId' => 'default', 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $report, 'redirectUrl' => Yii::app()->request->getRequestUri(), 'dataProvider' => $this->getDataProvider($report, $report->getId(), (bool) $runReport));
     $portletView = $portlet->getView();
     if (!RightsUtil::canUserAccessModule($portletView::getModuleClassName(), Yii::app()->user->userModel)) {
         $messageView = new AccessFailureView();
         $view = new AccessFailurePageView($messageView);
         echo $view->render();
         Yii::app()->end(0, false);
     }
     $view = new AjaxPageView($portletView);
     echo $view->render();
 }
 public function testSuperUserDefaultPortletControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $this->setGetArray(array('id' => self::$account->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(4, count($portlets[2]));
     $this->setGetArray(array('modelId' => self::$account->id, 'portletType' => 'AccountAccountAffiliationsRelatedList', 'uniqueLayoutId' => 'AccountDetailsAndRelationsView'));
     $this->resetPostArray();
     $this->runControllerWithRedirectExceptionAndGetContent('accounts/defaultPortlet/add');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(5, count($portlets[2]));
     //Load Details View again to make sure everything is ok after the layout change.
     $this->setGetArray(array('id' => self::$account->id));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
 }
 protected function renderContent()
 {
     $placedViewTypes = Portlet::getPlacedViewTypesByLayoutIdAndUser($this->uniqueLayoutId, Yii::app()->user->userModel->id);
     $content = '<ul class="available-portlets">';
     $modules = Module::getModuleObjects();
     $sortablePortlets = array();
     foreach ($modules as $module) {
         if ($module->isEnabled()) {
             $p = $module->getParentModule();
             $viewClassNames = $module::getViewClassNames();
             foreach ($viewClassNames as $className) {
                 $viewReflectionClass = new ReflectionClass($className);
                 if (!$viewReflectionClass->isAbstract()) {
                     $portletRules = PortletRulesFactory::createPortletRulesByView($className);
                     if ($viewReflectionClass->implementsInterface('RelatedPortletViewInterface')) {
                         if ($this->resolveLayoutIdInAllowedOnPortletViewClassNames($className) && $className::allowMultiplePlacement() == false && !in_array($portletRules->getType(), $placedViewTypes) && PortletsSecurityUtil::doesCurrentUserHavePermissionToAddPortlet($portletRules) === true) {
                             $metadata = $className::getMetadata();
                             $url = Yii::app()->createUrl($this->moduleId . '/defaultPortlet/add', array('uniqueLayoutId' => $this->uniqueLayoutId, 'modelId' => $this->modelId, 'portletType' => $portletRules->getType()));
                             $title = $metadata['perUser']['title'];
                             MetadataUtil::resolveEvaluateSubString($title);
                             $sortablePortlets[$title] = $url;
                         }
                     }
                 }
             }
         }
     }
     if (empty($sortablePortlets)) {
         $messageView = new NoPortletsToPlaceView();
         return $messageView->render();
     }
     //Sort by title
     ksort($sortablePortlets);
     foreach ($sortablePortlets as $title => $url) {
         $onClick = 'window.location.href = "' . $url . '"';
         $content .= '<li>';
         $label = '<span>\\</span>' . $title;
         $content .= ZurmoHtml::link(Zurmo::t('HomeModule', $label), null, array('onclick' => $onClick));
         $content .= '</li>';
     }
     $content .= '</ul>';
     return $content;
 }
 /**
  * Add portlet to first column, first position
  * and if there are other portlets in the first
  * column, shift their postion by 1 to accomodate
  * the new portlet
  *
  */
 public function actionAdd()
 {
     assert('!empty($_GET["uniqueLayoutId"])');
     assert('!empty($_GET["portletType"])');
     $maximumColumns = $this->resolveMaximumColumnsByDashboardId();
     $portletCollection = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition($_GET['uniqueLayoutId'], Yii::app()->user->userModel->id, array());
     if (!empty($portletCollection)) {
         if (isset($portletCollection[$maximumColumns])) {
             foreach ($portletCollection[$maximumColumns] as $position => $portlet) {
                 $portlet->position = $portlet->position + 1;
                 $portlet->save();
             }
         }
     }
     if (!empty($_GET['dashboardId'])) {
         $dashboardId = $_GET['dashboardId'];
     } else {
         $dashboardId = '';
     }
     Portlet::makePortletUsingViewType($_GET['portletType'], $_GET['uniqueLayoutId'], Yii::app()->user->userModel, $maximumColumns);
     $this->redirect(array('default/dashboardDetails', 'id' => $dashboardId));
 }
 public function testAdditionOfPortletsInEmptyRightPanel()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superAccountId = self::getModelIdByModelNameAndName('Account', 'superAccount');
     $accounts = Account::getAll();
     $this->assertEquals(1, count($accounts));
     //Load Model Detail Views
     $this->setGetArray(array('id' => $superAccountId, 'lockPortlets' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/default/details');
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(3, count($portlets[1]));
     $this->assertFalse(array_key_exists(3, $portlets));
     $this->assertEquals(4, count($portlets[2]));
     foreach ($portlets[2] as $position => $portlet) {
         $portlet->delete();
     }
     $this->setGetArray(array('modelId' => $superAccountId, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView', 'portletType' => 'ProductsForAccountRelatedList', 'redirect' => '0'));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/add', true);
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('AccountDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(1, count($portlets[2]));
 }
 /**
  * @depends testSuperUserAllDefaultControllerActions
  */
 public function testSuperUserDefaultPortletControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     //Save a layout change. Collapse all portlets in the GameReward Details View.
     //At this point portlets for this view should be created because we have already loaded the 'details' page in a request above.
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('GameRewardDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(2, count($portlets[1]));
     $this->assertFalse(array_key_exists(2, $portlets));
     $portletPostData = array();
     $portletCount = 0;
     foreach ($portlets as $column => $columnPortlets) {
         foreach ($columnPortlets as $position => $portlet) {
             $this->assertEquals('0', $portlet->collapsed);
             $portletPostData['GameRewardDetailsAndRelationsView_' . $portlet->id] = array('collapsed' => 'true', 'column' => 0, 'id' => 'GameRewardDetailsAndRelationsView_' . $portlet->id, 'position' => $portletCount);
             $portletCount++;
         }
     }
     //There should have been a total of 2 portlets.
     $this->assertEquals(2, $portletCount);
 }
 /**
  * @depends testSuperUserAllDefaultControllerActions
  */
 public function testSuperUserDefaultPortletControllerActions()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     $superLeadId4 = self::getModelIdByModelNameAndName('Contact', 'superLead4 superLead4son');
     //Save a layout change. Collapse all portlets in the Lead Details View.
     //At this point portlets for this view should be created because we have already loaded the 'details' page in a request above.
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('LeadDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(3, count($portlets[1]));
     $this->assertFalse(array_key_exists(3, $portlets));
     $portletPostData = array();
     $portletCount = 0;
     foreach ($portlets as $column => $columnPortlets) {
         foreach ($columnPortlets as $position => $portlet) {
             $this->assertEquals('0', $portlet->collapsed);
             $portletPostData['LeadDetailsAndRelationsView_' . $portlet->id] = array('collapsed' => 'true', 'column' => 0, 'id' => 'LeadDetailsAndRelationsView_' . $portlet->id, 'position' => $portletCount);
             $portletCount++;
         }
     }
     //There should have been a total of 5 portlets.
     $this->assertEquals(5, $portletCount);
     $this->resetGetArray();
     $this->setPostArray(array('portletLayoutConfiguration' => array('portlets' => $portletPostData, 'uniqueLayoutId' => 'LeadDetailsAndRelationsView')));
     $this->runControllerWithNoExceptionsAndGetContent('home/defaultPortlet/saveLayout', true);
     //Now test that all the portlets are collapsed and moved to the first column.
     $portlets = Portlet::getByLayoutIdAndUserSortedByColumnIdAndPosition('LeadDetailsAndRelationsView', $super->id, array());
     $this->assertEquals(5, count($portlets[1]));
     $this->assertFalse(array_key_exists(2, $portlets));
     foreach ($portlets as $column => $columns) {
         foreach ($columns as $position => $positionPortlets) {
             $this->assertEquals('1', $positionPortlets->collapsed);
         }
     }
     //Load Details View again to make sure everything is ok after the layout change.
     $this->setGetArray(array('id' => $superLeadId4));
     $this->resetPostArray();
     $this->runControllerWithNoExceptionsAndGetContent('leads/default/details');
 }
 protected function getPortletViewForDetails($id)
 {
     $id = intval($id);
     $modelName = $this->getModule()->getPrimaryModelName();
     $model = $modelName::getById($id);
     ControllerSecurityUtil::resolveAccessCanCurrentUserReadModel($model, true);
     $portlet = Portlet::getById(intval($_GET['portletId']));
     if (null != ($redirectUrl = ArrayUtil::getArrayValue($_GET, 'redirectUrl'))) {
         $redirectUrl = $redirectUrl;
     } else {
         $redirectUrl = Yii::app()->request->getRequestUri();
     }
     $portlet->params = array('controllerId' => 'default', 'relationModuleId' => $this->getModule()->getId(), 'relationModel' => $model, 'redirectUrl' => $redirectUrl);
     $portletView = $portlet->getView();
     return $portletView;
 }
 public function testFilteredResultsByStageForProductPortlet()
 {
     $super = $this->logoutCurrentUserLoginNewUserAndGetByUsername('super');
     Yii::app()->user->userModel = $super;
     //Setup test data owned by the super user.
     $account = AccountTestHelper::createAccountByNameForOwner('superAccount', $super);
     ProductTestHelper::createProductStagesIfDoesNotExist();
     $superProductId = self::getModelIdByModelNameAndName('Product', 'My Product 1');
     $product = Product::getById($superProductId);
     $product->account = $account;
     $product->stage->value = 'Open';
     $this->assertTrue($product->save());
     ProductTestHelper::createProductByNameForOwner("My Product 2", $super);
     $superProductId2 = self::getModelIdByModelNameAndName('Product', 'My Product 2');
     $product = Product::getById($superProductId2);
     $product->account = $account;
     $product->stage->value = 'Won';
     $this->assertTrue($product->save());
     $portlet = new Portlet();
     $portlet->column = 1;
     $portlet->position = 1;
     $portlet->layoutId = 'AccountDetailsAndRelationsView';
     $portlet->user = $super;
     $portlet->viewType = 'ProductsForAccountRelatedList';
     $this->assertTrue($portlet->save());
     $this->setGetArray(array('id' => $account->id, 'portletParams' => array('relationModuleId' => 'accounts', 'relationModelId' => $account->id), 'ProductsConfigurationForm' => array('filteredByStage' => 'Open'), 'redirectUrl' => Yii::app()->createUrl('accounts/default/details', array('id' => $account->id)), 'portletId' => $portlet->id, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_' . $portlet->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/modalRefresh');
     $this->assertContains('My Product 1', $content);
     $this->assertNotContains('My Product 2', $content);
     $this->setGetArray(array('id' => $account->id, 'portletParams' => array('relationModuleId' => 'accounts', 'relationModelId' => $account->id), 'ProductsConfigurationForm' => array('filteredByStage' => 'All'), 'redirectUrl' => Yii::app()->createUrl('accounts/default/details', array('id' => $account->id)), 'portletId' => $portlet->id, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_' . $portlet->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/modalRefresh');
     $this->assertContains('My Product 1', $content);
     $this->assertContains('My Product 2', $content);
     $this->setGetArray(array('id' => $account->id, 'portletParams' => array('relationModuleId' => 'accounts', 'relationModelId' => $account->id), 'ProductsConfigurationForm' => array('filteredByStage' => 'Won'), 'redirectUrl' => Yii::app()->createUrl('accounts/default/details', array('id' => $account->id)), 'portletId' => $portlet->id, 'uniqueLayoutId' => 'AccountDetailsAndRelationsView_' . $portlet->id));
     $content = $this->runControllerWithNoExceptionsAndGetContent('accounts/defaultPortlet/modalRefresh');
     $this->assertNotContains('My Product 1', $content);
     $this->assertContains('My Product 2', $content);
 }
 public static function pushDetailsAndRelationsViewPortlets(User $user, $model)
 {
     $layoutIdPrefix = get_class($model);
     $layoutId = $layoutIdPrefix . self::DETAILS_AND_RELATIONS_VIEW;
     $userLayoutPortlets = Portlet::getByLayoutIdAndUserSortedById($layoutId, $user->id);
     $pushedLayoutPortlets = Portlet::getByLayoutIdAndUserSortedById($layoutId, Yii::app()->user->userModel->id);
     foreach ($userLayoutPortlets as $portlet) {
         $portlet->delete();
         unset($portlet);
     }
     foreach ($pushedLayoutPortlets as $pushedLayoutPortlet) {
         $portlet = new Portlet();
         $portlet->column = $pushedLayoutPortlet->column;
         $portlet->position = $pushedLayoutPortlet->position;
         $portlet->layoutId = $layoutId;
         $portlet->collapsed = $pushedLayoutPortlet->collapsed;
         $portlet->viewType = $pushedLayoutPortlet->viewType;
         $portlet->serializedViewData = $pushedLayoutPortlet->serializedViewData;
         $portlet->user = $user;
         $portlet->save();
     }
 }
Example #30
0
 /**
  * Make a portlet with default values.
  */
 public static function makePortletUsingViewType($viewType, $uniqueLayoutId, $user)
 {
     $portlet = new Portlet();
     $portlet->column = 1;
     $portlet->position = 1;
     $portlet->layoutId = $uniqueLayoutId;
     $portlet->collapsed = false;
     $portlet->viewType = $viewType;
     $portlet->user = $user;
     $portlet->save();
 }