public function insertRandomRow() { /* generate the field values */ /* first generate the random values, then add them to query */ $workTypeId = rand(1, WorkType::getRowsNumber()); $districtId = rand(1, District::getRowsNumber()); $jobSubCategoryId = rand(1, JobSubCategory::getRowsNumber()); $salaryLow = rand(20, 200) * 1000; $salaryRange = rand(5, 30) * 1000; $daysOffset = -60 + rand(1, 90); $startDate = strtotime(sprintf("%+d", $daysOffset) . " day"); $endDate = strtotime(sprintf("%+d", $daysOffset + 30) . " day"); /* Processing this information */ $workType = WorkType::getWorkTypeName(WorkType::getWorkType($workTypeId)); $district = District::getDistrict($districtId); $districtName = District::getDistrictName($district); $regionName = Region::getRegionName(Region::getRegion(District::getRegionId($district))); $jobSubCategory = JobSubCategory::getJobSubCategory($jobSubCategoryId); $jobSubCategoryName = JobSubCategory::getJobSubCategoryName($jobSubCategory); $jobCategoryId = JobSubCategory::getJobCategoryId($jobSubCategory); $jobCategoryName = JobCategory::getJobCategoryName(JobCategory::getJobCategory($jobCategoryId)); $salaryHigh = $salaryLow + $salaryRange; $jobTitle = "Job in {$regionName}"; $jobDescription = "{$jobSubCategoryName} " . strtolower($workType) . " job in {$districtName}, {$regionName}, in the domain of {$jobCategoryName}, salary from \${$salaryLow} to \${$salaryHigh}.\n"; $jobDescription .= "Posted on " . date("D, jS \\of F, Y", $startDate) . ", valid until " . date("D, jS \\of F, Y", $endDate); /* Now build the query with the values generated above */ /* job_id */ $values = "NULL"; //AUTO_INCREMENT field /* job_title */ $values .= ", '{$jobTitle}'"; /* job_description */ $values .= ", '{$jobDescription}'"; /* work_type_id */ $values .= ", '{$workTypeId}'"; /* district_id */ $values .= ", '{$districtId}'"; /* subcategory_id */ $values .= ", '{$jobSubCategoryId}'"; /* salary_low */ $values .= ", '{$salaryLow}'"; /* SalaryHihg */ $values .= ", '{$salaryHigh}'"; /* start_ad_date */ /* format: '2013-05-14 00:00:00' */ $values .= ", '" . date("Y-m-d 00:00:00", $startDate) . "'"; /* end_ad_date */ $values .= ", '" . date("Y-m-d 00:00:00", $endDate) . "'"; /* Build the query */ $query = Job::insertRowQuery($values); return $query; }
public static function getJobSubCategory($job) { /* job -> JobSubCategoryId => JobSubCategory row -> JobSubCategoryName */ /* -> is array access; => is query access */ return JobSubCategory::getJobSubCategoryName(JobSubCategory::getJobSubCategory(self::getJobSubCategoryId($job))); }
protected function jsJobSubCategoryUpdate() { $output = ""; /* create the jobCategory <-> jobSubCategory connection */ $output .= "var jobSubCategoryNames = new Array();\n"; $output .= "var jobSubCategoryIds = new Array();\n"; $output .= "jobSubCategoryNames[" . static::anyJobCategoryCode . "] = [\"Select job category first\"];\n"; $output .= "jobSubCategoryIds[" . static::anyJobCategoryCode . "] = [\"" . static::anyJobSubCategoryCode . "\"];\n"; $jobCategoryList = JobCategory::getAllRows(); $jobCategoryCount = 0; while (($jobCategory = $jobCategoryList->fetch_row()) != NULL) { $jobCategoryId = JobCategory::getJobCategoryId($jobCategory); $jobSubCategoryList = JobSubCategory::getJobSubCategoryList($jobCategoryId); /* first the jobSubCategory names */ $output .= "jobSubCategoryNames[{$jobCategoryId}] = [\"Any job sub category\""; while (($jobSubCategory = $jobSubCategoryList->fetch_row()) != NULL) { $output .= ", \"" . JobSubCategory::getJobSubCategoryName($jobSubCategory) . "\""; } $output .= "];\n"; /* then the jobSubCategory Ids */ $output .= "jobSubCategoryIds[{$jobCategoryId}] = [\"" . static::anyJobSubCategoryCode . "\""; $jobSubCategoryList->data_seek(0); while (($jobSubCategory = $jobSubCategoryList->fetch_row()) != NULL) { $output .= ", \"" . JobSubCategory::getJobSubCategoryId($jobSubCategory) . "\""; } $output .= "];\n"; } /* print the jobSubCategoryUpdate() function */ /* the below code is JavaScript */ $output .= "\n"; $output .= "jobSubCategoryList = document." . static::formName . "." . static::jobSubCategoryIdFieldName . ";\n"; $output .= "function jobSubCategoryUpdate(selectedJobCategoryId){\n"; $output .= " jobSubCategoryList.options.length = 0;\n"; $output .= " for (i=0; i < jobSubCategoryNames[selectedJobCategoryId].length; i++) {\n"; $output .= " jobSubCategoryList.options[jobSubCategoryList.options.length] = new Option(jobSubCategoryNames[selectedJobCategoryId][i],jobSubCategoryIds[selectedJobCategoryId][i]);\n"; $output .= " }\n"; $output .= "}\n"; return $output; }