Search Through HABTM Checkbox/List - list

I have this contact form which also relates to a few other tables with a HABTM relationship. They are displayed in the form either as a list or as checkboxes. What I want is to be able to search through them while still in the form to select those that are applicable to the contact I am adding with the form. I'm not sure how to do this- was thinking maybe Javascript?
An example of what I am talking about is like Facebook when you're searching through your friends list.
Below are the HABTM relationships for the Contact Model:
public $hasAndBelongsToMany = array(
'Company' => array(
'className' => 'Company',
'joinTable' => 'companies_contacts',
'foreignKey' => 'contact_id',
'associationForeignKey' => 'company_id',
'unique' => 'keepExisting',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'Event' => array(
'className' => 'Event',
'joinTable' => 'contacts_events',
'foreignKey' => 'contact_id',
'associationForeignKey' => 'event_id',
'unique' => 'keepExisting',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'Screenoccupation' => array(
'className' => 'Screenoccupation',
'joinTable' => 'contacts_screenoccupations',
'foreignKey' => 'contact_id',
'associationForeignKey' => 'screenoccupation_id',
'unique' => 'keepExisting',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'Tapearchive' => array(
'className' => 'Tapearchive',
'joinTable' => 'contacts_tapearchives',
'foreignKey' => 'contact_id',
'associationForeignKey' => 'tapearchive_id',
'unique' => 'keepExisting',
'dependent' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
),
'Relation' => array(
'className' => 'Contact',
'joinTable' => 'contacts_contacts',
'foreignKey' => 'contact_id',
'associationForeignKey' => 'related_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'deleteQuery' => '',
'insertQuery' => ''
)
);
Not sure what other codes I need to show you guys, so please do let me know what codes are needed and I will add them to this question.
Thanks!

You could use a jquery plugin to do the job for you.
It seems that this one corresponds to your criteria. Chosen is nice too.
Anyway, do a google search to see all the jquery plugin available, and see if one fits your need.

Related

Product is listed on database is not listed in Admin > Products List

As an Opencart newbie, I'm adding the product with a static array just for testing the addProduct function but I could not get it to work.
Static array:
$data['pid'] = $this->model_catalog_product->addProduct([
'product_description' => [['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
'model' => 'amabigun',
'sku' => '',
'upc' => '',
'ean' => '',
'jan' => '',
'isbn' => '',
'mpn' => '',
'location' => '',
'price' => '',
'tax_class_id' => '0',
'quantity' => '1',
'minimum' => '1',
'subtract' => '1',
'stock_status_id' => '6',
'shipping' => '1',
'date_available' => '2019-12-31',
'length' => '',
'width' => '',
'height' => '',
'length_class_id' => '1',
'weight' => '',
'weight_class_id' => '1',
'status' => '1',
'sort_order' => '1',
'manufacturer' => '',
'manufacturer_id' => '',
'category' => '',
'filter' => '',
'product_store' => array(0 => '0',),
'download' => '',
'related' => '',
'option' => '',
'image' => '',
'points' => '',
'product_reward' => array(1 => array('points' => '',),),
'product_seo_url' => array(0 => array(1 => '',),),
'product_layout' => array(0 => '',)
]);
After this block, I see the entry in oc_product table just like others but not in Admin > Catalog > Products list. Is there another little stuff that I should prepare?
Take a look at the addProduct() function and you will see some code which performs inserts to the description table like this:
foreach ($data['product_description'] as $language_id => $value) {
...
}
According to that logic, the array key is the language_id. In your array you have:
'product_description' => [['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
Since there is no array key defined, your description is assigned to key 0. Do you have a language_id of 0 in your language table? Probably not. A typical (default) opencart installation has one language with language_id of 1. With that in mind, your array should look like this:
'product_description' => [1 => ['name' => 'bakbuişte', 'description' => '', 'meta_title' => 'metaraba', 'meta_description' => '', 'meta_keyword' => '', 'tag' => '']],
The reason that things to fail when you write description rows with the wrong language_id is that the product list is retrieved with a query like this:
SELECT *
FROM product p
LEFT JOIN product_description pd ON (p.product_id = pd.product_id)
WHERE pd.language_id = '1';
Notice the where condition at the end? If your description table is missing the corresponding row with language_id 1, the query will ignore your product row.

zf2 regex routing

I am struggling with regex routing....
The following urls should be valid:
/shop/api/list
/shop/api/cart
/shop/api/login
/shop/api/details/0123456789
And the details url, the last one, is not really cooperating with the following route:
'child_routes' => array(
'angularlist' => array(
'type' => 'Regex',
'options' => array(
'regex' => '/api/(?<page>login|cart|list|details(?<id>\/[0-9]+))',
'spec' => '/api/%page%[/:%id%]',
'defaults' => array(
'__NAMESPACE__' => 'Shop\Controller',
'controller' => 'Api',
//'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'action' => 'list',
// 'param' => '[0-9]',
),
/* todo ipv elke child toe te voegen 'route' => '/api/[:action]', 'constraints' => array(
'action' => 'list|details|login|dashboard'
)*/
),
),
)
Instead of struggling with less-readable & dirty regex hacks, you can easily implement a Segment route stack like below:
'shop' => array(
'type' => 'Segment',
'options' => array(
'route' => '/shop/api',
'defaults' => array(
'__NAMESPACE__' => 'Shop\Controller',
'controller' => 'Api',
'action' => 'index'
),
),
'may_terminate' => true,
'child_routes' => array(
'angularlist' => array(
'type' => 'Segment',
'options' => array(
'route' => '/:action[/:id]', // id is optional
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'action' => 'index',
),
),
),
)

Zend Framework 2 child regex and literal routing

Based on this stackoverflow question 15077075 i have accomplished that my application has a regex based route so i can pass this to my view and edit action.
app/123 - app controller view action (get by article id)
app/name-of-article - app controller view action (get by article name)
app/123/edit - app controller edit action (article id)
app/name-of-article/edit - app controller edit action (article name)
app/search/{search-string} - app controler search action (currently only accepts a searchstring without spaces and special characters)
This i have accomplished with the code below and is similar to the code in the link above:
'app' => array(
'type' => 'literal',
'options' => array(
'route' => '/app',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'index',
),
),
'may_terminate' => true,
),
'view' => array(
'type' => 'regex',
'options' => array(
'regex' => '/app/(?<view>[a-zA-Z0-9_-]+)',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'view',
),
'spec' => '/app/%view%',
),
'priority' => -1000,
),
'edit' => array(
'type' => 'regex',
'options' => array(
'regex' => '/app/(?<view>[a-zA-Z0-9_-]+)/(?<edit>[a-zA-Z0-9_-]+)',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'edit',
),
'spec' => '/app/%view%/%edit%',
),
'priority' => -1000,
),
I have twoone issue
the first is that the url viewhelper doesn't recognize my routes
$controller = app
$action = recent
$this->url( $controller, array( 'action' => $action ) )
it just prints /app instead of /app/recent,
The same occurs when $action = 'search' or $action = 'new' it only prints /app
the second is that the search is recognized to its controller action only it fails when i put spaces or special characters in it
when i try to add \s in the constraints of the searchkey ( '[\sa-zA-Z0-9_-]+' ) it routes to the edit function
the route of search looks like this
Edited the route to this and it worked
'search' => array(
'type' => 'literal',
'options' => array(
'route' => '/app/search',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'search',
),
),
'may_terminate' => true,
'child_routes' => array(
'search' => array(
'type' => 'segment',
'options' => array(
'route' => '/[:searchkey]',
'constraints' => array(
'searchkey' => '[a-zA-Z0-9_\+-]+'
),
'defaults' => array(
'action' => 'search'
),
),
),
),
),
i hope it's clear what i want if any code snippits are needed please ask
Sorted it out!
If one needs to get routes in his application this way you can use the code below
/App App/Index
/App/name-of-article App/View
/App/123 App/View
/App/name-of-article/edit App/Edit
/App/123/edit App/Edit
/App/recent App/Recent
/App/search App/Search
/App/new App/New
In my module.config.php i changed the route to:
'app' => array(
'type' => 'segment',
'options' => array(
'route' => '/app[/:action]',
'constraints' => array(
'action' => '[a-zA-Z][a-zA-Z0-9_-]*',
'id' => '[0-9]+',
),
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'index',
),
),
'may_terminate' => true,
),
'search' => array(
'type' => 'literal',
'options' => array(
'route' => '/app/search',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'search',
),
),
'priority' => 1,
'may_terminate' => true,
'child_routes' => array(
'search' => array(
'type' => 'segment',
'options' => array(
'route' => '/[:searchkey]',
'constraints' => array(
'searchkey' => '[\sa-zA-Z0-9_\+-]+'
),
'defaults' => array(
'action' => 'search'
),
),
'priority' => 2,
'may_terminate' => true,
),
),
),
'new' => array(
'type' => 'literal',
'options' => array(
'route' => '/app/new',
'defaults' => array(
'controller' => 'App',
'action' => 'recent',
),
),
'priority' => 2,
),
'view' => array(
'type' => 'regex',
'options' => array(
'regex' => '/app/(?<view>[a-zA-Z0-9_-]+)',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'view',
),
'spec' => '/app/%view%',
),
),
'edit' => array(
'type' => 'regex',
'options' => array(
'regex' => '/app/(?<view>[a-zA-Z0-9_-]+)/(?<edit>[a-zA-Z0-9_-]+)',
'defaults' => array(
'controller' => 'App\Controller\App',
'action' => 'edit',
),
'spec' => '/app/%view%/%edit%',
),
),
If you need other routes you can just add a new literal route below te app route, make sure you don't forget to set the priority

