Exemplo n.º 1
0
 /**
  * Returns a Record for a specific reference.
  * A DataSource can directly return the DataHash, so it doesn't have to be fetched.
  *
  * @param Record $record
  * @param string $attributeName The attribute it's being accessed on
  * @return Record
  */
 public function getReferenced($record, $attributeName)
 {
     if ($data = $record->getDirectly($attributeName)) {
         if (is_array($data)) {
             // If the data hash exists already, just return the Record with it.
             return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getRecordFromData($data));
         } elseif (is_int($data)) {
             // If data is an integer, it must be the id. So just get the record set with the data.
             return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->getRecordFromData(array('id' => (int) $data), true, false, false));
         } elseif ($data instanceof Record) {
             // The record is cached. Just return it.
             return $data;
         } else {
             Log::warning(sprintf('The data hash for `%s` was set but incorrect.', $attributeName));
             return null;
         }
     } else {
         // Otherwise: get the data hash and return the Record.
         $localKey = $this->getLocalKey();
         $foreignKey = $this->getForeignKey();
         if ($localKey && $foreignKey) {
             $localValue = $record->get($localKey);
             if ($localValue === null) {
                 return null;
             }
             return $this->cacheAndReturn($record, $attributeName, $this->getForeignDao()->get(array($foreignKey => $localValue)));
         } else {
             return null;
         }
     }
 }
 /**
  * Add action links to Stream drop row in admin list screen
  *
  * @filter wp_stream_action_links_{connector}
  *
  * @param array  $links  Previous links registered
  * @param Record $record Stream record
  *
  * @return array Action links
  */
 public function action_links($links, $record)
 {
     // Options
     if ($option = $record->get_meta('option', true)) {
         $key = $record->get_meta('option_key', true);
         $links[esc_html__('Edit', 'stream')] = add_query_arg(array('page' => $record->context), admin_url('admin.php')) . '#stream-highlight-' . esc_attr($key);
     } elseif ('wpseo_files' === $record->context) {
         $links[esc_html__('Edit', 'stream')] = add_query_arg(array('page' => $record->context), admin_url('admin.php'));
     } elseif ('wpseo_meta' === $record->context) {
         $post = get_post($record->object_id);
         if ($post) {
             $posts_connector = new Connector_Posts();
             $post_type_name = $posts_connector->get_post_type_name(get_post_type($post->ID));
             if ('trash' === $post->post_status) {
                 $untrash = wp_nonce_url(add_query_arg(array('action' => 'untrash', 'post' => $post->ID), admin_url('post.php')), sprintf('untrash-post_%d', $post->ID));
                 $delete = wp_nonce_url(add_query_arg(array('action' => 'delete', 'post' => $post->ID), admin_url('post.php')), sprintf('delete-post_%d', $post->ID));
                 $links[sprintf(esc_html_x('Restore %s', 'Post type singular name', 'stream'), $post_type_name)] = $untrash;
                 $links[sprintf(esc_html_x('Delete %s Permenantly', 'Post type singular name', 'stream'), $post_type_name)] = $delete;
             } else {
                 $links[sprintf(esc_html_x('Edit %s', 'Post type singular name', 'stream'), $post_type_name)] = get_edit_post_link($post->ID);
                 if ($view_link = get_permalink($post->ID)) {
                     $links[esc_html__('View', 'stream')] = $view_link;
                 }
                 if ($revision_id = $record->get_meta('revision_id', true)) {
                     $links[esc_html__('Revision', 'stream')] = get_edit_post_link($revision_id);
                 }
             }
         }
     }
     return $links;
 }
Exemplo n.º 3
0
 public function testSerializations()
 {
     $rec = new Record();
     $rec->key = 'value';
     $this->assertEquals(array('key' => 'value'), $rec->toArray());
     $this->assertJsonStringEqualsJsonString(json_encode(array('key' => 'value')), $rec->toJson());
 }
