Пример #1
0
 function Search($firstcount, $displaypg)
 {
     global $cache_types;
     uses("space", "industry", "area");
     $space = new Space();
     $area = new Areas();
     $industry = new Industries();
     $cache_options = cache_read('typeoption');
     $area_s = $space->array_multi2single($area->getCacheArea());
     $industry_s = $space->array_multi2single($area->getCacheArea());
     $result = $this->findAll("*,name AS title,content AS digest", null, null, $this->orderby, $firstcount, $displaypg);
     while (list($keys, $values) = each($result)) {
         $result[$keys]['typename'] = $cache_types['productsort'][$values['sort_id']];
         $result[$keys]['thumb'] = pb_get_attachmenturl($values['picture'], '', 'small');
         $result[$keys]['pubdate'] = df($values['begin_time']);
         if (!empty($result[$keys]['area_id'])) {
             $r1 = $area_s[$result[$keys]['area_id']];
         }
         if (!empty($result[$keys]['cache_companyname'])) {
             $r2 = "<a href='" . $space->rewrite($result[$keys]['cache_companyname'], $result[$keys]['company_id']) . "'>" . $result[$keys]['cache_companyname'] . "</a>";
         }
         if (!empty($r1) || !empty($r2)) {
             $result[$keys]['extra'] = implode(" - ", array($r1, $r2));
         }
         $result[$keys]['url'] = $this->getPermaLink($values['id']);
     }
     return $result;
 }
Пример #2
0
 /**
  * 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));
 }
Пример #3
0
 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";
 }
 /**
  * Returns an object to be used by `json_encode` to serialize objects of this class.
  *
  * @return object
  *
  * @see http://php.net/manual/en/jsonserializable.jsonserialize.php JsonSerializable::jsonSerialize
  */
 public function jsonSerialize()
 {
     $obj = new \stdClass();
     if ($this->id !== null) {
         $obj->id = $this->id;
     }
     if ($this->type !== null) {
         $obj->type = $this->type;
     }
     if ($this->space !== null) {
         $obj->space = (object) ['sys' => (object) ['type' => 'Link', 'linkType' => 'Space', 'id' => $this->space->getId()]];
     }
     if ($this->contentType !== null) {
         $obj->contentType = (object) ['sys' => (object) ['type' => 'Link', 'linkType' => 'ContentType', 'id' => $this->contentType->getId()]];
     }
     if ($this->revision !== null) {
         $obj->revision = $this->revision;
     }
     if ($this->createdAt !== null) {
         $obj->createdAt = $this->formatDateForJson($this->createdAt);
     }
     if ($this->updatedAt !== null) {
         $obj->updatedAt = $this->formatDateForJson($this->updatedAt);
     }
     if ($this->deletedAt !== null) {
         $obj->deletedAt = $this->formatDateForJson($this->deletedAt);
     }
     return $obj;
 }
Пример #5
0
 public function register(array $input = array())
 {
     $customrules = ['email' => 'required|email|unique:user,email'];
     $input['type'] = isset($input['type']) ? $input['type'] : 'user';
     $input['via'] = isset($input['via']) ? $input['via'] : 'register';
     $input['signup_ref'] = isset($input['signup_ref']) ? $input['signup_ref'] : null;
     $input['ref_code'] = $this->_refCodeGenerator();
     $validation = $this->model->validate($input, $customrules);
     if ($validation->passes()) {
         $user = $this->model->create($input);
         $this->_sendWelcomeMail($input);
         if ($input['signup_ref'] != null) {
             \Space::create(['user_id' => $user->id, 'type' => 'credit', 'nominal' => \Config::get('thankspace.space_credit.signup'), 'keterangan' => 'Space Credit for sign up from link referral']);
         }
         $this->_sendAdminNewCustomerMail($user->id);
         if ($input['via'] != 'admin') {
             $auth = $this->_handleLogin($user->id);
             return $auth;
         } else {
             return true;
         }
     } else {
         $this->setErrors($validation->messages()->all(':message'));
         return false;
     }
 }
Пример #6
0
 /**
  * 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));
 }
Пример #7
0
 /**
  * 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";
     }
 }
Пример #8
0
 /**
  * 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));
 }
Пример #9
0
 /**
  * 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('')
      ));
      });
     */
 }