zendframework 2 table gateway And doctrine 2- is it possible to operate both systems at same time

i am using Zendframework 2 . i wonder if it possible to use both table gateway and doctrine 2 in the same application.
below is my configuration. i tried to run it but i noticed that the speed of my application slowed down considrable.
i was wondering if this was beucase there is a conflict between both applications or because i have not configured it properly.
global PHP file
return array(
'db' => array(
'driver' => 'Pdo',
'dsn' => 'mysql:dbname=thetable;host=localhost',
'driver_options' => array(
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES \'UTF8\''
),
),
'service_manager' => array(
'factories' => array(
'Zend\Db\Adapter\Adapter'
=> 'Zend\Db\Adapter\AdapterServiceFactory',
),
),
);
local php
return array(
'db' => array(
'username' => 'user',
'password' => 'password',
),
'doctrine' => array(
'connection' => array(
'orm_default' => array(
'driverClass' => 'Doctrine\DBAL\Driver\PDOMySql\Driver',
'params' => array(
'host' => 'localhost',
'port' => '3306',
'user' => 'user',
'password' => 'password',
'dbname' => 'thetable'
)
)
)
),
);

ZF2 form validation not working properly for email

i have a input box with type="email" and validation it with zend validator
<input type="email" name="email" > email </input>
'email' => array(
'required' => true,
'validators' => array(
array(
'name' => 'Regex',
'options' => array(
'pattern'=>'/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+#[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/',
'messages' => array(
\Zend\Validator\Regex::NOT_MATCH=>'Please fill correct email ',
)
),
'break_chain_on_failure' => true
),
),
problem is if i use another array to check for
IS_EMPTY
zend regex again does not display the above error instead display default zend regex error and if i remove IS_EMPTY then it works fine. regex error is
1. input does not match to expression '/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+#[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/'
EXACTLY NOT ABLE TO UNDERSTAND WHY THIS WORKS FINE WITHOUT EMPTY CHECK AND DOESN'T WORK ALONG WITH IT
You don't need to use notEmpty, you only need to set the field as "required" and specify the error message:
$this->add(array(
'name' => 'email',
'required' => true,
'error_message' => 'Please entry e-mail.',
'validators' => array(
array(
'name' => 'EmailAddress',
'options' => array (
'messages' => array(EmailAddress::INVALID => 'Please specify a valid e-mail.'),
),
'break_chain_on_failure' => true,
),
),
));
I have also the same dilemma where this "input does not match to expression" always appears instead of the message for EmailAddress::INVALID_FORMAT. But I found that the code you posted fixed the same error I had. This is my code.
'validators' => array(
array (
'name' => 'Regex',
'options' => array(
'pattern'=>'/^[a-zA-Z0-9.!#$%&\'*+\/=?^_`{|}~-]+#[a-zA-Z0-9-]+(?:\.[a-zA-Z0-9-]+)*$/',
'messages' => array(
Regex::NOT_MATCH => 'Please provide a valid email address.',
),
),
'break_chain_on_failure' => true
),
array(
'name' => 'EmailAddress',
'options' => array(
'messages' => array(
EmailAddress::INVALID_FORMAT => 'Please provide a valid email address.',
EmailAddress::DOT_ATOM => '',
EmailAddress::INVALID_FORMAT => '',
EmailAddress::INVALID_LOCAL_PART => '',
EmailAddress::QUOTED_STRING => '',
)
),
),
),