public static function getLastNCreatedRobots($n)
 {
     $lastNRobots = array();
     try {
         $robots = RobotDataDB::getRobotDataBy();
         $lastNRobots = array_slice($robots, -$n, $n);
     } catch (Exception $e) {
         return $lastRobots;
     }
     return $lastNRobots;
 }
 public function testInsertDuplicateRobotData()
 {
     $myDb = DBMaker::create('botspacetest');
     Database::clearDB();
     $db = Database::getDB('botspacetest', 'C:\\xampp\\myConfig.ini');
     $beforeCount = count(RobotDataDB::getRobotDataBy());
     $robotDataCopy = RobotDataDB::getRobotDataBy('robotId', 2);
     $robotDataCopy = $robotDataCopy[0];
     $this->assertEquals(0, $robotDataCopy->getErrorCount(), 'The robot data copy object should have no errors');
     $dupRobotData = RobotDataDB::addRobotData($robotDataCopy);
     $afterCount = count(RobotDataDB::getRobotDataBy());
     $this->assertTrue(!empty($dupRobotData->getError('robotId')) && strcmp(Messages::getError('ROBOT_DATA_INVALID'), $dupRobotData->getError('robotId')) == 0, 'It should have a robotDataId error if the robot data is a duplicate');
     $this->assertEquals($afterCount, $beforeCount, 'There should be no additional robot data entries after the insertion attempt');
 }
 public static function setProfileDataForUser($userId)
 {
     $retVal = false;
     if (empty($userId) || !is_numeric($userId)) {
         return $retVal;
     }
     $user = null;
     $userData = null;
     $skillAssocs = null;
     $userRobots = null;
     $users = UsersDB::getUsersBy('userId', $userId);
     if (count($users) > 0) {
         $user = $users[0];
         if ($user->getErrorCount() != 0) {
             return $retVal;
         }
         $userDataArray = UserDataDB::getUserDataBy('userId', $userId);
         if (count($userDataArray) > 0) {
             $userData = $userDataArray[0];
         }
         if ($userData->getErrorCount() != 0) {
             return $retVal;
         }
         $skillAssocs = SkillAssocsDB::getSkillAssocsBy('userDataId', $userData->getUserDataId());
         foreach ($skillAssocs as $skillAssoc) {
             if ($skillAssoc->getErrorCount() != 0) {
                 return $retVal;
             }
         }
         $robotAssocs = RobotAssocsDB::getRobotAssocsBy('creatorId', $userData->getUserDataId());
         $userRobots = array();
         foreach ($robotAssocs as $robotAssoc) {
             $robotArray = RobotDataDB::getRobotDataBy('robotId', $robotAssoc->getRobotId());
             if (count($robotArray) > 0) {
                 array_push($userRobots, $robotArray[0]);
             }
         }
         $_SESSION['user'] = $user;
         $_SESSION['userData'] = $userData;
         $_SESSION['skillAssocs'] = $skillAssocs;
         $_SESSION['userRobots'] = $userRobots;
         $retVal = true;
     }
     return $retVal;
 }
 public static function updateRobotData()
 {
     $robotDataArray = RobotDataDB::getRobotDataBy('robotId', $_SESSION['arguments']);
     if (empty($robotDataArray)) {
         HomeView::show();
         header('Location: /' . $_SESSION['base']);
     } elseif ($_SERVER["REQUEST_METHOD"] == "GET") {
         $_SESSION['robotData'] = $robotDataArray[0];
         RobotDataView::showUpdate();
     } else {
         $robotData = $robotDataArray[0];
         $parms = $robotData->getParameters();
         $parms['robot_name'] = array_key_exists('robot_name', $_POST) ? $_POST['robot_name'] : "";
         $parms['status'] = array_key_exists('status', $_POST) ? $_POST['status'] : "";
         $parms['creators'] = array_key_exists('creators', $_POST) ? $_POST['creators'] : array();
         $revisedRobotData = new RobotData($parms);
         $revisedRobotData->setRobotId($robotData->getRobotId());
         $robotDataEntry = RobotDataDB::updateRobotData($revisedRobotData);
         if ($robotDataEntry->getErrorCount() != 0) {
             $_SESSION['robotData'] = array($revisedRobotData);
             RobotDataView::showUpdate();
         } else {
             HomeView::show();
             header('Location: /' . $_SESSION['base']);
         }
     }
 }
 public static function getRobotDataValuesBy($type = null, $value = null, $column)
 {
     $robotDataRows = RobotDataDB::getRobotDataRowSetsBy($type, $value);
     return RobotDataDB::getRobotDataValues($robotDataRows, $column);
 }