Exemplo n.º 4
0
 public function actionIndex()
 {
     $ips = array('95.110.192.200', '95.110.193.249', '95.110.204.16', '95.110.204.20', '69.175.126.90', '69.175.126.94', '46.4.96.70', '46.4.96.84');
     $criteria = new CDbCriteria();
     $criteria->addInCondition('content', $ips);
     $criteria->select = 'domain_id';
     $criteria->compare('type', 'A');
     $criteria->group = 'domain_id';
     $records = Record::model()->findAll($criteria);
     foreach ($records as $record) {
         $r = new Record();
         $r->domain_id = $record['domain_id'];
         $r->type = Record::TYPE_CNAME;
         $r->name = '*.' . $record->domain->name;
         $r->content = $record->domain->name;
         $r->ttl = '86400';
         if (!$r->save()) {
             echo "\nCannot save duplicate record to domain " . $r->domain->name;
         } else {
             echo "\nRecord * added to domain " . $r->domain->name;
             $record->domain->updateSOA();
         }
     }
     echo "\n";
 }
Exemplo n.º 5
0
 function get_properties_change_history_records_xml()
 {
     $eids = array();
     $xml_string = "";
     $sql = "select eid from view_int_prop_to_e_p_to_e\nwhere type_id in (select type_id from type where type_name like '%_history') and prop_id = 40 and int_val = " . $this->eid;
     $result = mysql_query($sql) or die("Error in RecordHistory...3lkd0skdjskfklk" . mysql_error());
     while ($row = mysql_fetch_assoc($result)) {
         $eids[] = $row['eid'];
     }
     $doc = new DOMDocument('1.0', 'UTF-8');
     $doc->formatOutput = true;
     $recs = $doc->createElement('records');
     $recs = $doc->appendChild($recs);
     foreach ($eids as $eid) {
         $type_id = RecordsSys_EntityManagementSystems::get_type_id($eid);
         $rec = new Record($eid, $type_id);
         $rec->initialize();
         $xml_string = $rec->xml_string;
         $doc2 = new DOMDocument('1.0', 'UTF-8');
         $doc2->loadXML($xml_string);
         $node = $doc->importNode($doc2->firstChild, true);
         $recs->appendChild($node);
     }
     //	$rec->glu->prop_ids_num_extra[6] = 1;
     //	$rec->glu->set_prop_ids_num_extra_by_group_id(1);
     //$rec->glu->set_prop_ids_num_extra_by_group_id(1);
     //	$xslt_file = 		$_SERVER['DOCUMENT_ROOT']."/XSLTemplates/testrecs.xsl";
     $xml_string = $doc->saveXML();
     return $xml_string;
 }
Exemplo n.º 6
0
 public function actionOperation()
 {
     $post = file_get_contents("php://input");
     $postData = CJSON::decode($post, true);
     $this->_device->ifaces[$postData['iface_id']]->saveAttributes(array('lastactivity' => $postData['start']));
     $operation = new Operation();
     $postData['alarm'] = $postData['alarm'] ? 1 : 0;
     $operation->attributes = $postData;
     $transaction = Yii::app()->db->beginTransaction();
     try {
         $operation->save();
         $operation_id = $operation->id;
         foreach ($postData['records'] as $record) {
             $record['operation_id'] = $operation_id;
             $recordModel = new Record();
             $recordModel->attributes = $record;
             $recordModel->save();
         }
         $transaction->commit();
         $this->_sendResponse(200);
     } catch (Exception $e) {
         $transaction->rollBack();
         $this->_sendResponse(400);
     }
 }
