/** * Return elapsed time between two datetimes in human readable format. * * @param datetime $start Initial datetime. * @param datetime $end Final datetime (default is current time). * * @return string The formatted elapsed time. */ public static function timeBetween($start, $end = null) { // Convert datetimes to timestamps $start = MiscUtils::datetime2timestamp($start); $end = is_null($end) ? time() : MiscUtils::datetime2timestamp($end); $SECOND = 1; $MINUTE = 60 * $SECOND; $HOUR = 60 * $MINUTE; $DAY = 24 * $HOUR; $WEEK = 7 * $DAY; $MONTH = 30 * $DAY; $YEAR = 365 * $DAY; $increments = array(array($SECOND, 'second'), array($MINUTE, 'minute'), array($HOUR, 'hour'), array($DAY, 'day'), array($WEEK, 'week'), array($MONTH, 'month'), array($YEAR, 'year')); $diff = $end - $start; $plural = ''; $units = ceil($diff / $increments[count($increments) - 1][0]); $unit = $increments[count($increments) - 1][1]; for ($i = 1; $i < count($increments); $i++) { if ($increments[$i - 1][0] <= $diff && $diff < $increments[$i][0]) { $units = ceil($diff / $increments[$i - 1][0]); $unit = $increments[$i - 1][1]; break; } } if ($units > 1) { $plural = 's'; } return sprintf("%d %s%s ago", $units, $unit, $plural); }
public function updateNameSlugColumn($slug) { if (empty($slug)) { $slug = MiscUtils::slugify($this->values["name"]); } // Slugify name, and check if slug generated does not already exist and generate a new one if needed $size = 1; while (Doctrine_Core::getTable("Image")->checkSlug($slug, $this->values["id"])) { $slug = MiscUtils::slugify($this->values["name"]) . substr(microtime(), -$size); $size++; } return $slug; }
/** * Executes edit action * * @param sfRequest $request A request object */ public function executeEdit(sfWebRequest $request) { // Get user profile from database $user = $this->getUser()->getGuardUser(); $profile = Doctrine_Core::getTable("SfGuardUserProfile")->findOneByUserId($user->getId()); $this->ldapAuthentication = sfConfig::get("app_authentication_method", "symfony") == "ldap" ? true : false; // If user has no profile, create a new one for him if (empty($profile)) { $profile = new sfGuardUserProfile(); $profile->setUserId($user->getId()); $profile->setToken(MiscUtils::generateToken()); $profile->setSecurityLevel(sfConfig::get("app_security_level_new_user", 0)); $profile->save(); } $this->form = new ProfileForm(array('first_name' => $user->getFirstName(), 'last_name' => $user->getLastName(), 'email' => $user->getEmailAddress())); $this->token = $profile->getToken(); $this->securityLevel = Labeler::getSecurityLevelLabel($profile->getSecurityLevel()); // Process form if ($request->isMethod("post")) { $this->processEdit($request, $this->form); } }
} ?> <?php $rowCount++; $globalRowCount++; ?> <tr class="<?php echo $rowCount % 2 == 0 ? "even" : "odd"; ?> "> <td class="date"><span title="<?php echo Labeler::getTestSessionStatusLabel($data["status"]); ?> " class="icon_status <?php echo "status_" . MiscUtils::slugify(Labeler::getTestSessionStatusLabel($data["status"]), '_'); ?> "></span><?php echo format_datetime($data["created_at"], "y-MM-dd HH:mm"); ?> </td> <td class="report_name"> <a href="<?php echo url_for("test_session", array("project" => $currentProject["name_slug"], "product" => $currentProduct["name_slug"], "environment" => $currentEnvironment["name_slug"], "image" => $data["i_slug"], "id" => $data["id"], "display" => "basic")); ?> " title="See basic report" class="shortcut_link">Basic</a> <a href="<?php echo url_for("test_session", array("project" => $currentProject["name_slug"], "product" => $currentProduct["name_slug"], "environment" => $currentEnvironment["name_slug"], "image" => $data["i_slug"], "id" => $data["id"], "display" => "detailed")); ?> " title="See detailed report" class="shortcut_link">Detailed</a> <a href="<?php
<?php require_once dirname(__FILE__) . '/common/common.inc.php'; if (isset($_COOKIE[OPERATOR])) { $_SESSION[OPERATOR] = json_decode($_COOKIE[OPERATOR]); } $template = MiscUtils::getParam('t', 'signin'); $options = MiscUtils::getParam('opts', MiscUtils::encode(array())); $smarty->assign('operator', MiscUtils::encode(array())); $smarty->assign('now', MiscUtils::encode(SimpleDate::create())); $smarty->assign('options', $options); $smarty->assign('template', $template); $smarty->display('gui/base.tpl');
echo $measure["measures"]["target"]["unit"]; ?> </span></td> <td class="testcase_limit"><?php echo $measure["measures"]["limit"]["value"]; ?> <span class="unit"><?php echo $measure["measures"]["limit"]["unit"]; ?> </span></td> <td class="testcase_to_target"><?php echo round($measure["measures"]["value"]["value"] / $measure["measures"]["target"]["value"] * 100, 1); ?> %</td> <td class="testcase_result <?php echo Labeler::decisionToText($measure["decision_criteria_id"]); ?> "> <span class="content"><?php echo ucfirst(Labeler::decisionToText($measure["decision_criteria_id"])); ?> </span> </td> <td class="testcase_bugs"><div class="content"><?php echo MiscUtils::formatWikimarkups($measure["bugs"]); ?> </div></td> <td class="testcase_notes"><div class="content"><?php echo nl2br(MiscUtils::formatWikimarkups($measure["comment"])); ?> </div></td>
/** * Slugify the test environment name. * * @return The slugified name. */ public function getSlug() { return MiscUtils::slugify($this->getName()); }
<?php echo MiscUtils::timeBetween($sf_guard_user->getLastLogin());
public function executeImportRestApi(sfWebRequest $request) { $qa_generic = sfConfig::get("app_table_qa_generic"); $qa_core = sfConfig::get("app_table_qa_core"); // Retrieve $_GET (main parameters) $get_params['auth_token'] = $request->getGetParameter("auth_token"); $get_params['release_version'] = $request->getGetParameter("release_version"); $get_params['target'] = $request->getGetParameter("target"); $get_params['testtype'] = $request->getGetParameter("testtype"); $get_params['testset'] = $request->getGetParameter("testset"); $get_params['hwproduct'] = $request->getGetParameter("hwproduct"); $get_params['product'] = $request->getGetParameter("product"); $get_params['hardware'] = $request->getGetParameter("hardware"); $get_params['image'] = $request->getGetParameter("image"); $get_params['build_id'] = $request->getGetParameter("build_id"); // Retrieve $_GET (additional parameters) $get_params['tested_at'] = $request->getGetParameter("tested_at"); $get_params['report_title'] = $request->getGetParameter("title"); $get_params['objective_txt'] = $request->getGetParameter("objective_txt"); $get_params['build_txt'] = $request->getGetParameter("build_txt"); $get_params['environment_txt'] = $request->getGetParameter("environment_txt"); $get_params['qa_summary_txt'] = $request->getGetParameter("qa_summary_txt"); $get_params['issue_summary_txt'] = $request->getGetParameter("issue_summary_txt"); $get_params['status'] = $request->getGetParameter("status"); // Retrieve $_GET (hwproduct additional fields) $get_params['te_desc'] = $request->getGetParameter("te_desc"); $get_params['te_cpu'] = $request->getGetParameter("te_cpu"); $get_params['te_board'] = $request->getGetParameter("te_board"); $get_params['te_gpu'] = $request->getGetParameter("te_gpu"); $get_params['te_hw'] = $request->getGetParameter("te_hw"); // Retrieve $_GET (image additional fields) $get_params['img_desc'] = $request->getGetParameter("img_desc"); $get_params['img_os'] = $request->getGetParameter("img_os"); $get_params['img_dist'] = $request->getGetParameter("img_dist"); $get_params['img_vers'] = $request->getGetParameter("img_vers"); $get_params['img_kernel'] = $request->getGetParameter("img_kernel"); $get_params['img_arch'] = $request->getGetParameter("img_arch"); $get_params['img_other'] = $request->getGetParameter("img_other"); $get_params['img_bin'] = $request->getGetParameter("img_bin"); $get_params['img_src'] = $request->getGetParameter("img_src"); // Old parameters support about test_environment (testtype) if (!isset($get_params['testtype'])) { $get_params['testtype'] = $get_params['testset']; } // Old parameters support about image (hwproduct) if (!isset($get_params['hwproduct'])) { if (!isset($get_params['product'])) { $get_params['hwproduct'] = $get_params['hardware']; } else { $get_params['hwproduct'] = $get_params['product']; } } // Check if auth_token parameter is empty if (empty($get_params['auth_token'])) { echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing auth_token parameter\"}}\n"; exit; } // Check if release_version parameter is empty if (empty($get_params['release_version'])) { echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing release_version parameter\"}}\n"; exit; } // Check if target parameter is empty if (empty($get_params['target'])) { echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing target parameter\"}}\n"; exit; } // Check if hwproduct parameter is empty if (empty($get_params['hwproduct'])) { echo "{\"ok\":\"0\",\"errors\":{\"Parameters error\":\"Missing hwproduct parameter\"}}\n"; exit; } // Check if image parameter is empty if (empty($get_params['image'])) { $get_params['image'] = "Empty_image"; } // Retrieve project_id relying on project name (if it doesn't exist, return an error) $query = "SELECT proj.id AS project_id\n\t\t\t\t\tFROM " . $qa_generic . ".project proj\n\t\t\t\t\tWHERE proj.name = '" . $get_params['release_version'] . "'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["project_id"])) { echo "{\"ok\":\"0\",\"errors\":{\"release_version\":\"Incorrect release_version '" . $get_params['release_version'] . "'\"}}\n"; exit; } $project_id = $result["project_id"]; // Retrieve project_group_id relying on project_group_name (if it doesn't exist, return an error) $query = "SELECT pg.id AS project_group_id\n\t\t\t\t\tFROM " . $qa_core . ".sf_guard_group pg\n\t\t\t\t\tWHERE pg.name = '" . sfConfig::get("app_project_group") . "'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["project_group_id"])) { echo "{\"ok\":\"0\",\"errors\":{\"project_group_name\":\"Incorrect project_group_name '" . sfConfig::get("app_project_group") . "'\"}}\n"; exit; } $project_group_id = $result["project_group_id"]; // Retrieve product_id relying on product formfactor (if it doesn't exist, return an error) $query = "SELECT pt.id AS product_id\n\t\t\t\t\tFROM " . $qa_core . ".product_type pt\n\t\t\t\t\tWHERE pt.name = '" . $get_params['target'] . "'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["product_id"])) { echo "{\"ok\":\"0\",\"errors\":{\"target\":\"Incorrect target '" . $get_params['target'] . "'\"}}\n"; exit; } $product_id = $result["product_id"]; // Retrieve project_to_product_id, relying on project_id, project_group_id, and product_id $query = "SELECT ptp.id AS ptp_id\n\t\t\t\t\tFROM " . $qa_generic . ".project_to_product ptp\n\t\t\t\t\tWHERE ptp.project_id = " . $project_id . "\n\t\t\t\t\t\tAND ptp.project_group_id = " . $project_group_id . "\n\t\t\t\t\t\tAND ptp.product_id = " . $product_id; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["ptp_id"])) { echo "{\"ok\":\"0\",\"errors\":{\"project_to_product\":\"Cannot find project_to_product_id\"}}\n"; exit; } $project_to_product_id = $result["ptp_id"]; // Retrieve user_id, relying on auth_token $query = "SELECT up.user_id\n\t\t\t\t\tFROM " . $qa_core . ".sf_guard_user_profile up\n\t\t\t\t\tWHERE up.token = '" . $get_params['auth_token'] . "'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["user_id"])) { echo "{\"ok\":\"0\",\"errors\":{\"auth_token\":\"Authorized token is not valid\"}}\n"; exit; } $user_id = $result["user_id"]; // Customize database connection to begin a transactionnal query $conn = Doctrine_Manager::getInstance()->getConnection("qa_generic"); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, FALSE); $conn->beginTransaction(); // If test_environment_name exists, retrieve id, else, create new entry and retrieve id $query = "SELECT te.id AS test_environment_id\n\t\t\t\t\tFROM " . $qa_generic . ".test_environment te\n\t\t\t\t\tWHERE te.name = '" . $get_params['hwproduct'] . "'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["test_environment_id"])) { // Check if creation of a new entry is allowed if (sfConfig::get("app_rest_configuration_creation", false) == false) { $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":{\"test_environment\":\"Creation of new test environment is forbidden\"}}\n"; exit; } else { // Add new environment $environment = new TestEnvironment(); $environment->setName($get_params['hwproduct']); $environment->setNameSlug(MiscUtils::slugify($get_params['hwproduct'])); // Add hwproduct additional fields if given as parameters if (isset($get_params['te_desc'])) { $environment->setDescription($get_params['te_desc']); } if (isset($get_params['te_cpu'])) { $environment->setCpu($get_params['te_cpu']); } if (isset($get_params['te_board'])) { $environment->setBoard($get_params['te_board']); } if (isset($get_params['te_gpu'])) { $environment->setGpu($get_params['te_gpu']); } if (isset($get_params['te_hw'])) { $environment->setOtherHardware($get_params['te_hw']); } // Save new environment $environment->save($conn); $environmentId = $environment->getId(); } } else { $environmentId = $result["test_environment_id"]; } // If image_name exists, retrieve id, else, create new entry and retrieve id $query = "SELECT i.id AS image_id\n\t\t\t\t\tFROM " . $qa_generic . ".image i\n\t\t\t\t\tWHERE i.name = '" . $get_params['image'] . "'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["image_id"])) { // Check if creation of a new entry is allowed if (sfConfig::get("app_rest_configuration_creation", false) == false) { $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":{\"image\":\"Creation of new image is forbidden\"}}\n"; exit; } else { // Add new image $image = new Image(); $image->setName($get_params['image']); $image->setNameSlug(MiscUtils::slugify($get_params['image'])); // Add image additional fields if given as parameters if (isset($get_params['img_desc'])) { $image->setDescription($get_params['img_desc']); } if (isset($get_params['img_os'])) { $image->setOs($get_params['img_os']); } if (isset($get_params['img_dist'])) { $image->setDistribution($get_params['img_dist']); } if (isset($get_params['img_vers'])) { $image->setVersion($get_params['img_vers']); } if (isset($get_params['img_kernel'])) { $image->setKernel($get_params['img_kernel']); } if (isset($get_params['img_arch'])) { $image->setArchitecture($get_params['img_arch']); } if (isset($get_params['img_other'])) { $image->setOtherFw($get_params['img_other']); } if (isset($get_params['img_bin'])) { $image->setBinaryLink($get_params['img_bin']); } if (isset($get_params['img_src'])) { $image->setSourceLink($get_params['img_src']); } // Save new image $image->save($conn); $imageId = $image->getId(); } } else { $imageId = $result["image_id"]; } // If configuration exists, retrieve id, else, create new entry and retrieve id $query = "SELECT c.id AS configuration_id\n\t\t\t\t\tFROM " . $qa_generic . ".configuration c\n\t\t\t\t\tWHERE c.project_to_product_id = " . $project_to_product_id . "\n\t\t\t\t\t\tAND c.test_environment_id = " . $environmentId . "\n\t\t\t\t\t\tAND c.image_id = " . $imageId; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); if (empty($result["configuration_id"])) { $configuration = new Configuration(); $configuration->setProjectToProductId($project_to_product_id); $configuration->setTestEnvironmentId($environmentId); $configuration->setImageId($imageId); $configuration->save($conn); $configurationId = $configuration->getId(); } else { $configurationId = $result["configuration_id"]; } $date_now = date("Y-m-d H:i:s"); $date_now_wo_sec = date("Y-m-d H:i"); $testSession = new TestSession(); $testSession->setName($get_params['target'] . " " . $get_params['testtype'] . " " . $get_params['hwproduct'] . " " . $date_now_wo_sec . " " . $get_params['build_id']); $testSession->setUserId($user_id); $testSession->setCreatedAt($date_now); $testSession->setUpdatedAt($date_now); $testSession->setStatus(2); $testSession->setPublished(1); $testSession->setConfigurationId($configurationId); // Fill in the build_id if it is given if (!empty($get_params['build_id'])) { $testSession->setBuildId($get_params['build_id']); $testSession->setBuildSlug(MiscUtils::slugify($get_params['build_id'])); } // Fill in the testset if it is given if (!empty($get_params['testtype'])) { $testSession->setTestset($get_params['testtype']); $testSession->setTestsetSlug(MiscUtils::slugify($get_params['testtype'])); } if (isset($get_params['report_title'])) { $testSession->setName($get_params['report_title']); } if (isset($get_params['objective_txt'])) { $testSession->setTestObjective($get_params['objective_txt']); } if (isset($get_params['environment_txt'])) { $testSession->setNotes($get_params['environment_txt']); } if (isset($get_params['qa_summary_txt'])) { $testSession->setQaSummary($get_params['qa_summary_txt']); } if (isset($get_params['issue_summary_txt'])) { $testSession->setIssueSummary($get_params['issue_summary_txt']); } if (isset($get_params['status'])) { $testSession->setStatus($get_params['status']); } $testSession->save($conn); $testSessionId = $testSession->getId(); // Retrieve table_name_test_session_id from table_name $query = "SELECT tn.id AS table_name_id\n\t\t\t\t\tFROM " . $qa_generic . ".table_name tn\n\t\t\t\t\tWHERE tn.name = 'test_session'"; $result = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); $tableNameTestSessionId = $result["table_name_id"]; // Concatenate directory path $dir_path = sfConfig::get('sf_upload_dir') . "/testsession_" . $testSessionId; // Get all files sent $files = $request->getFiles(); // Check if there is any report file to import if (empty($files)) { $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":\"Missing report file\"}\n"; exit; } // Import each report file and register attachment files $report_file_found = false; foreach ($files as $key => $file) { $reportType = false; $fileName = $file['name']; $fileSize = $file['size']; $fileType = $file['type']; $fileError = $file['error']; $fileChecksum = sha1_file($file["tmp_name"]); // Check file error and file size if (!$fileError and $fileSize <= sfConfig::get('app_max_file_size', '10000000')) { if (!is_dir($dir_path)) { mkdir($dir_path, 0777, true); } $dest_path = $dir_path . "/" . $fileName; // Move file to uploads directory move_uploaded_file($file['tmp_name'], $dest_path); $web_path = "/uploads" . "/testsession_" . $testSessionId . "/" . $fileName; $fileAttachment = new FileAttachment(); $fileAttachment->setName($fileName); $fileAttachment->setUserId($user_id); $fileAttachment->setUploadedAt(date("Y-m-d H:i:s")); $fileAttachment->setFilename($fileName); $fileAttachment->setFileSize($fileSize); $fileAttachment->setFileMimeType($fileType); $fileAttachment->setLink($web_path); $fileAttachment->setChecksum($fileChecksum); $fileAttachment->setTableNameId($tableNameTestSessionId); $fileAttachment->setTableEntryId($testSessionId); if ((preg_match("#\\.xml\$#i", $fileName) | preg_match("#\\.csv\$#i", $fileName)) & !preg_match("#attachment.?[0-9]*#i", $key)) { $report_file_found = true; $reportType = true; $fileAttachment->setCategory(1); } else { if (preg_match("#attachment.?[0-9]*#i", $key)) { $fileAttachment->setCategory(2); } else { $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":\"Only upload files with the extension .xml or .csv\"}\n"; exit; } } $fileAttachment->save($conn); // If it is an XML or CSV file, parse it and fill qa_generic database if ($reportType) { if ($err_code = Import::file($dest_path, $testSessionId, $configurationId, $conn)) { $error_message = Import::getImportErrorMessage($err_code); MiscUtils::deleteDir($dir_path); $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " is not valid = " . $error_message . "\"}\n"; exit; } } } else { MiscUtils::deleteDir($dir_path); $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":\"File " . $fileName . " exceed maximum size\"}\n"; exit; } } // If only attachment files have been found, cancel the new test session if (!$report_file_found) { $conn->rollback(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); echo "{\"ok\":\"0\",\"errors\":\"Missing report file\"}\n"; exit; } $conn->commit(); $conn->setAttribute(Doctrine_Core::ATTR_AUTOCOMMIT, TRUE); // Retrieve project name_slug, product name_slug, test environment name_slug and image name_slug $query = "SELECT i.name_slug image_name_slug, te.name_slug test_environment_name_slug, p.name_slug project_name_slug, pt.name_slug product_name_slug\n\t\t\t\t\tFROM " . $qa_generic . ".test_session ts\n\t\t\t\t\tJOIN " . $qa_generic . ".configuration c ON c.id = ts.configuration_id\n\t\t\t\t\tJOIN " . $qa_generic . ".image i ON i.id = c.image_id\n\t\t\t\t\tJOIN " . $qa_generic . ".test_environment te ON te.id = c.test_environment_id\n\t\t\t\t\tJOIN " . $qa_generic . ".project_to_product ptp ON ptp.id = c.project_to_product_id\n\t\t\t\t\tJOIN " . $qa_generic . ".project p ON p.id = ptp.project_id\n\t\t\t\t\tJOIN " . $qa_core . ".product_type pt ON pt.id = ptp.product_id\n\t\t\t\t\tWHERE ts.id = " . $testSessionId; $configInfo = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetch(PDO::FETCH_ASSOC); $projectNameSlug = $configInfo['project_name_slug']; $productNameSlug = $configInfo['product_name_slug']; $testEnvironmentNameSlug = $configInfo['test_environment_name_slug']; $imageNameSlug = $configInfo['image_name_slug']; // Return datas to CATS $url_to_return = $request->getUriPrefix() . $this->generateUrl("test_session", array('project' => $projectNameSlug, 'product' => $productNameSlug, 'environment' => $testEnvironmentNameSlug, 'image' => $imageNameSlug, 'id' => $testSessionId)); echo "{\"ok\":\"1\",\"url\":\"" . $url_to_return . "\"}\n"; // Return is done (with echo) so make sure nothing else will be sent exit; }
function findByRequest($myPdo) { global $tableVisitor; $result = new stdClass(); $result->data = array(); $sql = MiscUtils::getParam('sql', ''); $date = MiscUtils::getParam('date', NULL); $sql .= $date ? ' OR (v.weddingDay = \'' . SimpleDate::toStamp(json_decode($date)) . '\')' : ''; if ($sql) { try { $stmt = $myPdo->prepare($sql); $stmt->execute(); $i = 0; $count = 0; while ($i < $stmt->rowCount()) { $tmp = $stmt->fetch(PDO::FETCH_OBJ); $tmp->weddingDay = $tmp->weddingDay ? SimpleDate::fromStamp($tmp->weddingDay) : NULL; $result->data[] = $tmp; $i++; } echo json_encode($result); } catch (PDOException $e) { echo $e->getMessage(); } } }
if (array_key_exists($resultKey, $previousSessions[$i]->getRaw("measures"))) { $previousMeasures = $previousSessions[$i]->getRaw("measures"); array_push($measureValues, $previousMeasures[$resultKey]["measures"]["value"]["value"]); } } // Push current measure into the array array_push($measureValues, $measure["measures"]["value"]["value"]); // If there is only current measure, push it another time to get a flat graph if (count($measureValues) == 1) { array_push($measureValues, $measure["measures"]["value"]["value"]); } // Compute min, max, average and median $min = min($measureValues); $max = max($measureValues); $avg = array_sum($measureValues) / count($measureValues); $med = MiscUtils::median($measureValues); ?> <td class="testcase_graph"> <div class="bluff-wrapper2" style=""> <canvas id="nft-history-graph-<?php echo $measure["id"]; ?> " width="300" height="45"></canvas> <script type="text/javascript"> var g = new Bluff.Line('nft-history-graph-<?php echo $measure["id"]; ?> ', '300x45'); g.tooltips = true;
public static function decode($str) { return json_decode(MiscUtils::decrypt($str)); }
protected function processUpdate(sfWebRequest $request, ProjectFormCustom $form) { $qa_generic = sfConfig::get("app_table_qa_generic"); $form->bind($request->getParameter($form->getName())); if ($form->isValid()) { $values = $form->getValues(); // Get project and project group id $projectId = $values['id']; $projectGroupId = $values['group']; // Slugify name, check if generated slug does not already exist and generate a new one if needed if (empty($values['name_slug'])) { $slug = MiscUtils::slugify($values['name']); } else { $slug = $values['name_slug']; } $size = 1; while (Doctrine_Core::getTable("Project")->checkSlugForProject($projectId, $slug, false)) { $slug = MiscUtils::slugify($values['name']) . substr(microtime(), -$size); $size++; } // Update project data $projectObject = Doctrine_Core::getTable('Project')->find($projectId); $projectObject->setName($values['name']); $projectObject->setDescription($values['description']); $projectObject->setUserId($values['user_id']); $projectObject->setCreatedAt($values['created_at']); $projectObject->setStatus($values['status']); $projectObject->setSecurityLevel($values['security_level']); $projectObject->setNameSlug($slug); $projectObject->save(); // Get all products linked to the current project from the database (complementary_tool_relation table) $query = "SELECT ptp.id, ptp.product_id FROM " . $qa_generic . ".project_to_product ptp WHERE ptp.project_id = " . $projectId . " AND ptp.project_group_id = " . $projectGroupId; $results = Doctrine_Manager::getInstance()->getCurrentConnection()->execute($query)->fetchAll(PDO::FETCH_ASSOC); $productsFromDatabase = array(); foreach ($results as $projectToProduct) { // If one of the retrieved relationship is missing from form's products, delete the entry from database if (!in_array($projectToProduct['product_id'], $values['product'])) { Doctrine_Core::getTable('ProjectToProduct')->delete($projectToProduct['id']); } else { array_push($productsFromDatabase, $projectToProduct['product_id']); } } // Now, cycle through form's products to add the new entries foreach ($values['product'] as $product) { if (!in_array($product, $productsFromDatabase)) { // Create new entry into ProjectToProduct table $ptpObject = new ProjectToProduct(); $ptpObject->setProjectGroupId($values['group']); $ptpObject->setProjectId($projectId); $ptpObject->setProductId($product); $ptpObject->save(); } } $this->getUser()->setFlash('notice', 'Project has been updated'); $this->redirect(array('sf_route' => 'project_edit', 'sf_subject' => $projectObject)); } else { $this->getUser()->setFlash('error', 'The item has not been saved due to some errors.', false); } }
/** * * @param sfWebRequest $request * @param LdapForm $form */ protected function processLdap(sfWebRequest $request, LdapForm $form) { $form->bind($request->getParameter('signin')); if ($form->isValid()) { $values = $form->getValues(); // Check if user already exists in the DB $user = Doctrine::getTable('sfGuardUser')->findOneByUsername($values["username"]); // If not, create an account for him if (empty($user)) { $datetime = date("Y-m-d H:i:s"); // Create entry in sfGuardUser $sfGuardUser = new sfGuardUser(); $sfGuardUser->setEmailAddress($values["username"]); $sfGuardUser->setUsername($values["username"]); $sfGuardUser->setFirstName($values["firstname"]); $sfGuardUser->setLastName($values["lastname"]); $sfGuardUser->setCreatedAt($datetime); $sfGuardUser->setUpdatedAt($datetime); $sfGuardUser->save(); // Additional informations for user's profile $sfGuardUserProfile = new sfGuardUserProfile(); $sfGuardUserProfile->setUserId($sfGuardUser->getId()); $sfGuardUserProfile->setToken(MiscUtils::generateToken()); $sfGuardUserProfile->setSecurityLevel(sfConfig::get("app_security_level_new_user", 0)); $sfGuardUserProfile->save(); $permission = Doctrine_Core::getTable("sfGuardPermission")->findOneByName(sfConfig::get("app_permission_new_user", "User")); if (!$permission) { $this->getUser()->setFlash("error", "Unable to set permissions for this account! Contact your administrator."); $sfGuardUserProfile->delete(); $sfGuardUser->delete(); return; } // Give basic permissions for user $sfGuardPermission = new sfGuardUserPermission(); $sfGuardPermission->setUserId($sfGuardUser->getId()); $sfGuardPermission->setPermissionId($permission->getId()); $sfGuardPermission->setCreatedAt($datetime); $sfGuardPermission->setUpdatedAt($datetime); $sfGuardPermission->save(); $userGroup = Doctrine_Core::getTable("sfGuardGroup")->findOneByName(sfConfig::get("app_project_group")); if (!$userGroup) { $this->getUser()->setFlash("error", "Unable to set project group for this account! Contact your administrator."); $sfGuardUserProfile->delete(); $sfGuardUser->delete(); $sfGuardPermission->delete(); return; } // Create new entry into sfGuardUserGroup table $sfGuardGroup = new sfGuardUserGroup(); $sfGuardGroup->setUserId($sfGuardUser->getId()); $sfGuardGroup->setGroupId($userGroup->getId()); $sfGuardGroup->setCreatedAt($datetime); $sfGuardGroup->setUpdatedAt($datetime); $sfGuardGroup->save(); $user = $sfGuardUser; } $this->getUser()->signIn($user, array_key_exists('remember', $values) ? $values['remember'] : false); // Set the tow previous referer to the same value for: // 1) redirect to previous user's location // 2) avoid redirect loop in signin $this->getUser()->setReferer($this->getUser()->getReferer()); // Redirect to referer return $this->redirect($this->getUser()->getReferer()); } }
function succeeded($myManager) { $args = json_decode(MiscUtils::decryptParam('a', '[]')); $orm = classToOrm('pz_operation'); $orm1 = classToOrm('pz_visitor'); if ($orm && $orm1) { try { if ($args->operation != NULL) { $orm->add($myManager, $args->operation); } if ($args->visitor) { $orm1->update($myManager, $args->visitor); } $myManager->commit_t(); $myManager->start_t(); echo json_encode(array()); } catch (PDOException $e) { echo $e->getMessage(); } } }
?> <?php foreach ($currentSession["measures"] as $measure) { ?> <?php $featureKey = MiscUtils::slugify($measure["label"]); ?> <?php if ($featureKey != $previousFeatureKey) { ?> </tbody> <tbody> <tr id="<?php echo MiscUtils::slugify($measure["label"]); ?> " class="feature_name"> <?php $feature = $currentSession["features"]->getRaw($featureKey); $totalPassed = $feature["pass"]; ?> <td colspan="8"> <?php echo $measure["label"]; ?> <a class="see_all_toggle" href="#">+ see <?php echo $totalPassed; ?> passing tests</a> </td>
/** * @param sfWebRequest $request */ public function executeUpdateImage(sfWebRequest $request) { $this->image = Doctrine_Core::getTable("Image")->find($request->getParameter("id")); // Initialize form $this->form = new ImportImageForm($this->image); // Process form if ($request->isMethod("post")) { $this->form->bind($request->getParameter($this->form->getName()), $request->getFiles($this->form->getName())); if ($this->form->isValid()) { $values = $this->form->getValues(); // Check if an image with the same values does not already exist $image = Doctrine_Core::getTable("Image")->findByArray($values); // If not, just update the existing image if ($image == null) { $image = Doctrine_Core::getTable("Image")->find($values["id"]); $image->setName($values["name"]); $image->setDescription($values["description"]); $image->setOs($values["os"]); $image->setDistribution($values["distribution"]); $image->setVersion($values["version"]); $image->setKernel($values["kernel"]); $image->setArchitecture($values["architecture"]); $image->setOtherFw($values["other_fw"]); $image->setBinaryLink($values["binary_link"]); $image->setSourceLink($values["source_link"]); // Check if its slug does not already exist and generate a new one if needed $slug = MiscUtils::slugify($values["name"]); $size = 1; while (Doctrine_Core::getTable("Image")->checkSlug($slug)) { $slug = MiscUtils::slugify($values["name"]) . substr(microtime(), -$size); $size++; } $image->setNameSlug(MiscUtils::slugify($slug)); $image->save(); } else { Doctrine_Query::create()->update("Configuration")->set("image_id", $image["id"])->where("image_id = ?", $values["id"])->execute(); } } } }
<?php require_once dirname(__FILE__) . '/common/common.inc.php'; require_once dirname(__FILE__) . "/database/{$database}/database.inc.php"; header('Content-Type: text/plain'); $class = MiscUtils::decryptParam('name', NULL); $objectsToAddOrUpdate = json_decode(MiscUtils::decryptParam('o', NULL)); $objectsToRemove = json_decode(MiscUtils::decryptParam('r', NULL)); $orm = classToOrm($class); if ($orm) { try { $myManager->start_t(); foreach ($objectsToAddOrUpdate as &$object) { if (isset($object->id)) { $orm->update($myManager, $object); } else { $orm->add($myManager, $object); } } foreach ($objectsToRemove as &$object) { $orm->remove($myManager, $object); } $myManager->commit_t(); echo MiscUtils::encode(array()); } catch (PDOException $e) { echo MiscUtils::encode($e->getMessage()); } }
?> </th> </tr> </thead> <?php $previousFeatureKey = ""; ?> <?php $line = 0; ?> <?php foreach ($currentSession["results"] as $resultKey => $result) { ?> <?php $featureKey = MiscUtils::slugify($result["label"]); ?> <?php if ($featureKey != $previousFeatureKey) { ?> <?php $line = 0; ?> </tbody> <tbody id="<?php echo $featureKey; ?> "> <tr id="feature-<?php
?> ');delete_result('<?php echo url_for('delete_result', array("id" => $result["id"])); ?> ')" title="Remove">Remove</a> <?php echo $result["name"]; ?> </td> <td class="testcase_name"><?php echo $result["complement"]; ?> </td> <td class="testcase_result <?php echo Labeler::decisionToText($result["decision_criteria_id"]); ?> "> <span class="content"><?php echo ucfirst(str_replace("_", " ", Labeler::decisionToText($result["decision_criteria_id"]))); ?> </span> </td> <td class="testcase_bugs"><div class="content"><?php echo MiscUtils::formatWikimarkups($result["bugs"]); ?> </div></td> <td class="testcase_notes"><div class="content"><?php echo nl2br(MiscUtils::formatWikimarkups($result["comment"])); ?> </div></td>