Exemplo n.º 1
0
 public function saveComments($comments, $ref_entity_id, $param_class, $group_id, $param_group, $session)
 {
     $i = 0;
     $comments = $comments->getProperty('data');
     while ($comments->getProperty($i) != null) {
         $single_comment = $comments->getProperty($i);
         if ($param_class == 'Post') {
             $fb_comment = FbPostComment::model()->findByPk($single_comment->getProperty('id'));
         } else {
             if ($param_class == 'Doc') {
                 $fb_comment = FbDocComment::model()->findByPk($single_comment->getProperty('id'));
             } else {
                 if ($param_class == 'Files') {
                     $fb_comment = FbFilesComment::model()->findByPk($single_comment->getProperty('id'));
                 }
             }
         }
         if ($fb_comment == null) {
             $class = new ReflectionClass('Fb' . $param_class . 'Comment');
             $fb_comment = $class->newInstanceArgs();
         }
         $fb_comment->cid = $single_comment->getProperty('id');
         $fb_comment->author_id = $single_comment->getProperty('from')->getProperty('id');
         $fb_comment->like_count = $single_comment->getProperty('like_count');
         $fb_comment->message = $this->removeNames($single_comment->getProperty('message'));
         $fb_comment->message = $this->removeBadWords($fb_comment->message);
         $created_datetime = DateTime::createFromFormat(DateTime::ISO8601, $single_comment->getProperty('created_time'));
         $created_datetime->add(new DateInterval('PT1H'));
         $o = new ReflectionObject($created_datetime);
         $p = $o->getProperty('date');
         $created_date = $p->getValue($created_datetime);
         $fb_comment->created_time = $created_date;
         $fb_comment->ref_entity_id = $ref_entity_id;
         $this->saveMemberInfo($single_comment->getProperty('from'));
         $fb_comment->validate();
         $fb_comment->save();
         $this->saveMember($single_comment->getProperty('from'), $group_id, $param_group);
         if ($single_comment->getProperty('obejct_id') != null && $post->getProperty('properties') == null) {
             $this->savePhotos($single_comment->getProperty('obejct_id'), $fb_comment->cid, 'Comment', $session);
         }
         $i++;
     }
 }
