function afterSave($created) { if ($created) { // $user_id = $this->Auth->user('id'); $data = array(); $vlog_id = $this->getInsertID(); $datas = $this->data['VideoResponse']; if ($this->data['VideoLog']['user_id'] == 36) { } else { foreach ($datas as $key => $val) { $data = $this->VideoResponse->set(array('video_log_id' => $vlog_id, 'video_feedback_id' => $key, 'video_feedback_option_id' => $val['video_feedback_option_id'])); $this->VideoResponse->saveAll($data); } $this->Video->incrementvideoview($this->data['VideoLog']['video_id']); $vid = $this->Video->findVideo($this->data['VideoLog']['video_id']); $num_views = $vid['Video']['video_views']; $max_views = $vid['Video']['max_view']; if ($num_views == $max_views || $num_views > $max_views) { $this->Video->disableVideo($this->data['VideoLog']['video_id']); } App::import('Model', 'Viewer'); $viewer = new Viewer(); $trust = $viewer->getTrustScore($this->data['VideoLog']['user_id']); $credit = $this->Video->findCreditValue($this->data['VideoLog']['video_id']); $this->User->credituser($this->data['VideoLog']['user_id'], $credit, $trust); $currentbalance = $this->User->findCurrentBalance($this->data['VideoLog']['user_id']); App::import('Model', 'CreditLog'); $creditLog = new CreditLog(); $ext_id = $this->data['VideoLog']['video_id']; $rate = $trust / 16000; //checking trust percentage if ($rate == 1) { // check if user has 100% trust $creditLog->addCreditLog($this->data['VideoLog']['user_id'], $credit, $currentbalance, $ext_id); //log entry of the Video View } else { $credit_added = $credit * $rate; //eels credited to the users account $credit_left = $credit - $credit_added; // credits left from the video view $currentbalance_flipit = $this->User->findCurrentBalance(18); //current balance ofthe flipit account $creditLog->addCreditLog($this->data['VideoLog']['user_id'], $credit_added, $currentbalance, $ext_id); // log entry of the percentage of credit deposited into user account $creditLog->left_CreditLog(18, $credit_left, $currentbalance_flipit, $ext_id); // Log entry of the remaining crdits from the video to flipit account } } } }