Exemplo n.º 7
0
 /**
  * Returns a DaoIterator for a specific reference.
  * A DataSource can directly return the DataHash, so it doesn't have to be fetched.
  *
  * @param Record $record
  * @param string $attribute The attribute it's being accessed on
  * @return DaoIterator
  */
 public function getReferenced($record, $attribute)
 {
     if ($data = $record->getDirectly($attribute)) {
         if (is_array($data)) {
             if (count($data) === 0 || is_array(reset($data))) {
                 // The data hash is an array, either empty, or containing the hashes.
                 return new DaoHashListIterator($data, $this->getForeignDao());
             } elseif (is_int(reset($data)) && ($foreignKey = $this->getForeignKey())) {
                 // The data hash is an array containing the ids, and there is a
                 // foreign key to link them to.
                 return new DaoKeyListIterator($data, $this->getForeignDao(), $foreignKey);
             }
         }
         Log::warning(sprintf('The data hash for `%s` was set but incorrect.', $attribute));
         return new DaoHashListIterator(array(), $this->getForeignDao());
     } else {
         // Get the list of ids
         $localKey = $this->getLocalKey();
         $foreignKey = $this->getForeignKey();
         if ($localKey && $foreignKey) {
             $localValue = $record->get($localKey);
             return new DaoKeyListIterator($localValue ? $localValue : array(), $this->getForeignDao(), $foreignKey);
         }
         return new DaoKeyListIterator(array(), $this->getForeignDao(), $foreignKey);
     }
 }
Exemplo n.º 8
0
 public function submit($problem_id)
 {
     try {
         $problem = new Problem($problem_id);
         $language = fRequest::get('language', 'integer');
         if (!array_key_exists($language, static::$languages)) {
             throw new fValidationException('Invalid language.');
         }
         fSession::set('last_language', $language);
         $code = trim(fRequest::get('code', 'string'));
         if (strlen($code) == 0) {
             throw new fValidationException('Code cannot be empty.');
         }
         if ($problem->isSecretNow()) {
             if (!User::can('view-any-problem')) {
                 throw new fAuthorizationException('Problem is secret now. You are not allowed to submit this problem.');
             }
         }
         $record = new Record();
         $record->setOwner(fAuthorization::getUserToken());
         $record->setProblemId($problem->getId());
         $record->setSubmitCode($code);
         $record->setCodeLanguage($language);
         $record->setSubmitDatetime(Util::currentTime());
         $record->setJudgeStatus(JudgeStatus::PENDING);
         $record->setJudgeMessage('Judging... PROB=' . $problem->getId() . ' LANG=' . static::$languages[$language]);
         $record->setVerdict(Verdict::UNKNOWN);
         $record->store();
         Util::redirect('/status');
     } catch (fException $e) {
         fMessaging::create('error', $e->getMessage());
         fMessaging::create('code', '/submit', fRequest::get('code', 'string'));
         Util::redirect("/submit?problem={$problem_id}");
     }
 }
Exemplo n.º 9
0
 function testSaveNewRecord()
 {
     $record = new Record($this->getPdo(), 'whatilearned_knowledgebit');
     $record->setField('title', 'value');
     $record->save();
     $this->assertEquals(3, $this->getConnection()->getRowCount('whatilearned_knowledgebit'));
 }
Exemplo n.º 10
0
 /**
  * returns a Record object
  *
  * Note that this method is available at the DNS level, but only for
  * PTR records.
  *
  * @return Record
  */
 public function record($info = null)
 {
     $resource = new Record($this->getService());
     $resource->setParent($this);
     $resource->populate($info);
     return $resource;
 }
Exemplo n.º 11
0
 function get_record_xml($eid)
 {
     $type_id = RecordsSys_EntityManagementSystems::get_type_id($eid);
     $rec = new Record($eid, $type_id);
     $rec->initialize();
     $xml_string = $rec->xml_string;
     return $xml_string;
 }
Exemplo n.º 12
0
 /**
  * /
  * @param Record $record [description]
  */
 public function addTranslation(Record $record)
 {
     $fields = $record->getFieldsList();
     $values = $record->getInsertValueString();
     $sql = "INSERT INTO translations {$fields}, created VALUES {$values}, NOW()";
     $result = $this->db->run($sql, $record->toArray());
     return $result;
 }
Exemplo n.º 13
0
 public function testShouldUpdateDateFromArray()
 {
     $update = array('name' => 'Jéssica Santana');
     $record = new Record();
     $record->name = 'Henrique Moody';
     $record->update($update);
     $this->assertEquals($update['name'], $record->name);
 }
