Example #1
0
 /**
  * This function is the stn.
  *
  * @access public
  * @uses MENU_COMMON for the common menu
  * @uses MENU_OUTER for the menu of outer links
  * @uses MENU_INNERfor the menu of inner links
  * @uses View for the visual part
  */
 public static function start()
 {
     require_once dirname(__FILE__) . '/MenuElement.php';
     require_once dirname(__FILE__) . '/Service.php';
     $services = \psdtohtml\Service::getListOfTypeService(array('forAutocompletion' => false));
     // echo ' 41: <pre>';var_dump($services); echo '</pre>';
     $blockOfServices = '';
     foreach ($services as $idService => $service) {
         require_once dirname(__FILE__) . '/ServiceView.php';
         $blockOfServices .= \psdtohtml\ServiceView::buildService(array('service' => $service['object']));
     }
     $logos = '';
     require_once dirname(__FILE__) . '/Logo.php';
     $arrayOfLogos = \psdtohtml\Logo::getListOfTypeLogo(array('forAutocompletion' => false));
     foreach ($arrayOfLogos as $idLogo => $arrayOfLogo) {
         require_once dirname(__FILE__) . '/LogoView.php';
         $logos .= \psdtohtml\LogoView::buildLogo(array('logo' => $arrayOfLogo['object']));
     }
     require_once dirname(__FILE__) . '/Human.php';
     $designer = new \psdtohtml\Human();
     $designer->setId(ID_OF_DESIGNER);
     $designer->setCompleteHuman();
     require_once dirname(__FILE__) . '/Model.php';
     \psdtohtml\Model::setComplete();
     require_once dirname(__FILE__) . '/MenuView.php';
     require_once dirname(__FILE__) . '/View.php';
     // echo ' 69: <pre>';var_dump($commonMenu); echo '</pre>';
     echo \psdtohtml\View::buildView(array('address' => Model::getAddress(), 'blogDate' => Model::getBlogDate(), 'blogEntry' => Model::getBlogEntry(), 'designer' => $designer, 'logos' => $logos, 'menus' => array(MENU_COMMON => MenuView::buildMenu(array('type' => MENU_COMMON)), MENU_OUTER => MenuView::buildMenu(array('type' => MENU_OUTER)), MENU_INNER => MenuView::buildMenu(array('type' => MENU_INNER))), 'phoneNumber' => Model::getPhoneNumber(), 'services' => $blockOfServices, 'title' => Model::getTitle(), 'twitter' => Model::getTwitter()));
 }
 public function activate()
 {
     add_option('squirrels_inventory_version', self::VERSION);
     require_once ABSPATH . '/wp-admin/includes/upgrade.php';
     global $wpdb;
     /** Create tables */
     $charset_collate = '';
     if (!empty($wpdb->charset)) {
         $charset_collate .= "DEFAULT CHARACTER SET {$wpdb->charset}";
     }
     if (!empty($wpdb->collate)) {
         $charset_collate .= " COLLATE {$wpdb->collate}";
     }
     /** SQUIRRELS_FEATURES table */
     $table = $wpdb->prefix . "squirrels_features";
     if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) {
         $sql = "\n\t\t\t\tCREATE TABLE `" . $table . "`\n\t\t\t\t(\n\t\t\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`title` VARCHAR(50) DEFAULT NULL,\n\t\t\t\t\t`is_system` TINYINT(4) DEFAULT NULL,\n\t\t\t\t\t`is_true_false` TINYINT(4) DEFAULT NULL,\n\t\t\t\t\t`options` TEXT DEFAULT NULL,\n\t\t\t\t\t`created_at` DATETIME DEFAULT NULL,\n\t\t\t\t\t`updated_at` DATETIME DEFAULT NULL,\n\t\t\t\t\tPRIMARY KEY (`id`)\n\t\t\t\t)";
         $sql .= $charset_collate . ";";
         // new line to avoid PHP Storm syntax error
         dbDelta($sql);
     }
     /** SQUIRRELS_INVENTORY table */
     $table = $wpdb->prefix . Auto::TABLE_NAME;
     if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) {
         $sql = "\n\t\t\t\tCREATE TABLE `" . $table . "`\n\t\t\t\t(\n\t\t\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`inventory_number` VARCHAR(50) DEFAULT NULL,\n\t\t\t\t\t`vin` VARCHAR(50) DEFAULT NULL,\n\t\t\t\t\t`type_id` INT(11) DEFAULT NULL,\n\t\t\t\t\t`make_id` INT(11) DEFAULT NULL,\n\t\t\t\t\t`model_id` INT(11) DEFAULT NULL,\n\t\t\t\t\t`year` INT(2) DEFAULT NULL,\n\t\t\t\t\t`odometer_reading` INT(11) DEFAULT NULL,\n\t\t\t\t\t`features` TEXT,\n\t\t\t\t\t`is_visible` TINYINT(4) DEFAULT 0,\n\t\t\t\t\t`is_featured` TINYINT(4) DEFAULT 0,\n\t\t\t\t\t`description` TEXT,\n\t\t\t\t\t`price` DECIMAL(11,4) DEFAULT NULL,\n\t\t\t\t\t`exterior` VARCHAR(50) DEFAULT NULL,\n\t\t\t\t\t`interior` VARCHAR(50) DEFAULT NULL,\n\t\t\t\t\t`created_at` DATETIME DEFAULT NULL,\n\t\t\t\t\t`imported_at` DATETIME DEFAULT NULL,\n\t\t\t\t\t`updated_at` DATETIME DEFAULT NULL,\n\t\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\t\tKEY `type_id` (`type_id`),\n\t\t\t\t\tKEY `make_id` (`make_id`),\n\t\t\t\t\tKEY `model_id` (`model_id`)\n\t\t\t\t)";
         $sql .= $charset_collate . ";";
         // new line to avoid PHP Storm syntax error
         dbDelta($sql);
     }
     /** SQUIRRELS_IMAGES table */
     $table = $wpdb->prefix . "squirrels_images";
     if ($wpdb->get_var("SHOW TABLES LIKE '" . $table . "'") != $table) {
         $sql = "\n\t\t\t\tCREATE TABLE `" . $table . "`\n\t\t\t\t(\n\t\t\t\t\t`id` INT(11) NOT NULL AUTO_INCREMENT,\n\t\t\t\t\t`inventory_id` INT(11) DEFAULT NULL,\n\t\t\t\t\t`media_id` INT(11) DEFAULT NULL,\n\t\t\t\t\t`url` VARCHAR(250) DEFAULT NULL,\n\t\t\t\t\t`is_default` TINYINT(4) DEFAULT 0,\n\t\t\t\t\t`created_at` DATETIME DEFAULT NULL,\n\t\t\t\t\t`updated_at` DATETIME DEFAULT NULL,\n\t\t\t\t\tPRIMARY KEY (`id`),\n\t\t\t\t\tKEY `inventory_id` (`inventory_id`)\n\t\t\t\t)";
         $sql .= $charset_collate . ";";
         // new line to avoid PHP Storm syntax error
         dbDelta($sql);
     }
     $make_id = 0;
     $model_id = 0;
     $type_id = 0;
     /** Pre-load makes and models */
     $makes = $this->getMakesModels();
     foreach ($makes as $make_data) {
         $make = new Make();
         $make->setTitle($make_data['title'])->create();
         foreach ($make_data['models'] as $model_data) {
             $model = new Model();
             $model->setTitle($model_data['title'])->setMakeId($make->getId())->create();
             if ($make->getTitle() == 'Ford' && $model->getTitle() == 'Mustang') {
                 $make_id = $make->getId();
                 $model_id = $model->getId();
             }
         }
     }
     /** Pre-load Auto Types */
     $auto_types = array('Car', 'Truck', 'SUV', 'Motorcycle', 'RV', 'Boat');
     foreach ($auto_types as $title) {
         $auto_type = new AutoType();
         $auto_type->setTitle($title)->create();
         if ($title == 'Car') {
             $type_id = $auto_type->getId();
         }
     }
     /** Add a couple sample Features */
     if (Feature::getFeatureByTitle('Transmission') === FALSE) {
         $feature = new Feature();
         $feature->setTitle('Transmission')->setIsTrueFalse(FALSE)->addOption(new FeatureOption('Automatic', 1, TRUE))->addOption(new FeatureOption('Manual', 2, FALSE))->create();
         $feature = new Feature();
         $feature->setTitle('AWD')->setIsTrueFalse(TRUE)->create();
     }
     /** Add a sample Car */
     if ($make_id > 0 && $model_id > 0 && $type_id > 0) {
         $auto = new Auto();
         $auto->setTypeId($type_id)->setInventoryNumber('123456')->setVin('QWERTY')->setMakeId($make_id)->setModelId($model_id)->setYear('1965')->setOdometerReading(50000)->setPrice(100000)->setDescription('This is a sample car.')->setExterior('Red')->setInterior('Black')->setIsVisible(TRUE)->create();
     }
 }