示例#1
0
 /**
  * Records the event of the current tool having been used
  * This is used for the favorites list of the My Tools module
  *
  * @param      string  $app Name of app called
  * @param      integer $uid User ID
  * @return     void
  */
 private function _recordUsage($app, $uid)
 {
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'version.php';
     $tool = new \Components\Tools\Tables\Version($this->database);
     $tool->loadFromName($app);
     $created = Date::toSql();
     // Get a list of all their recent tools
     include_once dirname(dirname(__DIR__)) . DS . 'tables' . DS . 'recent.php';
     $rt = new \Components\Tools\Tables\Recent($this->database);
     $rows = $rt->getRecords($uid);
     $thisapp = 0;
     for ($i = 0, $n = count($rows); $i < $n; $i++) {
         if ($app == trim($rows[$i]->tool)) {
             $thisapp = $rows[$i]->id;
         }
     }
     // Get the oldest entry. We may need this later.
     $oldest = end($rows);
     // Check if any recent tools are the same as the one just launched
     if ($thisapp) {
         // There was one, so just update its creation time
         $rt->id = $thisapp;
         $rt->uid = $uid;
         $rt->tool = $app;
         $rt->created = $created;
     } else {
         // Check if we've reached 5 recent tools or not
         if (count($rows) < 5) {
             // Still under 5, so insert a new record
             $rt->uid = $uid;
             $rt->tool = $app;
             $rt->created = $created;
         } else {
             // We reached the limit, so update the oldest entry effectively replacing it
             $rt->id = $oldest->id;
             $rt->uid = $uid;
             $rt->tool = $app;
             $rt->created = $created;
         }
     }
     if (!$rt->store()) {
         App::abort(500, $rt->getError());
         return;
     }
 }
示例#2
0
 /**
  * Record Tool Usage
  *
  * @param		$tool		Alias of tool
  * @param		$userid		User ID
  *
  * @return 		BOOL
  */
 public static function recordToolUsage($tool, $userid = '')
 {
     //include needed files
     include_once dirname(__DIR__) . DS . 'tables' . DS . 'version.php';
     include_once dirname(__DIR__) . DS . 'tables' . DS . 'recent.php';
     //instantiate needed objects
     $database = \App::get('db');
     //load tool version
     $toolVersion = new \Components\Tools\Tables\Version($database);
     $toolVersion->loadFromName($tool);
     //make sure we have a user id
     if (!$userid) {
         $userid = User::get('id');
     }
     //get recent tools
     $recentTool = new \Components\Tools\Tables\Recent($database);
     $rows = $recentTool->getRecords($userid);
     //check to see if any recently used tools are this one
     $thisapp = 0;
     for ($i = 0, $n = count($rows); $i < $n; $i++) {
         if ($tool == trim($rows[$i]->tool)) {
             $thisapp = $rows[$i]->id;
         }
     }
     // Get the oldest entry. We may need this later.
     $oldest = end($rows);
     //createed date
     $created = Date::toSql();
     // Check if any recent tools are the same as the one just launched
     if ($thisapp) {
         // There was one, so just update its creation time
         $recentTool->id = $thisapp;
         $recentTool->uid = $userid;
         $recentTool->tool = $tool;
         $recentTool->created = $created;
     } else {
         // Check if we've reached 5 recent tools or not
         if (count($rows) < 5) {
             // Still under 5, so insert a new record
             $recentTool->uid = $userid;
             $recentTool->tool = $tool;
             $recentTool->created = $created;
         } else {
             // We reached the limit, so update the oldest entry effectively replacing it
             $recentTool->id = $oldest->id;
             $recentTool->uid = $userid;
             $recentTool->tool = $tool;
             $recentTool->created = $created;
         }
     }
     //store usage
     if (!$recentTool->store()) {
         return false;
     }
     return true;
 }