public static function setUpBeforeClass() { self::$CI =& get_instance(); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); self::$CI->load->model('call_task_model'); // Some data! $fixture = array(array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000000", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000001", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000002", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::INVALID_NUMBER, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000003", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::SUCCESSFUL, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000004", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_CONSENT, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000005", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NUMBER_CHANGE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000006", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::DISCARD, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000007", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000008", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "1000000000009", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "9999999999001", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::SUCCESSFUL, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date())))); // Assigned and Not Started. for ($r = 0; $r < 10; $r++) { $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $r + 100), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 1, 'activity' => array()); } // Unassigned. for ($r = 0; $r < 10; $r++) { $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $r + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => NULL, 'author' => 1, 'assignee_uid' => NULL, 'survey_sid' => 1, 'activity' => array()); } self::$CI->mongo_db->batchInsert(Call_task_model::COLLECTION, $fixture); // Add a few more to other users and surveys. $fixture = array(array('ctid' => increment_counter('call_task_ctid'), 'number' => "2000000000000", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 2, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "2000000000006", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 1, 'survey_sid' => 2, 'activity' => array(array('code' => Call_task_status::DISCARD, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()))), array('ctid' => increment_counter('call_task_ctid'), 'number' => "2000000000007", 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 2, 'survey_sid' => 1, 'activity' => array(array('code' => Call_task_status::NO_REPLY, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date()), array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 1, 'created' => Mongo_db::date())))); self::$CI->mongo_db->batchInsert(Call_task_model::COLLECTION, $fixture); // More call tasks. // These are used to test the clean reserved function and some call tasks // with the assigned date far in the past are needed $fixture = array(); for ($r = 0; $r < 4; $r++) { $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (3000000000000 + $r + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(time() - 86400 * 4), 'author' => 1, 'assignee_uid' => 4, 'survey_sid' => 4, 'activity' => array()); } // Not expired. $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (3000000000000 + $r + 1 + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(), 'author' => 1, 'assignee_uid' => 4, 'survey_sid' => 4, 'activity' => array()); // Old one but started. $fixture[] = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (3000000000000 + $r + 1 + 1000), 'created' => Mongo_db::date(), 'updated' => Mongo_db::date(), 'assigned' => Mongo_db::date(time() - 86400 * 4), 'author' => 1, 'assignee_uid' => 4, 'survey_sid' => 4, 'activity' => array(array('code' => Call_task_status::CANT_COMPLETE, 'message' => NULL, 'author' => 4, 'created' => Mongo_db::date()))); self::$CI->mongo_db->batchInsert(Call_task_model::COLLECTION, $fixture); }
/** * Saves a survey result to the database. * If the survey result is not saved yet, its srid will be added to the * survey_result_entity. * @param Survey_result_entity (by reference) * * @return boolean * Whether or not the save was successful. */ public function save(Survey_result_entity &$entity) { // To ensure date consistency. $date = Mongo_db::date(); // Set update date: $entity->updated = $date; if ($entity->author === NULL) { $entity->author = current_user()->uid; } $prepared_data = array(); foreach ($entity as $field_name => $field_value) { $prepared_data[$field_name] = $field_value; } if ($entity->is_new()) { // Add new properties. $entity->srid = increment_counter(self::COUNTER_COLLECTION); $entity->created = clone $date; // Add properties to prepared_data. $prepared_data['srid'] = $entity->srid; $prepared_data['created'] = $entity->created; $result = $this->mongo_db->insert(self::COLLECTION, $prepared_data); return $result !== FALSE ? TRUE : FALSE; } else { $result = $this->mongo_db->set($prepared_data)->where('srid', $entity->srid)->update(self::COLLECTION); return $result !== FALSE ? TRUE : FALSE; } }
public static function setUpBeforeClass() { self::$CI =& get_instance(); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); // Change Controller. self::$CI = new Survey(); self::$CI->mongo_db->switchDb('mongodb://*****:*****@localhost.dev', 'name' => 'Admin', 'username' => 'admin', 'password' => hash_password('admin'), 'roles' => array(ROLE_ADMINISTRATOR), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()))); }
public static function setUpBeforeClass() { self::$CI =& get_instance(); self::$CI->load->helper('password_hashing'); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); // Some data! $fixture = array(array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'Admin', 'username' => 'admin', 'password' => hash_password('admin'), 'roles' => array(ROLE_ADMINISTRATOR), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'test user', 'username' => 'test_user', 'password' => hash_password('test_user'), 'roles' => array(), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => 99, 'email' => '*****@*****.**', 'name' => 'multiple roles user', 'username' => 'multiple', 'password' => hash_password('multiple'), 'roles' => array(ROLE_ADMINISTRATOR, ROLE_CC_AGENT), 'author' => null, 'status' => User_entity::STATUS_ACTIVE, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'blocked user', 'username' => 'blocked', 'password' => hash_password('blocked'), 'roles' => array(), 'author' => null, 'status' => User_entity::STATUS_BLOCKED, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date()), array('uid' => increment_counter('user_uid'), 'email' => '*****@*****.**', 'name' => 'Deleted user', 'username' => 'deleted', 'password' => hash_password('deleted'), 'roles' => array(), 'author' => null, 'status' => User_entity::STATUS_DELETED, 'created' => Mongo_db::date(), 'updated' => Mongo_db::date())); self::$CI->mongo_db->batchInsert(User_model::COLLECTION, $fixture); // User model is autoloaded. // No need to load. }
public static function _fix_data() { $date = Mongo_db::date(); // We need to generate a large amount of varied data but we need // to ensure that is always the same. $surveys = array(1, 2, 3, 4, 5); $no_reply_x5 = array(1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0); // once every 17 $amount_no_reply = array(0, 0, 1, 0, 0, 1, 0, 2, 0, 0, 0, 2, 0, 3, 0, 0, 0, 1, 3, 0, 0, 0); $final_status = array(Call_task_status::SUCCESSFUL, Call_task_status::NO_CONSENT, Call_task_status::NUMBER_CHANGE, Call_task_status::DISCARD, Call_task_status::INVALID_NUMBER, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::DISCARD, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::NO_CONSENT, Call_task_status::SUCCESSFUL, Call_task_status::SUCCESSFUL, Call_task_status::NO_CONSENT, Call_task_status::SUCCESSFUL); // Clean db! self::$CI->mongo_db->dropDb('aw_datacollection_test'); ////////////////////////////////////////////////////////////// // Not assigned: for ($total_ct = 1; $total_ct <= 10000; $total_ct++) { $resp = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $total_ct), 'created' => $date, 'updated' => $date, 'assigned' => NULL, 'author' => 1, 'assignee_uid' => NULL, 'survey_sid' => get_next($surveys), 'activity' => array()); self::$CI->mongo_db->insert(Call_task_model::COLLECTION, $resp); } ////////////////////////////////////////////////////////////// // Assigned // 30000 per user (3 users) for ($assignee = 1; $assignee <= 3; $assignee++) { $status = array('message' => NULL, 'author' => $assignee, 'created' => $date); // Resolved 20000 for ($total_ct = 1; $total_ct <= 20000; $total_ct++) { $resp = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $assignee * 100000 + $total_ct), 'created' => $date, 'updated' => $date, 'assigned' => $date, 'author' => 1, 'assignee_uid' => $assignee, 'survey_sid' => get_next($surveys)); // Some no-reply. if (get_next($no_reply_x5)) { $status['code'] = Call_task_status::NO_REPLY; for ($i = 0; $i < Call_task_status::THRESHOLD_NO_REPLY; $i++) { $resp['activity'][] = $status; } } else { for ($i = 0; $i < get_next($amount_no_reply); $i++) { $status['code'] = Call_task_status::NO_REPLY; $resp['activity'][] = $status; } $status['code'] = get_next($final_status); $resp['activity'][] = $status; } self::$CI->mongo_db->insert(Call_task_model::COLLECTION, $resp); } // Unresolved 10000 for ($total_ct = 1; $total_ct <= 10000; $total_ct++) { $resp = array('ctid' => increment_counter('call_task_ctid'), 'number' => (string) (1000000000000 + $assignee * 1000000 + $total_ct), 'created' => $date, 'updated' => $date, 'assigned' => $date, 'author' => 1, 'assignee_uid' => $assignee, 'survey_sid' => get_next($surveys)); for ($i = 0; $i < get_next($amount_no_reply); $i++) { $status['code'] = Call_task_status::NO_REPLY; $resp['activity'][] = $status; } $status['code'] = Call_task_status::CANT_COMPLETE; $resp['activity'][] = $status; self::$CI->mongo_db->insert(Call_task_model::COLLECTION, $resp); } } // Add index: ctid. self::$CI->mongo_db->addIndex(Call_task_model::COLLECTION, array('ctid' => 1)); // Add index: survey_sid. self::$CI->mongo_db->addIndex(Call_task_model::COLLECTION, array('survey_sid' => 1)); }
<?php require_once '_config.php'; function increment_counter() { file_put_contents(COUNTER_FILENAME, (int) file_get_contents(COUNTER_FILENAME) + 1); } if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && strlen(trim($_POST['cue']))) { increment_counter(); $filename = !empty($_POST['filename']) ? pathinfo($_POST['filename'], PATHINFO_FILENAME) . '.cue' : 'untitled.cue'; // tell ugly IE that cach can be done header('Cache-Control: maxage=3600'); // and it's public header('Pragma: public'); header('Content-Type: application/octet-stream'); header('Content-Disposition: attachment; filename="' . $filename . '"'); header('Content-Length: ' . $_SERVER['content_length']); echo trim($_POST['cue']); // session_start(); // if (get_magic_quotes_gpc()) { // $_POST = array_map('stripslashes', $_POST); // } // $_SESSION['cue'] = $_POST['cue']; // $_SESSION['filename'] = $_POST['filename']; // $_SESSION['content_length'] = $_SERVER['CONTENT_LENGTH']; // // $meta_refresh = '<meta http-equiv="refresh" content="1; url=/cue.php" />'; increment_counter(); } else { require_once 'index.html'; }