Exemplo n.º 1
0
 public function redirectAction()
 {
     if (!($unit = Unit::find(intval($_GET['id'])))) {
         return $this->redirect('/');
     }
     $this->view->unit = $unit;
 }
Exemplo n.º 2
0
 public function showAction()
 {
     list(, , , $id) = explode('/', $this->getURI());
     $ret = new StdClass();
     if (!($unit = Unit::find(intval($id)))) {
         $ret->error = true;
         $ret->message = "Company not found";
         return $this->jsonp($ret, strval($_GET['callback']));
     }
     $ret->data = $unit->getData();
     return $this->jsonp($ret, strval($_GET['callback']));
 }
Exemplo n.º 3
0
 public function name($depth = 0)
 {
     $prefix = '';
     if (1 == $this->type) {
         // 公司
         $column_id = 2;
     } elseif (2 == $this->type) {
         // 商業登記
         $column_id = 33;
     } elseif (3 == $this->type) {
         // 分公司
         // 先取總公司
         $data = UnitData::search(array('id' => $this->id, 'column_id' => 50))->first();
         if (!$data) {
             return '';
         }
         $unit = Unit::find(json_decode($data->value));
         if (!$unit) {
             return '';
         }
         if ($depth) {
             return false;
         }
         $prefix = $unit->name($depth + 1);
         if (false === $prefix) {
             return '';
         }
         $column_id = 48;
     } else {
         $column_id = 43;
     }
     if ($data = UnitData::search(array('id' => $this->id, 'column_id' => $column_id))->first()) {
         // 公司名稱
         $v = json_decode($data->value);
         if (is_scalar($v)) {
             return $prefix . $v;
         } elseif (is_array($v)) {
             return $prefix . $v[0];
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Display the specified product.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $Unit = Unit::find($id);
     return Response::json($Unit);
 }
Exemplo n.º 5
0
<?php

include __DIR__ . '/../init.inc.php';
$fp = fopen(__DIR__ . '/../maps/rare-word.csv', 'r');
$words = array();
while ($rows = fgetcsv($fp)) {
    list($old, $new) = $rows;
    $words[$old] = $new;
    for ($i = 0; true; $i++) {
        $ret = SearchLib::searchCompaniesByName($old, $i + 1);
        foreach ($ret->hits->hits as $hit) {
            Unit::find($hit->_id)->updateSearch();
        }
        $total = $ret->hits->total;
        if ($i * 10 >= $total) {
            break;
        }
    }
}
fclose($fp);
Exemplo n.º 6
0
 public function deleteUnit($id)
 {
     if (Session::has('username') && Session::get('user_type') == "Root") {
         if (!is_numeric($id) || !Unit::find($id)) {
             return Redirect::to("settings/employees/units");
         }
         $unit = Unit::find($id);
         $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has deleted unit <strong>" . $unit->name . "</strong>.";
         //Log the changes made
         $newLog = new UserLog();
         $newLog->description = $desc;
         $newLog->user_id = Session::get('user_id');
         $newLog->type = "System";
         $newLog->save();
         $unit->delete();
         return Redirect::to("settings/employees/units");
     } else {
         return Redirect::to("/");
     }
 }
Exemplo n.º 7
0
 function getUnits()
 {
     $returned_units = $GLOBALS['DB']->query("SELECT * FROM units WHERE course_id = {$this->getId()};");
     $course_units = array();
     foreach ($returned_units as $unit) {
         $unit_id = $unit['id'];
         $found_unit = Unit::find($unit_id);
         array_push($course_units, $found_unit);
     }
     return $course_units;
 }
Exemplo n.º 8
0
 private function processImport($file)
 {
     if (Session::has('username') && (Session::get('user_type') == "Root" || Session::get('user_type') == "Admin")) {
         if (!in_array($file->getClientOriginalExtension(), array("xls", "xlsx", "csv"))) {
             Input::flash();
             return Redirect::to('employees/import')->with('message', "Invalid file selected.");
         } else {
             $filename = "upload-" . str_random(9) . "." . $file->getClientOriginalExtension();
             $file->move("uploads", $filename);
             $readFile = "uploads/" . $filename;
             $reader = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) {
             })->get();
             /*
              * 				Before validating each rows of the file uploaded, the file itself is checked if it has the valid attributes (columns)
              * 				using the algorithm found below.
              * 
              * 				1. File is read.
              * 				2. Boolean variable $excelIsValid to check if the file is valid. Set to false by default.
              * 	
              */
             $excelChecker = Excel::selectSheetsByIndex(0)->load($readFile, function ($reader) {
             })->get()->toArray();
             $excelIsValid = false;
             /*
              * 				3. Loop through the excel file and check if at least once all the columns have been present.
              * 				4. If it does, $excelIsValid is set to true.
              * 				5. If $excelIsValid is still false by end of the loop, it is automatically assumed that the file is:
              * 					A.) Empty
              * 					B.) Does not have the right attributes.
              * 					C.) Has valid columns, but does not have any valid entry.
              * 					
              */
             foreach ($excelChecker as $ex) {
                 if (isset($ex["employeenumber"]) && isset($ex["lastname"]) && isset($ex["firstname"]) && isset($ex["startdate"]) && isset($ex["status"])) {
                     $excelIsValid = true;
                 }
             }
             /*				6. If file is invalid, redirect to import form and return an error. */
             if (!$excelIsValid) {
                 Input::flash();
                 File::delete($readFile);
                 return Redirect::to('employees/import')->with('message', "Excel file has invalid attributes. Please download the form.");
             }
             /*				
              * 				CHECKING EXCEL FILE FOR ERRORS WHILE READING THE ROWS
              * 
              * 				1. $hasError is a Boolean variable that is simply used to tell if any error has been found.
              * 					This variable is, by default, set to false. If any error has been detected, it is set to true,
              * 					regardless of how many errors has been detected.
              * 
              * 				2. $rowIndex indexes which row the reader is currently reading. Default value set to 1 because
              * 					the first row of excel files is automatically set as the attribute row. When the reader reads each row,
              * 					$rowIndex is incremented. For example, reader is currently reading row 2, $rowIndex will then be incremented,
              * 					setting its value to 2, thus the row number.
              * 
              * 				3. $rowsWithErrors is the array of the rows with errors. To explain further, let's say excel file has 10 readable (non-attrib)
              * 					rows. No errors were found from rows number 2-8, but errors were found in rows 9, 10, and 11. These 9, 10, and 11
              * 					will then be in the $rowsWithError.
              * 
              * 				4. $error array is the variable that will be used to collect all errors found from the excel file.
              * 					This is a two-dimensional array.
              * 
              * 
              */
             $hasError = false;
             //Detects if there are any errors.
             $hasCorrectRows = false;
             $rowIndex = 1;
             //Indexes which row the reader is reading.
             $rowsWithErrors = array();
             //This is used to contain in an array the row numbers of the rows with error.
             $error = array();
             //Error details collector.
             foreach ($reader as $r) {
                 /*
                  * 				5. Here, we immediately increment the value of $rowIndex, since the variable will be used in the core logic of this method.
                  * 				
                  * 				6. $errorCount variable is a variable used in every loop. Set to 0 when the loop begins, so it always comes back to 0 for every loop.
                  * 					$errorCount is used to track the number of errors for the current row. This variable goes hand in hand with the
                  * 					$rowsWithError array when publishing the rows with errors, and the error details for each row with error.
                  * 
                  * 					This is how $rowsWithError and $rowCount will be used:
                  * 
                  * 					for each $rowWithErrors:
                  * 						Row $rowWithErrors Index:
                  * 							Errors Found :
                  * 							$rowCount 1. Foo bar
                  * 							$rowCount 2. Jane Doe etc..
                  * 
                  * 
                  */
                 $rowIndex += 1;
                 $errorCount = 0;
                 //Counts the number of errors for the currect row.
                 $rowHasError = false;
                 //Check if this row has error. I will use this before the reading of the row ends.
                 //					If $rowHasError is still false by end of the reading, then I will write it in the database.
                 /*
                  * 
                  */
                 $start_date = !empty(trim($r->startdate)) ? trim($r->startdate) : "1994-04-16";
                 $validator = Validator::make(array("employee number" => trim($r->employeenumber), "last name" => trim($r->lastname), "first name" => trim($r->firstname), "username" => trim($r->username), "start date" => trim($r->startdate), "end date" => trim($r->enddate), "email" => trim($r->email), "status" => trim($r->status)), array("employee number" => "required|numeric|unique:tbl_employees,employee_number", "last name" => "required", "first name" => "required", "username" => "unique:tbl_employees,username", "start date" => "required|date:Y-m-d", "end date" => "date:Y-m-d|after:" . $start_date, "email" => "unique:tbl_employees,email", "status" => "required"), array("after" => "The :attribute must be after the employee start date."));
                 if ($validator->fails()) {
                     /* 					7. When error has been found, $rowsWithError is immediately updated. Also, $hasError and $rowHasError are set to true.*/
                     $hasError = true;
                     $rowHasError = true;
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     /* 					8. Then I will check which fields has error.
                      * 
                     *					9. If an error has been found in a certain field,
                     *					   I will loop through the errors found on that field, increment the $errorCount (which, again, tracks
                     *					   how many errors has been found on a certain row.), update the two-dimensional $error array. 
                     *					   Please note that the first array of $error contains the row number which the errors found belong to.
                     *
                     */
                     if ($validator->messages()->get("employee number")) {
                         foreach ($validator->messages()->get("employee number") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("last name")) {
                         foreach ($validator->messages()->get("last name") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("first name")) {
                         foreach ($validator->messages()->get("first name") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("username")) {
                         foreach ($validator->messages()->get("username") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("start date")) {
                         foreach ($validator->messages()->get("start date") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("end date")) {
                         foreach ($validator->messages()->get("end date") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("email")) {
                         foreach ($validator->messages()->get("email") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                     if ($validator->messages()->get("status")) {
                         foreach ($validator->messages()->get("status") as $e) {
                             $errorCount += 1;
                             $error[$rowIndex][$errorCount] = $errorCount . ". " . $e . "<br/>";
                         }
                     }
                 }
                 if (!preg_match('/^[\\pL.-\\s]+$/u', $r->firstname) || !preg_match('/^[\\pL.-\\s]+$/u', $r->lastname)) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "First name/last name fields must only contain alphabetic characters and whitespaces." . "<br/>";
                 }
                 if (!is_numeric($r->manager)) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Manager ID should be numeric." . "<br/>";
                 }
                 if (is_numeric($r->manager) && !Manager::find($r->manager)) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Invalid manager ID." . "<br/>";
                 }
                 if (empty(trim($r->nsnid)) && !in_array(strtolower($r->status), array("academy", "ojt", "contractual", "graduate", "obsolete"))) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "The NSN ID is required." . "<br/>";
                 }
                 if (!empty($r->nsnid) && !is_numeric(trim($r->nsnid)) && !in_array($r->status, array("academy", "ojt", "contractual", "graduate", "obsolete"))) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "The NSN ID should be numeric." . "<br/>";
                 }
                 if (!empty($r->nsnid) && Employee::where("nsn_id", "=", $r->nsnid)->first()) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "NSN ID already exists." . "<br/>";
                 }
                 if (!empty($r->email) && !filter_var(trim($r->email), FILTER_VALIDATE_EMAIL)) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Invalid e-mail address." . "<br/>";
                 }
                 if (is_numeric($r->businessline) && !BusinessLine::find($r->businessline)) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Invalid Business Line ID." . "<br/>";
                 }
                 if (is_numeric($r->unit) && !Unit::find($r->unit)) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Invalid Unit ID." . "<br/>";
                 }
                 if (is_numeric($r->unit) && is_numeric($r->businessline) && (Unit::find($r->unit) && !Unit::where("id", "=", $r->unit)->where("businessline_id", "=", $r->businessline)->first())) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Selected Unit ID does not belong to the selected Business Line ID." . "<br/>";
                 }
                 if (!in_array(strtolower($r->status), array("ojt", "contractual", "nsn guest", "academy", "graduate", "on-board", "resigned", "obsolete"))) {
                     $hasError = true;
                     //This will only matter if no errors has been found above.
                     $rowHasError = true;
                     //This will only matter if no errors has been found above.
                     $rowsWithErrors[$rowIndex] = $rowIndex;
                     //This will only matter if no errors has been found above.
                     $errorCount += 1;
                     $error[$rowIndex][$errorCount] = $errorCount . ". " . "Invalid employee status." . "<br/>";
                 }
                 if (!$rowHasError) {
                     $hasCorrectRows = true;
                     $desc = "(" . Session::get('user_type') . ") " . "<strong>" . Session::get('username') . "</strong> has added employee <strong>" . trim($r->firstname) . " " . trim($r->lastname) . "</strong>, employee number <strong>" . trim($r->employeenumber) . "</strong>, with status <strong>" . trim($r->status) . "</strong>.";
                     $employee = new Employee();
                     $employee->employee_number = $r->employeenumber;
                     $employee->last_name = trim($r->lastname);
                     $employee->first_name = trim($r->firstname);
                     $employee->username = trim($r->username) != null ? trim($r->username) : null;
                     $employee->nickname = trim($r->nickname) != null ? trim($r->nickname) : null;
                     $employee->manager_id = $r->manager != null ? $r->manager : null;
                     $employee->start_date = $r->startdate;
                     $employee->end_date = $r->enddate != null ? $r->enddate : null;
                     $employee->nsn_id = $r->nsnid != null ? $r->nsnid : null;
                     $employee->email = trim($r->email) != null ? trim($r->email) : null;
                     $employee->business_line_id = $r->businessline != null ? $r->businessline : null;
                     $employee->unit_id = $r->unit != null ? $r->unit : null;
                     $employee->subunit = trim($r->subunit) != null ? trim($r->subunit) : null;
                     $employee->cellphone_number = trim($r->cellphonenumber) != null ? trim($r->cellphonenumber) : null;
                     $employee->status = trim($r->status);
                     $employee->save();
                     //Log the changes made
                     $newLog = new UserLog();
                     $newLog->description = $desc;
                     $newLog->user_id = Session::get('user_id');
                     $newLog->type = "Employees";
                     $newLog->save();
                 }
             }
             File::delete($readFile);
             if ($hasCorrectRows) {
                 //Log the changes made
                 $desc = "(" . Session::get("user_type") . ") <b>" . Session::get("username") . "</b> has imported data to the employees database. ";
                 $newLog = new UserLog();
                 $newLog->description = $desc;
                 $newLog->user_id = Session::get('user_id');
                 $newLog->type = "Employees";
                 $newLog->save();
             }
             return $this->importResult($hasError, $hasCorrectRows, $rowsWithErrors, $error);
         }
     } else {
         return Redirect::to('/');
     }
 }