Exemplo n.º 2
0
} else {
    $ref_id = $group->eid;
    $exam = ExamGroup::model()->findByPk($ref_id);
    $posts_exam = FbPost::model()->findAllByAttributes(array('exam_group_id' => $ref_id));
    $exam_member = MemberExamGroup::model()->findAllByAttributes(array('user_group_id' => $ref_id));
    // 			array_push($total_post_exam, $posts_exam);
    $docs_exam = FbDoc::model()->findAllByAttributes(array('exam_group_id' => $ref_id));
    $files_exam = FbFiles::model()->findAllByAttributes(array('exam_group_id' => $ref_id));
    foreach ($posts_exam as $pe) {
        $posts_exam_like = LikeFbPost::model()->findAllByAttributes(array('ref_entity_id' => $pe->fbpid));
        // 				array_push($total_posts_exam_like, $posts_exam_like);
        $n_total_post_exam_like += count($posts_exam_like);
        $photos_exam_post = PhotoFbPost::model()->findAllByAttributes(array('element_id' => $pe->fbpid));
        // 				array_push($total_photo_post_exam, $photos_exam_post);
        $n_total_photo_post_exam += count($photos_exam_post);
        $comments = FbPostComment::model()->findAllByAttributes(array('ref_entity_id' => $pe->fbpid));
        foreach ($comments as $c) {
            array_push($total_exam_post_comment, $c);
            $photo_exam_comments = PhotoFbCommentPost::model()->findAllByAttributes(array('element_id' => $c->cid));
            $n_total_photo_exam_comments += count($photo_exam_comments);
            // 					array_push($total_photo_exam_comments, $photo_exam_comments);
            $comment_exam_like = LikeFbCommentPost::model()->findAllByAttributes(array('ref_entity_id' => $c->cid));
            $n_total_like_comments += $c->like_count;
            // 					array_push($total_like_exam_comments, $comment_exam_like);
        }
    }
    $n_total_post_exam = count($posts_exam);
    // 		$n_total_post_exam_like = count($total_posts_exam_like);
    // 		$n_total_photo_post_exam = count($total_photo_post_exam);
    $n_total_exam_post_comment = count($total_exam_post_comment);
    // 		$n_total_photo_exam_comments = count($total_photo_exam_comments);
Exemplo n.º 3
0
 public function featuresRappresentation()
 {
     set_time_limit(0);
     $criteria = new CDbCriteria();
     $criteria->condition = " post_type_l1 is null";
     $post = FbPost::model()->findAll($criteria);
     foreach ($post as $p) {
         $features_rappresentation = new FeaturesRappresentation();
         $features_rappresentation->pid = $p->fbpid;
         $message = strtolower($p->message);
         $features_rappresentation->format_info = substr_count($message, "\n");
         $features_rappresentation->n_char = strlen($message);
         $comments = FbPostComment::model()->findAllByAttributes(array('ref_entity_id' => $p->fbpid));
         $features_rappresentation->n_comment = count($comments);
         $comment_char_lenght = 0;
         $n_like_comment = 0;
         $top_author_comment = "false";
         foreach ($comments as $c) {
             $comment_char_lenght += strlen($c->message);
             $n_like_comment += $c->like_count;
             $author_comment = Users::model()->findByPk($c->author_id);
             if ($author_comment->user_type == "top") {
                 $top_author_comment = "true";
             }
         }
         $features_rappresentation->comment_author_top = $top_author_comment;
         $features_rappresentation->n_char_comment_length = $comment_char_lenght;
         if ($features_rappresentation->comment_author_top != 0 && $features_rappresentation->n_char_comment_length != 0) {
             $features_rappresentation->n_char_comment_length_ratio = round($comment_char_lenght / $features_rappresentation->n_comment, 4);
         } else {
             $features_rappresentation->n_char_comment_length_ratio = 0;
         }
         $features_rappresentation->n_like_comment = $n_like_comment;
         if ($p->link != null) {
             $features_rappresentation->link_presence = "true";
         } else {
             $features_rappresentation->link_presence = "false";
         }
         if ($p->application != null) {
             $features_rappresentation->device = "mobile";
         } else {
             $features_rappresentation->device = "web";
         }
         $photo = PhotoFbPost::model()->findAllByAttributes(array("element_id" => $p->fbpid));
         if ($photo != null) {
             $features_rappresentation->picture_presence = "true";
         } else {
             $features_rappresentation->picture_presence = "false";
         }
         $like = LikeFbPost::model()->findAllByAttributes(array("ref_entity_id" => $p->fbpid));
         $features_rappresentation->n_like = count($like);
         $top_user_like = "false";
         foreach ($like as $l) {
             $author_like = Users::model()->findByPk($l->user_id);
             if ($author_like->user_type == "top") {
                 $top_user_like = "true";
                 break;
             }
         }
         $features_rappresentation->like_top_user = $top_user_like;
         $top_author = "false";
         $author_post = Users::model()->findByPk($p->author_id);
         if ($author_post->user_type == "top") {
             $features_rappresentation->top_author_user = "******";
         } else {
             $features_rappresentation->top_author_user = "******";
         }
         $features_rappresentation->question_mark_presence = substr_count($message, "?");
         $features_rappresentation->math_symbols_presence = $this->checkMathSymbol($message);
         $features_rappresentation->time_element_presence = $this->checkTemporalElement($message);
         $features_rappresentation->save();
     }
     echo 'OK ;)';
 }
Exemplo n.º 4
0
 public function addAnswer($pid, $question_id)
 {
     $criteria = new CDbCriteria();
     $criteria->condition = "ref_entity_id =" . $pid . " AND message is not null";
     $comments = FbPostComment::model()->findAll($criteria);
     // 		$comments = FbPostComment::model()->findAllByAttributes(array("ref_entity_id" => $pid));
     foreach ($comments as $c) {
         if ($this->addFakeName($c->author_id)) {
             $qa_user_id = $this->addAuthor($c->author_id);
         }
         if (is_array($qa_user_id)) {
             $qa_user_id = $qa_user_id[0];
         }
         if (qa_post_check_by_fb_id($c->cid) == null) {
             $answer_id = qa_post_create_with_data("A", $question_id, null, $c->message, '', $c->created_time, null, null, $qa_user_id);
             $this->addFakeLikes($answer_id, $c->like_count, $question_id);
             qa_post_create_fb_mapping($answer_id, $c->cid);
         }
     }
 }
Exemplo n.º 5
0
    public function calcolateMeanAnswerTime($id)
    {
        $sum_time_minutes = 0;
        $no_answer_question = 0;
        $array_sample = array();
        // 		$allPost = FbPost::model()->findAll();
        $allPost = FbPost::model()->findAllByAttributes(array('degree_group_id' => $id));
        if ($allPost == null) {
            $allPost = FbPost::model()->findAllByAttributes(array('exam_group_id' => $id));
        }
        foreach ($allPost as $post) {
            $minutes_single_post = 0;
            $post_time = new DateTime($post->created_time);
            $comment = FbPostComment::model()->findByAttributes(array('ref_entity_id' => $post->fbpid), array('order' => 'created_time ASC'));
            if (isset($comment)) {
                $comment_time = new DateTime($comment->created_time);
                $sum_time = $comment_time->diff($post_time);
                $minutes_single_post += $sum_time->d * 24 * 60 * 60;
                $minutes_single_post += $sum_time->h * 60 * 60;
                $minutes_single_post += $sum_time->i * 60;
                $minutes_single_post += $sum_time->s;
                $post->first_answer_time = $minutes_single_post;
                array_push($array_sample, $minutes_single_post);
                $sum_time_minutes += $sum_time->d * 24 * 60 * 60;
                $sum_time_minutes += $sum_time->h * 60 * 60;
                $sum_time_minutes += $sum_time->i * 60;
                $sum_time_minutes += $sum_time->s;
            } else {
                $post->first_answer_time = 0;
                $no_answer_question += 1;
            }
            // 			$post->validate();
            // 			$post->save();
        }
        $consideredPost = count($allPost) - $no_answer_question;
        echo '<b>Post Considerati: </b>' . $consideredPost;
        ?>
<br><br><?php 
        echo '<b>Post senza risposta: </b>' . $no_answer_question;
        ?>
<br><br><?php 
        echo '<b>Il Tempo medio e: </b>' . ($mean_answer_time = $sum_time_minutes / $consideredPost . ' secondi ');
        ?>
<br><br><?php 
        $dev = 0;
        foreach ($array_sample as $s) {
            $dev += pow($s - $mean_answer_time, 2);
        }
        $dev_std = sqrt($dev / $consideredPost - 1);
        echo '<b>La deviazione standard e: </b>' . $dev_std . ' secondi ';
        ?>
<br><br><?php 
    }