Пример #10
0
 /**
  * ユーザ・グループ検索機能を提供します
  *
  * @param string $title 項目名として表示させる文字列
  * @param string $pluginModel モデル名
  * @param int $roomId ルームID
  * @param array $selectUsers 選択済みユーザ配列
  * @return string HTML tags
  */
 public function select($title = '', $pluginModel = 'GroupsUser', $roomId = null, $selectUsers = array())
 {
     if (!isset($roomId)) {
         $roomId = Space::getRoomIdRoot(Space::COMMUNITY_SPACE_ID);
     }
     if ($title === '') {
         $title = __d('groups', 'User select');
     }
     return $this->_View->element('Groups.select', array('title' => $title, 'pluginModel' => $pluginModel, 'roomId' => $roomId, 'selectUsers' => $selectUsers));
 }
Пример #11
0
 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');
 }
 /** 
  * 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;
     }
 }
Пример #13
0
 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);
 }
Пример #14
0
 /**
  * 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();
 }
Пример #15
0
 /**
  * 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"));
                 }
             }
         }
     }
 }
Пример #16
0
 /**
  * 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));
 }
Пример #17
0
 /**
  * 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));
 }
Пример #18
0
 /**
  * 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));
 }
 /**
  * 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);
             }
         }
     }
 }
Пример #20
0
 /**
  * PrivateSpaceルームの生成
  *
  * @param array $data デフォルト値
  * @return array PrivateSpaceルーム配列
  */
 public function createRoom($data = array())
 {
     $this->loadModels(['Language' => 'M17n.Language', 'Room' => 'Rooms.Room', 'RoomsLanguage' => 'Rooms.RoomsLanguage']);
     $parentRoom = $this->Room->find('first', array('recursive' => -1, 'fields' => array('space_id', 'active', 'need_approval', 'page_layout_permitted'), 'conditions' => array('id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID))));
     $result = $this->Room->create(Hash::merge(array('id' => null, 'root_id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID), 'parent_id' => Space::getRoomIdRoot(Space::PRIVATE_SPACE_ID), 'default_role_key' => Role::ROOM_ROLE_KEY_ROOM_ADMINISTRATOR, 'default_participation' => false), $parentRoom['Room']));
     $languages = $this->Language->getLanguages();
     App::uses('L10n', 'I18n');
     $L10n = new L10n();
     foreach ($languages as $i => $language) {
         $catalog = $L10n->catalog($language['Language']['code']);
         $roomsLanguage = $this->RoomsLanguage->create(array('id' => null, 'language_id' => $language['Language']['id'], 'room_id' => null, 'name' => __d('private_space', $catalog['language'])));
         $result['RoomsLanguage'][$i] = $roomsLanguage['RoomsLanguage'];
     }
     $result['Page']['parent_id'] = null;
     return $result;
 }
 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();
 }
 /**
  * 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;
 }
Пример #23
0
 /**
  * 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)));
 }
Пример #24
0
 /**
  * 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;
 }
 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));
 }
Пример #26
0
 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;
 }
 /**
  * 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);
             }
         }
     }
 }
Пример #28
0
 /**
  * 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();
 }
Пример #29
0
<?php

/**
 *      [PHPB2B] Copyright (C) 2007-2099, Ualink Inc. All Rights Reserved.
 *      The contents of this file are subject to the License; you may not use this file except in compliance with the License. 
 *
 *      @version $Revision: 2048 $
 */
if (!defined('IN_PHPB2B')) {
    exit('Not A Valid Entry Point');
}
require CACHE_LANG_PATH . 'lang_space.php';
require CACHE_PATH . 'cache_membergroup.php';
uses("templet", "member", "company", "membertype", "space");
$member = new Members();
$space = new Space();
$membertype = new Membertypes();
$company = new Companies();
$templet = new Templets();
$space_name = '';
if (empty($theme_name)) {
    $theme_name = "default";
    $style_name = isset($_PB_CACHE['setting']['theme']) && !empty($_PB_CACHE['setting']['theme']) ? $_PB_CACHE['setting']['theme'] : "default";
    $ADODB_CACHE_DIR = DATA_PATH . 'dbcache';
}
$pdb->setFetchMode(ADODB_FETCH_ASSOC);
$smarty->flash_layout = $theme_name . "/flash";
$smarty->assign("theme_img_path", "templates/" . $theme_name . "/");
$smarty->assign('ThemeName', $theme_name);
//if caches
$space_cache_cycle = 86400;
Пример #30
0
 /**
  * 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();
 }