public function actionAssignAllMembers($args) { if (!isset($args[0])) { print "Error: Space guid parameter required!\n\n"; print $this->getHelp(); return; } $space = Space::model()->findByAttributes(array('guid' => $args[0])); if ($space == null) { print "Error: Space not found! Check guid!\n\n"; return; } $countMembers = 0; $countAssigns = 0; foreach (User::model()->findAllByAttributes(array('status' => User::STATUS_ENABLED)) as $user) { if ($space->isMember($user->id)) { #print "Already Member!"; $countMembers++; } else { print "Add member " . $user->displayName . "\n"; Yii::app()->user->setId($user->id); $space->addMember($user->id); $countAssigns++; } } print "\nAdded " . $countAssigns . " new members to space " . $space->name . "\n"; }
/** * Runs the Widget */ public function run() { // Possible Security Flaw: Check type! $type = $this->activity->type; $underlyingObject = $this->activity->getUnderlyingObject(); // Try to figure out wallEntryId of this activity $wallEntryId = 0; if ($underlyingObject != null) { if ($underlyingObject instanceof HActiveRecordContent || $underlyingObject instanceof HActiveRecordContentAddon) { $wallEntryId = $underlyingObject->content->getFirstWallEntryId(); } } // When element is assigned to a workspace, assign variable $workspace = null; if ($this->activity->content->space_id != "") { $workspace = Space::model()->findByPk($this->activity->content->space_id); } // User that fired the activity $user = $this->activity->content->user; if ($user == null) { Yii::log("Skipping activity without valid user", "warning"); return; } // Dertermine View $view = ""; if ($this->activity->module == "") { $view = 'application.modules_core.activity.views.activities.' . $this->activity->type; } else { $view = $this->activity->module . '.views.activities.' . $this->activity->type; } // Activity Layout can access it $this->wallEntryId = $wallEntryId; $this->render($view, array('activity' => $this->activity, 'wallEntryId' => $wallEntryId, 'user' => $user, 'target' => $underlyingObject, 'workspace' => $workspace)); }
/** * Executes the widgets */ public function run() { $statsCountSpaces = Space::model()->count(); $statsCountSpacesHidden = Space::model()->countByAttributes(array('visibility' => Space::VISIBILITY_NONE)); $statsSpaceMostMembers = Space::model()->find('id = (SELECT space_id FROM space_membership GROUP BY space_id ORDER BY count(*) DESC LIMIT 1)'); // Render widgets view $this->render('spaceStats', array('statsSpaceMostMembers' => $statsSpaceMostMembers, 'statsCountSpaces' => $statsCountSpaces, 'statsCountSpacesHidden' => $statsCountSpacesHidden)); }
/** * On rebuild of the search index, rebuild all space records * * @param type $event */ public static function onSearchRebuild($event) { foreach (Space::model()->findAll() as $obj) { if ($obj->visibility != Space::VISIBILITY_NONE) { HSearch::getInstance()->addModel($obj); } print "s"; } }
/** * Executes the widgets */ public function run() { $criteria = new CDbCriteria(); $criteria->join = 'LEFT JOIN space_membership ON t.id=space_membership.space_id AND space_membership.user_id=:userId'; $criteria->condition = 't.visibility != :visibilityNone OR space_membership.status = :statusMember'; $criteria->params = array(':userId' => Yii::app()->user->id, ':visibilityNone' => Space::VISIBILITY_NONE, ':statusMember' => SpaceMembership::STATUS_MEMBER); $newSpaces = Space::model()->active()->recently(10)->findAll($criteria); $this->render('newSpaces', array('newSpaces' => $newSpaces, 'showMoreButton' => $this->showMoreButton)); }
/** * Returns a List of Users */ public function actionIndex() { Yii::import('admin.forms.*'); $form = new BasicSettingsForm(); if (isset($_POST['ajax']) && $_POST['ajax'] === 'basic-settings-form') { echo CActiveForm::validate($form); Yii::app()->end(); } if (isset($_POST['BasicSettingsForm'])) { $_POST['BasicSettingsForm'] = Yii::app()->input->stripClean($_POST['BasicSettingsForm']); $form->attributes = $_POST['BasicSettingsForm']; if ($form->validate()) { HSetting::Set('name', $form->name); HSetting::Set('baseUrl', $form->baseUrl); HSetting::Set('defaultLanguage', $form->defaultLanguage); HSetting::Set('enable', $form->tour, 'tour'); $spaceGuids = explode(",", $form->defaultSpaceGuid); // Remove Old Default Spaces foreach (Space::model()->findAllByAttributes(array('auto_add_new_members' => 1)) as $space) { if (!in_array($space->guid, $spaceGuids)) { $space->auto_add_new_members = 0; $space->save(); } } // Add new Default Spaces foreach ($spaceGuids as $spaceGuid) { $space = Space::model()->findByAttributes(array('guid' => $spaceGuid)); if ($space != null && $space->auto_add_new_members != 1) { $space->auto_add_new_members = 1; $space->save(); } } // set flash message Yii::app()->user->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved')); $this->redirect(Yii::app()->createUrl('//admin/setting/index')); } } else { $form->name = HSetting::Get('name'); $form->baseUrl = HSetting::Get('baseUrl'); $form->defaultLanguage = HSetting::Get('defaultLanguage'); $form->tour = HSetting::Get('enable', 'tour'); $form->defaultSpaceGuid = ""; foreach (Space::model()->findAllByAttributes(array('auto_add_new_members' => 1)) as $defaultSpace) { $form->defaultSpaceGuid .= $defaultSpace->guid . ","; } } $this->render('index', array('model' => $form)); /* Yii::app()->interceptor->preattachEventHandler('SuperAdminNavigationWidget', 'onInit', function($event) { $event->sender->addItem(array( 'label' => 'Item Dynamic Inject Test', 'url' => Yii::app()->createUrl('') )); }); */ }
public function testGet() { $this->assertEquals(SpaceSetting::Get(1, 'globalSetting', 'core'), 'xyz'); $this->assertEquals(SpaceSetting::Get(1, 'globalSetting'), 'xyz'); $this->assertEquals(SpaceSetting::Get(1, 'moduleSetting', 'someModule'), 'zyx'); $space = Space::model()->findByPk(1); $this->assertEquals($space->getSetting('globalSetting', 'core'), 'xyz'); $this->assertEquals($space->getSetting('globalSetting'), 'xyz'); $this->assertEquals($space->getSetting('moduleSetting', 'someModule'), 'zyx'); }
public function testGetFollowers() { $space = Space::model()->findByPk(3); $space->follow(1); $space->follow(2); $space->follow(3); $users = $space->getFollowers(); $userIds = array_map(create_function('$user', 'return $user->id;'), $users); sort($userIds); $this->assertEquals(array(1, 2, 3), $userIds); }
/** * Returns a workspace list by json * * It can be filtered by by keyword. */ public function actionSearchJson() { $keyword = Yii::app()->request->getParam('keyword', ""); // guid of user/workspace $page = (int) Yii::app()->request->getParam('page', 1); // current page (pagination) $limit = (int) Yii::app()->request->getParam('limit', HSetting::Get('paginationSize')); // current page (pagination) $keyword = Yii::app()->input->stripClean($keyword); $hitCount = 0; $query = "model:Space "; if (strlen($keyword) > 2) { // Include Keyword if (strpos($keyword, "@") === false) { $keyword = str_replace(".", "", $keyword); $query .= "AND (title:" . $keyword . "* OR tags:" . $keyword . "*)"; } } //, $limit, $page $hits = new ArrayObject(HSearch::getInstance()->Find($query)); $hitCount = count($hits); // Limit Hits $hits = new LimitIterator($hits->getIterator(), ($page - 1) * $limit, $limit); $json = array(); #$json['totalHits'] = $hitCount; #$json['limit'] = $limit; #$results = array(); foreach ($hits as $hit) { $doc = $hit->getDocument(); $model = $doc->getField("model")->value; if ($model == "Space") { $workspaceId = $doc->getField('pk')->value; $workspace = Space::model()->findByPk($workspaceId); if ($workspace != null) { $wsInfo = array(); $wsInfo['guid'] = $workspace->guid; $wsInfo['title'] = CHtml::encode($workspace->name); $wsInfo['tags'] = CHtml::encode($workspace->tags); $wsInfo['image'] = $workspace->getProfileImage()->getUrl(); $wsInfo['link'] = $workspace->getUrl(); #$results[] = $wsInfo; $json[] = $wsInfo; } else { Yii::log("Could not load workspace with id " . $userId . " from search index!", CLogger::LEVEL_ERROR); } } else { Yii::log("Got no workspace hit from search index!", CLogger::LEVEL_ERROR); } } #$json['results'] = $results; print CJSON::encode($json); Yii::app()->end(); }
/** * Executes the widgets */ public function run() { $criteria = new CDbCriteria(); $criteria->join = 'LEFT JOIN space_membership ON t.id=space_membership.space_id AND space_membership.user_id=:userId'; $criteria->condition = 't.visibility != :visibilityNone OR space_membership.status = :statusMember'; $criteria->params = array(':userId' => Yii::app()->user->id, ':visibilityNone' => Space::VISIBILITY_NONE, ':statusMember' => SpaceMembership::STATUS_MEMBER); $newSpaces = Space::model()->active()->recently(10)->findAll($criteria); $statsCountSpaces = Space::model()->count(); $statsCountSpacesHidden = Space::model()->countByAttributes(array('visibility' => Space::VISIBILITY_NONE)); $statsSpaceMostMembers = Space::model()->find('id = (SELECT space_id FROM space_membership GROUP BY space_id ORDER BY count(*) DESC LIMIT 1)'); // Render widgets view $this->render('spaceStats', array('newSpaces' => $newSpaces, 'statsSpaceMostMembers' => $statsSpaceMostMembers, 'statsCountSpaces' => $statsCountSpaces, 'statsCountSpacesHidden' => $statsCountSpacesHidden)); }
/** * This validator function checks the defaultSpaceGuid. * * @param type $attribute * @param type $params */ public function checkSpaceGuid($attribute, $params) { if ($this->defaultSpaceGuid != "") { foreach (explode(',', $this->defaultSpaceGuid) as $spaceGuid) { if ($spaceGuid != "") { $space = Space::model()->findByAttributes(array('guid' => $spaceGuid)); if ($space == null) { $this->addError($attribute, Yii::t('AdminModule.forms_BasicSettingsForm', "Invalid space")); } } } } }
/** * Returns a List of Users */ public function actionBasic() { Yii::import('admin.forms.*'); $form = new BasicSettingsForm(); $form->name = HSetting::Get('name'); $form->baseUrl = HSetting::Get('baseUrl'); $form->defaultLanguage = HSetting::Get('defaultLanguage'); $form->dashboardShowProfilePostForm = HSetting::Get('showProfilePostForm', 'dashboard'); $form->tour = HSetting::Get('enable', 'tour'); $form->defaultSpaceGuid = ""; foreach (Space::model()->findAllByAttributes(array('auto_add_new_members' => 1)) as $defaultSpace) { $form->defaultSpaceGuid .= $defaultSpace->guid . ","; } if (isset($_POST['ajax']) && $_POST['ajax'] === 'basic-settings-form') { echo CActiveForm::validate($form); Yii::app()->end(); } if (isset($_POST['BasicSettingsForm'])) { $_POST['BasicSettingsForm'] = Yii::app()->input->stripClean($_POST['BasicSettingsForm']); $form->attributes = $_POST['BasicSettingsForm']; if ($form->validate()) { HSetting::Set('name', $form->name); HSetting::Set('baseUrl', $form->baseUrl); HSetting::Set('defaultLanguage', $form->defaultLanguage); HSetting::Set('enable', $form->tour, 'tour'); HSetting::Set('showProfilePostForm', $form->dashboardShowProfilePostForm, 'dashboard'); $spaceGuids = explode(",", $form->defaultSpaceGuid); // Remove Old Default Spaces foreach (Space::model()->findAllByAttributes(array('auto_add_new_members' => 1)) as $space) { if (!in_array($space->guid, $spaceGuids)) { $space->auto_add_new_members = 0; $space->save(); } } // Add new Default Spaces foreach ($spaceGuids as $spaceGuid) { $space = Space::model()->findByAttributes(array('guid' => $spaceGuid)); if ($space != null && $space->auto_add_new_members != 1) { $space->auto_add_new_members = 1; $space->save(); } } // set flash message Yii::app()->user->setFlash('data-saved', Yii::t('AdminModule.controllers_SettingController', 'Saved')); $this->redirect(Yii::app()->createUrl('//admin/setting/basic')); } } $this->render('basic', array('model' => $form)); }
/** * Recalculate user and content reputation every hour * Only do this in spaces where reputation module is enabled * * @param $event * @throws CException */ public static function onCronHourlyRun($event) { Yii::import('application.modules.reputation.models.*'); $cron = $event->sender; foreach (Space::model()->findAll() as $space) { if ($space->isModuleEnabled('reputation')) { $cronJobEnabled = SpaceSetting::Get($space->id, 'cron_job', 'reputation', ReputationBase::DEFAULT_CRON_JOB); if ($cronJobEnabled) { print "- Recalculating reputation for space: {$space->id} {$space->name}\n"; ReputationUser::model()->updateUserReputation($space, true); ReputationContent::model()->updateContentReputation($space, true); } } } }
/** * Page which shows all current workspaces */ public function actionSpaces() { $pageSize = 5; $criteria = new CDbCriteria(); $criteria->condition = 'visibility != ' . Space::VISIBILITY_NONE; $criteria->order = 'id DESC'; //$criteria->params = array (':id'=>$id); $workspaceCount = Space::model()->count($criteria); $pages = new CPagination($workspaceCount); $pages->setPageSize($pageSize); $pages->applyLimit($criteria); // the trick is here! $workspaces = Space::model()->findAll($criteria); $this->render('workspaces', array('workspaces' => $workspaces, 'pages' => $pages, 'workspaceCount' => $workspaceCount, 'pageSize' => $pageSize)); }
public function __construct() { if (!isset($this->id)) { $this->id = ''; } if (!isset($this->icon)) { $this->icon = ''; } if (!isset($this->targets)) { $this->targets = false; } if (!isset($this->notemplate)) { $this->notemplate = 0; } if (Yii::app()->request->getParam('sguid') != '' && ($this->space = Space::model()->findByPk(Yii::app()->request->getParam('sguid'))) == null) { $this->space = false; } return parent::__construct(); }
/** * Registers a user * @param array data */ private function registerUser($data) { $userModel = new User('register'); $userPasswordModel = new UserPassword(); $profileModel = $userModel->profile; $profileModel->scenario = 'register'; // User: Set values $userModel->username = $data['username']; $userModel->email = $data['email']; $userModel->group_id = $data['group_id']; $userModel->status = User::STATUS_ENABLED; // Profile: Set values $profileModel->firstname = $data['firstname']; $profileModel->lastname = $data['lastname']; // Password: Set values $userPasswordModel->setPassword($data['password']); if ($userModel->save()) { // Save user profile $profileModel->user_id = $userModel->id; $profileModel->save(); // Save user password $userPasswordModel->user_id = $userModel->id; $userPasswordModel->save(); // Join space / create then join space foreach ($data['space_names'] as $key => $space_name) { // Find space by name attribute $space = Space::model()->findByAttributes(array('name' => $space_name)); // Create the space if not found if ($space == null) { $space = new Space(); $space->name = $space_name; $space->save(); } // Add member into space $space->addMember($userModel->id); } return true; } else { Yii::app()->user->setFlash('error', CHtml::errorSummary($userModel)); return false; } }
/** * This is a special case, because we need to find a space to start the tour */ public function actionStartSpaceTour() { $space = null; // Loop over all spaces where the user is member foreach (SpaceMembership::GetUserSpaces() as $space) { if ($space->isAdmin()) { // If user is admin on this space, it´s the perfect match break; } } if ($space === null) { // If user is not member of any space, try to find a public space // to run tour in $space = Space::model()->find('visibility!=' . Space::VISIBILITY_NONE); } if ($space === null) { throw new CHttpException(404, 'Could not find any public space to run tour!'); } $this->redirect($space->getUrl(array('tour' => true))); }
/** * Get the Container this widget is embedded in. * @throws CHttpException if the container could not be found. * @return Either the User or the Space container. */ public function getContainer() { $container = null; $spaceGuid = Yii::app()->request->getQuery('sguid'); $userGuid = Yii::app()->request->getQuery('uguid'); if ($spaceGuid != "") { $container = Space::model()->findByAttributes(array('guid' => $spaceGuid)); if ($container == null) { throw new CHttpException(404, Yii::t('SpaceModule.base', 'Space not found!')); } } elseif ($userGuid != "") { $container = User::model()->findByAttributes(array('guid' => $userGuid)); if ($container == null) { throw new CHttpException(404, Yii::t('UserModule.base', 'Space not found!')); } } else { throw new CHttpException(500, Yii::t('base', 'Could not determine content container!')); } return $container; }
public function parseUrl($manager, $request, $pathInfo, $rawPathInfo) { if (substr($pathInfo, 0, 2) == "s/") { $parts = explode('/', $pathInfo, 3); if (isset($parts[1])) { $space = Space::model()->findByAttributes(array('guid' => $parts[1])); if ($space !== null) { $_GET['sguid'] = $space->guid; if (!isset($parts[2]) || substr($parts[2], 0, 4) == 'home') { $temp = 1; return 'space/space/index' . str_replace('home', '', $parts[2], $temp); } else { return $parts[2]; } } else { throw new CHttpException('404', Yii::t('SpaceModule.components_SpaceUrlRule', 'Space not found!')); } } } return false; }
public function testPublicContent() { $this->becomeUser('User2'); $space = Space::model()->findByPk(2); $post1 = new Post(); $post1->message = "Private Post"; $post1->content->setContainer($space); $post1->content->visibility = Content::VISIBILITY_PRIVATE; $post1->save(); $w1 = $post1->content->getFirstWallEntryId(); $post2 = new Post(); $post2->message = "Public Post"; $post2->content->setContainer($space); $post2->content->visibility = Content::VISIBILITY_PUBLIC; $post2->save(); $w2 = $post2->content->getFirstWallEntryId(); $this->becomeUser('User1'); $ids = $this->getStreamActionIds($space, 2); $this->assertFalse(in_array($w1, $ids)); $this->assertTrue(in_array($w2, $ids)); }
/** * Returns the current selected space by parameter guid * * If space doesnt exists or there a no permissions and exception * will thrown. * * @return Space */ public function getSpace() { if ($this->space != null) { return $this->space; } // Get Space GUID by parameter $guid = Yii::app()->request->getQuery('sguid'); if ($guid == "") { // Workaround for older version $guid = Yii::app()->request->getQuery('guid'); } // Try Load the space $this->space = Space::model()->findByAttributes(array('guid' => $guid)); if ($this->space == null) { throw new CHttpException(404, Yii::t('SpaceModule.behaviors_SpaceControllerBehavior', 'Space not found!')); } $this->checkAccess(); // Store current space to stash Yii::app()->params['currentSpace'] = $this->space; return $this->space; }
/** * Get a random space model from DB * * @return array of space and membership information from Space Model. */ private function getRandomSpace($randNum) { $criteria = new CDbCriteria(); $criteria->limit = 1; $criteria->offset = $randNum; if (Yii::app()->user->isGuest) { $criteria->condition = 'visibility =' . Space::VISIBILITY_ALL . " AND status =" . Space::STATUS_ENABLED; } else { $criteria->condition = "visibility IN (" . Space::VISIBILITY_ALL . "," . Space::VISIBILITY_REGISTERED_ONLY . ") AND status =" . Space::STATUS_ENABLED; } $spaces = Space::model()->findAll($criteria); if (!empty($spaces)) { foreach ($spaces as $space) { $members = array(); $membership = Yii::app()->db->createCommand()->select('user_id')->from('space_membership')->where('space_id=:id', array(':id' => $space->id))->queryAll(); if ($membership !== null) { foreach ($membership as $member) { $members[] = User::model()->findByPk($member['user_id']); } return array($space, $members); } } } }
/** * Automatically loads the underlying contentContainer (User/Space) by using * the uguid/sguid request parameter * * @return boolean */ public function init() { $spaceGuid = Yii::app()->request->getParam('sguid', ''); $userGuid = Yii::app()->request->getParam('uguid', ''); if ($spaceGuid != "") { $this->contentContainer = Space::model()->findByAttributes(array('guid' => $spaceGuid)); if ($this->contentContainer == null) { throw new CHttpException(404, Yii::t('base', 'Space not found!')); } $this->attachBehavior('SpaceControllerBehavior', array('class' => 'application.modules_core.space.behaviors.SpaceControllerBehavior', 'space' => $this->contentContainer)); Yii::app()->params['currentSpace'] = $this->contentContainer; $this->subLayout = "application.modules_core.space.views.space._layout"; } elseif ($userGuid != "") { $this->contentContainer = User::model()->findByAttributes(array('guid' => $userGuid)); if ($this->contentContainer == null) { throw new CHttpException(404, Yii::t('base', 'User not found!')); } $this->attachBehavior('ProfileControllerBehavior', array('class' => 'application.modules_core.user.behaviors.ProfileControllerBehavior', 'user' => $this->contentContainer)); Yii::app()->params['currentUser'] = $this->contentContainer; $this->subLayout = "application.modules_core.user.views.profile._layout"; } else { throw new CHttpException(500, Yii::t('base', 'Could not determine content container!')); } /** * Auto check access rights to this container */ if ($this->contentContainer != null) { if ($this->autoCheckContainerAccess) { $this->checkContainerAccess(); } } if (!$this->checkModuleIsEnabled()) { throw new CHttpException(405, Yii::t('base', 'Module is not on this content container enabled!')); } return parent::init(); }
/** * Returns a list of all spaces where this SpaceModule is * enabled. * * @return Array Space */ public function getSpaceModuleSpaces() { $spaces = array(); foreach (Space::model()->findAll() as $s) { if ($s->isModuleEnabled($this->owner->getId())) { $spaces[] = $s; } } return $spaces; }
/** * SearchAction * * Modes: normal for full page, quick as partial for lightbox */ public function actionIndex() { // Get Parameters $keyword = Yii::app()->request->getParam('keyword', ""); $spaceGuid = Yii::app()->request->getParam('sguid', ""); $mode = Yii::app()->request->getParam('mode', "normal"); $page = (int) Yii::app()->request->getParam('page', 1); // current page (pagination) // Cleanup $keyword = Yii::app()->input->stripClean($keyword); $spaceGuid = Yii::app()->input->stripClean($spaceGuid); if ($mode != 'quick') { $mode = "normal"; } $limit = HSetting::Get('paginationSize'); // Show Hits $hitCount = 0; // Total Hit Count $query = ""; // Lucene Query $append = " AND (model:User OR model:Space)"; // Appends for Lucene Query $moreResults = false; // Indicates if there are more hits $results = array(); // Quick Search shows always 1 if ($mode == 'quick') { $limit = 5; } // Load also Space if requested $currentSpace = null; if ($spaceGuid) { $currentSpace = Space::model()->findByAttributes(array('guid' => $spaceGuid)); } /* * $index = new Zend_Search_Lucene_Interface_MultiSearcher(); * $index->addIndex(Zend_Search_Lucene::open('search/index1')); * $index->addIndex(Zend_Search_Lucene::open('search/index2')); * $index->find('someSearchQuery'); */ // Do Search if ($keyword != "") { if ($currentSpace != null) { $append = " AND (model:User OR model:Space OR (belongsToType:Space AND belongsToId:" . $currentSpace->id . "))"; } $hits = new ArrayObject(HSearch::getInstance()->Find($keyword . "* " . $append)); $hitCount = count($hits); // Limit Hits $hits = new LimitIterator($hits->getIterator(), ($page - 1) * $limit, $limit); if ($hitCount > $limit) { $moreResults = true; } // Build Results Array foreach ($hits as $hit) { $doc = $hit->getDocument(); $model = $doc->getField('model')->value; $pk = $doc->getField('pk')->value; $object = $model::model()->findByPk($pk); $results[] = $object->getSearchResult(); } } // Create Pagination Class $pages = new CPagination($hitCount); $pages->setPageSize($limit); $_GET['keyword'] = $keyword; // Fix for post var if ($mode == 'quick') { $this->renderPartial('quick', array('keyword' => $keyword, 'results' => $results, 'spaceGuid' => $spaceGuid, 'moreResults' => $moreResults, 'hitCount' => $hitCount)); } else { $this->render('index', array('keyword' => $keyword, 'results' => $results, 'spaceGuid' => $spaceGuid, 'moreResults' => $moreResults, 'pages' => $pages, 'pageSize' => $limit, 'hitCount' => $hitCount)); } }
/** * Updates or creates user by given ldap node * * @param Zend_Ldap_Node $node * @return User User Object */ public function handleLdapUser($node) { $username = $node->getAttribute(HSetting::Get('usernameAttribute', 'authentication_ldap'), 0); $email = $node->getAttribute('mail', 0); $guid = $this->binToStrGuid($node->getAttribute('objectGUID', 0)); // Try to load User: $userChanged = false; $user = null; if ($guid != "") { $user = User::model()->findByAttributes(array('guid' => $guid, 'auth_mode' => User::AUTH_MODE_LDAP)); } else { // Fallback use e-mail $user = User::model()->findByAttributes(array('email' => $email, 'auth_mode' => User::AUTH_MODE_LDAP)); } if ($user === null) { $user = new User(); if ($guid != "") { $user->guid = $guid; } $user->status = User::STATUS_ENABLED; $user->auth_mode = User::AUTH_MODE_LDAP; $user->group_id = 1; Yii::log('Create ldap user ' . $username . '!', CLogger::LEVEL_INFO, 'authentication_ldap'); } // Update Group Mapping foreach (Group::model()->findAll('ldap_dn != ""') as $group) { if (in_array($group->ldap_dn, $node->getAttribute('memberOf'))) { if ($user->group_id != $group->id) { $userChanged = true; $user->group_id = $group->id; } } } // Update Users Field if ($user->username != $username) { $userChanged = true; $user->username = $username; } if ($user->email != $email) { $userChanged = true; $user->email = $email; } if ($user->validate()) { // Only Save user when something is changed if ($userChanged || $user->isNewRecord) { $user->save(); } // Update Profile Fields foreach (ProfileField::model()->findAll('ldap_attribute != ""') as $profileField) { $ldapAttribute = $profileField->ldap_attribute; $profileFieldName = $profileField->internal_name; $user->profile->{$profileFieldName} = $node->getAttribute($ldapAttribute, 0); } if ($user->profile->validate()) { $user->profile->save(); // Update Space Mapping foreach (Space::model()->findAll('ldap_dn != ""') as $space) { if (in_array($space->ldap_dn, $node->getAttribute('memberOf'))) { $space->addMember($user->id); } } } else { Yii::log('Could not create or update ldap user profile! (' . print_r($user->profile->getErrors(), true) . ")", CLogger::LEVEL_ERROR, 'authentication_ldap'); } } else { Yii::log('Could not create or update ldap user! (' . print_r($user->getErrors(), true) . ")", CLogger::LEVEL_ERROR, 'authentication_ldap'); } return $user; }
/** * After Save Addons * * @return type */ protected function afterSave() { // Search Stuff if (!$this->isNewRecord) { HSearch::getInstance()->deleteModel($this); } if ($this->status == User::STATUS_ENABLED) { HSearch::getInstance()->addModel($this); } if ($this->isNewRecord) { $userInvite = UserInvite::model()->findByAttributes(array('email' => $this->email)); if ($userInvite !== null) { // User was invited to a space if ($userInvite->source == UserInvite::SOURCE_INVITE) { $space = Space::model()->findByPk($userInvite->space_invite_id); if ($space != null) { $space->addMember($this->id); } } // Delete/Cleanup Invite Entry $userInvite->delete(); } // Auto Assign User to the Group Space $group = Group::model()->findByPk($this->group_id); if ($group != null && $group->space_id != "") { $space = Space::model()->findByPk($group->space_id); if ($space !== null) { $space->addMember($this->id); } } $this->notifyGroupAdminsForApproval(); // Auto Add User to the default spaces foreach (Space::model()->findAllByAttributes(array('auto_add_new_members' => 1)) as $space) { $space->addMember($this->id); } // Create new wall record for this user $wall = new Wall(); $wall->type = Wall::TYPE_USER; $wall->object_model = 'User'; $wall->object_id = $this->id; $wall->save(); $this->wall_id = $wall->id; $this->wall = $wall; User::model()->updateByPk($this->id, array('wall_id' => $wall->id)); } return parent::afterSave(); }
</div> <hr> <ul class="media-list"> <!-- BEGIN: Results --> <?php foreach ($hits as $hit) { ?> <?php $doc = $hit->getDocument(); $model = $doc->getField("model")->value; $spaceId = $doc->getField('pk')->value; $space = Space::model()->findByPk($spaceId); ?> <li> <div class="media"> <!-- Follow Handling --> <div class="pull-right"> <?php if (!$space->isMember()) { $followed = $space->isFollowedByUser(); echo HHtml::postLink(Yii::t('DirectoryModule.views_directory_members', 'Follow'), 'javascript:setFollow("' . $space->createUrl('//space/space/follow') . '", "' . $space->id . '")', array('class' => 'btn btn-success btn-sm ' . ($followed ? 'hide' : ''), 'id' => 'button_follow_' . $space->id)); echo HHtml::postLink(Yii::t('DirectoryModule.views_directory_members', 'Unfollow'), 'javascript:setUnfollow("' . $space->createUrl('//space/space/unfollow') . '", "' . $space->id . '")', array('class' => 'btn btn-primary btn-sm ' . ($followed ? '' : 'hide'), 'id' => 'button_unfollow_' . $space->id)); } ?> </div>
public function populateDefaultSpaceGuid() { $defaultSpace = Space::model()->findByPk($this->space_id); if ($defaultSpace !== null) { $this->defaultSpaceGuid = $defaultSpace->guid; } }
/** * Sets standard content informations like container, visibility, files * by ContentFormWidget Submit Data. */ public function populateByForm() { // Set Content Container $contentContainer = null; if (Yii::app()->request->getParam('containerClass') == 'User') { $contentContainer = User::model()->findByAttributes(array('guid' => Yii::app()->request->getParam('containerGuid', ""))); } elseif (Yii::app()->request->getParam('containerClass') == 'Space') { $contentContainer = Space::model()->findByAttributes(array('guid' => Yii::app()->request->getParam('containerGuid', ""))); } $this->container = $contentContainer; if (get_class($this->container) == 'Space') { $this->visibility = Yii::app()->request->getParam('visibility'); } elseif (get_class($this->container) == 'User') { $this->visibility = 1; } // Handle Notify User Features of ContentFormWidget // ToDo: Check permissions of user guids $userGuids = Yii::app()->request->getParam('notifyUserInput'); if ($userGuids != "") { foreach (explode(",", $userGuids) as $guid) { $user = User::model()->findByAttributes(array('guid' => trim($guid))); if ($user) { $this->notifyUsersOfNewContent[] = $user; } } } // Store List of attached Files to add them after Save $this->attachFileGuidsAfterSave = Yii::app()->request->getParam('fileList'); }