Esempio n. 1
0
 /**
  * On run of integrity check command, validate all wall data
  *
  * @param type $event
  */
 public static function onIntegrityCheck($event)
 {
     $integrityChecker = $event->sender;
     $integrityChecker->showTestHeadline("Validating Wall Module (" . WallEntry::model()->count() . " entries)");
     foreach (WallEntry::model()->with('content')->findAll() as $w) {
         if ($w->content === null) {
             $integrityChecker->showFix("Deleting wall entry id " . $w->id . " without assigned wall entry!");
             if (!$integrityChecker->simulate) {
                 $w->delete();
             }
             continue;
         }
     }
     //TODO: Maybe not the best place for that
     $integrityChecker->showTestHeadline("Validating Content Objects (" . Content::model()->count() . " entries)");
     foreach (Content::model()->findAll() as $content) {
         if ($content->user == null) {
             $integrityChecker->showFix("Deleting content id " . $content->id . " of type " . $content->object_model . " without valid user!");
             if (!$integrityChecker->simulate) {
                 $content->delete();
             }
             continue;
         }
         if ($content->getUnderlyingObject() == null) {
             $integrityChecker->showFix("Deleting content id " . $content->id . " of type " . $content->object_model . " without valid content object!");
             if (!$integrityChecker->simulate) {
                 $content->delete();
             }
             continue;
         }
     }
 }
Esempio n. 2
0
 /**
  * On given WallEntryId redirect the user to the corresponding content object.
  *
  * This is mainly used by ActivityStream or Permalinks.
  */
 public function actionWallEntry()
 {
     // Id of wall entry
     $id = Yii::app()->request->getParam('id', "");
     $wallEntry = WallEntry::model()->with('content')->findByPk($id);
     if ($wallEntry != null) {
         $obj = $wallEntry->content;
         // Type of IContent
         if ($obj) {
             $this->redirect($obj->container->getUrl(array('wallEntryId' => $id)));
             return;
         }
     }
     throw new CHttpException(404, Yii::t('WallModule.controllers_PermaController', 'Could not find requested permalink!'));
 }
Esempio n. 3
0
 public function run()
 {
     $this->init();
     $entries = WallEntry::model()->findAll($this->criteria);
     $output = "";
     $generatedWallEntryIds = array();
     $lastEntryId = "";
     foreach ($entries as $entry) {
         $underlyingObject = $entry->content->getUnderlyingObject();
         $user = $underlyingObject->content->user;
         $output .= Yii::app()->getController()->renderPartial('application.modules_core.wall.views.wallEntry', array('entry' => $entry, 'user' => $user, 'mode' => $this->mode, 'object' => $underlyingObject, 'content' => $underlyingObject->getWallOut()), true);
         $generatedWallEntryIds[] = $entry->id;
         $lastEntryId = $entry->id;
     }
     // Fire JQuery Time AGO
     Yii::app()->clientScript->registerScript('timeago', '$(".time").timeago();');
     $pageOut = "";
     Yii::app()->clientScript->renderHead($pageOut);
     Yii::app()->clientScript->renderBodyBegin($pageOut);
     $pageOut .= $output;
     Yii::app()->clientScript->renderBodyEnd($pageOut);
     $json = array();
     $json['output'] = $pageOut;
     $json['lastEntryId'] = $lastEntryId;
     $json['counter'] = count($entries);
     $json['entryIds'] = $generatedWallEntryIds;
     header('Content-type: application/json');
     echo CJSON::encode($json);
     Yii::app()->end();
 }
