Example #1
0
 /**
  * Fetch an image object by matching the URL.
  * @param  string $p_url
  * @return Image
  */
 public static function GetByUrl($p_url)
 {
     global $g_ado_db;
     $queryStr = "SELECT * FROM Images WHERE URL=" . $g_ado_db->escape($p_url);
     $row = $g_ado_db->GetRow($queryStr);
     $image = new Image();
     $image->fetch($row);
     return $image;
 }
Example #2
0
	/**
	 * Fetch an image object by matching the URL.
	 * @param string $p_url
	 * @return Image
	 */
	public static function GetByUrl($p_url)
	{
		global $g_ado_db;
		$queryStr = "SELECT * FROM Images WHERE URL='".mysql_real_escape_string($p_url)."'";
		$row = $g_ado_db->GetRow($queryStr);
		$image = new Image();
		$image->fetch($row);
		return $image;
	} // fn GetByUrl
Example #3
0
 /**
  * Execute the search and return the results.
  *
  * @return array
  *      An array of Image objects.
  */
 public function run()
 {
     global $g_ado_db;
     $tmpImage = new Image();
     $columnNames = $tmpImage->getColumnNames(true);
     $columnNames = implode(',', $columnNames);
     $this->m_whereQuery = count($this->m_whereGroups) ? ' WHERE ' . implode($this->m_whereGroups, ' AND ') : null;
     $queryStr = 'SELECT ' . $columnNames . ', COUNT(ArticleImages.IdImage) AS inUse' . ' FROM Images ' . ' LEFT JOIN ArticleImages On Images.Id=ArticleImages.IdImage' . ' ' . $this->m_whereQuery . ' GROUP BY Images.Id' . " {$this->m_orderQuery} LIMIT {$this->m_imageOffset}, " . $this->m_itemsPerPage;
     $numImagesFoundQueryStr = 'SELECT COUNT(DISTINCT(Images.Id))' . ' FROM Images ' . ' LEFT JOIN ArticleImages On Images.Id=ArticleImages.IdImage' . " {$this->m_whereQuery}";
     $rows = $g_ado_db->GetAll($queryStr);
     $this->m_numImagesFound = $g_ado_db->GetOne($numImagesFoundQueryStr);
     $this->m_imageData = array();
     if (is_array($rows)) {
         // Get "In Use" information
         $imageIds = array();
         foreach ($rows as $row) {
             $imageIds[$row['Id']] = '(IdImage=' . $row['Id'] . ')';
         }
         if (count($imageIds) > 0) {
             $imagesIdsQuery = " AND (" . implode(' OR ', $imageIds) . ")";
         } else {
             $imagesIdsQuery = "";
         }
         $inUseQuery = "SELECT ArticleImages.IdImage, COUNT(Articles.Number) as in_use " . " FROM Articles, ArticleImages " . " WHERE (Articles.Number=ArticleImages.NrArticle) " . $imagesIdsQuery . " GROUP By ArticleImages.IdImage";
         $tmpInUseArray = $g_ado_db->GetAll($inUseQuery);
         $inUseArray = array();
         // Make it an associative array for easy lookup in the next loop.
         if (is_array($tmpInUseArray)) {
             foreach ($tmpInUseArray as $inUseItem) {
                 $inUseArray[$inUseItem['IdImage']] = $inUseItem['in_use'];
             }
         }
         // Create image templates
         foreach ($rows as $row) {
             $tmpImage = new Image();
             $tmpImage->fetch($row);
             $template = $tmpImage->toTemplate();
             $template['in_use'] = 0;
             if (isset($inUseArray[$row['Id']])) {
                 $template['in_use'] = $inUseArray[$row['Id']];
             }
             $imageSize = @getimagesize($tmpImage->getImageStorageLocation()) ?: array(0, 0);
             $template['width'] = $imageSize[0];
             $template['height'] = $imageSize[1];
             $this->m_imageData[] = $template;
         }
     }
     return $this->m_imageData;
 }