Example #1
0
 /**
  * Collect monthly stats
  *
  * @param      integer 	$numMonths
  * @return     mixed False if error, Object on success
  */
 public function monthlyStats($numMonths = 3, $includeCurrent = false)
 {
     $stats = array();
     require_once PATH_CORE . DS . 'components' . DS . 'com_publications' . DS . 'tables' . DS . 'publication.php';
     $obj = new Project($this->_db);
     $objO = new Owner($this->_db);
     $objP = new \Components\Publications\Tables\Publication($this->_db);
     $testProjects = $obj->getProjectsByTag('test', true, 'id');
     $validProjectIds = $obj->getProjectsByTag('test', false, 'id');
     $n = $includeCurrent ? 0 : 1;
     for ($a = $numMonths; $a >= $n; $a--) {
         $yearNum = intval(date('y', strtotime("-" . $a . " month")));
         $monthNum = intval(date('m', strtotime("-" . $a . " month")));
         $log = $this->getLog($yearNum, $monthNum);
         if ($log) {
             $stats[date('M', strtotime("-" . $a . " month"))] = json_decode($log[0]->stats, true);
             // Get new users by month
             if (!isset($stats[date('M', strtotime("-" . $a . " month"))]['team']['new'])) {
                 $new = $objO->getTeamStats($testProjects, 'new', date('Y-m', strtotime("-" . $a . " month")));
                 $stats[date('M', strtotime("-" . $a . " month"))]['team']['new'] = $new ? $new : 0;
             }
             // Get publication release count by month
             if (!isset($stats[date('M', strtotime("-" . $a . " month"))]['pub']['new'])) {
                 $new = $objP->getPubStats($validProjectIds, 'released', date('Y-m', strtotime("-" . $a . " month")));
                 $stats[date('M', strtotime("-" . $a . " month"))]['pub']['new'] = $new ? $new : 0;
             }
         }
     }
     return $stats;
 }