Пример #1
0
 public function validate_checkIfRecordIdExists($field, $input, $param = null)
 {
     if (!isset($input[$field]) || empty($input[$field])) {
         return;
     }
     $model = new Model_Record();
     $results = $model->getByQuery('id = ?', $input[$field]);
     if (count($results) == 0) {
         return array('field' => $field, 'value' => $input[$field], 'rule' => __FUNCTION__, 'param' => $param);
     }
 }
Пример #2
0
 public static function createFromArray($data)
 {
     $Record = new \Model_Record();
     $Record->object_id = $data['object_id'];
     $Record->property = $data['property'];
     $Record->datatype = $data['datatype'];
     $Record->value = $data['value'];
     $Record->save();
     $Record->created_at = $data['created_at'];
     $Record->save();
     return $Record;
 }
Пример #3
0
 public function deleteAction()
 {
     $params = Request::getParams();
     $validator = new Validator();
     $params = $validator->sanitize($params);
     $validator->validation_rules(array("id" => "required|numeric|checkIfRecordIdExists"));
     $validated_data = $validator->run($params);
     if ($validated_data === false) {
         Response::setStatus(404);
         $returnArray = array("error" => "Invalid data was sent", "messages" => $validator->get_readable_errors());
     } else {
         $model = new Model_Record();
         $model->delete($params['id']);
         Response::setStatus(204);
         $returnArray = array();
     }
     return $returnArray;
 }
Пример #4
0
 public function fetchAll()
 {
     $rows = parent::fetchAll();
     $models = array();
     foreach ($rows as $row) {
         $model = $this->_getContainer()->Tag()->setData($row);
         $models[] = $model;
     }
     return $models;
 }
Пример #5
0
 /**
  * 
  * Building tree
  */
 public function action_index()
 {
     if ($_POST) {
         $val = \Validation::forge();
         $val->add_field('id', 'node id', 'required|min_length[1]|max_length[20]');
         $val->add_field('rel', 'node type', 'required|min_length[1]|max_length[20]');
         if ($val->run()) {
             switch ($this->gettype($val->validated('rel'))) {
                 //room
                 case 0:
                     $data['groups'] = Model_Group::find()->where('meta_update_user', $this->user)->get();
                     return \Response::forge(\View::forge('tree/group', $data));
                     break;
                     //group
                 //group
                 case 1:
                     $tests = Model_Test::find()->where('group_id', $val->validated('id'))->get();
                     $data['tests'] = $tests;
                     return \Response::forge(\View::forge('tree/test', $data));
                     break;
                     //test
                 //test
                 case 2:
                     $records = Model_Record::find()->where('test_id', $val->validated('id'))->get();
                     $data['records'] = $records;
                     return \Response::forge(\View::forge('tree/record', $data));
                     break;
                     //record
                 //record
                 case 3:
                     echo '{:P}';
                     break;
             }
             //echo $val->validated('id');
         }
     }
 }
Пример #6
0
 public static function saveInteractionStats($system_interaction_id, $interaction, $Model_Interaction_Meta_Instagram = false, $extended = false)
 {
     // reset latest setting
     $query = \DB::update('tracking_log');
     $query->where('object_id', $system_interaction_id);
     $query->where('source', 'instagram');
     $query->value('is_latest', 0);
     $query->execute();
     $stats = array('photos' => 1, 'comment' => $interaction->comments->count, 'like' => $interaction->likes->count);
     if ($extended) {
         // $stats['xxx'] = $interaction->xxx;
     }
     // $VenueRecord = self::getOrCreateVenueRecord($system_interaction_id);
     foreach ($stats as $property => $value) {
         $time_key = date('Y_m_d_H');
         /*
         $record_hash = implode('_', array(
         	'ig',
         	$interaction->id,
         	$property,
         	$time_key
         ));
         */
         try {
             $Record = new \Model_Record();
             // $Record->record_hash = $record_hash;
             $Record->object_id = $system_interaction_id;
             $Record->property = $property;
             $Record->value = $value;
             $Record->datatype = 'absolute';
             $Record->save();
             // $VenueRecord->$property = $value;
         } catch (\Database_Exception $err) {
             // catch error. normally there shouldn't be an error, but in the development phase it's possible to have incomplete data, so errors could occur at this place.
             echo $err;
             exit;
             return $err;
         }
     }
     // $VenueRecord->save();
     // keep track of tracking...
     $Log = new \Model_Tracking_Log();
     $Log->object_id = $system_interaction_id;
     $Log->success = 1;
     $Log->is_latest = 1;
     $Log->source = 'instagram';
     $Log->save();
     if ($Model_Interaction_Meta_Instagram) {
         $Model_Interaction_Meta_Instagram->comments = $interaction->comments->count;
         $Model_Interaction_Meta_Instagram->link = $interaction->link;
         $Model_Interaction_Meta_Instagram->likes = $interaction->likes->count;
         $Model_Interaction_Meta_Instagram->save();
     }
     return $stats;
 }
