public function actionLoad() { Payments::model()->deleteAll(); Trucks::model()->deleteAll(); ZReport::model()->deleteAll(); $this->render("load"); }
public function run($args) { $this->connection = new TwitterOAuth(Yii::app()->params['trucks']['twitter']['consumerKey'], Yii::app()->params['trucks']['twitter']['consumerSecret'], Yii::app()->params['trucks']['twitter']['oauthAccessToken'], Yii::app()->params['trucks']['twitter']['oauthAccessTokenSecret']); $mentions = $this->connection->get('statuses/mentions'); $num_mentions = count($mentions); for ($i = $num_mentions - 1; $i >= 0; $i--) { $mention = $mentions[$i]; $truck = Trucks::model()->findByAttributes(array('twitter_id' => $mention->user->id_str)); if (NULL === $truck) { $message = 'SKIPPED: Tweet (id=' . $mention->id_str . ') is from an unauthorized Tweeter (@' . $mention->user->screen_name . ").\n"; Yii::log($message, 'info', get_called_class()); echo $message; continue; } elseif (TwitterHelper::isGeoLocatable($mention)) { if (TwitterHelper::isValidFormat($mention)) { Yii::log("Tweet is valid. Checking for db insertion", 'info', get_called_class()); $truck_tweet = TrucksTweets::model()->findByAttributes(array('tweet_id' => $mention->id_str)); if (NULL === $truck_tweet) { $parsed_tweet = TwitterHelper::parseTruckTweet($mention->text); $truck_tweet = new TrucksTweets(); $truck_tweet->truck_id = $truck->id; $truck_tweet->tweet = $mention->text; $truck_tweet->tweet_id = $mention->id_str; $truck_tweet->menu_url = $parsed_tweet['menu_url']; $truck_tweet->start_time = TwitterHelper::convertTruckTime($mention->created_at, $parsed_tweet['start']); $truck_tweet->end_time = TwitterHelper::convertTruckTime($mention->created_at, $parsed_tweet['end']); $truck_tweet->geo_lat = $mention->coordinates->coordinates[1]; $truck_tweet->geo_long = $mention->coordinates->coordinates[0]; $truck_tweet->save(); $message = 'INSERTED: Tweet (text=' . $mention->text . ') from @' . $mention->user->screen_name . " successfully saved.\n"; Yii::log($message, 'info', get_called_class()); echo $message; } else { $message = 'SKIPPED: Tweet (id=' . $mention->id_str . ") already exists.\n"; Yii::log($message, 'info', get_called_class()); // Eating this output to save on cron tasks // echo $message; continue; } } else { $message = 'SKIPPED: Tweet (text=' . $mention->text . ") is an invalid format.\n"; Yii::log($message, 'info', get_called_class()); echo $message; continue; } } else { $message = 'SKIPPED: Tweet (text=' . $mention->text . ') from ' . $mention->user->screen_name . " is not geo-locatable.\n"; Yii::log($message, 'info', get_called_class()); echo $message; continue; } } }
public function actionList() { $criteria = new CDbCriteria(); $criteria->order = "id desc"; if ($_GET["search"] == 1) { $plates = explode(",", $_POST["plate"]); foreach ($plates as $plate) { $criteria->addSearchCondition("plate", trim(MYChtml::check_num($plate)), true, "OR"); } } $count = Trucks::model()->count($criteria); $pages = new CPagination($count); // results per page $pages->pageSize = 30; $pages->applyLimit($criteria); $trucks = Trucks::model()->findAll($criteria); $this->render("list", array("trucks" => $trucks, 'pages' => $pages)); }
public static function addBalanceFee($amountAddFee, $plate, $date = false) { $payment = new Payments(); $payment->plate = $plate; $payment->amount_fee_license = $amountAddFee; $payment->amount_installation = 0; if ($date) { $payment->date = $date; } else { $payment->date = new CDbExpression('NOW()'); } if ($payment->save()) { $truck = Trucks::model()->find("plate=:plate", array(":plate" => $plate)); if ($truck) { $truck->balance_license_fee += $amountAddFee; $truck->save(); } return true; } else { return false; } }
public static function checkPlate($plate) { $plate = MYChtml::check_num($plate); return Trucks::model()->find("plate=:plate", array(":plate" => $plate)); }
public function actionGetPayments($id) { $truck = Trucks::model()->findByPK($id); echo CJSON::encode($truck->payments); }
/** * Find a single truck based on their primary key! */ public static function get_truck_by_id($id) { $id = (int) $id; $truck = Trucks::model()->with('trucksTweets:coords')->find(array('condition' => 't.id=:id', 'params' => array(':id' => $id))); $ret = array(); if ($truck !== NULL) { $ret[] = Trucks::obj_to_array($truck); } return $ret; }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Trucks::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }