Example #1
0
 public function importCategories($categories)
 {
     Ak::import('category');
     $CategoryInstance = new Category(array('init' => false));
     if ($this->db) {
         $CategoryInstance->setConnection($this->db);
     }
     $CategoryInstance->init();
     foreach ($categories as $category_name => $related) {
         if (!($Category = $CategoryInstance->findFirstBy('name', $category_name))) {
             $Category = new Category(array('init' => false));
             if ($this->db) {
                 $Category->setConnection($this->db);
             }
             $Category->init();
             $Category->setAttributes(array('name' => $category_name));
             if ($Category->save()) {
                 $this->log('Created new category: ' . $category_name);
             }
         }
         if (!empty($related['relations'])) {
             foreach ($related['relations'] as $related_category) {
                 if (!($RelatedCategory = $CategoryInstance->findFirstBy('name', $related_category))) {
                     $RelatedCategory = new Category(array('init' => false));
                     if ($this->db) {
                         $Category->setConnection($this->db);
                     }
                     $Category->init();
                     $Category->setAttributes(array('name' => $related_category));
                     $RelatedCategory->save();
                 }
                 $this->log('Relating category ' . $related_category . ' with ' . $category_name);
                 $Category->related_category->add($RelatedCategory);
             }
         }
     }
 }
try {
    $row = explode('||', $line);
    if (count($row) == 5) {
        /* the data has valid number of elements, filter for any abnormalities in the data*/
        $name = $row[0];
        $name = str_replace("'", "''", $name);
        $address = $row[1];
        $contacts = relinquishContacts($row[2]);
        $phone = $contacts[0];
        $email = $contacts[1];
        $website = $contacts[2];
        $categoryLabel = $row[3];
        $position = $row[4];
        //create the category for the poi
        $category = new Category();
        $category->init($parentController->getParentCategory($categoryLabel), $categoryLabel, $user);
        if ($id = $categoryController->add($category)) {
            $category->setId($id);
            //create the poi object
            $poi = new POI();
            $poi->init($name, $address, $position, $category, $phone, $email, $website, "", $user);
            if ($poiController->add($poi)) {
                $insertCount++;
            } else {
                $skippedData[] = $line . "\n";
            }
        } else {
            $skippedData[] = $line . "\n";
        }
    } else {
        /* skip this data as it contains invalid number of data*/
Example #3
0
<?php

namespace ATPGallery\Model;

require_once "Image.php";
class Category extends \ATP\ActiveRecord
{
    public function displayName()
    {
        return $this->name;
    }
}
Category::init();