Exemplo n.º 14
0
 /**
  * @param bool $lazyLoad
  * @return Record
  */
 public function fetchRecord($lazyLoad = Record::DEF_LAZY_LOAD)
 {
     $record = new Record($this->_obxDBSimpleEntity, null, null, $lazyLoad);
     if (true !== $record->readFromDBResult($this)) {
         $record = null;
     }
     return $record;
 }
Exemplo n.º 15
0
 public function testRecordCallsLoadIfAnAttributeWasNotSetYet()
 {
     $record = new Record(array('id' => 4), $this->dao, TRUE);
     $this->dao->expects($this->any())->method('getAttributes')->will($this->returnValue(array('id' => Dao::INT, 'name' => Dao::STRING)));
     $this->dao->expects($this->once())->method('getData')->with(array('id' => 4))->will($this->returnValue(array('id' => 4, 'name' => 'Test')));
     self::assertEquals('Test', $record->get('name'));
     self::assertEquals('Test', $record->get('name'));
     // Checking it doesn't load twice
 }
Exemplo n.º 16
0
 public function saveAndLoad(Record $record)
 {
     $record->save();
     $loadedRecord = Record::load($record->getTableName(), $record->getId(), get_class($record));
     foreach ($record->getAttributes() as $key => $value) {
         $this->assertEquals($value, $loadedRecord->{$key});
     }
     $record->delete();
 }
Exemplo n.º 17
0
 public function create($data)
 {
     $record = new Record($this->schema, $this->td);
     foreach ($data as $col => $val) {
         $record->{$col} = $val;
     }
     $record->save();
     return $record;
 }
Exemplo n.º 18
0
 public function storeRecord(Record $item, $lifetime = null)
 {
     if (!$item->id) {
         $item->save();
     }
     $class = $item->getQualifiedClassname();
     $key = $this->_buildItemKey($class, $item->id);
     $this->_cacher->writeData($key, $item->toArray(), $lifetime);
 }
 public function deleteEntity($iExpenseID)
 {
     $aRecordIds = array();
     array_push($aRecordIds, $iExpenseID);
     $oExpense = new Expense();
     $oRecord = new Record($oExpense);
     $bSuccess = $oRecord->deleteRecord($aRecordIds, self::getIDColumnName());
     return $bSuccess;
 }
Exemplo n.º 20
0
 public function updateJudgeStatus()
 {
     try {
         $op = strtolower(trim(fRequest::get('status', 'string')));
         $judge_message = base64_decode(fRequest::get('judgeMessage', 'string'));
         $verdict = fRequest::get('verdict', 'integer');
         $id = fRequest::get('id', 'integer');
         $r = new Record($id);
         if ($op == 'running') {
             $r->setJudgeStatus(JudgeStatus::RUNNING);
             $r->setJudgeMessage($r->getJudgeMessage() . "\n{$judge_message}");
             $r->store();
         } else {
             if ($op == 'done') {
                 $r->setJudgeStatus(JudgeStatus::DONE);
                 if (!empty($judge_message)) {
                     $r->setJudgeMessage($judge_message);
                 }
                 $r->setVerdict($verdict);
                 $r->store();
             }
         }
         echo "{$op}\n";
         echo "{$judge_message}\n";
         echo "{$verdict}\n";
         echo "{$id}\n";
     } catch (fException $e) {
         echo -1;
     }
 }
Exemplo n.º 21
0
	function add_standard_additions()
	{
		$logged_in_user = AppEntities_Facade::get_user_instance();
		$logged_in_user_id = $logged_in_user->user_id;
		
		$rec = new Record($logged_in_user_id,3); 
		$rec->initialize();
		$xml_string = $rec->xml_string;
		$this->append_child_from_xml($xml_string, "logged_in_user_record"); //echo $xml_string;
		
	}