Пример #7
0
 public static function saveVenueStats($system_venue_id, $venue, $extended = false)
 {
     // reset latest setting
     $query = \DB::update('tracking_log');
     $query->where('object_id', $system_venue_id);
     $query->where('source', 'foursquare');
     $query->value('is_latest', 0);
     $query->execute();
     $stats = array('checkin' => $venue->stats->checkinsCount, 'checkin-unique' => $venue->stats->usersCount, 'review' => $venue->stats->tipCount, 'like' => $venue->likes->count, 'herenow' => isset($venue->herenow) ? $venue->herenow : 0);
     if ($extended) {
         $stats['rating'] = isset($venue->rating) ? $venue->rating * 100 : 0;
         $stats['price'] = isset($venue->price->tier) ? $venue->price->tier : 0;
         $stats['photos'] = $venue->photos->count;
         $stats['specials'] = $venue->specials->count;
         // $stats['herenow'] = $venue->hereNow->count;
         $stats['mayor'] = $venue->mayor->count;
     }
     $VenueRecord = self::getOrCreateVenueRecord($system_venue_id);
     foreach ($stats as $property => $value) {
         $time_key = date('Y_m_d_H');
         /*
         $record_hash = implode('_', array(
         	'4q',
         	$venue->id,
         	$property,
         	$time_key
         ));
         */
         try {
             $Record = new \Model_Record();
             // $Record->record_hash = $record_hash;
             $Record->object_id = $system_venue_id;
             $Record->property = $property;
             $Record->value = $value;
             $Record->datatype = 'absolute';
             $Record->save();
             $VenueRecord->{$property} = $value;
         } catch (\Database_Exception $err) {
             // catch error. normally there shouldn't be an error, but in the development phase it's possible to have incomplete data, so errors could occur at this place.
             return $err;
         }
     }
     $VenueRecord->save();
     // keep track of tracking...
     $Log = new \Model_Tracking_Log();
     $Log->object_id = $system_venue_id;
     $Log->success = 1;
     $Log->is_latest = 1;
     $Log->source = 'foursquare';
     $Log->save();
     return $stats;
 }
Пример #8
0
 public function post_price()
 {
     $system_venue_id = \Input::post('venue_id');
     $price = intval(\Input::post('price'));
     if (!$price || !$system_venue_id) {
         return $this->sendAPIResponse(null, 400, 'Please provide a value both for venue_id and price!');
     }
     $Venue = \Model_Venue::find($system_venue_id);
     if (!$Venue) {
         return $this->sendAPIResponse(null, 400, 'Unkown venue / invalid venue_id!');
     }
     try {
         $Record = new \Model_Record();
         // $Record->record_hash = $record_hash;
         $Record->object_id = $system_venue_id;
         $Record->property = 'price';
         $Record->value = $price;
         $Record->datatype = 'absolute';
         $Record->save();
         if (\Collection\Venue::calculateVenuePriceScore($system_venue_id)) {
             return $this->sendAPIResponse(array('success' => true));
         }
         return $this->sendAPIResponse(null, 400, 'Unkown error');
     } catch (\Database_Exception $err) {
         // catch error. normally there shouldn't be an error, but in the development phase it's possible to have incomplete data, so errors could occur at this place.
         return $this->sendAPIResponse(null, 400, $err);
     }
 }
Пример #9
0
 public function calculateDeltas()
 {
     $query = \DB::select_array();
     $query->from('record');
     $query->where('datatype', 'absolute');
     $query->where('property', 'NOT IN', array('herenow', 'rating'));
     $query->order_by('object_id');
     $query->order_by('property');
     $query->order_by('created_at', 'asc');
     // $query->limit(50);
     $Results = $query->execute();
     $last_value = -1;
     $object_id = -1;
     $data = array();
     foreach ($Results->as_array() as $key => $row) {
         if (!$row['object_id'] || !$row['property']) {
             continue;
         }
         if ($object_id != $row['object_id']) {
             $data = array();
             $property = $row['property'];
             $object_id = $row['object_id'];
             $last_value = -1;
             $this->cliOutput('write', 'object_id: ' . $row['object_id']);
         }
         if ($property != $row['property']) {
             $property = $row['property'];
             $last_value = -1;
         }
         if ($last_value != -1) {
             $Record = new \Model_Record();
             // $Record->record_hash = $row['record_hash'].'r';
             $Record->object_id = $row['object_id'];
             $Record->property = $property;
             $Record->value = $row['value'] - $last_value;
             $Record->datatype = 'relative';
             $Record->save();
             $Record->created_at = $row['created_at'];
             $Record->save();
         }
         $last_value = $row['value'];
     }
 }