Wordpress SQL Format In theme options - wordpress-theming

I have come across this code in wordpress theme options table options field:
a:34:{s:15:"generalsettings";N;s:0:"";N;s:12:"color_scheme";s:0:"";s:9:"site_name";s:0:"";s:11:"custom_logo";s:0:"";s:10:"twitter_id";s:48:"also include facebook username:this is a comment";s:13:"header_teaser";s:10:"customtext";s:12:"teaser_style";s:0:"";s:13:"teaser_custom";s:0:"";s:13:"cufon_disable";N;s:18:"breadcrumb_disable";N;s:14:"analytics_code";s:0:"";s:8:"homepage";N;s:11:"teaser_text";s:0:"";s:13:"teaser_button";s:2:"26";s:16:"mainpage_content";s:0:"";s:19:"home_teaser_disable";N;s:14:"slider_disable";s:1:"1";s:12:"slider_speed";s:0:"";s:15:"homepage_slider";s:6:"custom";s:15:"slider_showcats";s:0:"";s:12:"slider_count";s:0:"";s:4:"blog";N;s:9:"blog_page";s:0:"";s:16:"blog_excludecats";s:0:"";s:21:"related_popular_posts";N;s:16:"social_bookmarks";N;s:12:"about_author";N;s:7:"sidebar";N;s:14:"footersettings";N;s:11:"footer_text";s:0:"";s:14:"footer_include";s:0:"";s:11:"navsettings";N;s:12:"show_hide_pg";s:0:"";}
What format is this,and where can i find more information about it?.

Not exactly arrays. they are serialised data. you can use unserialize function to revert it back, and in this example, it is array! =)
Array ( [generalsettings] => [] => [color_scheme] => [site_name] => [custom_logo] => [twitter_id] => also include facebook username:this is a comment [header_teaser] => customtext [teaser_style] => [teaser_custom] => [cufon_disable] => [breadcrumb_disable] => [analytics_code] => [homepage] => [teaser_text] => [teaser_button] => 26 [mainpage_content] => [home_teaser_disable] => [slider_disable] => 1 [slider_speed] => [homepage_slider] => custom [slider_showcats] => [slider_count] => [blog] => [blog_page] => [blog_excludecats] => [related_popular_posts] => [social_bookmarks] => [about_author] => [sidebar] => [footersettings] => [footer_text] => [footer_include] => [navsettings] => [show_hide_pg] => )

Related

Laravel 8: Update a record in database using if statement

Below is the function I used to update my record.
public function store_upd_nilai_uji_program(Request $request)
{
$validated = $request->validate([
'nip' => 'required|numeric|digits_between:18,18',
'n1' => 'nullable|numeric',
'n2' => 'nullable|numeric',
'n3' => 'nullable|numeric',
'n4' => 'nullable|numeric',
'n5' => 'nullable|numeric',
'n6' => 'required|numeric',
'tanggal' => 'required',
'waktu' => 'required',
]);
NilaiUjiProgram::where('nim', $request->nim)->update([
'nip' => $request->nip,
'nilai_kemampuan_dasar_program' => floatval($request->n1),
'nilai_kecocokan_algoritma' => floatval($request->n2),
'nilai_penguasaan_program' => floatval($request->n3),
'nilai_penguasaan_ui' => floatval($request->n4),
'nilai_validasi_output' => floatval($request->n5),
'total' => floatval($request->n6),
'tanggal' => $request->tanggal,
'waktu' => $request->waktu,
]);
return redirect('/prodi/daftar_nilai_uji_program')->with('status', 'Nilai berhasil diperbaharui!');
}
Actually, I want to update the attribute 'nilai_kemampuan_dasar_program', 'nilai_kecocokan_algoritma','nilai_penguasaan_program','nilai_penguasaan_ui', and 'nilai_validasi_output' if only the equal value in $request is NOT NULL. If the value is null, I would like to keep my record fill with NULL. To keep in mind that my table doesn't have any primary key. Do you have any idea how to solve my problem?
NilaiUjiProgram::where('nim', $request->nim)->update([
'nip' => $request->nip,
'nilai_kemampuan_dasar_program' => $request->n1 ? floatval($request->n1) : null,
'nilai_kecocokan_algoritma' => $request->n2? floatval($request->n2) :null,
'nilai_penguasaan_program' => $request->n3 ? floatval($request->n3):null,
'nilai_penguasaan_ui' => $request->n4 ? floatval($request->n4) : null,
'nilai_validasi_output' => floatval($request->n5),
'total' => floatval($request->n6),
'tanggal' => $request->tanggal,
'waktu' => $request->waktu,
]);

Yii2 module or controller routing