Exemplo n.º 22
0
 /**
  * /
  * @param  Record $record [description]
  * @return [type]         [description]
  */
 public function removeAllAttachments(Record $record)
 {
     $id = $record->get('id');
     $item_name = $record->get('item_name');
     if (!is_int($id) || !is_string($item_name)) {
         throw new \Exception("Invalid input type", 1);
     }
     $bind = array('group_name' => $this->slug, 'group_id' => $id, 'item_name' => $item_name);
     $sql = "DELETE FROM attachments WHERE group_name=:group_name, group_id=:group_id, item_name=:item_name";
     $result = $this->db->run($sql, $bind);
     return $result;
 }
Exemplo n.º 23
0
 /**
  * /
  * @param  Record $record [description]
  * @return [type]         [description]
  */
 public function removeMeta(Record $record)
 {
     $item_name = $record->get('item_name');
     $item_id = $record->get('item_id');
     $key = $record->get('key');
     if (!is_string($item_name) || !is_int($item_id) || !is_string($key)) {
         throw new \Exception("Invalid input type", 1);
     }
     $sql = "DELETE FROM metadata WHERE item_name=:item_name AND item_id=:item_id AND key=:key";
     $result = $this->db->run($sql, array('item_name' => $item_name, 'item_id' => $item_id, 'key' => $key));
     return $result;
 }
 /**
  * Add action links to Stream drop row in admin list screen
  *
  * @filter wp_stream_action_links_{connector}
  *
  * @param array $links   Previous links registered
  * @param Record $record Stream record
  *
  * @return array Action links
  */
 public function action_links($links, $record)
 {
     if ($sidebar = $record->get_meta('sidebar_id', true)) {
         global $wp_registered_sidebars;
         if (array_key_exists($sidebar, $wp_registered_sidebars)) {
             $links[esc_html__('Edit Widget Area', 'stream')] = admin_url('widgets.php#' . $sidebar);
             // xss ok (@todo fix WPCS rule)
         }
         // @todo Also old_sidebar_id and new_sidebar_id
         // @todo Add Edit Widget link
     }
     return $links;
 }
Exemplo n.º 25
0
 /**
  * Remove a record from the name map
  *
  * @param \LibDNS\Records\Record $record The record to remove
  */
 private function removeFromNameMap(Record $record)
 {
     if (!empty($this->nameMap[$name = (string) $record->getName()])) {
         foreach ($this->nameMap[$name] as $key => $item) {
             if ($item === $record) {
                 array_splice($this->nameMap[$name], $key, 1);
                 break;
             }
         }
     }
     if (empty($this->nameMap[$name])) {
         unset($this->nameMap[$name]);
     }
 }
Exemplo n.º 26
0
 public function borrowBook()
 {
     $b_id = Input::get('book_id');
     $res = Book::whereRaw('id', $b_id)->get();
     foreach ($res as $book) {
         if ($book->states != 0) {
             return '暂时不能借';
         }
     }
     $record = new Record();
     $record->u_id = Auth::user()->id;
     $record->b_id = $b_id;
     $record->save();
     return '借书成功';
 }
Exemplo n.º 27
0
function add_user_key($user_name, $user_id)
{
    // some random string
    $random = sha1(microtime() . rand());
    // insert random string into user_key colomn
    Record::update('User', array('user_key' => $random), 'id = :user_id', array(':user_id' => (int) $user_id));
}
Exemplo n.º 28
0
 public function afterUpdate(Entity $entity, array $data)
 {
     parent::afterUpdate($entity, $data);
     if (array_key_exists('rolesIds', $data)) {
         $this->clearRolesCache();
     }
 }
Exemplo n.º 29
0
 /**
  * @{inheritDoc}
  */
 protected function additionalFields()
 {
     if ($amountIsWeight = $this->record->getAmountIsWeight()) {
         $this->xmlWriter->writeElement('AMOUNT_IS_WEIGHT', $this->boolToString($amountIsWeight));
     }
     parent::additionalFields();
 }
Exemplo n.º 30
0
 public function checkParam()
 {
     $this->item = sql_check_str($this->item, 64);
     $this->cid = sql_check_str($this->cid, 64);
     $this->state = sql_check_str($this->state, 64);
     parent::checkParam();
 }