示例#1
0
 static function searchCategories($query, $limit = 10)
 {
     //        $query = mysql_real_escape_string($query);
     $categoryObjects = CategoryModel::all(array('conditions' => 'categories_lang.name LIKE \'%' . $query . '%\'', "limit" => $limit, 'order' => '`order` ASC, `id` ASC', 'joins' => array('categories_lang'), 'group' => 'id'));
     $categories = array();
     foreach ($categoryObjects as $c) {
         $cat = Activerecord::returnArrayWithLang($c);
         $categories[] = $cat;
     }
     return $categories;
 }
示例#2
0
 /**
  * will query the db and get all the categories, if the categoryName is not
  * in the categories table, it will insert it,
  * otherwise it will return the category id
  */
 public static function getCategoryId($categoryName)
 {
     $categories = CategoryModel::all();
     // find the category id
     foreach ($categories as $cat) {
         if ($categoryName == $cat['category_name']) {
             return $cat['id'];
         }
     }
     // category wasn't found, so we need to insert one
     $query = 'INSERT INTO categories (category_name) VALUES (:category_name)';
     $stmt = static::$dbc->prepare($query);
     $stmt->bindValue(":category_name", $categoryName, PDO::PARAM_STR);
     $stmt->execute();
     return self::getCategoryId($categoryName);
 }
示例#3
0
function pageController()
{
    $errors['count'] = 0;
    $arrayCategoriesArray = CategoryModel::all();
    foreach ($arrayCategoriesArray as $categoriesArray) {
        $categorySelectionList[] = $categoriesArray['category_name'];
    }
    $imageSuccessMessage = "";
    //if an image was submitted - validate it even before validating the rest of the form
    if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['name'] != '') {
        try {
            $postImage = Input::getImage('fileToUpload');
            //image was successfully uploaded
            $imageSuccessMessage = "Image: " . basename($_FILES['fileToUpload']['name']) . " has been uploaded!";
            //store image in the session
            $_SESSION['image'] = $postImage;
        } catch (Exception $e) {
            $errors['image'] = 'Image: ' . $e->getMessage();
            $errors['count']++;
        }
    }
    //clicked on the upload image button without selecting a photo
    if (isset($_FILES['fileToUpload']) && $_FILES['fileToUpload']['name'] == '') {
        $errors['image'] = "Image:  Select an image to upload!";
        $errors['count']++;
    }
    //if the session['image'] is empty; then, no image was submitted
    if (!isset($_SESSION['image'])) {
        //no image was submitted - use placeholder image
        $postImage = "http://placehold.it/350x300";
    } else {
        //an image has been submitted; use the image stored in the $_SESSION
        $postImage = $_SESSION['image'];
    }
    //if there weren't any errors with the image; then, process then rest of the form
    if ($errors['count'] == 0) {
        $errors = processForm($postImage);
    }
    return array('categorySelectionList' => $categorySelectionList, 'errorMessages' => $errors, 'imageSuccessMessage' => $imageSuccessMessage);
}
示例#4
0
 function fixCategoryOrderRecursive($parent_id = null)
 {
     $parent_condition = $parent_id != null ? '`parent_id` = ' . $parent_id : '`parent_id` IS NULL';
     $categories = CategoryModel::all(array('conditions' => $parent_condition, 'order' => '`order` ASC'));
     $order = 0;
     if ($categories != null) {
         foreach ($categories as $c) {
             $c->order = $order;
             $c->save();
             $order++;
             $this->fixCategoryOrderRecursive($c->id);
         }
     }
 }