Exemplo n.º 9
0
 public static function GetByName($unitName)
 {
     return Unit::find(array('name' => $unitName));
 }
Exemplo n.º 10
0
 /**
  * Show the form for editing the specified unit.
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $unit = Unit::find($id);
     return View::make('units.edit', ['unit' => $unit])->withTitle("Ubah {$unit->nama}");
 }
Exemplo n.º 11
0
    $course_id = $unit->getCourseId();
    $course = Course::find($course_id);
    $user_id = $course->getUserId();
    return $app['twig']->render("edit_lesson.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'course' => $course, 'user' => User::find($user_id)));
});
$app->patch("/show_lesson_edit/edit_lesson/{id}", function ($id) use($app) {
    $lesson = Lesson::find($id);
    $new_title = $_POST['new_title'];
    $new_objective = $_POST['new_objective'];
    $new_materials = $_POST['new_materials'];
    $new_body = $_POST['new_body'];
    $lesson->updateLesson($new_title, $new_objective, $new_materials, $new_body);
    $unit_id = $lesson->getUnitId();
    $unit = Unit::find($unit_id);
    $course_id = $unit->getCourseId();
    $course = Course::find($course_id);
    $user_id = $course->getUserId();
    return $app['twig']->render("lesson.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'course' => $course, 'user' => User::find($user_id)));
});
//Delete a lesson
$app->get("/delete_lesson/{unit_id}/{lesson_id}", function ($unit_id, $lesson_id) use($app) {
    $lesson = Lesson::find($lesson_id);
    $unit_id = $lesson->getUnitId();
    $unit = Unit::find($unit_id);
    $course_id = $unit->getCourseId();
    $course = Course::find($course_id);
    $user_id = $course->getUserId();
    $lesson->delete();
    return $app['twig']->render("unit.html.twig", array('lesson' => $lesson, 'unit' => $unit, 'lessons' => $unit->getLessons(), 'course' => $course, 'user' => User::find($user_id)));
});
return $app;
Exemplo n.º 12
0
 public function update($id, $options = array())
 {
     $unit = Unit::find($id);
     if (!$unit) {
         // 找不到檔案就不用判斷了
     } else {
         $modified_at = $unit->updated_at;
         if (array_key_exists('month', $options)) {
             $query_time = strtotime('+1 month', mktime(0, 0, 0, $options['month'], 1, $options['year']));
             if ($query_time < $modified_at) {
                 return;
             }
         }
     }
     $url = 'http://gcis.nat.gov.tw/pub/cmpy/cmpyInfoAction.do?method=detail&banNo=' . $id;
     // 一秒只更新一個檔案
     while (!is_null(self::$_last_fetch) and microtime(true) - self::$_last_fetch < 0.5) {
         usleep(1000);
     }
     self::$_last_fetch = microtime(true);
     $content = self::http($url);
     if (!$content) {
         trigger_error("找不到網頁內容: {$url}", E_USER_WARNING);
         return;
     }
     $info = self::parseFile($content);
     if (!($parsed_id = $info->{'統一編號'})) {
         trigger_error("找不到統一編號: {$id}", E_USER_WARNING);
         return;
         throw new Exception('統一編號 not found?');
     }
     unset($info->{'統一編號'});
     if (!($unit = Unit::find($id))) {
         $unit = Unit::insert(array('id' => $id, 'type' => 1));
     } else {
         $unit->update(array('type' => 1));
     }
     $unit->updateData($info);
     foreach (self::searchBranch($unit->id()) as $id) {
         // 跳過 branch 等同自己的
         if ($id == $unit->id()) {
             continue;
         }
         self::updateBranch($id);
     }
     return $unit;
 }
Exemplo n.º 13
0
 function testFind()
 {
     $name = "John Doe";
     $password = "******";
     $email = "*****@*****.**";
     $signed_in = 0;
     $test_user = new User($name, $password, $email, $signed_in);
     $test_user->save();
     $course_title = "Literature";
     $subject = "English";
     $course_description = "Deconstructing English literature.";
     $user_id = $test_user->getId();
     $test_course = new Course($course_title, $subject, $course_description, $user_id);
     $test_course->save();
     $unit_title = "Into the Wild";
     $unit_description = "The life and death of Chris McCandless.";
     $course_id = $test_course->getId();
     $test_unit = new Unit($unit_title, $unit_description, $course_id);
     $test_unit->save();
     $unit_title2 = "The Catcher in the Rye";
     $unit_description2 = "Foul-mouthed kid is angsty.";
     $test_unit2 = new Unit($unit_title2, $unit_description2, $course_id);
     $test_unit2->save();
     $result = Unit::find($test_unit->getId());
     $this->assertEquals($test_unit, $result);
 }
Exemplo n.º 14
0
 /**
  * Show the form for editing the specified resource.
  * GET /units/{id}/edit
  *
  * @param  int  $id
  * @return Response
  */
 public function edit($id)
 {
     $unit = Unit::find($id);
     return View::make('admin.units.edit', compact('unit'));
 }