Esempio n. 4
0
 /**
  * Before Delete of a User
  *
  */
 public function beforeDelete()
 {
     // We don't allow deletion of users who owns a space - validate that
     foreach (SpaceMembership::GetUserSpaces($this->id) as $workspace) {
         if ($workspace->isSpaceOwner($this->id)) {
             throw new Exception("Tried to delete a user which is owner of a space!");
         }
     }
     UserSetting::model()->deleteAllByAttributes(array('user_id' => $this->id));
     // Disable all enabled modules
     foreach ($this->getAvailableModules() as $moduleId => $module) {
         if ($this->isModuleEnabled($moduleId)) {
             $this->disableModule($moduleId);
         }
     }
     HSearch::getInstance()->deleteModel($this);
     // Delete Profile Image
     $this->getProfileImage()->delete();
     // Delete all pending invites
     UserInvite::model()->deleteAllByAttributes(array('user_originator_id' => $this->id));
     Follow::model()->deleteAllByAttributes(array('user_id' => $this->id));
     Follow::model()->deleteAllByAttributes(array('object_model' => 'User', 'object_id' => $this->id));
     // Delete all group admin assignments
     GroupAdmin::model()->deleteAllByAttributes(array('user_id' => $this->id));
     // Delete wall entries
     WallEntry::model()->deleteAllByAttributes(array('wall_id' => $this->wall_id));
     // Deletes all content created by this user
     foreach (Content::model()->findAllByAttributes(array('user_id' => $this->id)) as $content) {
         $content->delete();
     }
     foreach (Content::model()->findAllByAttributes(array('created_by' => $this->id)) as $content) {
         $content->delete();
     }
     // Delete all passwords
     foreach (UserPassword::model()->findAllByAttributes(array('user_id' => $this->id)) as $password) {
         $password->delete();
     }
     return parent::beforeDelete();
 }
Esempio n. 5
0
 /**
  * Returns the Wall Entries, which belongs to this Content.
  *
  * @return Array of wall entries for this content
  */
 public function getWallEntries()
 {
     $entries = WallEntry::model()->findAllByAttributes(array('content_id' => $this->id));
     return $entries;
 }
Esempio n. 6
0
 /**
  * Execute the Stream Action and returns a JSON output.
  */
 public function run()
 {
     $this->init();
     $this->prepareSQL();
     $this->setupFilterSQL();
     Yii::beginProfile('runStreamAction');
     $stickedFirstOrder = "";
     // Show sticked items?
     if (($this->type == Wall::TYPE_SPACE || $this->type == Wall::TYPE_USER) && $this->wallEntryLimit != 1) {
         if ($this->wallEntryFrom == "") {
             $stickedFirstOrder = "content.sticked DESC,";
         } else {
             $this->sqlWhere .= " AND (content.sticked != 1 OR content.sticked is NULL)";
         }
     }
     //$order = "ORDER BY ".$stickedFirstOrder."wall_entry.created_at DESC";
     $order = "ORDER BY " . $stickedFirstOrder . "wall_entry.id DESC";
     if ($this->sorting == self::SORT_UPDATED_AT) {
         $order = "ORDER BY " . $stickedFirstOrder . "wall_entry.updated_at DESC";
     }
     $sql = "SELECT wall_entry.*\n\t\t\tFROM wall_entry\n                        LEFT JOIN content ON wall_entry.content_id = content.id\n                        LEFT JOIN user creator ON creator.id = content.created_by\n\t\t\t{$this->sqlJoin}\n\t\t\tWHERE creator.status = 1\n\t\t\t{$this->sqlWhere}\n\t\t\t{$this->sqlGroupBy}\n            {$order}\n\t\t\tLIMIT {$this->wallEntryLimit}\n\t\t";
     // Execute SQL
     $entries = WallEntry::model()->with('content')->findAllBySql($sql, $this->sqlParams);
     // Save Wall Type
     Wall::$currentType = $this->type;
     $output = "";
     $lastEntryId = "";
     $generatedWallEntryIds = array();
     foreach ($entries as $entry) {
         $underlyingObject = $entry->content->getUnderlyingObject();
         $user = $underlyingObject->content->user;
         $output .= Yii::app()->getController()->renderPartial('application.modules_core.wall.views.wallEntry', array('entry' => $entry, 'user' => $user, 'mode' => $this->mode, 'object' => $underlyingObject, 'content' => $underlyingObject->getWallOut()), true);
         $generatedWallEntryIds[] = $entry->id;
         $lastEntryId = $entry->id;
     }
     // Fire JQuery Time AGO
     Yii::app()->clientScript->registerScript('timeago', '$(".time").timeago();');
     $pageOut = "";
     Yii::app()->clientScript->renderHead($pageOut);
     Yii::app()->clientScript->renderBodyBegin($pageOut);
     $pageOut .= $output;
     Yii::app()->clientScript->renderBodyEnd($pageOut);
     $json = array();
     $json['output'] = $pageOut;
     $json['lastEntryId'] = $lastEntryId;
     $json['counter'] = count($entries);
     $json['entryIds'] = $generatedWallEntryIds;
     Yii::endProfile('runStreamAction');
     echo CJSON::encode($json);
     Yii::app()->end();
 }