I try use routing for module and controller
'<controller>'=>'<controller>/index',
'<controller>/<id:\d+>'=>'<controller>/view',
'<controller>/<action>'=>'<controller>/<action>',
'<module>' => '<module>/default/index',
'<module>/<id:\d+>' => '<module>/default/view',
'<module>/edit/<id:\d+>' => '<module>/default/edit',
'<module>/delete/<id:\d+>' => '<module>/default/delete',
'<module>/<action>' => '<module>/default/<action>',
'<module>/<controller>' => '<module>/<controller>/index',
'<module>/<controller>/edit/<id:\d+>' => '<module>/<controller>/edit',
'<module>/<controller>/delete/<id:\d+>' => '<module>/<controller>/delete',
'<module>/<controller>/<id:\d+>' => '<module>/<controller>/view',
'<module>/<controller>/<action>' => '<module>/<controller>/<action>',
but for some reason, if the first matching rule did not work, then the rest are not checked, you get a 404 error.
For example, if the controller is not found, then 404 is obtained, and the check does not reach the modules.
url manager config
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'store/upload'=>'store/upload',
'stores'=>'store/index',
// 'post/<id:\d+>'=>'post/view',
'comment/send'=>'comment/send',
['class' => 'yii\rest\UrlRule', 'controller' => 'Api', 'prefix' => 'api'],
'api/<id:\d+>'=>'api/view',
[
'pattern' => 'users',
'route' => 'users/index',
'suffix' => '/',
'normalizer' => false, // отключаем нормализатор для этого правила
],
// '<controller>'=>'<controller>/index',
// '<controller>/<id:\d+>'=>'<controller>/view',
// '<controller>/<action>'=>'<controller>/<action>',
'<module>' => '<module>/default/index',
'<module>/<id:\d+>' => '<module>/default/view',
'<module>/edit/<id:\d+>' => '<module>/default/edit',
'<module>/delete/<id:\d+>' => '<module>/default/delete',
'<module>/<action>' => '<module>/default/<action>',
'<module>/<controller>' => '<module>/<controller>/index',
'<module>/<controller>/edit/<id:\d+>' => '<module>/<controller>/edit',
'<module>/<controller>/delete/<id:\d+>' => '<module>/<controller>/delete',
'<module>/<controller>/<id:\d+>' => '<module>/<controller>/view',
'<module>/<controller>/<action>' => '<module>/<controller>/<action>',
],
],
Request Url http://yii2/post
To PostController/actionIndex()
I fix routing, It work.The controllers are checked first, then the modules.
'<controller:\w+>'=>'<controller>/index',
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action>'=>'<controller>/<action>',
'<module:\w+>' => '<module>/default/index',
'<module:\w+>/<id:\d+>' => '<module>/default/view',
'<module:\w+>/edit/<id:\d+>' => '<module>/default/edit',
'<module:\w+>/delete/<id:\d+>' => '<module>/default/delete',
'<module:\w+>/<action:\w+>' => '<module>/default/<action>',
'<module:\w+>/<controller:\w+>' => '<module>/<controller>/index',
'<module:\w+>/<controller:\w+>/edit/<id:\d+>' => '<module>/<controller>/edit',
'<module:\w+>/<controller:\w+>/delete/<id:\d+>' => '<module>/<controller>/delete',
'<module:\w+>/<controller:\w+>/<id:\d+>' => '<module>/<controller>/view',
'<module:\w+>/<controller:\w+>/<action>' => '<module>/<controller>/<action>',

Yii2 sort object defaultOrder

I have a table of policies that belong to chapters. When I view the policies in my grid view I want the default order be policy title within chapter title. I see how to set up sort attributes to enable this, but I can't figure out how to set the defaultOrder to be based on chapter title and then policy title. When ever I try to set policy.title as an attribute in the defaultOrder setting I get an error.
If Policy is model class of policy table that has a relation with chapter table named 'chapter' and linked by chapter_id field, such as:
public function getChapter()
{
return $this->hasOne(Chapter::className(), ['chapter_id' => 'chapter_id']);
}
Now you build query object with policy joined with chapter:
$query = Policy::find()
->joinWith(['chapter']);
$dataProvider = new ActiveDataProvider([
'query' => $query,
'sort'=> ['defaultOrder' => ['chapter.title'=>SORT_ASC, 'policy.title' => SORT_ASC]]
]);
I could not get Fabrizio's answer to work, because my chapter table is policy_chapter, not just chapter and so is not the same as the relation name. When I tried to use the relation name, I got errors. I finally figured out in the sort, you have to use the names of the related tables, not the relations, and add them as attributes. e.g.:
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => ['pageSize' => 50],
'sort' => [
'defaultOrder' => ['policy_chapter.sort' => SORT_ASC,'policy_chapter.title' => SORT_ASC],
'enableMultiSort' => true,
'attributes' => [
'id' => [
'asc' => ['policy.id' => SORT_ASC],
'desc' => ['policy.id' => SORT_DESC],
'default' => SORT_ASC
],
'chapter_id' => [
'asc' => ['policy_chapter.sort' => SORT_ASC,'policy_chapter.title' => SORT_ASC],
'desc' => ['policy_chapter.sort' => SORT_DESC,'policy_chapter.title' => SORT_DESC],
'default' => SORT_ASC,
],
'reference' => [
'asc' => ['reference' => SORT_ASC],
'desc' => ['reference' => SORT_DESC],
'default' => SORT_ASC
],
'title' => [
'asc' => ['policy.title' => SORT_ASC],
'desc' => ['policy.title' => SORT_DESC],
'default' => SORT_ASC
],
'policy_chapter.sort',
'policy_chapter.title',
],
],
]);
Use the relation name or leave out the attributes and you get errors. Before I was writing
'defaultOrder' => ['policy_chapter.sort' => SORT_ASC,'policy_chapter.title' => SORT_ASC],
and Yii was not happy

