ALEX-TRASK
12/15/2016 - 7:39 AM

Сategories.php

<?php

class Application_Model_DbTable_Categories extends Zend_Db_Table_Abstract
{

    protected $_name = 'categories';
    protected $_primary = array('id');
    protected $_dependentTables = array('Application_Model_DbTable_Products');

    /**
     * Метод заповнення таблиці
     *
     * @param $data - масив даних в форматі JSON
     */
    public function addCategoriesFromData($data)
    {
        $categoriesRawsData = json_decode($data, true);

        foreach($categoriesRawsData as $key => $value) {
            $categoryRow = $this->createRow($value);
            $categoryRow->save();
        }
    }

    /**
     * Метод видалення всіх даних з таблиці
     */
    public function deleteAllCategories()
    {
        $сategoriesRowset =  $this->fetchAll();

        foreach($сategoriesRowset as $row) {
            $row->delete();
        }
    }
}