Exemplo n.º 15
0
    }
    if (!$id_table) {
        die('找不到統一編號');
    }
    $is_empty = true;
    foreach ($id_table->getElementsByTagName('tr') as $tr_dom) {
        if (!in_array($tr_dom->getAttribute('class'), array('td_style01', 'td_style02'))) {
            continue;
        }
        $is_empty = false;
        $td_doms = $tr_dom->getElementsByTagName('td');
        $obj = new StdClass();
        $obj->{'類別'} = $td_doms->item(1)->nodeValue;
        $id = $td_doms->item(2)->nodeValue;
        $obj->{'名稱'} = $td_doms->item(3)->nodeValue;
        $obj->{'來源'} = 'http://140.111.34.54/GENERAL/index.aspx';
        if ($unit = Unit::find($id)) {
            if ($unit->type != 99 and $unit->type != 4) {
                var_dump($unit->toArray());
                die;
            }
            $unit->update(array('type' => 4));
        } else {
            $unit = Unit::insert(array('id' => $id, 'type' => 4, 'updated_at' => time()));
        }
        $unit->updateData($obj);
    }
    if ($is_empty) {
        break;
    }
}
Exemplo n.º 16
0
<?php

include __DIR__ . '/../init.inc.php';
Pix_Table::$_save_memory = true;
$ids = Updater::searchByKeyword($_SERVER['argv'][1]);
foreach ($ids as $id) {
    if (Unit::find($id)) {
        continue;
    }
    Updater::update($id);
    Unit::find($id)->updateSearch();
}
$ids = Updater::searchBussinessByKeyword($_SERVER['argv'][1]);
foreach ($ids as $id) {
    if (Unit::find($id)) {
        continue;
    }
    if ($u = Updater::updateBussiness($id)) {
        $u->updateSearch();
    }
}