Update a HasMany records

I am converting a working app from cakephp2 to cakephp3. I'm struggling to get a form that updates hasMany records to work.
The app has the following structure:
MODELS:
use Cake\ORM\Table;
use Cake\Validation\Validator;
class AwardsTable extends Table
{
public function initialize(array $config)
{
$this->hasMany('Levels', ['sort' => 'sort_order']);
}
}
namespace App\Model\Entity;
use Cake\Auth\DefaultPasswordHasher;
use Cake\ORM\Entity;
class Award extends Entity
{
protected $_accessible = [
'name' => true,
'url' => true,
'organisation' => true,
'detail' => true,
'logo' => true,
'levels' => true,
'Levels' => true
];
}
IN THE FORM:
<?= $this->Form->input("levels.$i.name", 'label'=>false,'type'=>'text','value' => $award->name]);?>
<?= $this->Form->input("levels.$i.id", ['value' => $award->id]); ?>
CONTROLLER
$this->Awards->patchEntity($award, $this->request->data, ['associated' => ['Levels']]);
if ($this->Awards->save($award)) {
$this->Flash->success(__('Your Award has been saved.'));
$this->redirect(['action' => 'index']);
}
This seems inline with what is recommended here: http://book.cakephp.org/3.0/en/views/helpers/form.html#associated-form-inputs
I've tried a few variations with capitalisation & pluralisation. The award data saves correctly but the associated levels data does not save.
What am I missing to get the has_many association data to save?
EDIT: Example Data array submitted:
2016-01-28 23:32:56 Error: Array
(
[id] => 4
[name] => test award
[organisation] => test org
[url] => http://www.example.com
[detail] =>
[levels] => Array
(
[0] => Array
(
[name] => test 1
[id] => 4
)
[11] => Array
(
[name] => test
[id] => 16
)
)
[image] => Array
(
[name] =>
[type] =>
[tmp_name] =>
[error] => 4
[size] => 0
)
)
In LevelEntity verify if 'id' is accessible
protected $_accessible = [
'*' => true,
'id' => true,
];

How to parse complicated hash ref in perl?

I used JSON::Parse to decode a json file. When I dumped it to a file it looks as printed below. I need to extract the 'url' from each of the repositories. How can I go about doing that? I have tried to access the elements, but cannot seem to get to them. Any suggestions?
How I decoded the .json file:
my $json_hash_ref = {};
$json_hash_ref= json_file_to_perl ($REPO_JSON_FILE) or confess "No repos found";
This is the data dump:
$VAR1 = {
'repositories' => [
{
'size' => 2970,
'watchers' => 49,
'created_at' => '2012-03-20T05:04:42Z',
'url' => 'http://github.cerner.com/aeon-core/aeon-topology',
'open_issues' => 0,
'followers' => 49,
'owner' => 'aeon-core',
'has_downloads' => 1,
'has_issues' => 0,
'language' => 'Java',
'pushed' => '2014-06-17T18:32:37Z',
'private' => ${\$VAR1->{'repositories'}[0]{'has_issues'}},
'name' => 'aeon-topology',
'score' => '1',
'has_wiki' => ${\$VAR1->{'repositories'}[0]{'has_issues'}},
'pushed_at' => '2014-06-17T18:32:37Z',
'description' => '',
'username' => 'aeon-core',
'created' => '2012-03-20T05:04:42Z',
'homepage' => '',
'forks' => 59,
'fork' => ${\$VAR1->{'repositories'}[0]{'has_issues'}},
'type' => 'repo'
},
{
.....
},...
my #urls = map $_->{url}, #{ $json_hash_ref->{repositories} };
For good information on traversing deep data structures, read the perl references tutorial.